[Xfce4-commits] [xfce/xfwm4] 32/32: Replace XEvent with XfwmEvent + add xfwm_device_* grabs usage

noreply at xfce.org noreply at xfce.org
Tue Dec 5 09:22:18 CET 2017


This is an automated email from the git hooks/post-receive script.

o   l   i   v   i   e   r       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfwm4.

commit ef33ff7b2666ffc320700592fc7d4a300d5a8163
Author: Viktor Odintsev <ninetls at xfce.org>
Date:   Mon Nov 27 16:42:18 2017 +0300

    Replace XEvent with XfwmEvent + add xfwm_device_* grabs usage
---
 src/client.c       | 101 +++++++-----
 src/client.h       |   2 +-
 src/compositor.c   |  12 +-
 src/compositor.h   |   4 +-
 src/cycle.c        | 222 +++++++++++++-------------
 src/cycle.h        |   2 +-
 src/display.c      |  82 ++++++----
 src/display.h      |   2 +-
 src/event_filter.c | 208 +++++++++++++-----------
 src/event_filter.h |   2 +-
 src/events.c       | 458 ++++++++++++++++++++++++++++-------------------------
 src/events.h       |   2 +-
 src/focus.c        |   9 +-
 src/hints.c        |   5 +-
 src/keyboard.c     | 182 +++++++++++----------
 src/keyboard.h     |  24 +--
 src/menu.c         |  18 +--
 src/misc.c         |   8 +-
 src/misc.h         |   6 +-
 src/moveresize.c   | 186 +++++++++++-----------
 src/moveresize.h   |   4 +-
 src/netwm.c        |  43 ++---
 src/screen.c       |  69 +++++---
 src/screen.h       |  10 +-
 24 files changed, 891 insertions(+), 770 deletions(-)

diff --git a/src/client.c b/src/client.c
index 735dcf5..0fb5627 100644
--- a/src/client.c
+++ b/src/client.c
@@ -332,7 +332,8 @@ clientGrabButtons (Client *c)
     screen_info = c->screen_info;
     if (screen_info->params->easy_click)
     {
-        grabButton(clientGetXDisplay (c), AnyButton, screen_info->params->easy_click, c->window);
+        grabButton (c->screen_info->display_info->devices, clientGetXDisplay (c),
+                    AnyButton, screen_info->params->easy_click, c->window);
     }
 }
 
@@ -343,7 +344,8 @@ clientUngrabButtons (Client *c)
     TRACE ("entering clientUngrabButtons");
     TRACE ("grabbing buttons for client \"%s\" (0x%lx)", c->name, c->window);
 
-    XUngrabButton (clientGetXDisplay (c), AnyButton, AnyModifier, c->window);
+    xfwm_device_ungrab_button (c->screen_info->display_info->devices, clientGetXDisplay (c),
+                               AnyButton, AnyModifier, c->window);
 }
 
 static gboolean
@@ -3761,7 +3763,7 @@ clientUpdateAllCursor (ScreenInfo *screen_info)
 }
 
 static eventFilterStatus
-clientButtonPressEventFilter (XEvent * xevent, gpointer data)
+clientButtonPressEventFilter (XfwmEvent *event, gpointer data)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
@@ -3779,42 +3781,56 @@ clientButtonPressEventFilter (XEvent * xevent, gpointer data)
     display_info = screen_info->display_info;
 
     /* Update the display time */
-    myDisplayUpdateCurrentTime (display_info, xevent);
+    myDisplayUpdateCurrentTime (display_info, event);
 
-    status = EVENT_FILTER_STOP;
+    status = EVENT_FILTER_CONTINUE;
     pressed = TRUE;
 
-    switch (xevent->type)
+    switch (event->meta.type)
     {
-        case EnterNotify:
-            if ((xevent->xcrossing.mode != NotifyGrab) && (xevent->xcrossing.mode != NotifyUngrab))
-            {
-                c->button_status[b] = BUTTON_STATE_PRESSED;
-                frameQueueDraw (c, FALSE);
-            }
+        case XFWM_EVENT_KEY:
+            status = EVENT_FILTER_STOP;
             break;
-        case LeaveNotify:
-            if ((xevent->xcrossing.mode != NotifyGrab) && (xevent->xcrossing.mode != NotifyUngrab))
+        case XFWM_EVENT_BUTTON:
+            if (!event->button.pressed)
             {
-                c->button_status[b] = BUTTON_STATE_NORMAL;
-                frameQueueDraw (c, FALSE);
+                pressed = FALSE;
+                status = EVENT_FILTER_STOP;
             }
             break;
-        case ButtonRelease:
-            pressed = FALSE;
+        case XFWM_EVENT_MOTION:
             break;
-        case UnmapNotify:
-            if (xevent->xunmap.window == c->window)
+        case XFWM_EVENT_CROSSING:
+            if (event->crossing.enter)
             {
-                pressed = FALSE;
-                c->button_status[b] = BUTTON_STATE_NORMAL;
+                if ((event->crossing.mode != NotifyGrab) && (event->crossing.mode != NotifyUngrab))
+                {
+                    c->button_status[b] = BUTTON_STATE_PRESSED;
+                    frameQueueDraw (c, FALSE);
+                }
             }
+            else
+            {
+                if ((event->crossing.mode != NotifyGrab) && (event->crossing.mode != NotifyUngrab))
+                {
+                    c->button_status[b] = BUTTON_STATE_NORMAL;
+                    frameQueueDraw (c, FALSE);
+                }
+            }
+            status = EVENT_FILTER_STOP;
             break;
-        case KeyPress:
-        case KeyRelease:
-            break;
-        default:
-            status = EVENT_FILTER_CONTINUE;
+        case XFWM_EVENT_X:
+            switch (event->meta.x->type)
+            {
+                case UnmapNotify:
+                    if (event->meta.window == c->window)
+                    {
+                        pressed = FALSE;
+                        c->button_status[b] = BUTTON_STATE_NORMAL;
+                    }
+                    status = EVENT_FILTER_STOP;
+                    break;
+            }
             break;
     }
 
@@ -3828,12 +3844,13 @@ clientButtonPressEventFilter (XEvent * xevent, gpointer data)
 }
 
 void
-clientButtonPress (Client *c, Window w, XButtonEvent * bev)
+clientButtonPress (Client *c, Window w, XfwmEventButton *event)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
     ButtonPressData passdata;
-    int b, g1;
+    gint b;
+    gboolean g1;
 
     g_return_if_fail (c != NULL);
     TRACE ("entering clientButtonPress");
@@ -3849,20 +3866,15 @@ clientButtonPress (Client *c, Window w, XButtonEvent * bev)
     screen_info = c->screen_info;
     display_info = screen_info->display_info;
 
-    g1 = XGrabPointer (display_info->dpy, w, FALSE,
-                       ButtonReleaseMask | EnterWindowMask | LeaveWindowMask,
-                       GrabModeAsync, GrabModeAsync,
-                       screen_info->xroot, None,
-                       myDisplayGetCurrentTime (display_info));
-
-    if (g1 != GrabSuccess)
+    g1 = xfwm_device_grab (display_info->devices, &display_info->devices->pointer,
+                           display_info->dpy, w, FALSE,
+                           ButtonReleaseMask | EnterWindowMask | LeaveWindowMask,
+                           GrabModeAsync, screen_info->xroot, None,
+                           myDisplayGetCurrentTime (display_info));
+    if (!g1)
     {
         TRACE ("grab failed in clientButtonPress");
         gdk_beep ();
-        if (g1 == GrabSuccess)
-        {
-            XUngrabKeyboard (display_info->dpy, myDisplayGetCurrentTime (display_info));
-        }
         return;
     }
 
@@ -3878,7 +3890,8 @@ clientButtonPress (Client *c, Window w, XButtonEvent * bev)
     eventFilterPop (display_info->xfilter);
     TRACE ("leaving button press loop");
 
-    XUngrabPointer (display_info->dpy, myDisplayGetCurrentTime (display_info));
+    xfwm_device_ungrab (display_info->devices, &display_info->devices->pointer,
+                        display_info->dpy, myDisplayGetCurrentTime (display_info));
 
     if (c->button_status[b] == BUTTON_STATE_PRESSED)
     {
@@ -3909,15 +3922,15 @@ clientButtonPress (Client *c, Window w, XButtonEvent * bev)
             case MAXIMIZE_BUTTON:
                 if (CLIENT_CAN_MAXIMIZE_WINDOW (c))
                 {
-                    if (bev->button == Button1)
+                    if (event->button == Button1)
                     {
                         clientToggleMaximized (c, CLIENT_FLAG_MAXIMIZED, TRUE);
                     }
-                    else if (bev->button == Button2)
+                    else if (event->button == Button2)
                     {
                         clientToggleMaximized (c, CLIENT_FLAG_MAXIMIZED_VERT, TRUE);
                     }
-                    else if (bev->button == Button3)
+                    else if (event->button == Button3)
                     {
                         clientToggleMaximized (c, CLIENT_FLAG_MAXIMIZED_HORIZ, TRUE);
                     }
diff --git a/src/client.h b/src/client.h
index 76b851b..e8a72d7 100644
--- a/src/client.h
+++ b/src/client.h
@@ -489,7 +489,7 @@ void                     clientScreenResize                     (ScreenInfo *,
                                                                  gboolean);
 void                     clientButtonPress                      (Client *,
                                                                  Window,
-                                                                 XButtonEvent *);
+                                                                 XfwmEventButton *);
 xfwmPixmap *             clientGetButtonPixmap                  (Client *,
                                                                  int,
                                                                  int);
diff --git a/src/compositor.c b/src/compositor.c
index 4d1b01f..922afee 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4000,7 +4000,7 @@ compositorHandleEvent (DisplayInfo *display_info, XEvent *ev)
 }
 
 void
-compositorZoomIn (ScreenInfo *screen_info, XButtonEvent *ev)
+compositorZoomIn (ScreenInfo *screen_info, XfwmEventButton *event)
 {
 #ifdef HAVE_COMPOSITOR
     screen_info->transform.matrix[0][0] -= 4096;
@@ -4015,8 +4015,8 @@ compositorZoomIn (ScreenInfo *screen_info, XButtonEvent *ev)
     if (!screen_info->zoomed)
     {
         XFixesHideCursor (screen_info->display_info->dpy, screen_info->xroot);
-        screen_info->cursorLocation.x = ev->x_root - screen_info->cursorOffsetX;
-        screen_info->cursorLocation.x = ev->y_root - screen_info->cursorOffsetY;
+        screen_info->cursorLocation.x = event->x_root - screen_info->cursorOffsetX;
+        screen_info->cursorLocation.x = event->y_root - screen_info->cursorOffsetY;
     }
 
     screen_info->zoomed = TRUE;
@@ -4025,12 +4025,12 @@ compositorZoomIn (ScreenInfo *screen_info, XButtonEvent *ev)
         screen_info->zoom_timeout_id = g_timeout_add ((1000 / 30 /* per second */),
                                                       zoom_timeout_cb, screen_info);
     }
-    recenter_zoomed_area (screen_info, ev->x_root, ev->y_root);
+    recenter_zoomed_area (screen_info, event->x_root, event->y_root);
 #endif /* HAVE_COMPOSITOR */
 }
 
 void
-compositorZoomOut (ScreenInfo *screen_info, XButtonEvent *ev)
+compositorZoomOut (ScreenInfo *screen_info, XfwmEventButton *event)
 {
 #ifdef HAVE_COMPOSITOR
     /* don't do anything if the user disabled the zoom feature */
@@ -4049,7 +4049,7 @@ compositorZoomOut (ScreenInfo *screen_info, XButtonEvent *ev)
 
             XFixesShowCursor (screen_info->display_info->dpy, screen_info->xroot);
         }
-        recenter_zoomed_area (screen_info, ev->x_root, ev->y_root);
+        recenter_zoomed_area (screen_info, event->x_root, event->y_root);
     }
 #endif /* HAVE_COMPOSITOR */
 }
diff --git a/src/compositor.h b/src/compositor.h
index 3666279..74e6703 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -59,9 +59,9 @@ Pixmap                   compositorGetWindowPixmapAtSize        (ScreenInfo *,
 void                     compositorHandleEvent                  (DisplayInfo *,
                                                                  XEvent *);
 void                     compositorZoomIn                       (ScreenInfo *,
-                                                                 XButtonEvent *);
+                                                                 XfwmEventButton *);
 void                     compositorZoomOut                      (ScreenInfo *,
-                                                                 XButtonEvent *);
+                                                                 XfwmEventButton *);
 void                     compositorInitDisplay                  (DisplayInfo *);
 void                     compositorSetCompositeMode             (DisplayInfo *,
                                                                  gboolean);
diff --git a/src/cycle.c b/src/cycle.c
index 60488c4..c897f7b 100644
--- a/src/cycle.c
+++ b/src/cycle.c
@@ -29,6 +29,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
+#include <X11/XKBlib.h>
 #include <X11/extensions/shape.h>
 
 #include <glib.h>
@@ -236,7 +237,7 @@ clientCycleUpdateWireframe (Client *c, ClientCycleData *passdata)
 }
 
 static eventFilterStatus
-clientCycleEventFilter (XEvent * xevent, gpointer data)
+clientCycleEventFilter (XfwmEvent *event, gpointer data)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
@@ -267,81 +268,70 @@ clientCycleEventFilter (XEvent * xevent, gpointer data)
     down = screen_info->params->keys[KEY_DOWN].keycode;
     modifiers = (screen_info->params->keys[KEY_CYCLE_WINDOWS].modifier |
                  screen_info->params->keys[KEY_CYCLE_REVERSE_WINDOWS].modifier);
-    status = EVENT_FILTER_STOP;
+    status = EVENT_FILTER_CONTINUE;
     removed = NULL;
     cycling = TRUE;
     gone = FALSE;
 
     /* Update the display time */
-    myDisplayUpdateCurrentTime (display_info, xevent);
+    myDisplayUpdateCurrentTime (display_info, event);
 
-    switch (xevent->type)
+    switch (event->meta.type)
     {
-        case DestroyNotify:
-            status = EVENT_FILTER_CONTINUE;
-            if ((removed = myScreenGetClientFromWindow (screen_info, ((XDestroyWindowEvent *) xevent)->window, SEARCH_WINDOW)) == NULL)
-                break; /* No need to go any further */
-            gone |= (c == removed);
-            FALLTHROUGH;
-        case UnmapNotify:
-            status = EVENT_FILTER_CONTINUE;
-            if (!removed && (removed = myScreenGetClientFromWindow (screen_info, ((XUnmapEvent *) xevent)->window, SEARCH_WINDOW)) == NULL)
-                break; /* No need to go any further */
-            gone |= (c == removed);
-            c = tabwinRemoveClient(passdata->tabwin, removed);
-            cycling = clientCycleUpdateWireframe (c, passdata);
-            break;
-        case KeyPress:
-            key = myScreenGetKeyPressed (screen_info, (XKeyEvent *) xevent);
-            /*
-             * We cannot simply check for key == KEY_CANCEL here because of the
-             * modidier being pressed, so we need to look at the keycode directly.
-             */
-            if (xevent->xkey.keycode == cancel)
-            {
-                c2 = tabwinSelectHead (passdata->tabwin);
-                cycling = FALSE;
-            }
-            else if (xevent->xkey.keycode == up)
-            {
-                c2 = tabwinSelectDelta(passdata->tabwin, -1, 0);
-            }
-            else if (xevent->xkey.keycode == down)
+        case XFWM_EVENT_KEY:
+            if (event->key.pressed)
             {
-                c2 = tabwinSelectDelta(passdata->tabwin, 1, 0);
-            }
-            else if (xevent->xkey.keycode == left)
-            {
-                c2 = tabwinSelectDelta(passdata->tabwin, 0, -1);
-            }
-            else if (xevent->xkey.keycode == right)
-            {
-                c2 = tabwinSelectDelta(passdata->tabwin, -0, 1);
-            }
-            else if (key == KEY_CYCLE_REVERSE_WINDOWS)
-            {
-                TRACE ("Cycle: previous");
-                c2 = tabwinSelectPrev(passdata->tabwin);
-            }
-            else if (key == KEY_CYCLE_WINDOWS)
-            {
-                TRACE ("Cycle: next");
-                c2 = tabwinSelectNext(passdata->tabwin);
-            }
-            if (c2)
-            {
-                clientCycleUpdateWireframe (c2, passdata);
-            }
+                key = myScreenGetKeyPressed (screen_info, &event->key);
+                /*
+                 * We cannot simply check for key == KEY_CANCEL here because of the
+                 * modidier being pressed, so we need to look at the keycode directly.
+                 */
+                if (event->key.keycode == cancel)
+                {
+                    c2 = tabwinSelectHead (passdata->tabwin);
+                    cycling = FALSE;
+                }
+                else if (event->key.keycode == up)
+                {
+                    c2 = tabwinSelectDelta(passdata->tabwin, -1, 0);
+                }
+                else if (event->key.keycode == down)
+                {
+                    c2 = tabwinSelectDelta(passdata->tabwin, 1, 0);
+                }
+                else if (event->key.keycode == left)
+                {
+                    c2 = tabwinSelectDelta(passdata->tabwin, 0, -1);
+                }
+                else if (event->key.keycode == right)
+                {
+                    c2 = tabwinSelectDelta(passdata->tabwin, -0, 1);
+                }
+                else if (key == KEY_CYCLE_REVERSE_WINDOWS)
+                {
+                    TRACE ("Cycle: previous");
+                    c2 = tabwinSelectPrev(passdata->tabwin);
+                }
+                else if (key == KEY_CYCLE_WINDOWS)
+                {
+                    TRACE ("Cycle: next");
+                    c2 = tabwinSelectNext(passdata->tabwin);
+                }
+                if (c2)
+                {
+                    clientCycleUpdateWireframe (c2, passdata);
+                }
 
-            /* If last key press event had not our modifiers pressed, finish cycling */
-            if (!(xevent->xkey.state & modifiers))
-            {
-                cycling = FALSE;
+                /* If last key press event had not our modifiers pressed, finish cycling */
+                if (!(event->key.state & modifiers))
+                {
+                    cycling = FALSE;
+                }
+                status = EVENT_FILTER_STOP;
             }
-            break;
-        case KeyRelease:
+            else
             {
-                int keysym = XLookupKeysym (&xevent->xkey, 0);
+                int keysym = XkbKeycodeToKeysym (event->meta.x->xany.display, event->key.keycode, 0, 0);
 
                 if (IsModifierKey(keysym))
                 {
@@ -351,53 +341,75 @@ clientCycleEventFilter (XEvent * xevent, gpointer data)
                     }
                 }
             }
+            status = EVENT_FILTER_STOP;
             break;
-        case ButtonPress:
-            /* only accept events for the tab windows */
-            for (li = passdata->tabwin->tabwin_list; li != NULL; li = li->next)
+        case XFWM_EVENT_BUTTON:
+            if (event->button.pressed)
             {
-                if (GDK_WINDOW_XID (gtk_widget_get_window (li->data)) == xevent->xbutton.window)
+                /* only accept events for the tab windows */
+                for (li = passdata->tabwin->tabwin_list; li != NULL; li = li->next)
                 {
-                    if  (xevent->xbutton.button == Button1)
-                    {
-                        c2 = tabwinSelectHovered (passdata->tabwin);
-                        cycling = FALSE;
-                        break;
-                    }
-                    else if  (xevent->xbutton.button == Button4)
+                    if (GDK_WINDOW_XID (gtk_widget_get_window (li->data)) == event->meta.window)
                     {
-                        /* Mouse wheel scroll up */
-                        TRACE ("Cycle: previous");
-                        c2 = tabwinSelectPrev(passdata->tabwin);
+                        if  (event->button.button == Button1)
+                        {
+                            c2 = tabwinSelectHovered (passdata->tabwin);
+                            cycling = FALSE;
+                            break;
+                        }
+                        else if (event->button.button == Button4)
+                        {
+                            /* Mouse wheel scroll up */
+                            TRACE ("Cycle: previous");
+                            c2 = tabwinSelectPrev(passdata->tabwin);
+                        }
+                        else if (event->button.button == Button5)
+                        {
+                            /* Mouse wheel scroll down */
+                            TRACE ("Cycle: next");
+                            c2 = tabwinSelectNext(passdata->tabwin);
+                        }
                     }
-                    else if (xevent->xbutton.button == Button5)
+                    if (c2)
                     {
-                        /* Mouse wheel scroll down */
-                        TRACE ("Cycle: next");
-                        c2 = tabwinSelectNext(passdata->tabwin);
+                        clientCycleUpdateWireframe (c2, passdata);
                     }
                 }
-                if (c2)
-                {
-                    clientCycleUpdateWireframe (c2, passdata);
-                }
             }
+            status = EVENT_FILTER_STOP;
             break;
-        case ButtonRelease:
+        case XFWM_EVENT_MOTION:
             break;
-        case EnterNotify:
-        case LeaveNotify:
+        case XFWM_EVENT_CROSSING:
             /* Track whether the pointer is inside one of the tab-windows */
             for (li = passdata->tabwin->tabwin_list; li != NULL; li = li->next)
             {
-                if (GDK_WINDOW_XID (gtk_widget_get_window (li->data)) == xevent->xcrossing.window)
+                if (GDK_WINDOW_XID (gtk_widget_get_window (li->data)) == event->meta.window)
                 {
-                    passdata->inside = (xevent->xcrossing.type == EnterNotify);
+                    passdata->inside = event->crossing.enter;
                 }
             }
+            status = EVENT_FILTER_STOP;
             break;
-        default:
-            status = EVENT_FILTER_CONTINUE;
+        case XFWM_EVENT_X:
+            switch (event->meta.x->type)
+            {
+                case DestroyNotify:
+                    status = EVENT_FILTER_CONTINUE;
+                    if ((removed = myScreenGetClientFromWindow (screen_info, ((XDestroyWindowEvent *) event->meta.x)->window, SEARCH_WINDOW)) == NULL)
+                        break; /* No need to go any further */
+                    gone |= (c == removed);
+                    FALLTHROUGH;
+                case UnmapNotify:
+                    status = EVENT_FILTER_CONTINUE;
+                    if (!removed && (removed = myScreenGetClientFromWindow (screen_info, ((XUnmapEvent *) event->meta.x)->window, SEARCH_WINDOW)) == NULL)
+                        break; /* No need to go any further */
+                    gone |= (c == removed);
+                    c = tabwinRemoveClient(passdata->tabwin, removed);
+                    cycling = clientCycleUpdateWireframe (c, passdata);
+                    status = EVENT_FILTER_STOP;
+                    break;
+            }
             break;
     }
 
@@ -411,27 +423,23 @@ clientCycleEventFilter (XEvent * xevent, gpointer data)
 }
 
 static eventFilterStatus
-clientCycleFlushEventFilter (XEvent * xevent, gpointer data)
+clientCycleFlushEventFilter (XfwmEvent *event, gpointer data)
 {
     DisplayInfo *display_info = (DisplayInfo *) data;
 
     /* Update the display time */
-    myDisplayUpdateCurrentTime (display_info, xevent);
+    myDisplayUpdateCurrentTime (display_info, event);
 
-    switch (xevent->type)
+    if (event->meta.type == XFWM_EVENT_CROSSING && event->crossing.enter)
     {
-        case EnterNotify:
-            gtk_main_quit ();
-            return EVENT_FILTER_STOP;
-            break;
-        default:
-            break;
+        gtk_main_quit ();
+        return EVENT_FILTER_STOP;
     }
     return EVENT_FILTER_CONTINUE;
 }
 
 void
-clientCycle (Client * c, XKeyEvent * ev)
+clientCycle (Client * c, XfwmEventKey *event)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
@@ -452,7 +460,7 @@ clientCycle (Client * c, XKeyEvent * ev)
     }
 
     modifier = 0;
-    key = myScreenGetKeyPressed (screen_info, ev);
+    key = myScreenGetKeyPressed (screen_info, event);
     if (key == KEY_CYCLE_REVERSE_WINDOWS)
     {
         selected = g_list_last (client_list);
@@ -481,9 +489,9 @@ clientCycle (Client * c, XKeyEvent * ev)
         return;
     }
 
-    myScreenGrabPointer (screen_info, TRUE, NoEventMask, None, ev->time);
+    myScreenGrabPointer (screen_info, TRUE, EnterWindowMask | LeaveWindowMask, None, event->time);
     /* Grabbing the pointer may fail e.g. if the user is doing a drag'n drop */
-    if (!myScreenGrabKeyboard (screen_info, ev->time))
+    if (!myScreenGrabKeyboard (screen_info, KeyPressMask | KeyReleaseMask, event->time))
     {
         TRACE ("grab failed in clientCycle");
 
diff --git a/src/cycle.h b/src/cycle.h
index 58c192d..f9f1bf3 100644
--- a/src/cycle.h
+++ b/src/cycle.h
@@ -35,7 +35,7 @@
 #define INC_CYCLE_H
 
 void                     clientCycle                            (Client *,
-                                                                 XKeyEvent *);
+                                                                 XfwmEventKey *);
 gboolean                 clientSwitchWindow                     (void);
 gboolean                 clientSwitchApp                        (void);
 #endif /* INC_CYCLE_H */
diff --git a/src/display.c b/src/display.c
index 29a932d..ef48657 100644
--- a/src/display.c
+++ b/src/display.c
@@ -758,50 +758,70 @@ myDisplayGetDefaultScreen (DisplayInfo *display)
 }
 
 guint32
-myDisplayUpdateCurrentTime (DisplayInfo *display, XEvent *ev)
+myDisplayUpdateCurrentTime (DisplayInfo *display, XfwmEvent *event)
 {
     guint32 timestamp;
+    XEvent *xevent;
 
     g_return_val_if_fail (display != NULL, (guint32) CurrentTime);
 
     timestamp = (guint32) CurrentTime;
-    switch (ev->type)
+    switch (event->meta.type)
     {
-        case KeyPress:
-        case KeyRelease:
-            timestamp = (guint32) ev->xkey.time;
+        case XFWM_EVENT_KEY:
+            timestamp = (guint32) event->key.time;
             break;
-        case ButtonPress:
-        case ButtonRelease:
-            timestamp = (guint32) ev->xbutton.time;
+        case XFWM_EVENT_BUTTON:
+            timestamp = (guint32) event->button.time;
             break;
-        case MotionNotify:
-            timestamp = (guint32) ev->xmotion.time;
+        case XFWM_EVENT_MOTION:
+            timestamp = (guint32) event->motion.time;
             break;
-        case EnterNotify:
-        case LeaveNotify:
-            timestamp = (guint32) ev->xcrossing.time;
+        case XFWM_EVENT_CROSSING:
+            timestamp = (guint32) event->crossing.time;
             break;
-        case PropertyNotify:
-            timestamp = (guint32) ev->xproperty.time;
-            break;
-        case SelectionClear:
-            timestamp = (guint32) ev->xselectionclear.time;
-            break;
-        case SelectionRequest:
-            timestamp = (guint32) ev->xselectionrequest.time;
-            break;
-        case SelectionNotify:
-            timestamp = (guint32) ev->xselection.time;
-            break;
-        default:
-#ifdef HAVE_XSYNC
-            if ((display->have_xsync) && (ev->type == display->xsync_event_base + XSyncAlarmNotify))
+        case XFWM_EVENT_X:
+            xevent = event->meta.x;
+
+            switch (xevent->type)
             {
-                timestamp = ((XSyncAlarmNotifyEvent*) ev)->time;
-            }
+                case KeyPress:
+                case KeyRelease:
+                    timestamp = (guint32) xevent->xkey.time;
+                    break;
+                case ButtonPress:
+                case ButtonRelease:
+                    timestamp = (guint32) xevent->xbutton.time;
+                    break;
+                case MotionNotify:
+                    timestamp = (guint32) xevent->xmotion.time;
+                    break;
+                case EnterNotify:
+                case LeaveNotify:
+                    timestamp = (guint32) xevent->xcrossing.time;
+                    break;
+                case PropertyNotify:
+                    timestamp = (guint32) xevent->xproperty.time;
+                    break;
+                case SelectionClear:
+                    timestamp = (guint32) xevent->xselectionclear.time;
+                    break;
+                case SelectionRequest:
+                    timestamp = (guint32) xevent->xselectionrequest.time;
+                    break;
+                case SelectionNotify:
+                    timestamp = (guint32) xevent->xselection.time;
+                    break;
+                default:
+#ifdef HAVE_XSYNC
+                    if ((display->have_xsync) &&
+                        (xevent->type == display->xsync_event_base + XSyncAlarmNotify))
+                    {
+                        timestamp = ((XSyncAlarmNotifyEvent*) xevent)->time;
+                    }
 #endif /* HAVE_XSYNC */
-            break;
+                    break;
+            }
     }
 
     if ((timestamp != (guint32) CurrentTime))
diff --git a/src/display.h b/src/display.h
index 882b2b3..59670c3 100644
--- a/src/display.h
+++ b/src/display.h
@@ -408,7 +408,7 @@ Client                  *myDisplayGetClientFromXSyncAlarm       (DisplayInfo *,
 #endif /* HAVE_XSYNC */
 ScreenInfo              *myDisplayGetDefaultScreen              (DisplayInfo *);
 guint32                  myDisplayUpdateCurrentTime             (DisplayInfo *,
-                                                                 XEvent *);
+                                                                 XfwmEvent *);
 guint32                  myDisplayGetCurrentTime                (DisplayInfo *);
 guint32                  myDisplayGetTime                       (DisplayInfo *,
                                                                  guint32);
diff --git a/src/event_filter.c b/src/event_filter.c
index c1340c3..88502fd 100644
--- a/src/event_filter.c
+++ b/src/event_filter.c
@@ -33,112 +33,128 @@
 #include "event_filter.h"
 
 static eventFilterStatus
-default_event_filter (XEvent * xevent, gpointer data)
+default_event_filter (XfwmEvent *event, gpointer data)
 {
-    switch (xevent->type)
+    switch (event->meta.type)
     {
-        case KeyPress:
-            TRACE ("Unhandled KeyPress event");
+        case XFWM_EVENT_KEY:
+            TRACE ("Unhandled XFWM_EVENT_KEY [%d] event", event->key.pressed);
             break;
-        case KeyRelease:
-            TRACE ("Unhandled KeyRelease event");
+        case XFWM_EVENT_BUTTON:
+            TRACE ("Unhandled XFWM_EVENT_BUTTON [%d] event", event->button.pressed);
             break;
-        case ButtonPress:
-            TRACE ("Unhandled ButtonPress event");
+        case XFWM_EVENT_MOTION:
+            TRACE ("Unhandled XFWM_EVENT_MOTION event");
             break;
-        case ButtonRelease:
-            TRACE ("Unhandled ButtonRelease event");
-            break;
-        case MotionNotify:
-            TRACE ("Unhandled MotionNotify event");
-            break;
-        case EnterNotify:
-            TRACE ("Unhandled EnterNotify event");
-            break;
-        case LeaveNotify:
-            TRACE ("Unhandled LeaveNotify event");
-            break;
-        case FocusIn:
-            TRACE ("Unhandled FocusIn event");
-            break;
-        case FocusOut:
-            TRACE ("Unhandled FocusOut event");
-            break;
-        case KeymapNotify:
-            TRACE ("Unhandled KeymapNotify event");
-            break;
-        case Expose:
-            TRACE ("Unhandled Expose event");
-            break;
-        case GraphicsExpose:
-            TRACE ("Unhandled GraphicsExpose event");
-            break;
-        case NoExpose:
-            TRACE ("Unhandled NoExpose event");
-            break;
-        case VisibilityNotify:
-            TRACE ("Unhandled VisibilityNotify event");
-            break;
-        case DestroyNotify:
-            TRACE ("Unhandled DestroyNotify event");
-            break;
-        case UnmapNotify:
-            TRACE ("Unhandled UnmapNotify event");
-            break;
-        case MapNotify:
-            TRACE ("Unhandled MapNotify event");
-            break;
-        case MapRequest:
-            TRACE ("Unhandled MapRequest event");
-            break;
-        case ReparentNotify:
-            TRACE ("Unhandled ReparentNotify event");
-            break;
-        case ConfigureNotify:
-            TRACE ("Unhandled ConfigureNotify event");
-            break;
-        case ConfigureRequest:
-            TRACE ("Unhandled ConfigureRequest event");
-            break;
-        case GravityNotify:
-            TRACE ("Unhandled GravityNotify event");
-            break;
-        case ResizeRequest:
-            TRACE ("Unhandled ResizeRequest event");
-            break;
-        case CirculateNotify:
-            TRACE ("Unhandled CirculateNotify event");
-            break;
-        case CirculateRequest:
-            TRACE ("Unhandled CirculateRequest event");
-            break;
-        case PropertyNotify:
-            TRACE ("Unhandled PropertyNotify event");
-            break;
-        case SelectionClear:
-            TRACE ("Unhandled SelectionClear event");
-            break;
-        case SelectionRequest:
-            TRACE ("Unhandled SelectionRequest event");
-            break;
-        case SelectionNotify:
-            TRACE ("Unhandled SelectionNotify event");
-            break;
-        case ColormapNotify:
-            TRACE ("Unhandled ColormapNotify event");
-            break;
-        default:
-            TRACE ("Unhandled Unknown event");
+        case XFWM_EVENT_CROSSING:
+            TRACE ("Unhandled XFWM_EVENT_CROSSING [%d] event", event->crossing.enter);
             break;
+        case XFWM_EVENT_X:
+            switch (event->meta.x->type)
+            {
+                case KeyPress:
+                    TRACE ("Unhandled KeyPress event");
+                    break;
+                case KeyRelease:
+                    TRACE ("Unhandled KeyRelease event");
+                    break;
+                case ButtonPress:
+                    TRACE ("Unhandled ButtonPress event");
+                    break;
+                case ButtonRelease:
+                    TRACE ("Unhandled ButtonRelease event");
+                    break;
+                case MotionNotify:
+                    TRACE ("Unhandled MotionNotify event");
+                    break;
+                case EnterNotify:
+                    TRACE ("Unhandled EnterNotify event");
+                    break;
+                case LeaveNotify:
+                    TRACE ("Unhandled LeaveNotify event");
+                    break;
+                case FocusIn:
+                    TRACE ("Unhandled FocusIn event");
+                    break;
+                case FocusOut:
+                    TRACE ("Unhandled FocusOut event");
+                    break;
+                case KeymapNotify:
+                    TRACE ("Unhandled KeymapNotify event");
+                    break;
+                case Expose:
+                    TRACE ("Unhandled Expose event");
+                    break;
+                case GraphicsExpose:
+                    TRACE ("Unhandled GraphicsExpose event");
+                    break;
+                case NoExpose:
+                    TRACE ("Unhandled NoExpose event");
+                    break;
+                case VisibilityNotify:
+                    TRACE ("Unhandled VisibilityNotify event");
+                    break;
+                case DestroyNotify:
+                    TRACE ("Unhandled DestroyNotify event");
+                    break;
+                case UnmapNotify:
+                    TRACE ("Unhandled UnmapNotify event");
+                    break;
+                case MapNotify:
+                    TRACE ("Unhandled MapNotify event");
+                    break;
+                case MapRequest:
+                    TRACE ("Unhandled MapRequest event");
+                    break;
+                case ReparentNotify:
+                    TRACE ("Unhandled ReparentNotify event");
+                    break;
+                case ConfigureNotify:
+                    TRACE ("Unhandled ConfigureNotify event");
+                    break;
+                case ConfigureRequest:
+                    TRACE ("Unhandled ConfigureRequest event");
+                    break;
+                case GravityNotify:
+                    TRACE ("Unhandled GravityNotify event");
+                    break;
+                case ResizeRequest:
+                    TRACE ("Unhandled ResizeRequest event");
+                    break;
+                case CirculateNotify:
+                    TRACE ("Unhandled CirculateNotify event");
+                    break;
+                case CirculateRequest:
+                    TRACE ("Unhandled CirculateRequest event");
+                    break;
+                case PropertyNotify:
+                    TRACE ("Unhandled PropertyNotify event");
+                    break;
+                case SelectionClear:
+                    TRACE ("Unhandled SelectionClear event");
+                    break;
+                case SelectionRequest:
+                    TRACE ("Unhandled SelectionRequest event");
+                    break;
+                case SelectionNotify:
+                    TRACE ("Unhandled SelectionNotify event");
+                    break;
+                case ColormapNotify:
+                    TRACE ("Unhandled ColormapNotify event");
+                    break;
+                default:
+                    TRACE ("Unhandled Unknown event");
+                    break;
+            }
     }
     /* This is supposed to be the default fallback event handler, so we return EVENT_FILTER_STOP since we have "treated" the event */
     return EVENT_FILTER_STOP;
 }
 
 static GdkFilterReturn
