]> xenbits.xensource.com Git - xenclient/ioemu.git/commitdiff
Add touchpad support for dom0_driver
authorJean Guyader <jean.guyader@eu.citrix.com>
Wed, 19 Nov 2008 12:23:34 +0000 (12:23 +0000)
committerJean Guyader <jean.guyader@eu.citrix.com>
Wed, 19 Nov 2008 12:23:34 +0000 (12:23 +0000)
  Improve the switching in intel driver

console.h
dom0_driver.c
intel.c
vl.c

index b63f9421a5428dbde8d2042fc398460ee7a665c8..67ce1d9a2944d8920b890a8545877bb30c11f034 100644 (file)
--- a/console.h
+++ b/console.h
@@ -169,4 +169,8 @@ void readline_start(const char *prompt, int is_password,
 /* dom0_driver.c */
 void dom0_driver_init(const char *position);
 
+/* intel.c */
+void intel_display_init(DisplayState *ds, const char *arg);
+void intel_focus(int focus);
+
 #endif
index 220d7571377e60212fdc86c733a26e037a04b07c..07b35c072f23f5087a206c2672fe1012e16677f3 100644 (file)
@@ -62,30 +62,13 @@ void xenstore_watch_dom0_driver(const char *, const char *);
 
 #define ABS(x)          ((x) > 0 ? (x) : -(x))
 
-int                     dom0_driver_focus = 0;
-
 static void             dom0_read(void *opaque);
 static void             dom0_driver_reset_keyboard(void);
 
-enum dom0Direction
-{
-    DOM0_LEFT,
-    DOM0_TOP,
-    DOM0_CENTER,
-    DOM0_BOTTOM,
-    DOM0_RIGHT,
-    DOM0_OUT
-};
-
-static const char *str2pos[] =
-{
-    "left", "top", "center", "bottom", "right"
-};
-
-struct dom0Driver
+struct dom0_driver
 {
-    int keyboard_fd;
-    int mouse_fd;
+    int keyboard_fds[4];
+    int mouse_fds[4];
     int mouse_button_state;
     QEMUTimer *xs_timer;
     uint8_t scroll_lock_count;
@@ -101,16 +84,15 @@ struct dom0_driver_xs_info
   int new_slot;
 };
 
-static struct dom0Driver driver;
+static struct dom0_driver driver;
 
 static int dom0_driver_xs_read_dom0(const char *key)
 {
     char        *str = NULL;
-    int         blank;
 
     if (!(str = xenstore_read_dom0_driver(key)))
     {
-        fprintf(stderr, "dom0_driver: fatal the node blank don't exits\n");
+        fprintf(stderr, "dom0_driver: fatal the node %s don't exits\n", key);
         exit(2);
     }
     return strtol(str, NULL, 10);
@@ -297,38 +279,6 @@ static void dom0_get_positions(int *positions)
     free(domids);
 }
 
-static int dom0_get_next_domid(int dir, int id)
-{
-    int pos = 0, next_pos = -1;
-    int positions[NB_SLOTS];
-
-    dom0_get_positions(positions);
-    /* Find current domain pos */
-    for (pos = 0; pos < DOM0_OUT; pos++)
-       if (positions[pos] && positions[pos]  == id)
-           break;
-    assert(pos != DOM0_OUT);
-
-    if (pos == DOM0_LEFT && dir == DOM0_RIGHT)
-        next_pos = DOM0_CENTER;
-    else if (pos == DOM0_RIGHT && dir == DOM0_LEFT)
-        next_pos = DOM0_CENTER;
-    else if (pos == DOM0_TOP && dir == DOM0_BOTTOM)
-        next_pos = DOM0_CENTER;
-    else if (pos == DOM0_BOTTOM && dir == DOM0_TOP)
-        next_pos = DOM0_CENTER;
-    else if (pos == DOM0_CENTER && dir != DOM0_CENTER)
-        next_pos = dir;
-
-    if (next_pos == -1)
-        next_pos = pos;
-
-    if (!positions[next_pos])
-        return domid;
-    else
-        return positions[next_pos];
-}
-
 static void dom0_read(void *opaque)
 {
     struct input_event  event[5];
@@ -417,22 +367,25 @@ static void dom0_gr_devices(int grab, int controller)
     int         *fd = NULL;
 
     if (controller == DOM0_MOUSE)
-        fd = &driver.mouse_fd;
+        fd = driver.mouse_fds;
     if (controller == DOM0_KEYBOARD)
-        fd = &driver.keyboard_fd;
+        fd = driver.keyboard_fds;
     assert(fd != NULL);
 
-    if (ioctl(*fd, EVIOCGRAB, grab) == -1)
+    for (; *fd != -1; fd++)
     {
-        DEBUG("Try to %s on %d\n", 1 ? "grab" : "release", *fd);
-        return;
-    }
-    DEBUG("%s succed %d\n", grab ? "grab" : "release", *fd);
+        if (ioctl(*fd, EVIOCGRAB, grab) == -1)
+        {
+            DEBUG("Try to %s on %d\n", 1 ? "grab" : "release", *fd);
+            return;
+        }
+        DEBUG("%s succed %d\n", grab ? "grab" : "release", *fd);
 
-    if (grab)
-        qemu_set_fd_handler(*fd, dom0_read, NULL, fd);
-    else
-        qemu_set_fd_handler(*fd, NULL, NULL, fd);
+        if (grab)
+            qemu_set_fd_handler(*fd, dom0_read, NULL, fd);
+        else
+            qemu_set_fd_handler(*fd, NULL, NULL, fd);
+    }
 
     if (controller == DOM0_MOUSE)
     {
@@ -444,7 +397,7 @@ static void dom0_gr_devices(int grab, int controller)
 
             dom0_driver_read_xs_info(&info, DOM0_MOUSE);
             if (dom0_driver_xs_read_dom0("natif") != info.domid)
-                dom0_driver_focus = grab;
+                intel_focus(!grab);
         }
     }
 
