[mutter/wip/barriers: 9/16] devices-xi2: Enable touch events



commit 7971d5a871021ff84a3bd5e2612bf689dfe434a2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Aug 2 19:21:36 2011 +0200

    devices-xi2: Enable touch events

 src/core/core.c            |    4 +++-
 src/core/devices-xi2.c     |    8 ++++++++
 src/core/display-private.h |    4 ++++
 src/core/display.c         |   30 ++++++++++++++++++++++++++++++
 src/core/input-events.h    |    5 +++++
 src/core/window.c          |    9 +++++++++
 6 files changed, 59 insertions(+), 1 deletions(-)
---
diff --git a/src/core/core.c b/src/core/core.c
index a64d251..4a6502e 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -27,6 +27,7 @@
 #include "core.h"
 #include "frame.h"
 #include "workspace-private.h"
+#include "input-events.h"
 #include <meta/prefs.h>
 #include <meta/errors.h>
 
@@ -866,7 +867,8 @@ meta_core_select_events (Display  *xdisplay,
       XISelectEvents (xdisplay, xwindow, &mask, 1);
 
       /* Unset any input event so they are only handled via XInput2 */
-      evmask &= ~(KeyPressMask | KeyReleaseMask |
+      evmask &= ~(META_INPUT_TOUCH_EVENTS_MASK |
+                  KeyPressMask | KeyReleaseMask |
                   ButtonPressMask | ButtonReleaseMask |
                   EnterWindowMask | LeaveWindowMask |
                   PointerMotionMask | PointerMotionHintMask |
diff --git a/src/core/devices-xi2.c b/src/core/devices-xi2.c
index cd6fb1b..53fb9dc 100644
--- a/src/core/devices-xi2.c
+++ b/src/core/devices-xi2.c
@@ -25,6 +25,7 @@
 #include "devices-xi2.h"
 #include "display-private.h"
 #include "screen-private.h"
+#include "input-events.h"
 #include <X11/extensions/XInput2.h>
 
 /* Common functions */
@@ -97,6 +98,13 @@ meta_device_xi2_translate_event_mask (guint  evmask,
       XISetMask (mask, XI_FocusOut);
     }
 
+  if (evmask & META_INPUT_TOUCH_EVENTS_MASK)
+    {
+      XISetMask (mask, XI_TouchBegin);
+      XISetMask (mask, XI_TouchEnd);
+      XISetMask (mask, XI_TouchUpdate);
+    }
+
   return mask;
 }
 
diff --git a/src/core/display-private.h b/src/core/display-private.h
index 27cf657..cd49cfe 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -425,6 +425,10 @@ void     meta_display_grab_window_buttons    (MetaDisplay *display,
                                               Window       xwindow);
 void     meta_display_ungrab_window_buttons  (MetaDisplay *display,
                                               Window       xwindow);
+void     meta_display_grab_window_touches    (MetaDisplay *display,
+                                              MetaWindow  *window);
+void     meta_display_ungrab_window_touches  (MetaDisplay *display,
+                                              MetaWindow  *window);
 
 void meta_display_grab_focus_window_button   (MetaDisplay *display,
                                               MetaWindow  *window);
diff --git a/src/core/display.c b/src/core/display.c
index 4d10beb..9ebccaf 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -4372,6 +4372,36 @@ meta_display_ungrab_window_buttons  (MetaDisplay *display,
     }
 }
 
+void
+meta_display_grab_window_touches (MetaDisplay *display,
+                                  MetaWindow  *window)
+{
+  if (!window->frame)
+    return;
+
+  meta_error_trap_push_with_return (display);
+  meta_device_map_grab_touch (display->device_map,
+                              window->frame->xwindow);
+
+  if (meta_error_trap_pop_with_return (display) != Success)
+    {
+      meta_verbose ("Unable to add a passive touch grab on window '%s'\n",
+                    window->desc);
+      return;
+    }
+}
+
+void
+meta_display_ungrab_window_touches (MetaDisplay *display,
+                                    MetaWindow  *window)
+{
+  if (!window->frame)
+    return;
+
+  meta_device_map_ungrab_touch (display->device_map,
+                                window->frame->xwindow);
+}
+
 /* Grab buttons we only grab while unfocused in click-to-focus mode */
 #define MAX_FOCUS_BUTTON 4
 void
diff --git a/src/core/input-events.h b/src/core/input-events.h
index a53d1e3..99e3224 100644
--- a/src/core/input-events.h
+++ b/src/core/input-events.h
@@ -35,6 +35,11 @@
 #include "display-private.h"
 #include <meta/device-map.h>
 
+/* Add an extra flag for touch events in
+ * evmasks, an arbitrarily high bit is taken.
+ */
+#define META_INPUT_TOUCH_EVENTS_MASK (1L<<31)
+
 gboolean meta_input_event_get_type          (MetaDisplay *display,
                                              XEvent      *ev,
                                              guint       *ev_type);
diff --git a/src/core/window.c b/src/core/window.c
index faaf8e0..850e1c2 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -1297,6 +1297,14 @@ meta_window_new_with_attrs (MetaDisplay       *display,
       meta_display_grab_focus_window_button (window->display, window);
     }
 
+  if (window->frame &&
+      (window->type == META_WINDOW_NORMAL ||
+       window->type == META_WINDOW_DIALOG ||
+       window->type == META_WINDOW_MODAL_DIALOG))
+    {
+      meta_display_grab_window_touches (window->display, window);
+    }
+
   if (window->type == META_WINDOW_DESKTOP ||
       window->type == META_WINDOW_DOCK)
     {
@@ -1905,6 +1913,7 @@ meta_window_unmanage (MetaWindow  *window,
   meta_window_ungrab_keys (window);
   meta_display_ungrab_window_buttons (window->display, window->xwindow);
   meta_display_ungrab_focus_window_button (window->display, window);
+  meta_display_ungrab_window_touches (window->display, window);
 
   meta_display_unregister_x_window (window->display, window->xwindow);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]