-eventXfwmFilter (GdkXEvent * gdk_xevent, GdkEvent * event, gpointer data)
+eventXfwmFilter (GdkXEvent *gdk_xevent, GdkEvent *gevent, gpointer data)
 {
-    XEvent *xevent;
+    XfwmEvent *event;
     eventFilterStatus loop;
     eventFilterSetup *setup;
     eventFilterStack *filterelt;
@@ -149,15 +165,17 @@ eventXfwmFilter (GdkXEvent * gdk_xevent, GdkEvent * event, gpointer data)
     filterelt = setup->filterstack;
     g_return_val_if_fail (filterelt != NULL, GDK_FILTER_CONTINUE);
 
-    xevent = (XEvent *) gdk_xevent;
+    event = xfwm_device_translate_event (setup->devices, (XEvent *)gdk_xevent, NULL);
     loop = EVENT_FILTER_CONTINUE;
 
     while ((filterelt) && (loop == EVENT_FILTER_CONTINUE))
     {
         eventFilterStack *filterelt_next = filterelt->next;
-        loop = (*filterelt->filter) (xevent, filterelt->data);
+        loop = (*filterelt->filter) (event, filterelt->data);
         filterelt = filterelt_next;
     }
+
+    xfwm_device_free_event (event);
     return (loop & EVENT_FILTER_REMOVE) ? GDK_FILTER_REMOVE : GDK_FILTER_CONTINUE;
 }
 
diff --git a/src/event_filter.h b/src/event_filter.h
index 8ee2153..b9f14d0 100644
--- a/src/event_filter.h
+++ b/src/event_filter.h
@@ -42,7 +42,7 @@ typedef enum {
 }
 eventFilterStatus;
 
-typedef eventFilterStatus (*XfwmFilter) (XEvent * xevent, gpointer data);
+typedef eventFilterStatus (*XfwmFilter) (XfwmEvent *event, gpointer data);
 
 typedef struct eventFilterStack
 {
diff --git a/src/events.c b/src/events.c
index ff590ab..f536fee 100644
--- a/src/events.c
+++ b/src/events.c
@@ -87,7 +87,7 @@ static xfwmWindow menu_event_window;
 /* Forward decl. */
 
 static eventFilterStatus handleEvent (DisplayInfo *display_info,
-                                      XEvent * ev);
+                                      XfwmEvent *event);
 static void menu_callback            (Menu * menu,
                                       MenuOp op,
                                       Window xid,
@@ -150,7 +150,7 @@ typeOfClick_end (gpointer data)
 }
 
 static eventFilterStatus
-typeOfClick_event_filter (XEvent * xevent, gpointer data)
+typeOfClick_event_filter (XfwmEvent *event, gpointer data)
 {
     XfwmButtonClickData *passdata;
     eventFilterStatus status;
@@ -162,7 +162,7 @@ typeOfClick_event_filter (XEvent * xevent, gpointer data)
     status = EVENT_FILTER_CONTINUE;
 
     /* Update the display time */
-    timestamp = myDisplayUpdateCurrentTime (passdata->display_info, xevent);
+    timestamp = myDisplayUpdateCurrentTime (passdata->display_info, event);
 
     if (timestamp)
     {
@@ -172,9 +172,9 @@ typeOfClick_event_filter (XEvent * xevent, gpointer data)
             keep_going = FALSE;
         }
     }
-    if ((xevent->type == ButtonRelease) || (xevent->type == ButtonPress))
+    if (event->meta.type == XFWM_EVENT_BUTTON)
     {
-        if (xevent->xbutton.button == passdata->button)
+        if (event->button.button == passdata->button)
         {
             passdata->clicks++;
         }
@@ -186,10 +186,10 @@ typeOfClick_event_filter (XEvent * xevent, gpointer data)
         }
         status = EVENT_FILTER_STOP;
     }
-    else if (xevent->type == MotionNotify)
+    else if (event->meta.type == XFWM_EVENT_MOTION)
     {
-        passdata->xcurrent = xevent->xmotion.x_root;
-        passdata->ycurrent = xevent->xmotion.y_root;
+        passdata->xcurrent = event->motion.x_root;
+        passdata->ycurrent = event->motion.y_root;
 
         if ((ABS (passdata->x0 - passdata->xcurrent) > passdata->double_click_distance) ||
             (ABS (passdata->y0 - passdata->ycurrent) > passdata->double_click_distance))
@@ -198,9 +198,9 @@ typeOfClick_event_filter (XEvent * xevent, gpointer data)
         }
         status = EVENT_FILTER_STOP;
     }