@@ -469,7 +422,6 @@ static int dom0_dom_alive(int id)
 }
 
 
-
 static int dom0_driver_failover_switch(void *opaque)
 {
     struct dom0_driver_xs_info  info;
@@ -501,19 +453,51 @@ out:
 }
 
 
+static void dom0_driver_dev_init(void)
+{
+    int         i = 0;
+    int         fd = 0;
+    int         keyboard = 0, mouse = 0;
+    char        path[strlen(EVENT_PATH) + 3];
+    char        name[128];
+
+    driver.keyboard_fds[0] = -1;
+    driver.mouse_fds[0] = -1;
+    while (1)
+    {
+        sprintf(path, "%s%i", EVENT_PATH, i++);
+        if (!(fd = open(path, O_RDONLY)))
+            break;
+        if (ioctl(fd, EVIOCGNAME(128), name) == -1)
+            break;
+
+        if (strcasestr(name, "keyboard"))
+        {
+            driver.keyboard_fds[keyboard] = fd;
+            driver.keyboard_fds[keyboard + 1] = -1;
+            keyboard++;
+            DEBUG("Use \"%s\" as a keyboard %d\n", name, fd);
+        }
+        else
+        {
+            driver.mouse_fds[mouse] = fd;
+            driver.mouse_fds[mouse + 1] = -1;
+            mouse++;
+            DEBUG("Use \"%s\" as a mouse %d\n", name, fd);
+        }
+    }
+    assert(driver.keyboard_fds[0] != -1);
+    assert(driver.mouse_fds[0] != -1);
+}
+
 static void dom0_driver_event_init(const char *str_arg)
 {
-    char                dev_name[strlen(EVENT_PATH) + 3];
     int                 positions[NB_SLOTS];
     char                str[10];
-    int                 fd = -1;
     int                 pos = 0;
     int                 i = 0;
-    struct input_id     input;
-    char                name[128];
 
-    driver.keyboard_fd = open("/dev/input/event0", O_RDONLY);
-    driver.mouse_fd = open("/dev/input/event2", O_RDONLY);
+    dom0_driver_dev_init();
 
     pos = strtol(str_arg, NULL, 10);
     dom0_get_positions(positions);
@@ -556,15 +540,6 @@ static void dom0_driver_slots(int controller)
         dom0_get_positions(positions);
         if (positions[info.new_slot] != 0)
         {
-            /*
-            if (info.domid == domid &&
-                positions[info.new_slot] == domid)
-            {
-                DEBUG("already on this slot\n");
-                return;
-            }
-            */
-
             if (info.state == 0 && info.domid == domid)
             {
                 DEBUG("release devices\n");
@@ -592,8 +567,8 @@ static void dom0_driver_blank_done(void)
 
     if (info.state == 1 && blank == 2)
     {
-        dom0_driver_focus = info.domid == domid;
-        xenstore_write_dom0_driver("blank", 3);
+        sleep(1);
+        intel_focus(info.domid == domid);
     }
 }
 
diff --git a/intel.c b/intel.c
index f3adb1a6eb929ae39a56bf780c573626c7c3b670..c673cc039fdb1ae87cf45f292216fc071a25076a 100644 (file)
--- a/intel.c
+++ b/intel.c
@@ -31,8 +31,10 @@ static int                      fd_mem_rw = -1;
 static unsigned char            *intel_mem = NULL;
 static unsigned char            *intel_mmio = NULL;
 static int                      intel_force_full_update = 0;
-
-extern int dom0_driver_focus;
+static int                      intel_have_focus;
+static int                      solid_line[8];
+static int                      dashed_line[8];
+static DisplayState             *lds = NULL;
 
 static inline unsigned int intel_get_reg(unsigned int reg)
 {
@@ -51,8 +53,6 @@ static inline unsigned int intel_get_offset(DisplayState *ds, int x, int y)
 
 static inline void intel_blit_tile(DisplayState *ds, int x, int y)
 {
-    static const int    solid_line[] = {0,1,2,3,4,5,6,7};
-    static const int    dashed_line[] = {};
     unsigned int        toffset, offset, to, o;
     unsigned char       *buff;
     int                 i, j;
@@ -62,7 +62,7 @@ static inline void intel_blit_tile(DisplayState *ds, int x, int y)
     /* Copy the solid lines */
     toffset = intel_get_tiled_offset(x, y);
     offset = intel_get_offset(ds, x * TileW, y * TileH);
-    for (i = 0; i < sizeof (solid_line) / sizeof (int); i++)
+    for (i = 0; solid_line[i] != -1; i++)
     {
         to = toffset + solid_line[i] * TileW * 4;
         o = offset + solid_line[i] * ds->width * 4;
@@ -71,7 +71,7 @@ static inline void intel_blit_tile(DisplayState *ds, int x, int y)
 
     toffset = to = intel_get_tiled_offset(x, y);
     offset = o = intel_get_offset(ds, x * TileW, y * TileH);
-    for (i = 0; i <  sizeof (dashed_line) / sizeof (int); i++)
+    for (i = 0; dashed_line[i] != -1; i++)
     {
         to = toffset + dashed_line[i] * TileW * 4;
         o = offset + dashed_line[i] * ds->width * 4 + 16 * 4;
@@ -106,14 +106,8 @@ static void intel_update_tiled(DisplayState *ds, int x, int y, int w, int h)
 
 static void intel_update(DisplayState *ds, int x, int y, int w, int h)
 {
-    if (!dom0_driver_focus)
-        return;
-
-    if (intel_force_full_update)
-        intel_update_tiled(ds, 0, 0, 1280, 800);
-
-    intel_update_tiled(ds, x, y, w, h);
-    intel_force_full_update = 0;
+    if (intel_have_focus)
+        intel_update_tiled(ds, x, y, w, h);
 }
 
 static void intel_resize(DisplayState *ds, int w, int h)
@@ -126,12 +120,6 @@ static void intel_resize(DisplayState *ds, int w, int h)
 
 static void intel_refresh(DisplayState *ds)
 {
-    if (!dom0_driver_focus)
-    {
-        intel_force_full_update = 1;
-        return;
-    }
-
     vga_hw_update();
 }
 
@@ -182,8 +170,41 @@ static void intel_init_mapping(void)
     }
 }
 
-void intel_display_init(DisplayState *ds)
+void intel_focus(int focus)
+{
+    if (focus)
+        intel_update_tiled(lds, 0, 0, lds->width, lds->height);
+    intel_have_focus = focus;
+}
+
+static void intel_parse_arg(const char *arg)
+{
+    int         *tab = NULL;
+    char        *next = NULL;
+    
+    tab = solid_line;
+    while (arg && *arg)
+    {
+        tab[0] = strtol(arg, next, 10);
+        tab[1] = -1;
+        INTEL_DEBUG("solid/dashed line %d\n", *tab);
+        if (!next || !*next)
+            return;
+        if (*next == ',')
+            tab++;
+        else if (*next == '|')
+            tab = dashed_line;
+        else
+        {
+            INTEL_DEBUG("unknow separator %c for intel arguement\n", *next);
+            exit (2);
+        }
+    }
+}
+
+void intel_display_init(DisplayState *ds, const char *arg)
 {
+    intel_parse_arg(arg);
     intel_init_mapping();
 
     INTEL_DEBUG("Frambuffer is at 0x%x\n", intel_get_reg(REG_DR_DSPASURF));
@@ -194,6 +215,7 @@ void intel_display_init(DisplayState *ds)
     ds->height = 400;
     ds->linesize = 640 * 4;
     ds->depth = 32;
+    lds = ds;
 
     ds->dpy_update = intel_update;
     ds->dpy_resize = intel_resize;
diff --git a/vl.c b/vl.c
index 0a4cecb15182b7a850001ae939eff5bd1b92b064..b14b03b946e2bf44258febee0b0e6fb4e657c780 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -211,7 +211,7 @@ int opengl_enabled = 0;
 #endif
 const char *dom0_input = NULL;
 int vga_passthrough = 0;
-int intel_output = 0;
+char *intel_output = NULL;
 static const char *direct_pci;
 static int nb_pci_emulation = 0;
 static char pci_emulation_config_text[MAX_PCI_EMULATION][256];
@@ -8369,7 +8369,7 @@ int main(int argc, char **argv)
                 }
                 break;
             case QEMU_OPTION_intel:
-                intel_output = 1;
+                intel_output = strdup(optarg);
                 break;
             case QEMU_OPTION_g:
                 {
@@ -8840,7 +8840,8 @@ int main(int argc, char **argv)
     }
     else if (intel_output)
     {
-        intel_display_init(ds);
+        intel_display_init(ds, intel_output);
+        free(intel_output);
         xenstore_write_vncport(-1);
     }
     else if (vnc_display != NULL || vncunused != 0) {