From bf0c67b2af09e724fe290eafb227d3e7e597750c Mon Sep 17 00:00:00 2001
From: Valentin Voigt <mail@valentinvoigt.info>
Date: Thu, 11 Aug 2011 21:57:22 +0200
Subject: [PATCH] Warp cursor when changing workspace.

---
 include/xcb.h   |  6 ++++++
 src/workspace.c |  9 +++++++++
 src/xcb.c       | 10 ++++++++++
 3 files changed, 25 insertions(+)

diff --git a/include/xcb.h b/include/xcb.h
index 13fafb0b..4d7eafa0 100644
--- a/include/xcb.h
+++ b/include/xcb.h
@@ -152,4 +152,10 @@ void xcb_set_window_rect(xcb_connection_t *conn, xcb_window_t window, Rect r);
 
 bool xcb_reply_contains_atom(xcb_get_property_reply_t *prop, xcb_atom_t atom);
 
+/**
+ * Moves the mouse pointer into the middle of rect.
+ *
+ */
+void xcb_warp_pointer_rect(xcb_connection_t *conn, Rect *rect);
+
 #endif
diff --git a/src/workspace.c b/src/workspace.c
index 2fe96304..5dd25357 100644
--- a/src/workspace.c
+++ b/src/workspace.c
@@ -217,10 +217,19 @@ void workspace_show(const char *num) {
         }
     }
 
+    /* Memorize current output */
+    Con *old_output = con_get_output(focused);
+
     con_focus(next);
     workspace->fullscreen_mode = CF_OUTPUT;
     LOG("focused now = %p / %s\n", focused, focused->name);
 
+    /* Set mouse pointer */
+    Con *new_output = con_get_output(focused);
+    if (old_output != new_output) {
+       xcb_warp_pointer_rect(conn, &next->rect);
+    }
+
     /* Update the EWMH hints */
     if (changed_num_workspaces)
         ewmh_update_workarea();
diff --git a/src/xcb.c b/src/xcb.c
index 2c194013..a70f27fa 100644
--- a/src/xcb.c
+++ b/src/xcb.c
@@ -361,3 +361,13 @@ bool xcb_reply_contains_atom(xcb_get_property_reply_t *prop, xcb_atom_t atom) {
     return false;
 
 }
+
+/**
+ * Moves the mouse pointer into the middle of rect.
+ *
+ */
+void xcb_warp_pointer_rect(xcb_connection_t *conn, Rect *rect) {
+    xcb_warp_pointer(conn, XCB_NONE, root, 0, 0, 0, 0,
+        rect->x + (rect->width / 2),
+        rect->y + (rect->height / 2));
+}