-    else if ((xevent->type == DestroyNotify) || (xevent->type == UnmapNotify))
+    else if ((event->meta.x->type == DestroyNotify) || (event->meta.x->type == UnmapNotify))
     {
-        if (xevent->xany.window == passdata->w)
+        if (event->meta.window == passdata->w)
         {
             /* Discard, mark the click as undefined */
             passdata->clicks = (guint) XFWM_BUTTON_UNDEFINED;
@@ -221,33 +221,33 @@ typeOfClick_event_filter (XEvent * xevent, gpointer data)
 }
 
 static XfwmButtonClickType
-typeOfClick (ScreenInfo *screen_info, Window w, XEvent * ev, gboolean allow_double_click)
+typeOfClick (ScreenInfo *screen_info, Window w, XfwmEventButton *event, gboolean allow_double_click)
 {
     DisplayInfo *display_info;
     XfwmButtonClickData passdata;
     gboolean g;
 
     g_return_val_if_fail (screen_info != NULL, XFWM_BUTTON_UNDEFINED);
-    g_return_val_if_fail (ev != NULL, XFWM_BUTTON_UNDEFINED);
+    g_return_val_if_fail (event != NULL, XFWM_BUTTON_UNDEFINED);
     g_return_val_if_fail (w != None, XFWM_BUTTON_UNDEFINED);
 
     display_info = screen_info->display_info;
-    g = myScreenGrabPointer (screen_info, FALSE, DOUBLE_CLICK_GRAB, None, ev->xbutton.time);
+    g = myScreenGrabPointer (screen_info, FALSE, DOUBLE_CLICK_GRAB, None, event->time);
 
     if (!g)
     {
         TRACE ("grab failed in typeOfClick");
         gdk_beep ();
-        myScreenUngrabPointer (screen_info, ev->xbutton.time);
+        myScreenUngrabPointer (screen_info, event->time);
         return XFWM_BUTTON_UNDEFINED;
     }
 
     passdata.display_info = display_info;
-    passdata.button = ev->xbutton.button;
+    passdata.button = event->button;
     passdata.w = w;
-    passdata.x0 = ev->xbutton.x_root;
-    passdata.y0 = ev->xbutton.y_root;
-    passdata.t0 = ev->xbutton.time;
+    passdata.x0 = event->x_root;
+    passdata.y0 = event->y_root;
+    passdata.t0 = event->time;
     passdata.xcurrent = passdata.x0;
     passdata.ycurrent = passdata.y0;
     passdata.tcurrent = passdata.t0;
@@ -284,14 +284,14 @@ toggle_show_desktop (ScreenInfo *screen_info)
 }
 
 static eventFilterStatus
-handleMotionNotify (DisplayInfo *display_info, XMotionEvent * ev)
+handleMotionNotify (DisplayInfo *display_info, XfwmEventMotion *event)
 {
     TRACE ("entering handleMotionNotify");
     return EVENT_FILTER_REMOVE;
 }
 
 static eventFilterStatus
-handleKeyPress (DisplayInfo *display_info, XKeyEvent * ev)
+handleKeyPress (DisplayInfo *display_info, XfwmEventKey *event)
 {
     eventFilterStatus status;
     ScreenInfo *screen_info;
@@ -301,7 +301,7 @@ handleKeyPress (DisplayInfo *display_info, XKeyEvent * ev)
 
     TRACE ("entering handleKeyPress");
 
-    ev_screen_info = myDisplayGetScreenFromRoot (display_info, ev->root);
+    ev_screen_info = myDisplayGetScreenFromRoot (display_info, event->root);
     if (!ev_screen_info)
     {
         return EVENT_FILTER_PASS;
@@ -312,20 +312,20 @@ handleKeyPress (DisplayInfo *display_info, XKeyEvent * ev)
     if (c)
     {
         screen_info = c->screen_info;
-        key = myScreenGetKeyPressed (screen_info, ev);
+        key = myScreenGetKeyPressed (screen_info, event);
         status = EVENT_FILTER_REMOVE;
 
         switch (key)
         {
             case KEY_MOVE:
-                clientMove (c, (XEvent *) ev);
+                clientMove (c, NULL);
                 break;
             case KEY_RESIZE:
-                clientResize (c, CORNER_BOTTOM_RIGHT, (XEvent *) ev);
+                clientResize (c, CORNER_BOTTOM_RIGHT, NULL);
                 break;
             case KEY_CYCLE_WINDOWS:
             case KEY_CYCLE_REVERSE_WINDOWS:
-                clientCycle (c, ev);
+                clientCycle (c, event);
                 break;
             case KEY_CLOSE_WINDOW:
                 clientClose (c);
@@ -378,22 +378,22 @@ handleKeyPress (DisplayInfo *display_info, XKeyEvent * ev)
                 clientToggleFullscreen (c);
                 break;
             case KEY_MOVE_NEXT_WORKSPACE:
-                workspaceSwitch (screen_info, screen_info->current_ws + 1, c, TRUE, ev->time);
+                workspaceSwitch (screen_info, screen_info->current_ws + 1, c, TRUE, event->time);
                 break;
             case KEY_MOVE_PREV_WORKSPACE:
-                workspaceSwitch (screen_info, screen_info->current_ws - 1, c, TRUE, ev->time);
+                workspaceSwitch (screen_info, screen_info->current_ws - 1, c, TRUE, event->time);
                 break;
             case KEY_MOVE_UP_WORKSPACE:
-                workspaceMove (screen_info, -1, 0, c, ev->time);
+                workspaceMove (screen_info, -1, 0, c, event->time);
                 break;
             case KEY_MOVE_DOWN_WORKSPACE:
-                workspaceMove (screen_info, 1, 0, c, ev->time);
+                workspaceMove (screen_info, 1, 0, c, event->time);
                 break;
             case KEY_MOVE_LEFT_WORKSPACE:
-                workspaceMove (screen_info, 0, -1, c, ev->time);
+                workspaceMove (screen_info, 0, -1, c, event->time);
                 break;
             case KEY_MOVE_RIGHT_WORKSPACE:
-                workspaceMove (screen_info, 0, 1, c, ev->time);
+                workspaceMove (screen_info, 0, 1, c, event->time);
                 break;
             case KEY_MOVE_WORKSPACE_1:
             case KEY_MOVE_WORKSPACE_2:
@@ -416,7 +416,7 @@ handleKeyPress (DisplayInfo *display_info, XKeyEvent * ev)
             case KEY_POPUP_MENU:
                 show_window_menu (c, frameExtentX (c) + frameLeft (c),
                                      frameExtentY (c) + frameTop (c),
-                                     Button1, ev->time);
+                                     Button1, event->time);
                 break;
             case KEY_FILL_WINDOW:
                 clientFill (c, CLIENT_FILL);
@@ -473,14 +473,14 @@ handleKeyPress (DisplayInfo *display_info, XKeyEvent * ev)
     }
     else
     {
-        key = myScreenGetKeyPressed (ev_screen_info, ev);
+        key = myScreenGetKeyPressed (ev_screen_info, event);
         switch (key)
         {
             case KEY_CYCLE_WINDOWS:
                 status = EVENT_FILTER_REMOVE;
                 if (ev_screen_info->clients)
                 {
-                    clientCycle (ev_screen_info->clients->prev, ev);
+                    clientCycle (ev_screen_info->clients->prev, event);
                 }
                 break;
             case KEY_CLOSE_WINDOW:
@@ -505,27 +505,27 @@ handleKeyPress (DisplayInfo *display_info, XKeyEvent * ev)
             break;
         case KEY_NEXT_WORKSPACE:
             status = EVENT_FILTER_REMOVE;
-            workspaceSwitch (ev_screen_info, ev_screen_info->current_ws + 1, NULL, TRUE, ev->time);
+            workspaceSwitch (ev_screen_info, ev_screen_info->current_ws + 1, NULL, TRUE, event->time);
             break;
         case KEY_PREV_WORKSPACE:
             status = EVENT_FILTER_REMOVE;
-            workspaceSwitch (ev_screen_info, ev_screen_info->current_ws - 1, NULL, TRUE, ev->time);
+            workspaceSwitch (ev_screen_info, ev_screen_info->current_ws - 1, NULL, TRUE, event->time);
             break;
         case KEY_UP_WORKSPACE:
             status = EVENT_FILTER_REMOVE;
-            workspaceMove(ev_screen_info, -1, 0, NULL, ev->time);
+            workspaceMove(ev_screen_info, -1, 0, NULL, event->time);
             break;
         case KEY_DOWN_WORKSPACE:
             status = EVENT_FILTER_REMOVE;
-            workspaceMove(ev_screen_info, 1, 0, NULL, ev->time);
+            workspaceMove(ev_screen_info, 1, 0, NULL, event->time);
             break;
         case KEY_LEFT_WORKSPACE:
             status = EVENT_FILTER_REMOVE;
-            workspaceMove(ev_screen_info, 0, -1, NULL, ev->time);
+            workspaceMove(ev_screen_info, 0, -1, NULL, event->time);
             break;
         case KEY_RIGHT_WORKSPACE:
             status = EVENT_FILTER_REMOVE;
-            workspaceMove(ev_screen_info, 0, 1, NULL, ev->time);
+            workspaceMove(ev_screen_info, 0, 1, NULL, event->time);
             break;
         case KEY_ADD_WORKSPACE:
             status = EVENT_FILTER_REMOVE;
@@ -556,7 +556,7 @@ handleKeyPress (DisplayInfo *display_info, XKeyEvent * ev)
             status = EVENT_FILTER_REMOVE;
             if ((guint) (key - KEY_WORKSPACE_1) < ev_screen_info->workspace_count)
             {
-                workspaceSwitch (ev_screen_info, key - KEY_WORKSPACE_1, NULL, TRUE, ev->time);
+                workspaceSwitch (ev_screen_info, key - KEY_WORKSPACE_1, NULL, TRUE, event->time);
             }
             break;
         case KEY_SHOW_DESKTOP:
@@ -574,7 +574,7 @@ handleKeyPress (DisplayInfo *display_info, XKeyEvent * ev)
 }
 
 static eventFilterStatus
-handleKeyRelease (DisplayInfo *display_info, XKeyEvent * ev)
+handleKeyRelease (DisplayInfo *display_info, XfwmEventKey *event)
 {
     TRACE ("entering handleKeyRelease");
 
@@ -590,39 +590,39 @@ handleKeyRelease (DisplayInfo *display_info, XKeyEvent * ev)
  * Button 3 : Resize
  */
 static void
-edgeButton (Client * c, int part, XButtonEvent * ev)
+edgeButton (Client *c, int part, XfwmEventButton *event)
 {
     ScreenInfo *screen_info;
     XfwmButtonClickType tclick;
     guint state;
 
     screen_info = c->screen_info;
-    state = ev->state & MODIFIER_MASK;
+    state = event->state & MODIFIER_MASK;
 
-    if (ev->button == Button2)
+    if (event->button == Button2)
     {
-        tclick = typeOfClick (screen_info, c->window, (XEvent *) ev, FALSE);
+        tclick = typeOfClick (screen_info, c->window, event, FALSE);
         if (tclick == XFWM_BUTTON_CLICK)
         {
             clientLower (c, None);
         }
         else if (tclick == XFWM_BUTTON_DRAG)
         {
-            clientMove (c, (XEvent *) ev);
+            clientMove (c, event);
         }
     }
-    else if ((ev->button == Button1) || (ev->button == Button3))
+    else if ((event->button == Button1) || (event->button == Button3))
     {
-        if ((ev->button == Button1) ||
+        if ((event->button == Button1) ||
             ((screen_info->params->easy_click) && (state == screen_info->params->easy_click)))
         {
             if (!(c->type & WINDOW_TYPE_DONT_FOCUS))
             {
-                clientSetFocus (screen_info, c, ev->time, NO_FOCUS_FLAG);
+                clientSetFocus (screen_info, c, event->time, NO_FOCUS_FLAG);
             }
             clientRaise (c, None);
         }
-        tclick = typeOfClick (screen_info, c->window, (XEvent *) ev, TRUE);
+        tclick = typeOfClick (screen_info, c->window, event, TRUE);
         if (tclick == XFWM_BUTTON_DOUBLE_CLICK)
         {
             switch (part)
@@ -642,13 +642,13 @@ edgeButton (Client * c, int part, XButtonEvent * ev)
         }
         else if (tclick == XFWM_BUTTON_DRAG)
         {
-            clientResize (c, part, (XEvent *) ev);
+            clientResize (c, part, event);
         }
     }
 }
 
 static int
-edgeGetPart (Client *c, XButtonEvent * ev)
+edgeGetPart (Client *c, XfwmEventButton *event)
 {
     int part, x_corner_pixels, y_corner_pixels, x_distance, y_distance;
 
@@ -657,8 +657,8 @@ edgeGetPart (Client *c, XButtonEvent * ev)
     y_corner_pixels = MAX(c->height / 3, 50);
 
     /* Distance from event to edge of client window */
-    x_distance = c->width / 2 - abs(c->width / 2 - ev->x);
-    y_distance = c->height / 2 - abs(c->height / 2 - ev->y);
+    x_distance = c->width / 2 - abs(c->width / 2 - event->x);
+    y_distance = c->height / 2 - abs(c->height / 2 - event->y);
 
     /* Set a sensible default value */
     part = CORNER_BOTTOM_RIGHT;
@@ -666,9 +666,9 @@ edgeGetPart (Client *c, XButtonEvent * ev)
     if (x_distance < x_corner_pixels && y_distance < y_corner_pixels)
     {
         /* In a corner */
-        if (ev->x < c->width / 2)
+        if (event->x < c->width / 2)
         {
-            if (ev->y < c->height / 2)
+            if (event->y < c->height / 2)
             {
                 part = CORNER_TOP_LEFT;
             }
@@ -679,7 +679,7 @@ edgeGetPart (Client *c, XButtonEvent * ev)
         }
         else
         {
-            if (ev->y < c->height / 2)
+            if (event->y < c->height / 2)
             {
                 part = CORNER_TOP_RIGHT;
             }
@@ -695,7 +695,7 @@ edgeGetPart (Client *c, XButtonEvent * ev)
         if (x_distance / x_corner_pixels < y_distance / y_corner_pixels)
         {
             /* Left or right side */
-            if (ev->x < c->width / 2)
+            if (event->x < c->width / 2)
             {
                 part = CORNER_COUNT + SIDE_LEFT;
             }
@@ -707,7 +707,7 @@ edgeGetPart (Client *c, XButtonEvent * ev)
         else
         {
             /* Top or bottom side */
-            if (ev->y < c->height / 2)
+            if (event->y < c->height / 2)
             {
                 part = CORNER_COUNT + SIDE_TOP;
             }
@@ -721,26 +721,26 @@ edgeGetPart (Client *c, XButtonEvent * ev)
     return part;
 }
 static void
-button1Action (Client * c, XButtonEvent * ev)
+button1Action (Client *c, XfwmEventButton *event)
 {
     ScreenInfo *screen_info;
     XfwmButtonClickType tclick;
 
     g_return_if_fail (c != NULL);
-    g_return_if_fail (ev != NULL);
+    g_return_if_fail (event != NULL);
 
     screen_info = c->screen_info;
 
     if (!(c->type & WINDOW_TYPE_DONT_FOCUS))
     {
-        clientSetFocus (screen_info, c, ev->time, NO_FOCUS_FLAG);
+        clientSetFocus (screen_info, c, event->time, NO_FOCUS_FLAG);
     }
     clientRaise (c, None);
 
-    tclick = typeOfClick (screen_info, c->window, (XEvent *) ev, TRUE);
+    tclick = typeOfClick (screen_info, c->window, event, TRUE);
     if ((tclick == XFWM_BUTTON_DRAG) || (tclick == XFWM_BUTTON_CLICK_AND_DRAG))
     {
-        clientMove (c, (XEvent *) ev);
+        clientMove (c, event);
     }
     else if (tclick == XFWM_BUTTON_DOUBLE_CLICK)
     {
@@ -768,44 +768,44 @@ button1Action (Client * c, XButtonEvent * ev)
 }
 
 static void
-titleButton (Client * c, guint state, XButtonEvent * ev)
+titleButton (Client *c, guint state, XfwmEventButton *event)
 {
     ScreenInfo *screen_info;
 
     g_return_if_fail (c != NULL);
-    g_return_if_fail (ev != NULL);
+    g_return_if_fail (event != NULL);
 
     /* Get Screen data from the client itself */
     screen_info = c->screen_info;
 
-    if (ev->button == Button1)
+    if (event->button == Button1)
     {
-        button1Action (c, ev);
+        button1Action (c, event);
     }
-    else if (ev->button == Button2)
+    else if (event->button == Button2)
     {
         clientLower (c, None);
     }
-    else if (ev->button == Button3)
+    else if (event->button == Button3)
     {
         XfwmButtonClickType tclick;
 
-        tclick = typeOfClick (screen_info, c->window, (XEvent *) ev, FALSE);
+        tclick = typeOfClick (screen_info, c->window, event, FALSE);
         if (tclick == XFWM_BUTTON_DRAG)
         {
-            clientMove (c, (XEvent *) ev);
+            clientMove (c, event);
         }
         else if (tclick != XFWM_BUTTON_UNDEFINED)
         {
             if (!(c->type & WINDOW_TYPE_DONT_FOCUS))
             {
-                clientSetFocus (screen_info, c, ev->time, NO_FOCUS_FLAG);
+                clientSetFocus (screen_info, c, event->time, NO_FOCUS_FLAG);
             }
             if (screen_info->params->raise_on_click)
             {
                 clientRaise (c, None);
             }
-            ev->window = ev->root;
+            xfwm_device_button_update_window (event, event->root);
             if (screen_info->button_handler_id)
             {
                 g_signal_handler_disconnect (G_OBJECT (myScreenGetGtkWidget (screen_info)), screen_info->button_handler_id);
@@ -815,7 +815,7 @@ titleButton (Client * c, guint state, XButtonEvent * ev)
             /* Let GTK handle this for us. */
         }
     }
-    else if (ev->button == Button4)
+    else if (event->button == Button4)
     {
         /* Mouse wheel scroll up */
 #ifdef HAVE_COMPOSITOR
@@ -833,7 +833,7 @@ titleButton (Client * c, guint state, XButtonEvent * ev)
             }
         }
     }
-    else if (ev->button == Button5)
+    else if (event->button == Button5)
     {
         /* Mouse wheel scroll down */
 #ifdef HAVE_COMPOSITOR
@@ -854,12 +854,12 @@ titleButton (Client * c, guint state, XButtonEvent * ev)
 #ifdef HAVE_COMPOSITOR
     else if (screen_info->params->horiz_scroll_opacity)
     {
-        if (ev->button == Button6)
+        if (event->button == Button6)
         {
             /* Mouse wheel scroll left, or left side button */
             clientDecOpacity(c);
         }
-        else if (ev->button == Button7)
+        else if (event->button == Button7)
         {
             /* Mouse wheel scroll right, or right side button */
             clientIncOpacity(c);
@@ -869,38 +869,38 @@ titleButton (Client * c, guint state, XButtonEvent * ev)
 }
 
 static void
-rootScrollButton (DisplayInfo *display_info, XButtonEvent * ev)
+rootScrollButton (DisplayInfo *display_info, XfwmEventButton *event)
 {
     static guint32 lastscroll = CurrentTime;
     ScreenInfo *screen_info;
 
-    if ((ev->time - lastscroll) < 25)  /* ms */
+    if ((event->time - lastscroll) < 25)  /* ms */
     {
         /* Too many events in too little time, drop this event... */
         return;
     }
-    lastscroll = ev->time;
+    lastscroll = event->time;
 
     /* Get the screen structure from the root of the event */
-    screen_info = myDisplayGetScreenFromRoot (display_info, ev->root);
+    screen_info = myDisplayGetScreenFromRoot (display_info, event->root);
     if (!screen_info)
     {
         return;
     }
 
-    if (ev->button == Button4)
+    if (event->button == Button4)
     {
-        workspaceSwitch (screen_info, screen_info->current_ws - 1, NULL, TRUE, ev->time);
+        workspaceSwitch (screen_info, screen_info->current_ws - 1, NULL, TRUE, event->time);
     }
-    else if (ev->button == Button5)
+    else if (event->button == Button5)
     {
-        workspaceSwitch (screen_info, screen_info->current_ws + 1, NULL, TRUE, ev->time);
+        workspaceSwitch (screen_info, screen_info->current_ws + 1, NULL, TRUE, event->time);
     }
 }
 
 
 static eventFilterStatus
-handleButtonPress (DisplayInfo *display_info, XButtonEvent * ev)
+handleButtonPress (DisplayInfo *display_info, XfwmEventButton *event)
 {
     ScreenInfo *screen_info;
     Client *c;
@@ -911,74 +911,75 @@ handleButtonPress (DisplayInfo *display_info, XButtonEvent * ev)
     TRACE ("entering handleButtonPress");
 
     replay = FALSE;
-    c = myDisplayGetClientFromWindow (display_info, ev->window, SEARCH_FRAME | SEARCH_WINDOW);
+    c = myDisplayGetClientFromWindow (display_info, event->meta.window,
+                                      SEARCH_FRAME | SEARCH_WINDOW);
     if (c)
     {
-        state = ev->state & MODIFIER_MASK;
-        win = ev->subwindow;
+        state = event->state & MODIFIER_MASK;
+        win = event->subwindow;
         screen_info = c->screen_info;
 
-        if ((ev->button == Button1) && (state) && (state == screen_info->params->easy_click))
+        if ((event->button == Button1) && (state) && (state == screen_info->params->easy_click))
         {
-            button1Action (c, ev);
+            button1Action (c, event);
         }
-        else if ((ev->button == Button2) && (state) && (state == screen_info->params->easy_click))
+        else if ((event->button == Button2) && (state) && (state == screen_info->params->easy_click))
         {
             clientLower (c, None);
         }
-        else if ((ev->button == Button3) && (state) && (state == screen_info->params->easy_click))
+        else if ((event->button == Button3) && (state) && (state == screen_info->params->easy_click))
         {
-            part = edgeGetPart (c, ev);
-            edgeButton (c, part, ev);
+            part = edgeGetPart (c, event);
+            edgeButton (c, part, event);
         }
 #ifdef HAVE_COMPOSITOR
-        else if ((ev->button == Button4) && (screen_info->params->zoom_desktop) && (state) &&
+        else if ((event->button == Button4) && (screen_info->params->zoom_desktop) && (state) &&
                  (state == screen_info->params->easy_click) && compositorIsActive (screen_info))
         {
-            compositorZoomIn(screen_info, ev);
+            compositorZoomIn(screen_info, event);
         }
-        else if ((ev->button == Button5) && (screen_info->params->zoom_desktop) && (state) &&
+        else if ((event->button == Button5) && (screen_info->params->zoom_desktop) && (state) &&
                  (state == screen_info->params->easy_click) && compositorIsActive (screen_info))
         {
-            compositorZoomOut(screen_info, ev);
+            compositorZoomOut(screen_info, event);
         }
 #endif /* HAVE_COMPOSITOR */
-        else if ((ev->button == Button8) && (state) && (state == screen_info->params->easy_click))
+        else if ((event->button == Button8) && (state) && (state == screen_info->params->easy_click))
         {
-            workspaceSwitch (screen_info, screen_info->current_ws - 1, NULL, TRUE, ev->time);
+            workspaceSwitch (screen_info, screen_info->current_ws - 1, NULL, TRUE, event->time);
         }
-        else if ((ev->button == Button9) && (state) && (state == screen_info->params->easy_click))
+        else if ((event->button == Button9) && (state) && (state == screen_info->params->easy_click))
         {
-            workspaceSwitch (screen_info, screen_info->current_ws + 1, NULL, TRUE, ev->time);
+            workspaceSwitch (screen_info, screen_info->current_ws + 1, NULL, TRUE, event->time);
         }
 
         else if (WIN_IS_BUTTON (win))
         {
-            if (ev->button <= Button3)
+            if (event->button <= Button3)
             {
                 if (!(c->type & WINDOW_TYPE_DONT_FOCUS))
                 {
-                    clientSetFocus (screen_info, c, ev->time, NO_FOCUS_FLAG);
+                    clientSetFocus (screen_info, c, event->time, NO_FOCUS_FLAG);
                 }
                 if (screen_info->params->raise_on_click)
                 {
                     clientClearDelayedRaise ();
                     clientRaise (c, None);
                 }
-                clientButtonPress (c, win, ev);
+                clientButtonPress (c, win, event);
             }
         }
         else if (win == MYWINDOW_XWINDOW (c->title))
         {
-            titleButton (c, state, ev);
+            titleButton (c, state, event);
         }
         else if (win == MYWINDOW_XWINDOW (c->buttons[MENU_BUTTON]))
         {
-            if (ev->button == Button1)
+            if (event->button == Button1)
             {
                 XfwmButtonClickType tclick;
 
-                tclick = typeOfClick (screen_info, c->window, (XEvent *) ev, TRUE);
+                tclick = typeOfClick (screen_info, c->window, event, TRUE);
 
                 if (tclick == XFWM_BUTTON_DOUBLE_CLICK)
                 {
@@ -988,14 +989,14 @@ handleButtonPress (DisplayInfo *display_info, XButtonEvent * ev)
                 {
                     if (!(c->type & WINDOW_TYPE_DONT_FOCUS))
                     {
-                        clientSetFocus (screen_info, c, ev->time, NO_FOCUS_FLAG);
+                        clientSetFocus (screen_info, c, event->time, NO_FOCUS_FLAG);
                     }
                     if (screen_info->params->raise_on_click)
                     {
                         clientClearDelayedRaise ();
                         clientRaise (c, None);
                     }
-                    ev->window = ev->root;
+                    xfwm_device_button_update_window (event, event->root);
                     if (screen_info->button_handler_id)
                     {
                         g_signal_handler_disconnect (G_OBJECT (myScreenGetGtkWidget (screen_info)), screen_info->button_handler_id);
@@ -1009,51 +1010,52 @@ handleButtonPress (DisplayInfo *display_info, XButtonEvent * ev)
         else if ((win == MYWINDOW_XWINDOW (c->corners[CORNER_TOP_LEFT]))
             && (state == 0))
         {
-            edgeButton (c, CORNER_TOP_LEFT, ev);
+            edgeButton (c, CORNER_TOP_LEFT, event);
         }
         else if ((win == MYWINDOW_XWINDOW (c->corners[CORNER_TOP_RIGHT]))
             && (state == 0))
         {
-            edgeButton (c, CORNER_TOP_RIGHT, ev);
+            edgeButton (c, CORNER_TOP_RIGHT, event);
         }
         else if ((win == MYWINDOW_XWINDOW (c->corners[CORNER_BOTTOM_LEFT]))
             && (state == 0))
         {
-            edgeButton (c, CORNER_BOTTOM_LEFT, ev);
+            edgeButton (c, CORNER_BOTTOM_LEFT, event);
         }
         else if ((win == MYWINDOW_XWINDOW (c->corners[CORNER_BOTTOM_RIGHT]))
             && (state == 0))
         {
-            edgeButton (c, CORNER_BOTTOM_RIGHT, ev);
+            edgeButton (c, CORNER_BOTTOM_RIGHT, event);
         }
         else if ((win == MYWINDOW_XWINDOW (c->sides[SIDE_BOTTOM]))
             && (state == 0))
         {
-            edgeButton (c, CORNER_COUNT + SIDE_BOTTOM, ev);
+            edgeButton (c, CORNER_COUNT + SIDE_BOTTOM, event);
         }
         else if ((win == MYWINDOW_XWINDOW (c->sides[SIDE_TOP]))
             && (state == 0))
         {
-            edgeButton (c, CORNER_COUNT + SIDE_TOP, ev);
+            edgeButton (c, CORNER_COUNT + SIDE_TOP, event);
         }
         else if ((win == MYWINDOW_XWINDOW (c->sides[SIDE_LEFT]))
             && (state == 0))
         {
-            edgeButton (c, CORNER_COUNT + SIDE_LEFT, ev);
+            edgeButton (c, CORNER_COUNT + SIDE_LEFT, event);
         }
         else if ((win == MYWINDOW_XWINDOW (c->sides[SIDE_RIGHT]))
             && (state == 0))
         {
-            edgeButton (c, CORNER_COUNT + SIDE_RIGHT, ev);
+            edgeButton (c, CORNER_COUNT + SIDE_RIGHT, event);
         }
-        else if (ev->window == c->window)
+        else if (event->meta.window == c->window)
         {
             replay = TRUE;
-            if (((screen_info->params->raise_with_any_button) && (c->type & WINDOW_REGULAR_FOCUSABLE)) || (ev->button == Button1))
+            if (((screen_info->params->raise_with_any_button) && (c->type & WINDOW_REGULAR_FOCUSABLE))
+                    || (event->button == Button1))
             {
                 if (!(c->type & WINDOW_TYPE_DONT_FOCUS))
                 {
-                    clientSetFocus (screen_info, c, ev->time, NO_FOCUS_FLAG);
+                    clientSetFocus (screen_info, c, event->time, NO_FOCUS_FLAG);
                 }
                 if ((screen_info->params->raise_on_click) ||
                     !FLAG_TEST (c->xfwm_flags, XFWM_FLAG_HAS_BORDER))
@@ -1070,18 +1072,19 @@ handleButtonPress (DisplayInfo *display_info, XButtonEvent * ev)
            The event did not occur in one of our known good clients...
            Get the screen structure from the root of the event.
          */
-        screen_info = myDisplayGetScreenFromRoot (display_info, ev->root);
+        screen_info = myDisplayGetScreenFromRoot (display_info, event->root);
         if (screen_info)
         {
-            if ((ev->window == screen_info->xroot) && (screen_info->params->scroll_workspaces)
-                    && ((ev->button == Button4) || (ev->button == Button5)))
+            if ((event->meta.window == screen_info->xroot) && (screen_info->params->scroll_workspaces)
+                    && ((event->button == Button4) || (event->button == Button5)))
             {
-                rootScrollButton (display_info, ev);
+                rootScrollButton (display_info, event);
             }
             else
             {
-                XUngrabPointer (display_info->dpy, ev->time);
-                XSendEvent (display_info->dpy, screen_info->xfwm4_win, FALSE, SubstructureNotifyMask, (XEvent *) ev);
+                xfwm_device_ungrab (display_info->devices, &display_info->devices->pointer,
+                                    display_info->dpy, event->time);
+                XSendEvent (display_info->dpy, screen_info->xfwm4_win, FALSE, SubstructureNotifyMask, event->meta.x);
             }
         }
     }
@@ -1093,17 +1096,18 @@ handleButtonPress (DisplayInfo *display_info, XButtonEvent * ev)
 }
 
 static eventFilterStatus
-handleButtonRelease (DisplayInfo *display_info, XButtonEvent * ev)
+handleButtonRelease (DisplayInfo *display_info, XfwmEventButton *event)
 {
     ScreenInfo *screen_info;
 
     TRACE ("entering handleButtonRelease");
 
     /* Get the screen structure from the root of the event */
-    screen_info = myDisplayGetScreenFromRoot (display_info, ev->root);
+    screen_info = myDisplayGetScreenFromRoot (display_info, event->root);
     if (screen_info)
     {
-        XSendEvent (display_info->dpy, screen_info->xfwm4_win, FALSE, SubstructureNotifyMask, (XEvent *) ev);
+        XSendEvent (display_info->dpy, screen_info->xfwm4_win, FALSE, SubstructureNotifyMask,
+                    (XEvent *) event->meta.x);
     }
 
     /* Release pending events */
@@ -1383,7 +1387,7 @@ handleConfigureRequest (DisplayInfo *display_info, XConfigureRequestEvent * ev)
 }
 
 static eventFilterStatus
-handleEnterNotify (DisplayInfo *display_info, XCrossingEvent * ev)
+handleEnterNotify (DisplayInfo *display_info, XfwmEventCrossing *event)
 {
     ScreenInfo *screen_info;
     Client *c;
@@ -1394,17 +1398,18 @@ handleEnterNotify (DisplayInfo *display_info, XCrossingEvent * ev)
 
     TRACE ("entering handleEnterNotify");
 
-    if ((ev->mode == NotifyGrab) || (ev->mode == NotifyUngrab)
-        || (ev->detail > NotifyNonlinearVirtual))
+    if ((event->mode == NotifyGrab) || (event->mode == NotifyUngrab)
+        || (event->detail > NotifyNonlinearVirtual))
     {
         /* We're not interested in such notifications */
         return EVENT_FILTER_PASS;
     }
 
-    TRACE ("EnterNotify on window (0x%lx)", ev->window);
+    TRACE ("EnterNotify on window (0x%lx)", event->meta.window);
 
     need_redraw = FALSE;
-    c = myDisplayGetClientFromWindow (display_info, ev->window, SEARCH_FRAME | SEARCH_BUTTON);
+    c = myDisplayGetClientFromWindow (display_info, event->meta.window,
+                                      SEARCH_FRAME | SEARCH_BUTTON);
     if (c)
     {
         screen_info = c->screen_info;
@@ -1417,11 +1422,11 @@ handleEnterNotify (DisplayInfo *display_info, XCrossingEvent * ev)
                 if(screen_info->params->focus_delay)
                 {
                     clientClearDelayedFocus ();
-                    clientAddDelayedFocus (c, ev->time);
+                    clientAddDelayedFocus (c, event->time);
                 }
                 else
                 {
-                    clientSetFocus (c->screen_info, c, ev->time, NO_FOCUS_FLAG);
+                    clientSetFocus (c->screen_info, c, event->time, NO_FOCUS_FLAG);
                 }
             }
             else
@@ -1433,7 +1438,7 @@ handleEnterNotify (DisplayInfo *display_info, XCrossingEvent * ev)
         {
             for (b = 0; b < BUTTON_COUNT; b++)
             {
-                if (MYWINDOW_XWINDOW(c->buttons[b]) == ev->window)
+                if (MYWINDOW_XWINDOW(c->buttons[b]) == event->meta.window)
                 {
                     if (!xfwmPixmapNone(clientGetButtonPixmap(c, b, PRELIGHT)))
                     {
@@ -1461,7 +1466,7 @@ handleEnterNotify (DisplayInfo *display_info, XCrossingEvent * ev)
     }
 
     /* Get the screen structure from the root of the event */
-    screen_info = myDisplayGetScreenFromRoot (display_info, ev->root);
+    screen_info = myDisplayGetScreenFromRoot (display_info, event->root);
 
     if (!screen_info)
     {
@@ -1470,14 +1475,14 @@ handleEnterNotify (DisplayInfo *display_info, XCrossingEvent * ev)
 
     if (screen_info->params->wrap_workspaces && screen_info->workspace_count > 1)
     {
-        clientMoveWarp (NULL, screen_info, &ev->x_root, &ev->y_root, ev->time);
+        clientMoveWarp (NULL, screen_info, &event->x_root, &event->y_root, event->time);
     }
 
     return EVENT_FILTER_REMOVE;
 }
 
 static eventFilterStatus
-handleLeaveNotify (DisplayInfo *display_info, XCrossingEvent * ev)
+handleLeaveNotify (DisplayInfo *display_info, XfwmEventCrossing *event)
 {
     Client *c;
     int b;
@@ -1486,14 +1491,15 @@ handleLeaveNotify (DisplayInfo *display_info, XCrossingEvent * ev)
     TRACE ("entering handleLeaveNotify");
 
     need_redraw = FALSE;
-    c = myDisplayGetClientFromWindow (display_info, ev->window, SEARCH_FRAME | SEARCH_BUTTON);
+    c = myDisplayGetClientFromWindow (display_info, event->meta.window,
+                                      SEARCH_FRAME | SEARCH_BUTTON);
     if (c)
     {
         for (b = 0; b < BUTTON_COUNT; b++)
         {
             if ((c->button_status[b] == BUTTON_STATE_PRELIGHT) || (c->button_status[b] == BUTTON_STATE_PRESSED))
             {
-                if (MYWINDOW_XWINDOW(c->buttons[b]) == ev->window)
+                if (MYWINDOW_XWINDOW(c->buttons[b]) == event->meta.window)
                 {
                     c->button_status[b] = BUTTON_STATE_NORMAL;
                     need_redraw = TRUE;
@@ -2193,7 +2199,7 @@ handleXSyncAlarmNotify (DisplayInfo *display_info, XSyncAlarmNotifyEvent * ev)
 #endif /* HAVE_XSYNC */
 
 static eventFilterStatus
-handleEvent (DisplayInfo *display_info, XEvent * ev)
+handleEvent (DisplayInfo *display_info, XfwmEvent *event)
 {
     eventFilterStatus status;
     status = EVENT_FILTER_PASS;
@@ -2201,81 +2207,101 @@ handleEvent (DisplayInfo *display_info, XEvent * ev)
     TRACE ("entering handleEvent");
 
     /* Update the display time */
-    myDisplayUpdateCurrentTime (display_info, ev);
-    sn_process_event (ev);
-    switch (ev->type)
+    myDisplayUpdateCurrentTime (display_info, event);
+    sn_process_event (event->meta.x);
+
+    switch (event->meta.type)
     {
-        case MotionNotify:
-            status = handleMotionNotify (display_info, (XMotionEvent *) ev);
-            break;
-        case KeyPress:
-            status = handleKeyPress (display_info, (XKeyEvent *) ev);
-            break;
-        case KeyRelease:
-            status = handleKeyRelease (display_info, (XKeyEvent *) ev);
-            break;
-        case ButtonPress:
-            status = handleButtonPress (display_info, (XButtonEvent *) ev);
-            break;
-        case ButtonRelease:
-            status = handleButtonRelease (display_info, (XButtonEvent *) ev);
-            break;
-        case DestroyNotify:
-            status = handleDestroyNotify (display_info, (XDestroyWindowEvent *) ev);
-            break;
-        case UnmapNotify:
-            status = handleUnmapNotify (display_info, (XUnmapEvent *) ev);
-            break;
-        case MapRequest:
-            status = handleMapRequest (display_info, (XMapRequestEvent *) ev);
-            break;
-        case MapNotify:
-            status = handleMapNotify (display_info, (XMapEvent *) ev);
-            break;
-        case ConfigureNotify:
-            status = handleConfigureNotify (display_info, (XConfigureEvent *) ev);
-            break;
-        case ConfigureRequest:
-            status = handleConfigureRequest (display_info, (XConfigureRequestEvent *) ev);
-            break;
-        case EnterNotify:
-            status = handleEnterNotify (display_info, (XCrossingEvent *) ev);
-            break;
-        case LeaveNotify:
-            status = handleLeaveNotify (display_info, (XCrossingEvent *) ev);
-            break;
-        case FocusIn:
-            status = handleFocusIn (display_info, (XFocusChangeEvent *) ev);
-            break;
-        case FocusOut:
-            status = handleFocusOut (display_info, (XFocusChangeEvent *) ev);
-            break;
-        case PropertyNotify:
-            status = handlePropertyNotify (display_info, (XPropertyEvent *) ev);
-            break;
-        case ClientMessage:
-            status = handleClientMessage (display_info, (XClientMessageEvent *) ev);
-            break;
-        case SelectionClear:
-            status = handleSelectionClear (display_info, (XSelectionClearEvent *) ev);
+        case XFWM_EVENT_KEY:
+            if (event->key.pressed)
+            {
+                status = handleKeyPress (display_info, &event->key);
+            }
+            else
+            {
+                status = handleKeyRelease (display_info, &event->key);
+            }
             break;
-        case ColormapNotify:
-            handleColormapNotify (display_info, (XColormapEvent *) ev);
+        case XFWM_EVENT_BUTTON:
+            if (event->button.pressed)
+            {
+                status = handleButtonPress (display_info, &event->button);
+            }
+            else
+            {
+                status = handleButtonRelease (display_info, &event->button);
+            }
             break;
-        case ReparentNotify:
-            status = handleReparentNotify (display_info, (XReparentEvent *) ev);
+        case XFWM_EVENT_MOTION:
+            status = handleMotionNotify (display_info, &event->motion);
             break;
-        default:
-            if ((display_info->have_shape) && (ev->type == display_info->shape_event_base))
+        case XFWM_EVENT_CROSSING:
+            if (event->crossing.enter)
             {
-                status = handleShape (display_info, (XShapeEvent *) ev);
+                status = handleEnterNotify (display_info, &event->crossing);
             }
-#ifdef HAVE_XSYNC
-            if ((display_info->have_xsync) && (ev->type == (display_info->xsync_event_base + XSyncAlarmNotify)))
+            else
             {
-                status = handleXSyncAlarmNotify (display_info, (XSyncAlarmNotifyEvent *) ev);
+                status = handleLeaveNotify (display_info, &event->crossing);
             }
+            break;
+        case XFWM_EVENT_X:
+            switch (event->meta.x->type)
+            {
+                case DestroyNotify:
+                    status = handleDestroyNotify (display_info, (XDestroyWindowEvent *) event->meta.x);
+                    break;
+                case UnmapNotify:
+                    status = handleUnmapNotify (display_info, (XUnmapEvent *) event->meta.x);
+                    break;
+                case MapRequest:
+                    status = handleMapRequest (display_info, (XMapRequestEvent *) event->meta.x);
+                    break;
+                case MapNotify:
+                    status = handleMapNotify (display_info, (XMapEvent *) event->meta.x);
+                    break;
+                case ConfigureNotify:
+                    status = handleConfigureNotify (display_info, (XConfigureEvent *) event->meta.x);
+                    break;
+                case ConfigureRequest:
+                    status = handleConfigureRequest (display_info, (XConfigureRequestEvent *) event->meta.x);
+                    break;
+                case FocusIn:
+                    status = handleFocusIn (display_info, (XFocusChangeEvent *) event->meta.x);
+                    break;
+                case FocusOut:
+                    status = handleFocusOut (display_info, (XFocusChangeEvent *) event->meta.x);
+                    break;
+                case PropertyNotify:
+                    status = handlePropertyNotify (display_info, (XPropertyEvent *) event->meta.x);
+                    break;
+                case ClientMessage:
+                    status = handleClientMessage (display_info, (XClientMessageEvent *) event->meta.x);
+                    break;
+                case SelectionClear:
+                    status = handleSelectionClear (display_info, (XSelectionClearEvent *) event->meta.x);
+                    break;
+                case ColormapNotify:
+                    handleColormapNotify (display_info, (XColormapEvent *) event->meta.x);
+                    break;
+                case ReparentNotify:
+                    status = handleReparentNotify (display_info, (XReparentEvent *) event->meta.x);
+                    break;
+                default:
+                    if ((display_info->have_shape) &&
+                            (event->meta.x->type == display_info->shape_event_base))
+                    {
+                        status = handleShape (display_info, (XShapeEvent *) event->meta.x);
+                    }
+#ifdef HAVE_XSYNC
+                    if ((display_info->have_xsync) &&
+                            (event->meta.x->type == (display_info->xsync_event_base + XSyncAlarmNotify)))
+                    {
+                        status = handleXSyncAlarmNotify (display_info, (XSyncAlarmNotifyEvent *) event->meta.x);
+                    }
 #endif /* HAVE_XSYNC */
+                    break;
+            }
             break;
     }
     if (!gdk_events_pending () && !XPending (display_info->dpy))
@@ -2296,13 +2322,13 @@ handleEvent (DisplayInfo *display_info, XEvent * ev)
         }
     }
 
-    compositorHandleEvent (display_info, ev);
+    compositorHandleEvent (display_info, event->meta.x);
 
     return status;
 }
 
 eventFilterStatus
-xfwm4_event_filter (XEvent * xevent, gpointer data)
+xfwm4_event_filter (XfwmEvent *event, gpointer data)
 {
     eventFilterStatus status;
     DisplayInfo *display_info;
@@ -2310,7 +2336,7 @@ xfwm4_event_filter (XEvent * xevent, gpointer data)
     display_info = (DisplayInfo *) data;
 
     TRACE ("entering xfwm4_event_filter");
-    status = handleEvent (display_info, xevent);
+    status = handleEvent (display_info, event);
     TRACE ("leaving xfwm4_event_filter");
     return EVENT_FILTER_STOP | status;
 }
diff --git a/src/events.h b/src/events.h
index d83dba5..714baaf 100644
--- a/src/events.h
+++ b/src/events.h
@@ -38,7 +38,7 @@
 #include "event_filter.h"
 
 void                     initMenuEventWin                       (void);
-eventFilterStatus        xfwm4_event_filter                     (XEvent *,
+eventFilterStatus        xfwm4_event_filter                     (XfwmEvent *,
                                                                  gpointer);
 void                     initPerScreenCallbacks                 (ScreenInfo *);
 void                     initPerDisplayCallbacks                (DisplayInfo *);
diff --git a/src/focus.c b/src/focus.c
index 7255544..24851d7 100644
--- a/src/focus.c
+++ b/src/focus.c
@@ -705,11 +705,13 @@ clientGrabMouseButton (Client * c)
     screen_info = c->screen_info;
     if (screen_info->params->raise_with_any_button)
     {
-        grabButton(clientGetXDisplay (c), AnyButton, AnyModifier, c->window);
+        grabButton (c->screen_info->display_info->devices, clientGetXDisplay (c),
+                    AnyButton, AnyModifier, c->window);
     }
     else
     {
-        grabButton(clientGetXDisplay (c), Button1, AnyModifier, c->window);
+        grabButton (c->screen_info->display_info->devices, clientGetXDisplay (c),
+                    Button1, AnyModifier, c->window);
     }
 }
 
@@ -720,7 +722,8 @@ clientUngrabMouseButton (Client * c)
     TRACE ("entering clientUngrabMouseButton");
     TRACE ("ungrabing buttons for client \"%s\" (0x%lx)", c->name, c->window);
 
-    ungrabButton(clientGetXDisplay (c), AnyButton, AnyModifier, c->window);
+    ungrabButton (c->screen_info->display_info->devices, clientGetXDisplay (c),
+                  AnyButton, AnyModifier, c->window);
     /* We've ungrabbed way too much, so regrab the regular buttons/modifiers */
     clientGrabButtons (c);
 }
diff --git a/src/hints.c b/src/hints.c
index c86e28c..ae36399 100644
--- a/src/hints.c
+++ b/src/hints.c
@@ -1217,6 +1217,7 @@ getXServerTime (DisplayInfo *display_info)
 {
     ScreenInfo *screen_info;
     XEvent xevent;
+    XfwmEvent *event;
     guint32 timestamp;
 
     g_return_val_if_fail (display_info, CurrentTime);
@@ -1229,7 +1230,9 @@ getXServerTime (DisplayInfo *display_info)
         TRACE ("getXServerTime: Using X server roundtrip");
         updateXserverTime (display_info);
         XWindowEvent (display_info->dpy, display_info->timestamp_win, PropertyChangeMask, &xevent);
-        timestamp = myDisplayUpdateCurrentTime (display_info, &xevent);
+        event = xfwm_device_translate_event (display_info->devices, &xevent, NULL);
+        timestamp = myDisplayUpdateCurrentTime (display_info, event);
+        xfwm_device_free_event (event);
     }
 
     TRACE ("getXServerTime gives timestamp=%u", (guint32) timestamp);
diff --git a/src/keyboard.c b/src/keyboard.c
index d26f212..a66fc46 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -64,6 +64,10 @@ unsigned int HyperMask;
     PointerMotionMask | \
     PointerMotionHintMask
 
+#define KEYCODE_GRAB_MASK \
+    KeyPressMask | \
+    KeyReleaseMask
+
 static KeyCode
 getKeycode (Display *dpy, const char *str)
 {
@@ -148,7 +152,7 @@ parseKeyString (Display * dpy, MyKey * key, const char *str)
 }
 
 gboolean
-grabKey (Display * dpy, MyKey * key, Window w)
+grabKey (XfwmDevices *devices, Display *dpy, MyKey *key, Window w)
 {
     int status;
 
@@ -159,119 +163,111 @@ grabKey (Display * dpy, MyKey * key, Window w)
     {
         if (key->modifier != 0)
         {
-            status |=
-                XGrabKey (dpy, key->keycode,
-                                        key->modifier, w,
-                                        TRUE, GrabModeAsync, GrabModeSync);
+            status |= xfwm_device_grab_keycode (devices, dpy, key->keycode,
+                                                key->modifier,
+                                                w, TRUE, KEYCODE_GRAB_MASK,
+                                                GrabModeAsync, GrabModeSync);
         }
 
         /* Here we grab all combinations of well known modifiers */
-        status |=
-            XGrabKey (dpy, key->keycode,
-                                    key->modifier | ScrollLockMask, w,
-                                    TRUE, GrabModeAsync, GrabModeSync);
-        status |=
-            XGrabKey (dpy, key->keycode,
-                                    key->modifier | NumLockMask, w,
-                                    TRUE, GrabModeAsync, GrabModeSync);
-        status |=
-            XGrabKey (dpy, key->keycode,
-                                    key->modifier | LockMask, w,
-                                    TRUE, GrabModeAsync, GrabModeSync);
-        status |=
-            XGrabKey (dpy, key->keycode,
-                                    key->modifier | ScrollLockMask | NumLockMask, w,
-                                    TRUE, GrabModeAsync, GrabModeSync);
-        status |=
-            XGrabKey (dpy, key->keycode,
-                                    key->modifier | ScrollLockMask | LockMask, w,
-                                    TRUE, GrabModeAsync, GrabModeSync);
-        status |=
-            XGrabKey (dpy, key->keycode,
-                                    key->modifier | LockMask | NumLockMask, w,
-                                    TRUE, GrabModeAsync, GrabModeSync);
-        status |=
-            XGrabKey (dpy, key->keycode,
-                                    key->modifier | ScrollLockMask | LockMask | NumLockMask, w,
-                                    TRUE, GrabModeAsync, GrabModeSync);
+        status |= xfwm_device_grab_keycode (devices, dpy, key->keycode,
+                                            key->modifier | ScrollLockMask,
+                                            w, TRUE, KEYCODE_GRAB_MASK,
+                                            GrabModeAsync, GrabModeSync);
+        status |= xfwm_device_grab_keycode (devices, dpy, key->keycode,
+                                            key->modifier | NumLockMask,
+                                            w, TRUE, KEYCODE_GRAB_MASK,
+                                            GrabModeAsync, GrabModeSync);
+        status |= xfwm_device_grab_keycode (devices, dpy, key->keycode,
+                                            key->modifier | LockMask,
+                                            w, TRUE, KEYCODE_GRAB_MASK,
+                                            GrabModeAsync, GrabModeSync);
+        status |= xfwm_device_grab_keycode (devices, dpy, key->keycode,
+                                            key->modifier | ScrollLockMask | NumLockMask,
+                                            w, TRUE, KEYCODE_GRAB_MASK,
+                                            GrabModeAsync, GrabModeSync);
+        status |= xfwm_device_grab_keycode (devices, dpy, key->keycode,
+                                            key->modifier | ScrollLockMask | LockMask,
+                                            w, TRUE, KEYCODE_GRAB_MASK,
+                                            GrabModeAsync, GrabModeSync);
+        status |= xfwm_device_grab_keycode (devices, dpy, key->keycode,
+                                            key->modifier | LockMask | NumLockMask,
+                                            w, TRUE, KEYCODE_GRAB_MASK,
+                                            GrabModeAsync, GrabModeSync);
+        status |= xfwm_device_grab_keycode (devices, dpy, key->keycode,
+                                            key->modifier | ScrollLockMask | LockMask | NumLockMask,
+                                            w, TRUE, KEYCODE_GRAB_MASK,
+                                            GrabModeAsync, GrabModeSync);
     }
 
     return (status == GrabSuccess);
 }
 
 void
-ungrabKeys (Display * dpy, Window w)
+ungrabKeys (XfwmDevices *devices, Display *dpy, Window w)
 {
     TRACE ("entering ungrabKeys");
 
-    XUngrabKey (dpy, AnyKey, AnyModifier, w);
+    xfwm_device_ungrab_keycode (devices, dpy, AnyKey, AnyModifier, w);
 }
 
 gboolean
-grabButton (Display * dpy, int button, int modifier, Window w)
+grabButton (XfwmDevices *devices, Display *dpy, guint button, guint modifier, Window w)
 {
-    int status;
+    gboolean result;
 
     TRACE ("entering grabButton");
 
-    status = GrabSuccess;
+    result = TRUE;
     if (modifier == AnyModifier)
     {
-        status |=
-            XGrabButton (dpy, button, AnyModifier, w, FALSE,
-                                BUTTON_GRAB_MASK, GrabModeSync, GrabModeAsync,
-                                None, None);
+        result &= xfwm_device_grab_button (devices, dpy, button,
+                                           AnyModifier,
+                                           w, FALSE, BUTTON_GRAB_MASK,
+                                           GrabModeSync, GrabModeAsync, None, None);
     }
     else
     {
         /* Here we grab all combinations of well known modifiers */
-        status |=
-            XGrabButton (dpy, button, modifier,
-                                w, FALSE,
-                                BUTTON_GRAB_MASK, GrabModeSync, GrabModeAsync,
-                                None, None);
-        status |=
-            XGrabButton (dpy, button, modifier | ScrollLockMask,
-                                w, FALSE,
-                                BUTTON_GRAB_MASK, GrabModeSync, GrabModeAsync,
-                                None, None);
-        status |=
-            XGrabButton (dpy, button, modifier | NumLockMask,
-                                w, FALSE,
-                                BUTTON_GRAB_MASK, GrabModeSync, GrabModeAsync,
-                                None, None);
-        status |=
-            XGrabButton (dpy, button, modifier | LockMask, w, FALSE,
-                                BUTTON_GRAB_MASK, GrabModeSync, GrabModeAsync,
-                                None, None);
-        status |=
-            XGrabButton (dpy, button, modifier | ScrollLockMask | NumLockMask,
-                                w, FALSE,
-                                BUTTON_GRAB_MASK, GrabModeSync, GrabModeAsync,
-                                None, None);
-        status |=
-            XGrabButton (dpy, button, modifier | ScrollLockMask | LockMask,
-                                w, FALSE,
-                                BUTTON_GRAB_MASK, GrabModeSync, GrabModeAsync,
-                                None, None);
-        status |=
-            XGrabButton (dpy, button, modifier | LockMask | NumLockMask,
-                                w, FALSE,
-                                BUTTON_GRAB_MASK, GrabModeSync, GrabModeAsync,
-                                None, None);
-        status |=
-            XGrabButton (dpy, button,
-                                modifier | ScrollLockMask | LockMask | NumLockMask,
-                                w, FALSE,
-                                BUTTON_GRAB_MASK, GrabModeSync, GrabModeAsync,
-                                None, None);
+        result &= xfwm_device_grab_button (devices, dpy, button,
+                                           modifier,
+                                           w, FALSE, BUTTON_GRAB_MASK,
+                                           GrabModeSync, GrabModeAsync, None, None);
+        result &= xfwm_device_grab_button (devices, dpy, button,
+                                           modifier | ScrollLockMask,
+                                           w, FALSE, BUTTON_GRAB_MASK,
+                                           GrabModeSync, GrabModeAsync, None, None);
+        result &= xfwm_device_grab_button (devices, dpy, button,
+                                           modifier | NumLockMask,
+                                           w, FALSE, BUTTON_GRAB_MASK,
+                                           GrabModeSync, GrabModeAsync, None, None);
+        result &= xfwm_device_grab_button (devices, dpy, button,
+                                           modifier | LockMask,
+                                           w, FALSE, BUTTON_GRAB_MASK,
+                                           GrabModeSync, GrabModeAsync, None, None);
+        result &= xfwm_device_grab_button (devices, dpy, button,
+                                           modifier | ScrollLockMask | NumLockMask,
+                                           w, FALSE, BUTTON_GRAB_MASK,
+                                           GrabModeSync, GrabModeAsync, None, None);
+        result &= xfwm_device_grab_button (devices, dpy, button,
+                                           modifier | ScrollLockMask | LockMask,
+                                           w, FALSE, BUTTON_GRAB_MASK,
+                                           GrabModeSync, GrabModeAsync, None, None);
+        result &= xfwm_device_grab_button (devices, dpy, button,
+                                           modifier | LockMask | NumLockMask,
+                                           w, FALSE, BUTTON_GRAB_MASK,
+                                           GrabModeSync, GrabModeAsync, None, None);
+        result &= xfwm_device_grab_button (devices, dpy, button,
+                                           modifier | ScrollLockMask | LockMask | NumLockMask,
+                                           w, FALSE, BUTTON_GRAB_MASK,
+                                           GrabModeSync, GrabModeAsync, None, None);
     }
 
-    return (status == GrabSuccess);
+    return result;
 }
 
 void
-ungrabButton (Display * dpy, int button, int modifier, Window w)
+ungrabButton (XfwmDevices *devices, Display *dpy, guint button, guint modifier, Window w)
 {
     TRACE ("entering ungrabKeys");
 
@@ -279,19 +275,19 @@ ungrabButton (Display * dpy, int button, int modifier, Window w)
 
     if (modifier == AnyModifier)
     {
-        XUngrabButton (dpy, button, AnyModifier, w);
+        xfwm_device_ungrab_button (devices, dpy, button, AnyModifier, w);
     }
     else
     {
         /* Here we ungrab all combinations of well known modifiers */
-        XUngrabButton (dpy, button, modifier, w);
-        XUngrabButton (dpy, button, modifier | ScrollLockMask, w);
-        XUngrabButton (dpy, button, modifier | NumLockMask, w);
-        XUngrabButton (dpy, button, modifier | LockMask, w);
-        XUngrabButton (dpy, button, modifier | ScrollLockMask | NumLockMask, w);
-        XUngrabButton (dpy, button, modifier | ScrollLockMask | LockMask, w);
-        XUngrabButton (dpy, button, modifier | LockMask | NumLockMask, w);
-        XUngrabButton (dpy, button, modifier | ScrollLockMask | LockMask | NumLockMask, w);
+        xfwm_device_ungrab_button (devices, dpy, button, modifier, w);
+        xfwm_device_ungrab_button (devices, dpy, button, modifier | ScrollLockMask, w);
+        xfwm_device_ungrab_button (devices, dpy, button, modifier | NumLockMask, w);
+        xfwm_device_ungrab_button (devices, dpy, button, modifier | LockMask, w);
+        xfwm_device_ungrab_button (devices, dpy, button, modifier | ScrollLockMask | NumLockMask, w);
+        xfwm_device_ungrab_button (devices, dpy, button, modifier | ScrollLockMask | LockMask, w);
+        xfwm_device_ungrab_button (devices, dpy, button, modifier | LockMask | NumLockMask, w);
+        xfwm_device_ungrab_button (devices, dpy, button, modifier | ScrollLockMask | LockMask | NumLockMask, w);
     }
 }
 
diff --git a/src/keyboard.h b/src/keyboard.h
index 1e8210b..93bf1bf 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -28,13 +28,15 @@
 #include "config.h"
 #endif
 
+#include "device.h"
+
 #include <X11/keysym.h>
 
 typedef struct _MyKey MyKey;
 struct _MyKey
 {
     KeyCode keycode;
-    int modifier;
+    guint modifier;
     gchar *internal_name;
 };
 
@@ -50,18 +52,22 @@ gboolean                 getModifierMap                         (const char *,
 void                     parseKeyString                         (Display *,
                                                                  MyKey *,
                                                                  const char *);
-gboolean                 grabKey                                (Display *,
+gboolean                 grabKey                                (XfwmDevices *,
+                                                                 Display *,
                                                                  MyKey *,
                                                                  Window);
-void                     ungrabKeys                             (Display *,
+void                     ungrabKeys                             (XfwmDevices *,
+                                                                 Display *,
                                                                  Window);
-gboolean                 grabButton                             (Display *,
-                                                                 int,
-                                                                 int,
+gboolean                 grabButton                             (XfwmDevices *,
+                                                                 Display *,
+                                                                 guint,
+                                                                 guint,
                                                                  Window);
-void                     ungrabButton                           (Display *,
-                                                                 int,
-                                                                 int,
+void                     ungrabButton                           (XfwmDevices *,
+                                                                 Display *,
+                                                                 guint,
+                                                                 guint,
                                                                  Window);
 void                     initModifiers                          (Display *);
 
diff --git a/src/menu.c b/src/menu.c
index 82fd2f7..63a9979 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -80,20 +80,16 @@ static MenuItem menuitems[] = {
 };
 
 static eventFilterStatus
-menu_filter (XEvent * xevent, gpointer data)
+menu_filter (XfwmEvent *event, gpointer data)
 {
-    switch (xevent->type)
+    switch (event->meta.type)
     {
-        case KeyPress:
-        case KeyRelease:
-        case ButtonPress:
-        case ButtonRelease:
-        case MotionNotify:
-        case EnterNotify:
-        case LeaveNotify:
+        case XFWM_EVENT_KEY:
+        case XFWM_EVENT_BUTTON:
+        case XFWM_EVENT_MOTION:
+        case XFWM_EVENT_CROSSING:
             return EVENT_FILTER_STOP;
-            break;
-        default:
+        case XFWM_EVENT_X:
             break;
     }
     return EVENT_FILTER_CONTINUE;
diff --git a/src/misc.c b/src/misc.c
index 9551c6a..6040040 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -44,12 +44,12 @@
 #include "client.h"
 #include "misc.h"
 
-unsigned int
-getMouseXY (ScreenInfo *screen_info, Window w, int *x2, int *y2)
+guint
+getMouseXY (ScreenInfo *screen_info, Window w, gint *x2, gint *y2)
 {
     Window w1, w2;
-    unsigned int mask;
-    int x1, y1;
+    guint mask;
+    gint x1, y1;
 
     TRACE ("entering getMouseXY");
 
diff --git a/src/misc.h b/src/misc.h
index 96fb0d0..2924014 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -60,10 +60,10 @@
 #define Button9 9
 #endif
 
-unsigned int             getMouseXY                             (ScreenInfo *,
+guint                    getMouseXY                             (ScreenInfo *,
                                                                  Window,
-                                                                 int *,
-                                                                 int *);
+                                                                 gint *,
+                                                                 gint *);
 GC                       createGC                               (ScreenInfo *,
                                                                  char *,
                                                                  int,
diff --git a/src/moveresize.c b/src/moveresize.c
index f9f02bd..9dbc561 100644
--- a/src/moveresize.c
+++ b/src/moveresize.c
@@ -29,6 +29,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
+#include <X11/XKBlib.h>
 #include <X11/extensions/shape.h>
 
 #include <glib.h>
@@ -52,12 +53,15 @@
 #include "workspaces.h"
 #include "xsync.h"
 
-#define MOVERESIZE_EVENT_MASK \
+#define MOVERESIZE_POINTER_EVENT_MASK \
     PointerMotionMask | \
     ButtonMotionMask | \
     ButtonReleaseMask | \
     LeaveWindowMask
 
+#define MOVERESIZE_KEYBOARD_EVENT_MASK \
+    KeyPressMask
+
 #define TILE_DISTANCE 10
 #define BORDER_TILE_LENGTH_RELATIVE 5
 #define use_xor_move(screen_info) (screen_info->params->box_move && !compositorIsActive (screen_info))
@@ -180,9 +184,9 @@ clientMovePointer (DisplayInfo *display_info, gint dx, gint dy, guint repeat)
 }
 
 static gboolean
-clientKeyPressIsModifier (XEvent *xevent)
+clientKeyPressIsModifier (XfwmEventKey *event)
 {
-    int keysym = XLookupKeysym (&xevent->xkey, 0);
+    int keysym = XkbKeycodeToKeysym (event->meta.x->xany.display, event->keycode, 0, 0);
     return (gboolean) IsModifierKey(keysym);
 }
 
@@ -614,7 +618,7 @@ clientSnapPosition (Client * c, int prev_x, int prev_y)
 }
 
 static eventFilterStatus
-clientButtonReleaseFilter (XEvent * xevent, gpointer data)
+clientButtonReleaseFilter (XfwmEvent *event, gpointer data)
 {
     MoveResizeData *passdata = (MoveResizeData *) data;
     ScreenInfo *screen_info;
@@ -625,11 +629,10 @@ clientButtonReleaseFilter (XEvent * xevent, gpointer data)
 
     TRACE ("entering clientButtonReleaseFilter");
 
-    if ((xevent->type == ButtonRelease &&
-         (passdata->button == AnyButton ||
-          passdata->button == xevent->xbutton.button)) ||
-        (xevent->type == KeyPress &&
-         xevent->xkey.keycode == screen_info->params->keys[KEY_CANCEL].keycode))
+    if ((event->meta.type == XFWM_EVENT_BUTTON && !event->button.pressed &&
+        (passdata->button == AnyButton || passdata->button == event->button.button)) ||
+        (event->meta.type == XFWM_EVENT_KEY && event->key.pressed &&
+         event->key.keycode == screen_info->params->keys[KEY_CANCEL].keycode))
     {
         gtk_main_quit ();
         return EVENT_FILTER_STOP;
@@ -780,7 +783,7 @@ clientMoveWarp (Client * c, ScreenInfo * screen_info, int * x_root, int * y_root
 }
 
 static gboolean
-clientMoveTile (Client *c, XMotionEvent *xevent)
+clientMoveTile (Client *c, XfwmEventMotion *event)
 {
     ScreenInfo *screen_info;
     GdkRectangle rect;
@@ -793,8 +796,8 @@ clientMoveTile (Client *c, XMotionEvent *xevent)
         return FALSE;
     }
 
-    x = xevent->x;
-    y = xevent->y;
+    x = event->x;
+    y = event->y;
 
     myScreenFindMonitorAtPoint (screen_info, x, y, &rect);
     disp_x = rect.x;
@@ -864,7 +867,7 @@ clientMoveTile (Client *c, XMotionEvent *xevent)
 }
 
 static eventFilterStatus
-clientMoveEventFilter (XEvent * xevent, gpointer data)
+clientMoveEventFilter (XfwmEvent *event, gpointer data)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
@@ -892,16 +895,17 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
     moving = FLAG_TEST (c->xfwm_flags, XFWM_FLAG_MOVING_RESIZING);
 
     /* Update the display time */
-    myDisplayUpdateCurrentTime (display_info, xevent);
+    myDisplayUpdateCurrentTime (display_info, event);
 
-    if (xevent->type == KeyPress)
+    if (event->meta.type == XFWM_EVENT_KEY && event->key.pressed)
     {
         int key_move;
 
-        while (XCheckMaskEvent (display_info->dpy, KeyPressMask, xevent))
+        while (xfwm_device_check_mask_event (display_info->devices, display_info->dpy,
+                                             KeyPressMask, event))
         {
             /* Update the display time */
-            myDisplayUpdateCurrentTime (display_info, xevent);
+            myDisplayUpdateCurrentTime (display_info, event);
         }
 
         key_move = 16;
@@ -909,23 +913,23 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
         {
             key_move = MAX (key_move, screen_info->params->snap_width + 1);
         }
-        if (xevent->xkey.keycode == screen_info->params->keys[KEY_LEFT].keycode)
+        if (event->key.keycode == screen_info->params->keys[KEY_LEFT].keycode)
         {
             clientMovePointer (display_info, -1, 0, key_move);
         }
-        else if (xevent->xkey.keycode == screen_info->params->keys[KEY_RIGHT].keycode)
+        else if (event->key.keycode == screen_info->params->keys[KEY_RIGHT].keycode)
         {
             clientMovePointer (display_info, 1, 0, key_move);
         }
-        else if (xevent->xkey.keycode == screen_info->params->keys[KEY_UP].keycode)
+        else if (event->key.keycode == screen_info->params->keys[KEY_UP].keycode)
         {
             clientMovePointer (display_info, 0, -1, key_move);
         }
-        else if (xevent->xkey.keycode == screen_info->params->keys[KEY_DOWN].keycode)
+        else if (event->key.keycode == screen_info->params->keys[KEY_DOWN].keycode)
         {
             clientMovePointer (display_info, 0, 1, key_move);
         }
-        else if (xevent->xkey.keycode == screen_info->params->keys[KEY_CANCEL].keycode)
+        else if (event->key.keycode == screen_info->params->keys[KEY_CANCEL].keycode)
         {
             moving = FALSE;
             passdata->released = passdata->use_keys;
@@ -955,7 +959,7 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
 
             if (screen_info->current_ws != passdata->cancel_workspace)
             {
-                workspaceSwitch (screen_info, passdata->cancel_workspace, c, FALSE, xevent->xkey.time);
+                workspaceSwitch (screen_info, passdata->cancel_workspace, c, FALSE, event->key.time);
             }
             cancel_maximize_flags = passdata->cancel_flags & CLIENT_FLAG_MAXIMIZED;
             if (!FLAG_TEST_AND_NOT(c->flags, cancel_maximize_flags, CLIENT_FLAG_MAXIMIZED))
@@ -987,23 +991,25 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
         }
         else if (passdata->use_keys)
         {
-            moving = clientKeyPressIsModifier(xevent);
+            moving = clientKeyPressIsModifier(&event->key);
         }
     }
-    else if (xevent->type == ButtonRelease)
+    else if (event->meta.type == XFWM_EVENT_BUTTON && !event->button.pressed)
     {
         moving = FALSE;
         passdata->released = (passdata->use_keys ||
                               passdata->button == AnyButton ||
-                              passdata->button == xevent->xbutton.button);
+                              passdata->button == event->button.button);
     }
-    else if (xevent->type == MotionNotify)
+    else if (event->meta.type == XFWM_EVENT_MOTION)
     {
-        while (XCheckMaskEvent (display_info->dpy, PointerMotionMask | ButtonMotionMask, xevent))
+        while (xfwm_device_check_mask_event (display_info->devices, display_info->dpy,
+                                             PointerMotionMask | ButtonMotionMask, event))
         {
             /* Update the display time */
-            myDisplayUpdateCurrentTime (display_info, xevent);
+            myDisplayUpdateCurrentTime (display_info, event);
         }
+
         if (!passdata->grab && use_xor_move(screen_info))
         {
             myDisplayGrabServer (display_info);
@@ -1017,23 +1023,23 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
         if ((screen_info->workspace_count > 1) && !(passdata->is_transient))
         {
             clientMoveWarp (c, screen_info,
-                            &xevent->xmotion.x_root,
-                            &xevent->xmotion.y_root,
-                            xevent->xmotion.time);
+                            &event->motion.x_root,
+                            &event->motion.y_root,
+                            event->motion.time);
         }
 
         if (FLAG_TEST (c->flags, CLIENT_FLAG_RESTORE_SIZE_POS))
         {
 
-            if ((ABS (xevent->xmotion.x_root - passdata->mx) > 15) ||
-                (ABS (xevent->xmotion.y_root - passdata->my) > 15))
+            if ((ABS (event->motion.x_root - passdata->mx) > 15) ||
+                (ABS (event->motion.y_root - passdata->my) > 15))
             {
                 gboolean size_changed;
                 /* to keep the distance from the edges of the window proportional. */
                 double xratio, yratio;
 
-                xratio = (xevent->xmotion.x_root - frameExtentX (c)) / (double) frameExtentWidth (c);
-                yratio = (xevent->xmotion.y_root - frameExtentY (c)) / (double) frameExtentHeight (c);
+                xratio = (event->motion.x_root - frameExtentX (c)) / (double) frameExtentWidth (c);
+                yratio = (event->motion.y_root - frameExtentY (c)) / (double) frameExtentHeight (c);
 
                 size_changed = clientToggleMaximized (c, c->flags & CLIENT_FLAG_MAXIMIZED, FALSE);
                 if (clientRestoreSizePos (c))
@@ -1063,16 +1069,16 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
             }
             else
             {
-                xevent->xmotion.x_root = c->x - passdata->ox + passdata->mx;
-                xevent->xmotion.y_root = c->y - passdata->oy + passdata->my;
+                event->motion.x_root = c->x - passdata->ox + passdata->mx;
+                event->motion.y_root = c->y - passdata->oy + passdata->my;
             }
         }
 
-        c->x = passdata->ox + (xevent->xmotion.x_root - passdata->mx);
-        c->y = passdata->oy + (xevent->xmotion.y_root - passdata->my);
+        c->x = passdata->ox + (event->motion.x_root - passdata->mx);
+        c->y = passdata->oy + (event->motion.y_root - passdata->my);
 
         clientSnapPosition (c, prev_x, prev_y);
-        if (clientMoveTile (c, (XMotionEvent *) xevent))
+        if (clientMoveTile (c, &event->motion))
         {
             passdata->configure_flags = CFG_FORCE_REDRAW;
             passdata->move_resized = TRUE;
@@ -1118,7 +1124,7 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
             passdata->configure_flags = NO_CFG_FLAG;
         }
     }
-    else if ((xevent->type == UnmapNotify) && (xevent->xunmap.window == c->window))
+    else if ((event->meta.x->type == UnmapNotify) && (event->meta.window == c->window))
     {
         moving = FALSE;
         status = EVENT_FILTER_CONTINUE;
@@ -1128,7 +1134,7 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
             clientDrawOutline (c);
         }
     }
-    else if (xevent->type == EnterNotify)
+    else if (event->meta.type == XFWM_EVENT_CROSSING && event->crossing.enter)
     {
         /* Ignore enter events */
     }
@@ -1150,7 +1156,7 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
 }
 
 void
-clientMove (Client * c, XEvent * ev)
+clientMove (Client * c, XfwmEventButton *event)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
@@ -1198,11 +1204,11 @@ clientMove (Client * c, XEvent * ev)
 
     clientSaveSizePos (c);
 
-    if (ev && (ev->type == ButtonPress))
+    if (event && event->pressed)
     {
-        passdata.button = ev->xbutton.button;
-        passdata.mx = ev->xbutton.x_root;
-        passdata.my = ev->xbutton.y_root;
+        passdata.button = event->button;
+        passdata.mx = event->x_root;
+        passdata.my = event->y_root;
         passdata.px = passdata.mx - frameExtentX (c);
         passdata.py = passdata.my - frameExtentY (c);
     }
@@ -1212,10 +1218,9 @@ clientMove (Client * c, XEvent * ev)
         passdata.released = passdata.use_keys = TRUE;
     }
 
-    g1 = myScreenGrabKeyboard (screen_info, myDisplayGetCurrentTime (display_info));
-    g2 = myScreenGrabPointer (screen_info,
-                              FALSE,
-                              MOVERESIZE_EVENT_MASK,
+    g1 = myScreenGrabKeyboard (screen_info, MOVERESIZE_KEYBOARD_EVENT_MASK,
+                               myDisplayGetCurrentTime (display_info));
+    g2 = myScreenGrabPointer (screen_info, FALSE, MOVERESIZE_POINTER_EVENT_MASK,
                               myDisplayGetCursorMove (display_info),
                               myDisplayGetCurrentTime (display_info));
     if (!g1 || !g2)
@@ -1330,7 +1335,7 @@ move_cleanup:
 }
 
 static gboolean
-clientChangeHandle(MoveResizeData *passdata, int handle)
+clientChangeHandle (MoveResizeData *passdata, XfwmEvent *event, int handle)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
@@ -1351,7 +1356,7 @@ clientChangeHandle(MoveResizeData *passdata, int handle)
     {
         cursor = myDisplayGetCursorMove (display_info);
     }
-    grab = myScreenChangeGrabPointer (screen_info, MOVERESIZE_EVENT_MASK,
+    grab = myScreenChangeGrabPointer (screen_info, FALSE, MOVERESIZE_POINTER_EVENT_MASK,
                                       cursor, myDisplayGetCurrentTime (display_info));
 
     return (grab);
@@ -1388,7 +1393,7 @@ clientResizeConfigure (Client *c, int pw, int ph)
 }
 
 static eventFilterStatus
-clientResizeEventFilter (XEvent * xevent, gpointer data)
+clientResizeEventFilter (XfwmEvent *event, gpointer data)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
@@ -1444,16 +1449,17 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
     prev_height = c->height;
 
     /* Update the display time */
-    myDisplayUpdateCurrentTime (display_info, xevent);
+    myDisplayUpdateCurrentTime (display_info, event);
 
-    if (xevent->type == KeyPress)
+    if (event->meta.type == XFWM_EVENT_KEY && event->key.pressed)
     {
         int key_width_inc, key_height_inc;
 
-        while (XCheckMaskEvent (display_info->dpy, KeyPressMask, xevent))
+        while (xfwm_device_check_mask_event (display_info->devices, display_info->dpy,
+                                             KeyPressMask, event))
         {
             /* Update the display time */
-            myDisplayUpdateCurrentTime (display_info, xevent);
+            myDisplayUpdateCurrentTime (display_info, event);
         }
 
         key_width_inc = c->size->width_inc;
@@ -1468,7 +1474,7 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
             key_height_inc = ((int) (10 / key_height_inc)) * key_height_inc;
         }
 
-        if (xevent->xkey.keycode == screen_info->params->keys[KEY_UP].keycode)
+        if (event->key.keycode == screen_info->params->keys[KEY_UP].keycode)
         {
             if ((passdata->handle == CORNER_COUNT + SIDE_BOTTOM) ||
                 (passdata->handle == CORNER_COUNT + SIDE_TOP))
@@ -1477,10 +1483,10 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
             }
             else
             {
-                clientChangeHandle (passdata, CORNER_COUNT + SIDE_TOP);
+                clientChangeHandle (passdata, event, CORNER_COUNT + SIDE_TOP);
             }
         }
-        else if (xevent->xkey.keycode == screen_info->params->keys[KEY_DOWN].keycode)
+        else if (event->key.keycode == screen_info->params->keys[KEY_DOWN].keycode)
         {
             if ((passdata->handle == CORNER_COUNT + SIDE_BOTTOM) ||
                 (passdata->handle == CORNER_COUNT + SIDE_TOP))
@@ -1489,10 +1495,10 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
             }
             else
             {
-                clientChangeHandle (passdata, CORNER_COUNT + SIDE_BOTTOM);
+                clientChangeHandle (passdata, event, CORNER_COUNT + SIDE_BOTTOM);
             }
         }
-        else if (xevent->xkey.keycode == screen_info->params->keys[KEY_LEFT].keycode)
+        else if (event->key.keycode == screen_info->params->keys[KEY_LEFT].keycode)
         {
             if ((passdata->handle == CORNER_COUNT + SIDE_LEFT) ||
                 (passdata->handle == CORNER_COUNT + SIDE_RIGHT))
@@ -1501,10 +1507,10 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
             }
             else
             {
-                clientChangeHandle (passdata, CORNER_COUNT + SIDE_LEFT);
+                clientChangeHandle (passdata, event, CORNER_COUNT + SIDE_LEFT);
             }
         }
-        else if (xevent->xkey.keycode == screen_info->params->keys[KEY_RIGHT].keycode)
+        else if (event->key.keycode == screen_info->params->keys[KEY_RIGHT].keycode)
         {
             if ((passdata->handle == CORNER_COUNT + SIDE_LEFT) ||
                 (passdata->handle == CORNER_COUNT + SIDE_RIGHT))
@@ -1513,10 +1519,10 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
             }
             else
             {
-                clientChangeHandle (passdata, CORNER_COUNT + SIDE_RIGHT);
+                clientChangeHandle (passdata, event, CORNER_COUNT + SIDE_RIGHT);
             }
         }
-        else if (xevent->xkey.keycode == screen_info->params->keys[KEY_CANCEL].keycode)
+        else if (event->key.keycode == screen_info->params->keys[KEY_CANCEL].keycode)
         {
             resizing = FALSE;
             passdata->released = passdata->use_keys;
@@ -1549,18 +1555,19 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
         }
         else if (passdata->use_keys)
         {
-            resizing = clientKeyPressIsModifier(xevent);
+            resizing = clientKeyPressIsModifier(&event->key);
         }
     }
-    else if (xevent->type == MotionNotify)
+    else if (event->meta.type == XFWM_EVENT_MOTION)
     {
-        while (XCheckMaskEvent (display_info->dpy, ButtonMotionMask | PointerMotionMask, xevent))
+        while (xfwm_device_check_mask_event (display_info->devices, display_info->dpy,
+                                             ButtonMotionMask | PointerMotionMask, event))
         {
             /* Update the display time */
-            myDisplayUpdateCurrentTime (display_info, xevent);
+            myDisplayUpdateCurrentTime (display_info, event);
         }
 
-        if (xevent->type == ButtonRelease)
+        if (event->meta.x->type == ButtonRelease)
         {
             resizing = FALSE;
         }
@@ -1581,7 +1588,7 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
 
         if (move_left)
         {
-            c->width = passdata->ow - (xevent->xmotion.x_root - passdata->mx);
+            c->width = passdata->ow - (event->motion.x_root - passdata->mx);
             c->x = c->x - (c->width - passdata->oldw);
 
             /* Snap the left edge to something. -Cliff */
@@ -1590,7 +1597,7 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
         }
         else if (move_right)
         {
-            c->width = passdata->ow + (xevent->xmotion.x_root - passdata->mx);
+            c->width = passdata->ow + (event->motion.x_root - passdata->mx);
 
             /* Attempt to snap the right edge to something. -Cliff */
             c->width = clientFindClosestEdgeX (c, c->x + c->width + frameExtentRight (c)) - c->x - frameExtentRight (c);
@@ -1600,7 +1607,7 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
         {
             if (move_top)
             {
-                c->height = passdata->oh - (xevent->xmotion.y_root - passdata->my);
+                c->height = passdata->oh - (event->motion.y_root - passdata->my);
                 c->y = c->y - (c->height - passdata->oldh);
 
                 /* Snap the top edge to something. -Cliff */
@@ -1609,7 +1616,7 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
             }
             else if (move_bottom)
             {
-                c->height = passdata->oh + (xevent->xmotion.y_root - passdata->my);
+                c->height = passdata->oh + (event->motion.y_root - passdata->my);
 
                 /* Attempt to snap the bottom edge to something. -Cliff */
                 c->height = clientFindClosestEdgeY (c, c->y + c->height + frameExtentBottom (c)) - c->y - frameExtentBottom (c);
@@ -1658,14 +1665,14 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
             clientResizeConfigure (c, prev_width, prev_height);
         }
     }
-    else if (xevent->type == ButtonRelease)
+    else if (event->meta.type == XFWM_EVENT_BUTTON && !event->button.pressed)
     {
         resizing = FALSE;
         passdata->released = (passdata->use_keys ||
                               passdata->button == AnyButton ||
-                              passdata->button == xevent->xbutton.button);
+                              passdata->button == event->button.button);
     }
-    else if ((xevent->type == UnmapNotify) && (xevent->xunmap.window == c->window))
+    else if ((event->meta.x->type == UnmapNotify) && (event->meta.window == c->window))
     {
         resizing = FALSE;
         status = EVENT_FILTER_CONTINUE;
@@ -1675,7 +1682,7 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
             clientDrawOutline (c);
         }
     }
-    else if (xevent->type == EnterNotify)
+    else if (event->meta.type == XFWM_EVENT_CROSSING && event->crossing.enter)
     {
         /* Ignore enter events */
     }
@@ -1696,7 +1703,7 @@ clientResizeEventFilter (XEvent * xevent, gpointer data)
 }
 
 void
-clientResize (Client * c, int handle, XEvent * ev)
+clientResize (Client * c, int handle, XfwmEventButton *event)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
@@ -1717,7 +1724,7 @@ clientResize (Client * c, int handle, XEvent * ev)
     {
         if (FLAG_TEST (c->xfwm_flags, XFWM_FLAG_HAS_MOVE))
         {
-            clientMove (c, ev);
+            clientMove (c, event);
         }
         return;
     }
@@ -1747,11 +1754,11 @@ clientResize (Client * c, int handle, XEvent * ev)
     w_orig = c->width;
     h_orig = c->height;
 
-    if (ev && (ev->type == ButtonPress))
+    if (event && event->pressed)
     {
-        passdata.button = ev->xbutton.button;
-        passdata.mx = ev->xbutton.x_root;
-        passdata.my = ev->xbutton.y_root;
+        passdata.button = event->button;
+        passdata.mx = event->x_root;
+        passdata.my = event->y_root;
     }
     else
     {
@@ -1767,8 +1774,9 @@ clientResize (Client * c, int handle, XEvent * ev)
         cursor = myDisplayGetCursorMove (display_info);
     }
 
-    g1 = myScreenGrabKeyboard (screen_info, myDisplayGetCurrentTime (display_info));
-    g2 = myScreenGrabPointer (screen_info, FALSE, MOVERESIZE_EVENT_MASK,
+    g1 = myScreenGrabKeyboard (screen_info, MOVERESIZE_KEYBOARD_EVENT_MASK,
+                               myDisplayGetCurrentTime (display_info));
+    g2 = myScreenGrabPointer (screen_info, FALSE, MOVERESIZE_POINTER_EVENT_MASK,
                               cursor, myDisplayGetCurrentTime (display_info));
 
     if (!g1 || !g2)
diff --git a/src/moveresize.h b/src/moveresize.h
index 7e4f2ea..f9bcce9 100644
--- a/src/moveresize.h
+++ b/src/moveresize.h
@@ -45,9 +45,9 @@ void                     clientMoveWarp                         (Client *,
                                                                  int *,
                                                                  guint32);
 void                     clientMove                             (Client *,
-                                                                 XEvent *);
+                                                                 XfwmEventButton *);
 void                     clientResize                           (Client *,
                                                                  int,
-                                                                 XEvent *);
+                                                                 XfwmEventButton *);
 
 #endif /* INC_MOVERESIZE_H */
diff --git a/src/netwm.c b/src/netwm.c
index bc354c6..501e251 100644
--- a/src/netwm.c
+++ b/src/netwm.c
@@ -601,7 +601,8 @@ clientNetMoveResize (Client * c, XClientMessageEvent * ev)
     int x_root, y_root, action, button;
     int corner;
     gboolean resize; /* true == resize, false == move */
-    XEvent *event;
+    XEvent *xevent;
+    XfwmEvent *event;
 
     g_return_if_fail (c != NULL);
     TRACE ("entering clientNetMoveResize");
@@ -614,7 +615,7 @@ clientNetMoveResize (Client * c, XClientMessageEvent * ev)
     y_root = (int) ev->data.l[1];
     action = (int) ev->data.l[2];
     button = (int) ev->data.l[3];
-    event  = (XEvent *) ev;
+    xevent  = (XEvent *) ev;
 
     /* We don't deal with button > 7, in such a case we pretent it's just any button */
     if (button > Button7)
@@ -625,69 +626,69 @@ clientNetMoveResize (Client * c, XClientMessageEvent * ev)
     corner = CORNER_BOTTOM_RIGHT;
     resize = TRUE;
 
-    event->xbutton.button = button;
-    event->xbutton.x_root = event->xkey.x_root = x_root;
-    event->xbutton.y_root = event->xkey.y_root = y_root;
-    event->xbutton.time = event->xkey.time = (Time) myDisplayGetCurrentTime (display_info);
+    xevent->xbutton.button = button;
+    xevent->xbutton.x_root = xevent->xkey.x_root = x_root;
+    xevent->xbutton.y_root = xevent->xkey.y_root = y_root;
+    xevent->xbutton.time = xevent->xkey.time = (Time) myDisplayGetCurrentTime (display_info);
 
     switch (action)
     {
         /* Keyboard */
         case NET_WM_MOVERESIZE_SIZE_KEYBOARD:
-            event->type = KeyPress;
+            xevent->type = KeyPress;
             corner = CORNER_BOTTOM_RIGHT;
             resize = TRUE; /* Resize */
             break;
         case NET_WM_MOVERESIZE_MOVE_KEYBOARD:
-            event->type = KeyPress;
+            xevent->type = KeyPress;
             resize = FALSE; /* Move */
             break;
 
         /* Sides */
         case NET_WM_MOVERESIZE_SIZE_TOP:
-            event->type = ButtonPress;
+            xevent->type = ButtonPress;
             corner = CORNER_COUNT + SIDE_TOP;
             resize = TRUE; /* Resize */
             break;
         case NET_WM_MOVERESIZE_SIZE_BOTTOM:
-            event->type = ButtonPress;
+            xevent->type = ButtonPress;
             corner = CORNER_COUNT + SIDE_BOTTOM;
             resize = TRUE; /* Resize */
             break;
         case NET_WM_MOVERESIZE_SIZE_RIGHT:
-            event->type = ButtonPress;
+            xevent->type = ButtonPress;
             corner = CORNER_COUNT + SIDE_RIGHT;
             resize = TRUE; /* Resize */
             break;
         case NET_WM_MOVERESIZE_SIZE_LEFT:
-            event->type = ButtonPress;
+            xevent->type = ButtonPress;
             corner = CORNER_COUNT + SIDE_LEFT;
             resize = TRUE; /* Resize */
             break;
 
         /* Corners */
         case NET_WM_MOVERESIZE_SIZE_TOPLEFT:
-            event->type = ButtonPress;
+            xevent->type = ButtonPress;
             corner = CORNER_TOP_LEFT;
             resize = TRUE; /* Resize */
             break;
         case NET_WM_MOVERESIZE_SIZE_TOPRIGHT:
-            event->type = ButtonPress;
+            xevent->type = ButtonPress;
             corner = CORNER_TOP_RIGHT;
             resize = TRUE; /* Resize */
             break;
         case NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT:
-            event->type = ButtonPress;
+            xevent->type = ButtonPress;
             corner = CORNER_BOTTOM_LEFT;
             resize = TRUE; /* Resize */
             break;
         case NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT:
-            event->type = ButtonPress;
+            xevent->type = ButtonPress;
             corner = CORNER_BOTTOM_RIGHT;
             resize = TRUE; /* Resize */
             break;
         case NET_WM_MOVERESIZE_MOVE:
-            event->type = ButtonPress;
+            xevent->type = ButtonPress;
             resize = FALSE; /* Move */
             break;
         case NET_WM_MOVERESIZE_CANCEL:
@@ -702,11 +703,15 @@ clientNetMoveResize (Client * c, XClientMessageEvent * ev)
     {
         if (resize && FLAG_TEST_ALL (c->xfwm_flags, XFWM_FLAG_HAS_RESIZE | XFWM_FLAG_IS_RESIZABLE))
         {
-            clientResize (c, corner, event);
+            event = xfwm_device_translate_event (display_info->devices, xevent, NULL);
+            clientResize (c, corner, event->meta.type == XFWM_EVENT_BUTTON ? &event->button : NULL);
+            xfwm_device_free_event (event);
         }
         else if (FLAG_TEST (c->xfwm_flags, XFWM_FLAG_HAS_MOVE))
         {
-            clientMove (c, event);
+            event = xfwm_device_translate_event (display_info->devices, xevent, NULL);
+            clientMove (c, event->meta.type == XFWM_EVENT_BUTTON ? &event->button : NULL);
+            xfwm_device_free_event (event);
         }
     }
 }
diff --git a/src/screen.c b/src/screen.c
index 3e8695a..3352f1d 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -426,7 +426,7 @@ myScreenGetGdkWindow (ScreenInfo *screen_info)
 }
 
 gboolean
-myScreenGrabKeyboard (ScreenInfo *screen_info, guint32 timestamp)
+myScreenGrabKeyboard (ScreenInfo *screen_info, guint event_mask, guint32 timestamp)
 {
     gboolean grab;
 
@@ -437,11 +437,11 @@ myScreenGrabKeyboard (ScreenInfo *screen_info, guint32 timestamp)
     grab = TRUE;
     if (screen_info->key_grabs == 0)
     {
-        grab = (XGrabKeyboard (myScreenGetXDisplay (screen_info),
-                               screen_info->xroot,
-                               TRUE,
-                               GrabModeAsync, GrabModeAsync,
-                               (Time) timestamp) == GrabSuccess);
+        grab = xfwm_device_grab (screen_info->display_info->devices,
+                                 &screen_info->display_info->devices->keyboard,
+                                 myScreenGetXDisplay (screen_info), screen_info->xroot,
+                                 TRUE, event_mask, GrabModeAsync, screen_info->xroot,
+                                 None, (Time) timestamp);
     }
     screen_info->key_grabs++;
     TRACE ("global key grabs %i", screen_info->key_grabs);
@@ -450,7 +450,8 @@ myScreenGrabKeyboard (ScreenInfo *screen_info, guint32 timestamp)
 }
 
 gboolean
-myScreenGrabPointer (ScreenInfo *screen_info, gboolean owner_events, unsigned int event_mask, Cursor cursor, guint32 timestamp)
+myScreenGrabPointer (ScreenInfo *screen_info, gboolean owner_events,
+                     guint event_mask, Cursor cursor, guint32 timestamp)
 {
     gboolean grab;
 
@@ -460,13 +461,11 @@ myScreenGrabPointer (ScreenInfo *screen_info, gboolean owner_events, unsigned in
     grab = TRUE;
     if (screen_info->pointer_grabs == 0)
     {
-        grab = (XGrabPointer (myScreenGetXDisplay (screen_info),
-                              screen_info->xroot,
-                              owner_events, event_mask,
-                              GrabModeAsync, GrabModeAsync,
-                              screen_info->xroot,
-                              cursor,
-                              (Time) timestamp) == GrabSuccess);
+        grab = xfwm_device_grab (screen_info->display_info->devices,
+                                 &screen_info->display_info->devices->pointer,
+                                 myScreenGetXDisplay (screen_info), screen_info->xroot,
+                                 owner_events, event_mask, GrabModeAsync, screen_info->xroot,
+                                 cursor, (Time) timestamp);
     }
     screen_info->pointer_grabs++;
     TRACE ("global pointer grabs %i", screen_info->pointer_grabs);
@@ -475,7 +474,8 @@ myScreenGrabPointer (ScreenInfo *screen_info, gboolean owner_events, unsigned in
 }
 
 gboolean
-myScreenChangeGrabPointer (ScreenInfo *screen_info, unsigned int event_mask, Cursor cursor, guint32 timestamp)
+myScreenChangeGrabPointer (ScreenInfo *screen_info, gboolean owner_events,
+                           guint event_mask, Cursor cursor, guint32 timestamp)
 {
     gboolean grab;
 
@@ -485,8 +485,19 @@ myScreenChangeGrabPointer (ScreenInfo *screen_info, unsigned int event_mask, Cur
     grab = FALSE;
     if (screen_info->pointer_grabs > 0)
     {
-        grab = (XChangeActivePointerGrab (myScreenGetXDisplay (screen_info),
-                                          event_mask, cursor, (Time) timestamp) == GrabSuccess);
+        if (screen_info->display_info->devices->pointer.xi2_device == None)
+        {
+            grab = (XChangeActivePointerGrab (myScreenGetXDisplay (screen_info),
+                                              event_mask, cursor, (Time) timestamp) == GrabSuccess);
+        }
+        else
+        {
+            grab = xfwm_device_grab (screen_info->display_info->devices,
+                                     &screen_info->display_info->devices->pointer,
+                                     myScreenGetXDisplay (screen_info), screen_info->xroot,
+                                     owner_events, event_mask, GrabModeAsync, screen_info->xroot,
+                                     cursor, (Time) timestamp);
+        }
     }
 
     return grab;
@@ -505,7 +516,9 @@ myScreenUngrabKeyboard (ScreenInfo *screen_info, guint32 timestamp)
     }
     if (screen_info->key_grabs == 0)
     {
-        XUngrabKeyboard (myScreenGetXDisplay (screen_info), (Time) timestamp);
+        xfwm_device_ungrab (screen_info->display_info->devices,
+                            &screen_info->display_info->devices->keyboard,
+                            myScreenGetXDisplay (screen_info), (Time) timestamp);
     }
     TRACE ("global key grabs %i", screen_info->key_grabs);
 
@@ -525,7 +538,9 @@ myScreenUngrabPointer (ScreenInfo *screen_info, guint32 timestamp)
     }
     if (screen_info->pointer_grabs == 0)
     {
-        XUngrabPointer (myScreenGetXDisplay (screen_info), (Time) timestamp);
+        xfwm_device_ungrab (screen_info->display_info->devices,
+                            &screen_info->display_info->devices->pointer,
+                            myScreenGetXDisplay (screen_info), (Time) timestamp);
     }
     TRACE ("global pointer grabs %i", screen_info->pointer_grabs);
 
@@ -545,7 +560,8 @@ myScreenGrabKeys (ScreenInfo *screen_info)
 
     for (i = FIRST_KEY; i < KEY_COUNT; i++)
     {
-        grabKey (dpy, &screen_info->params->keys[i], screen_info->xroot);
+        grabKey (screen_info->display_info->devices, dpy,
+                 &screen_info->params->keys[i], screen_info->xroot);
     }
 }
 
@@ -558,20 +574,21 @@ myScreenUngrabKeys (ScreenInfo *screen_info)
     g_return_if_fail (screen_info != NULL);
 
     dpy = myScreenGetXDisplay (screen_info);
-    ungrabKeys (dpy, screen_info->xroot);
+    ungrabKeys (screen_info->display_info->devices, dpy, screen_info->xroot);
 }
 
-int
-myScreenGetKeyPressed (ScreenInfo *screen_info, XKeyEvent * ev)
+gint
+myScreenGetKeyPressed (ScreenInfo *screen_info, XfwmEventKey *event)
 {
-    int key, state;
+    gint key;
+    guint state;
 
     TRACE ("entering myScreenGetKeyPressed");
 
-    state = ev->state & MODIFIER_MASK;
+    state = event->state & MODIFIER_MASK;
     for (key = 0; key < KEY_COUNT; key++)
     {
-        if ((screen_info->params->keys[key].keycode == ev->keycode)
+        if ((screen_info->params->keys[key].keycode == event->keycode)
             && (screen_info->params->keys[key].modifier == state))
         {
             break;
diff --git a/src/screen.h b/src/screen.h
index 5bb7905..14a2d84 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -237,14 +237,16 @@ Display                 *myScreenGetXDisplay                    (ScreenInfo *);
 GtkWidget               *myScreenGetGtkWidget                   (ScreenInfo *);
 GdkWindow               *myScreenGetGdkWindow                   (ScreenInfo *);
 gboolean                 myScreenGrabKeyboard                   (ScreenInfo *,
+                                                                 guint,
                                                                  guint32);
 gboolean                 myScreenGrabPointer                    (ScreenInfo *,
                                                                  gboolean,
-                                                                 unsigned int,
+                                                                 guint,
                                                                  Cursor,
                                                                  guint32);
 gboolean                 myScreenChangeGrabPointer              (ScreenInfo *,
-                                                                 unsigned int,
+                                                                 gboolean,
+                                                                 guint,
                                                                  Cursor,
                                                                  guint32);
 unsigned int             myScreenUngrabKeyboard                 (ScreenInfo *,
@@ -253,8 +255,8 @@ unsigned int             myScreenUngrabPointer                  (ScreenInfo *,
                                                                  guint32);
 void                     myScreenGrabKeys                       (ScreenInfo *);
 void                     myScreenUngrabKeys                     (ScreenInfo *);
-int                      myScreenGetKeyPressed                  (ScreenInfo *,
-                                                                 XKeyEvent *);
+gint                     myScreenGetKeyPressed                  (ScreenInfo *,
+                                                                 XfwmEventKey *);
 int                      myScreenGetModifierPressed             (ScreenInfo *);
 Client                  *myScreenGetClientFromWindow            (ScreenInfo *,
                                                                  Window,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list