diff options
author | Alex Merry <dev@randomguy3.me.uk> | 2013-09-01 11:59:38 +0100 |
---|---|---|
committer | Alex Merry <dev@randomguy3.me.uk> | 2013-09-01 11:59:38 +0100 |
commit | 367a9dd91462b2f1b52292d3f9af3be8d325cddb (patch) | |
tree | 367b0f20aad8e373806d065e0636889730fefd07 /tikzit/src/gtk | |
parent | 3a212c1d5fd1f279559b36fd555473441e836562 (diff) |
GTK: delay setting cursor on non-realised windows
Calling -[WidgetSurface setCursor:] when the underlying GtkWidget has
not been realised yet used to result in a warning that the GdkWindow did
not exist. As a result, the cursor would not actually be set.
To deal with this, if the widget has not been realised, we delay setting
the cursor until it is.
Diffstat (limited to 'tikzit/src/gtk')
-rw-r--r-- | tikzit/src/gtk/WidgetSurface.m | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/tikzit/src/gtk/WidgetSurface.m b/tikzit/src/gtk/WidgetSurface.m index 680cf90..004e722 100644 --- a/tikzit/src/gtk/WidgetSurface.m +++ b/tikzit/src/gtk/WidgetSurface.m @@ -31,6 +31,8 @@ static gboolean motion_notify_event_cb (GtkWidget *widget, GdkEventMotion *event static gboolean key_press_event_cb (GtkWidget *widget, GdkEventKey *event, WidgetSurface *surface); static gboolean key_release_event_cb (GtkWidget *widget, GdkEventKey *event, WidgetSurface *surface); static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, WidgetSurface *surface); +static void set_cursor (GtkWidget *widget, GdkCursor *cursor); +static void unref_cursor (gpointer cursor, GClosure *closure); // }}} @interface WidgetSurface (Private) @@ -298,7 +300,6 @@ static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, Widge } - (void) setCursor:(Cursor)c { - GdkWindow *window = gtk_widget_get_window (widget); GdkCursor *cursor = NULL; switch (c) { case ResizeRightCursor: @@ -327,9 +328,19 @@ static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, Widge break; default: break; } - gdk_window_set_cursor (window, cursor); - if (cursor != NULL) { - gdk_cursor_unref (cursor); + GdkWindow *window = gtk_widget_get_window (widget); + g_signal_handlers_disconnect_matched (window, + G_SIGNAL_MATCH_FUNC, 0, 0, NULL, + G_CALLBACK (set_cursor), NULL); + if (window) { + gdk_window_set_cursor (window, cursor); + if (cursor != NULL) { + gdk_cursor_unref (cursor); + } + } else { + g_signal_connect_data (widget, + "realize", G_CALLBACK (set_cursor), cursor, + unref_cursor, 0); } } @@ -598,6 +609,22 @@ static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, Widge [pool drain]; return FALSE; } + +static void unref_cursor (gpointer cursor, GClosure *closure) { + if (cursor != NULL) { + gdk_cursor_unref ((GdkCursor*)cursor); + } +} + +static void set_cursor (GtkWidget *widget, GdkCursor *cursor) { + GdkWindow *window = gtk_widget_get_window (widget); + if (window) { + gdk_window_set_cursor (window, cursor); + if (cursor != NULL) { + gdk_cursor_unref (cursor); + } + } +} // }}} // vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker |