Cache the browser's GDK cursor object

This commit is contained in:
Přemysl Eric Janouch 2021-11-13 13:40:10 +01:00
parent 7d972e9334
commit 1f0d6b24d8
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 8 additions and 8 deletions

View File

@ -45,6 +45,7 @@ struct _FastivBrowser {
GArray *layouted_rows; ///< [Row] GArray *layouted_rows; ///< [Row]
int selected; int selected;
GdkCursor *pointer; ///< Cached pointer cursor
cairo_surface_t *glow; ///< CAIRO_FORMAT_A8 mask cairo_surface_t *glow; ///< CAIRO_FORMAT_A8 mask
int item_border_x; ///< L/R .item margin + border int item_border_x; ///< L/R .item margin + border
int item_border_y; ///< T/B .item margin + border int item_border_y; ///< T/B .item margin + border
@ -285,6 +286,7 @@ fastiv_browser_finalize(GObject *gobject)
g_array_free(self->entries, TRUE); g_array_free(self->entries, TRUE);
g_array_free(self->layouted_rows, TRUE); g_array_free(self->layouted_rows, TRUE);
cairo_surface_destroy(self->glow); cairo_surface_destroy(self->glow);
g_clear_object(&self->pointer);
G_OBJECT_CLASS(fastiv_browser_parent_class)->finalize(gobject); G_OBJECT_CLASS(fastiv_browser_parent_class)->finalize(gobject);
} }
@ -345,6 +347,11 @@ fastiv_browser_realize(GtkWidget *widget)
gtk_widget_register_window(widget, window); gtk_widget_register_window(widget, window);
gtk_widget_set_window(widget, window); gtk_widget_set_window(widget, window);
gtk_widget_set_realized(widget, TRUE); gtk_widget_set_realized(widget, TRUE);
FastivBrowser *self = FASTIV_BROWSER(widget);
g_clear_object(&self->pointer);
self->pointer =
gdk_cursor_new_from_name(gdk_window_get_display(window), "pointer");
} }
static void static void
@ -410,14 +417,7 @@ fastiv_browser_motion_notify_event(GtkWidget *widget, GdkEventMotion *event)
const Entry *entry = entry_at(self, event->x, event->y); const Entry *entry = entry_at(self, event->x, event->y);
GdkWindow *window = gtk_widget_get_window(widget); GdkWindow *window = gtk_widget_get_window(widget);
if (entry) { gdk_window_set_cursor(window, entry ? self->pointer : NULL);
GdkCursor *cursor =
gdk_cursor_new_from_name(gdk_window_get_display(window), "pointer");
gdk_window_set_cursor(window, cursor);
g_object_unref(cursor);
} else {
gdk_window_set_cursor(window, NULL);
}
return TRUE; return TRUE;
} }