From beb73ece8fb57c480f4c49e46ed600c10db64b27 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 17 Jun 2005 17:26:24 +0000 Subject: [PATCH] Handle cursor theme changes for cached cursors which are not associated 2005-06-17 Matthias Clasen * gdk/x11/gdkprivate-x11.h: * gdk/x11/gdkcursor-x11.c: Handle cursor theme changes for cached cursors which are not associated with a window at the time of the theme change, by storing a serial number in each cursor, and updating the theme_serial counter whenever the cursor theme changes. * gdk/x11/gdkcursor-x11.c (_gdk_x11_cursor_update_theme): Private function to update a cursor to the current cursor theme if necessary. * gdk/x11/gdkmain-x11.c (gdk_pointer_grab): * gdk/x11/gdkwindow-x11.c (gdk_window_set_cursor): Call _gdk_x11_cursor_update_theme() here. --- ChangeLog | 17 +++++++++++++ ChangeLog.pre-2-10 | 17 +++++++++++++ ChangeLog.pre-2-8 | 17 +++++++++++++ gdk/x11/gdkcursor-x11.c | 54 ++++++++++++++++++++++++++++------------ gdk/x11/gdkmain-x11.c | 6 +++-- gdk/x11/gdkprivate-x11.h | 5 +++- gdk/x11/gdkwindow-x11.c | 5 +++- 7 files changed, 101 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b45444007..f605227dbd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2005-06-17 Matthias Clasen + + * gdk/x11/gdkprivate-x11.h: + * gdk/x11/gdkcursor-x11.c: Handle cursor theme changes + for cached cursors which are not associated with a window + at the time of the theme change, by storing a serial + number in each cursor, and updating the theme_serial + counter whenever the cursor theme changes. + + * gdk/x11/gdkcursor-x11.c (_gdk_x11_cursor_update_theme): + Private function to update a cursor to the current + cursor theme if necessary. + + * gdk/x11/gdkmain-x11.c (gdk_pointer_grab): + * gdk/x11/gdkwindow-x11.c (gdk_window_set_cursor): Call + _gdk_x11_cursor_update_theme() here. + 2005-06-17 Owen Taylor * gdk/gdkcairo.c (gdk_cairo_set_source_pixbuf): Fix diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 7b45444007..f605227dbd 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,20 @@ +2005-06-17 Matthias Clasen + + * gdk/x11/gdkprivate-x11.h: + * gdk/x11/gdkcursor-x11.c: Handle cursor theme changes + for cached cursors which are not associated with a window + at the time of the theme change, by storing a serial + number in each cursor, and updating the theme_serial + counter whenever the cursor theme changes. + + * gdk/x11/gdkcursor-x11.c (_gdk_x11_cursor_update_theme): + Private function to update a cursor to the current + cursor theme if necessary. + + * gdk/x11/gdkmain-x11.c (gdk_pointer_grab): + * gdk/x11/gdkwindow-x11.c (gdk_window_set_cursor): Call + _gdk_x11_cursor_update_theme() here. + 2005-06-17 Owen Taylor * gdk/gdkcairo.c (gdk_cairo_set_source_pixbuf): Fix diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 7b45444007..f605227dbd 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,20 @@ +2005-06-17 Matthias Clasen + + * gdk/x11/gdkprivate-x11.h: + * gdk/x11/gdkcursor-x11.c: Handle cursor theme changes + for cached cursors which are not associated with a window + at the time of the theme change, by storing a serial + number in each cursor, and updating the theme_serial + counter whenever the cursor theme changes. + + * gdk/x11/gdkcursor-x11.c (_gdk_x11_cursor_update_theme): + Private function to update a cursor to the current + cursor theme if necessary. + + * gdk/x11/gdkmain-x11.c (gdk_pointer_grab): + * gdk/x11/gdkwindow-x11.c (gdk_window_set_cursor): Call + _gdk_x11_cursor_update_theme() here. + 2005-06-17 Owen Taylor * gdk/gdkcairo.c (gdk_cairo_set_source_pixbuf): Fix diff --git a/gdk/x11/gdkcursor-x11.c b/gdk/x11/gdkcursor-x11.c index ccc757ff6b..4ebeb7be3c 100644 --- a/gdk/x11/gdkcursor-x11.c +++ b/gdk/x11/gdkcursor-x11.c @@ -46,6 +46,7 @@ #include #include "gdkalias.h" +static guint theme_serial = 0; /** * gdk_cursor_new_for_display: @@ -134,6 +135,8 @@ gdk_cursor_new_for_display (GdkDisplay *display, private->display = display; private->xcursor = xcursor; private->name = NULL; + private->serial = theme_serial; + cursor = (GdkCursor *) private; cursor->type = cursor_type; cursor->ref_count = 1; @@ -238,6 +241,8 @@ gdk_cursor_new_from_pixmap (GdkPixmap *source, private->display = display; private->xcursor = xcursor; private->name = NULL; + private->serial = theme_serial; + cursor = (GdkCursor *) private; cursor->type = GDK_CURSOR_IS_PIXMAP; cursor->ref_count = 1; @@ -390,27 +395,21 @@ gdk_cursor_get_image (GdkCursor *cursor) return pixbuf; } -static void -update_cursor (gpointer key, - gpointer value, - gpointer data) +void +_gdk_x11_cursor_update_theme (GdkCursor *cursor) { Display *xdisplay; - GdkCursor *cursor; GdkCursorPrivate *private; Cursor new_cursor = None; - if (!GDK_IS_WINDOW (value)) - return; - - cursor = _gdk_x11_window_get_cursor (GDK_WINDOW (value)); - - if (!cursor) - return; - private = (GdkCursorPrivate *) cursor; - xdisplay = (Display *)data; + xdisplay = GDK_DISPLAY_XDISPLAY (private->display); + if (private->serial == theme_serial) + return; + + private->serial = theme_serial; + if (private->xcursor != None) { if (cursor->type == GDK_CURSOR_IS_PIXMAP) @@ -426,6 +425,24 @@ update_cursor (gpointer key, } } +static void +update_cursor (gpointer key, + gpointer value, + gpointer data) +{ + GdkCursor *cursor; + + if (!GDK_IS_WINDOW (value)) + return; + + cursor = _gdk_x11_window_get_cursor (GDK_WINDOW (value)); + + if (!cursor) + return; + + _gdk_x11_cursor_update_theme (cursor); +} + /** * gdk_x11_display_set_cursor_theme: * @display: a #GdkDisplay @@ -468,11 +485,12 @@ gdk_x11_display_set_cursor_theme (GdkDisplay *display, old_theme && strcmp (old_theme, theme) == 0) return; + theme_serial++; + XcursorSetTheme (xdisplay, theme); XcursorSetDefaultSize (xdisplay, size); - g_hash_table_foreach (display_x11->xid_ht, - update_cursor, xdisplay); + g_hash_table_foreach (display_x11->xid_ht, update_cursor, NULL); } #else @@ -607,6 +625,8 @@ gdk_cursor_new_from_pixbuf (GdkDisplay *display, private->display = display; private->xcursor = xcursor; private->name = NULL; + private->serial = theme_serial; + cursor = (GdkCursor *) private; cursor->type = GDK_CURSOR_IS_PIXMAP; cursor->ref_count = 1; @@ -652,6 +672,8 @@ gdk_cursor_new_from_name (GdkDisplay *display, private->display = display; private->xcursor = xcursor; private->name = g_strdup (name); + private->serial = theme_serial; + cursor = (GdkCursor *) private; cursor->type = GDK_CURSOR_IS_PIXMAP; cursor->ref_count = 1; diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c index 21e369abf9..47b06cef77 100644 --- a/gdk/x11/gdkmain-x11.c +++ b/gdk/x11/gdkmain-x11.c @@ -194,8 +194,10 @@ gdk_pointer_grab (GdkWindow * window, if (!cursor) xcursor = None; else - xcursor = cursor_private->xcursor; - + { + _gdk_x11_cursor_update_theme (cursor); + xcursor = cursor_private->xcursor; + } xevent_mask = 0; for (i = 0; i < _gdk_nenvent_masks; i++) diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h index ef96554ede..222ae6ba0f 100644 --- a/gdk/x11/gdkprivate-x11.h +++ b/gdk/x11/gdkprivate-x11.h @@ -76,6 +76,7 @@ struct _GdkCursorPrivate Cursor xcursor; GdkDisplay *display; gchar *name; + guint serial; }; struct _GdkVisualPrivate @@ -98,7 +99,7 @@ gint _gdk_send_xevent (GdkDisplay *display, GType _gdk_gc_x11_get_type (void); -gboolean _gdk_x11_have_render (GdkDisplay *display); +gboolean _gdk_x11_have_render (GdkDisplay *display); GdkGC *_gdk_x11_gc_new (GdkDrawable *drawable, GdkGCValues *values, @@ -171,6 +172,8 @@ void _gdk_input_init (GdkDisplay *display); PangoRenderer *_gdk_x11_renderer_get (GdkDrawable *drawable, GdkGC *gc); +void _gdk_x11_cursor_update_theme (GdkCursor *cursor); + extern GdkDrawableClass _gdk_x11_drawable_class; extern gboolean _gdk_use_xshm; extern const int _gdk_nenvent_masks; diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index 04a6088112..87957a3cf0 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -2877,7 +2877,10 @@ gdk_window_set_cursor (GdkWindow *window, if (!cursor) xcursor = None; else - xcursor = cursor_private->xcursor; + { + _gdk_x11_cursor_update_theme (cursor); + xcursor = cursor_private->xcursor; + } if (!GDK_WINDOW_DESTROYED (window)) {