[mutter/wip/xinput2: 43/49] core: Make frame handle per-pointer cursors.



commit 855095ad1a34e04c080ce6ee07eeff514177eeac
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jul 4 19:24:04 2011 +0200

    core: Make frame handle per-pointer cursors.

 src/core/core.c  |   19 +++++++++++++++----
 src/core/core.h  |    7 ++++---
 src/core/frame.c |   36 +++++++++++++++++++-----------------
 src/core/frame.h |    5 +++--
 src/ui/frames.c  |   11 +++++++++++
 5 files changed, 52 insertions(+), 26 deletions(-)
---
diff --git a/src/core/core.c b/src/core/core.c
index 0b0d1f6..6c80876 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -757,13 +757,24 @@ meta_core_grab_buttons  (Display *xdisplay,
 }
 
 void
-meta_core_set_screen_cursor (Display *xdisplay,
-                             Window   frame_on_screen,
-                             MetaCursor cursor)
+meta_core_set_screen_cursor (Display    *xdisplay,
+                             Window      frame_on_screen,
+                             gint        device_id,
+                             MetaCursor  cursor)
 {
   MetaWindow *window = get_window (xdisplay, frame_on_screen);
+  MetaDevice *pointer;
+
+  pointer = meta_device_map_lookup (window->display->device_map,
+                                    device_id);
+
+  if (pointer == NULL)
+    return;
+
+  if (!META_IS_DEVICE_POINTER (pointer))
+    pointer = meta_device_get_paired_device (pointer);
 
-  meta_frame_set_screen_cursor (window->frame, cursor);
+  meta_frame_set_screen_cursor (window->frame, pointer, cursor);
 }
 
 void
diff --git a/src/core/core.h b/src/core/core.h
index 48171a7..28e753c 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -200,9 +200,10 @@ Window     meta_core_get_frame       (Display    *xdisplay,
 void       meta_core_grab_buttons  (Display *xdisplay,
                                     Window   frame_xwindow);
 
-void       meta_core_set_screen_cursor (Display *xdisplay,
-                                        Window   frame_on_screen,
-                                        MetaCursor cursor);
+void       meta_core_set_screen_cursor (Display    *xdisplay,
+                                        Window      frame_on_screen,
+                                        int         device_id,
+                                        MetaCursor  cursor);
 
 void       meta_core_select_events     (Display  *xdisplay,
                                         Window    xwindow,
diff --git a/src/core/frame.c b/src/core/frame.c
index 74015fd..130c03b 100644
--- a/src/core/frame.c
+++ b/src/core/frame.c
@@ -28,6 +28,7 @@
 #include "bell.h"
 #include <meta/errors.h>
 #include "keybindings-private.h"
+#include "device-pointer.h"
 
 #include <X11/extensions/Xrender.h>
 
@@ -64,7 +65,7 @@ meta_window_ensure_frame (MetaWindow *window)
   frame->child_y = 0;
   frame->bottom_height = 0;
   frame->right_width = 0;
-  frame->current_cursor = 0;
+  frame->cursors = g_hash_table_new (NULL, NULL);
 
   frame->mapped = FALSE;
   frame->need_reapply_frame_shape = TRUE;
@@ -229,9 +230,10 @@ meta_window_destroy_frame (MetaWindow *window)
 
   /* Move keybindings to window instead of frame */
   meta_window_grab_keys (window);
-  
+
+  g_hash_table_destroy (frame->cursors);
   g_free (frame);
-  
+
   /* Put our state back where it should be */
   meta_window_queue (window, META_QUEUE_CALC_SHOWING);
   meta_window_queue (window, META_QUEUE_MOVE_RESIZE);
@@ -425,22 +427,22 @@ meta_frame_queue_draw (MetaFrame *frame)
 }
 
 void
-meta_frame_set_screen_cursor (MetaFrame	*frame,
-			      MetaCursor cursor)
+meta_frame_set_screen_cursor (MetaFrame	 *frame,
+                              MetaDevice *pointer,
+			      MetaCursor  cursor)
 {
-  Cursor xcursor;
-  if (cursor == frame->current_cursor)
+  MetaCursor old_cursor;
+
+  old_cursor = GPOINTER_TO_UINT (g_hash_table_lookup (frame->cursors, pointer));
+
+  if (cursor == old_cursor)
     return;
-  frame->current_cursor = cursor;
-  if (cursor == META_CURSOR_DEFAULT)
-    XUndefineCursor (frame->window->display->xdisplay, frame->xwindow);
-  else
-    { 
-      xcursor = meta_display_create_x_cursor (frame->window->display, cursor);
-      XDefineCursor (frame->window->display->xdisplay, frame->xwindow, xcursor);
-      XFlush (frame->window->display->xdisplay);
-      XFreeCursor (frame->window->display->xdisplay, xcursor);
-    }
+
+  g_hash_table_insert (frame->cursors, pointer,
+                       GUINT_TO_POINTER (cursor));
+  meta_device_pointer_set_window_cursor (META_DEVICE_POINTER (pointer),
+                                         frame->xwindow, cursor);
+  XFlush (frame->window->display->xdisplay);
 }
 
 Window
diff --git a/src/core/frame.h b/src/core/frame.h
index 7a637e8..03c4a7c 100644
--- a/src/core/frame.h
+++ b/src/core/frame.h
@@ -45,7 +45,7 @@ struct _MetaFrame
   /* reparent window */
   Window xwindow;
 
-  MetaCursor current_cursor;
+  GHashTable *cursors;
 
   /* This rect is trusted info from where we put the
    * frame, not the result of ConfigureNotify
@@ -80,7 +80,8 @@ gboolean meta_frame_sync_to_window (MetaFrame         *frame,
 
 cairo_region_t *meta_frame_get_frame_bounds (MetaFrame *frame);
 
-void meta_frame_set_screen_cursor (MetaFrame	*frame,
+void meta_frame_set_screen_cursor (MetaFrame   *frame,
+                                   MetaDevice  *pointer,
 				   MetaCursor	cursor);
 
 #endif
diff --git a/src/ui/frames.c b/src/ui/frames.c
index 96a6167..079fbda 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -725,10 +725,18 @@ meta_frames_unmanage_window (MetaFrames *frames,
        */
       invalidate_all_caches (frames);
       
+#if 0
+      /* This function is only called when destroying the frame
+       * in core/frame.c, ideally this should be done for every
+       * device with a cursor on the frame, but in practical
+       * effects it doesn't matter.
+       */
+
       /* restore the cursor */
       meta_core_set_screen_cursor (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
                                    frame->xwindow,
                                    META_CURSOR_DEFAULT);
+#endif
 
       gdk_window_set_user_data (frame->window, NULL);
 
@@ -1971,8 +1979,10 @@ meta_frames_update_prelit_control (MetaFrames      *frames,
                                    MetaFrameControl control)
 {
   MetaFrameControl old_control;
+  GdkDevice *device;
   MetaCursor cursor;
 
+  device = gtk_get_current_event_device ();
 
   meta_verbose ("Updating prelit control from %u to %u\n",
                 frame->prelit_control, control);
@@ -2038,6 +2048,7 @@ meta_frames_update_prelit_control (MetaFrames      *frames,
   /* set/unset the prelight cursor */
   meta_core_set_screen_cursor (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
                                frame->xwindow,
+                               gdk_x11_device_get_id (device),
                                cursor);  
 
   switch (control)



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