[gtk+] gtk: Use gtk_widget_set_cursor()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtk: Use gtk_widget_set_cursor()
- Date: Sat, 4 Nov 2017 00:45:11 +0000 (UTC)
commit a409320cda345c4a456b5ae2fdd10d10f30ab0a8
Author: Benjamin Otte <otte redhat com>
Date: Sat Nov 4 01:37:03 2017 +0100
gtk: Use gtk_widget_set_cursor()
... and gtk_widget_set_cursor_from_name() instead of setting cursors on
GdkWindows.
gtk/gtkaboutdialog.c | 35 ++---------------------------------
gtk/gtkcolorplane.c | 19 +++----------------
gtk/gtkentry.c | 11 ++---------
gtk/gtkfilechooserwidget.c | 14 ++------------
gtk/gtklabel.c | 15 ++++-----------
gtk/gtklinkbutton.c | 11 ++---------
gtk/gtkpaned.c | 9 ++-------
gtk/gtkplacesview.c | 10 ++--------
gtk/gtkprintunixdialog.c | 10 ++--------
gtk/gtkrecentchooserdefault.c | 14 ++------------
gtk/gtkscrolledwindow.c | 6 +-----
gtk/gtktreeview.c | 5 +----
tests/testgtk.c | 12 +-----------
13 files changed, 26 insertions(+), 145 deletions(-)
---
diff --git a/gtk/gtkaboutdialog.c b/gtk/gtkaboutdialog.c
index d80ee1f..079cf4f 100644
--- a/gtk/gtkaboutdialog.c
+++ b/gtk/gtkaboutdialog.c
@@ -180,9 +180,6 @@ struct _GtkAboutDialogPrivate
GtkWidget *license_view;
GtkWidget *system_view;
- GdkCursor *hand_cursor;
- GdkCursor *regular_cursor;
-
GSList *visited_links;
GtkLicense license_type;
@@ -224,8 +221,6 @@ static void gtk_about_dialog_set_property (GObject
guint prop_id,
const GValue *value,
GParamSpec *pspec);
-static void gtk_about_dialog_realize (GtkWidget *widget);
-static void gtk_about_dialog_unrealize (GtkWidget *widget);
static void gtk_about_dialog_show (GtkWidget *widget);
static void update_name_version (GtkAboutDialog *about);
static void follow_if_link (GtkAboutDialog *about,
@@ -320,8 +315,6 @@ gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
object_class->finalize = gtk_about_dialog_finalize;
widget_class->show = gtk_about_dialog_show;
- widget_class->realize = gtk_about_dialog_realize;
- widget_class->unrealize = gtk_about_dialog_unrealize;
klass->activate_link = gtk_about_dialog_activate_link;
@@ -848,30 +841,6 @@ gtk_about_dialog_finalize (GObject *object)
}
static void
-gtk_about_dialog_realize (GtkWidget *widget)
-{
- GtkAboutDialog *about = GTK_ABOUT_DIALOG (widget);
- GtkAboutDialogPrivate *priv = about->priv;
-
- GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->realize (widget);
-
- priv->hand_cursor = gdk_cursor_new_from_name ("pointer", NULL);
- priv->regular_cursor = gdk_cursor_new_from_name ("text", NULL);
-}
-
-static void
-gtk_about_dialog_unrealize (GtkWidget *widget)
-{
- GtkAboutDialog *about = GTK_ABOUT_DIALOG (widget);
- GtkAboutDialogPrivate *priv = about->priv;
-
- g_clear_object (&priv->hand_cursor);
- g_clear_object (&priv->regular_cursor);
-
- GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->unrealize (widget);
-}
-
-static void
gtk_about_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -2113,9 +2082,9 @@ set_cursor_if_appropriate (GtkAboutDialog *about,
priv->hovering_over_link = hovering_over_link;
if (hovering_over_link)
- gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device,
priv->hand_cursor);
+ gtk_widget_set_cursor_from_name (GTK_WIDGET (text_view), "pointer");
else
- gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device,
priv->regular_cursor);
+ gtk_widget_set_cursor_from_name (GTK_WIDGET (text_view), "text");
}
g_slist_free (tags);
diff --git a/gtk/gtkcolorplane.c b/gtk/gtkcolorplane.c
index 1c83374..023a4c2 100644
--- a/gtk/gtkcolorplane.c
+++ b/gtk/gtkcolorplane.c
@@ -212,23 +212,10 @@ static void
set_cross_cursor (GtkWidget *widget,
gboolean enabled)
{
- GdkCursor *cursor = NULL;
- GdkWindow *window;
- GdkDevice *device;
-
- window = gtk_widget_get_window (widget);
- device = gtk_gesture_get_device (GTK_COLOR_PLANE (widget)->priv->drag_gesture);
-
- if (!window || !device)
- return;
-
if (enabled)
- cursor = gdk_cursor_new_from_name ("crosshair", NULL);
-
- gdk_window_set_device_cursor (window, device, cursor);
-
- if (cursor)
- g_object_unref (cursor);
+ gtk_widget_set_cursor_from_name (widget, "crosshair");
+ else
+ gtk_widget_set_cursor (widget, NULL);
}
static void
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index e318c35..941c87d 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -2804,11 +2804,7 @@ _gtk_entry_get_display_text (GtkEntry *entry,
static void
set_text_cursor (GtkWidget *widget)
{
- GdkCursor *cursor;
-
- cursor = gdk_cursor_new_from_name ("text", NULL);
- gtk_widget_set_cursor (widget, cursor);
- g_clear_object (&cursor);
+ gtk_widget_set_cursor_from_name (widget, "text");
}
static void
@@ -2817,7 +2813,6 @@ update_cursors (GtkWidget *widget)
GtkEntry *entry = GTK_ENTRY (widget);
GtkEntryPrivate *priv = entry->priv;
EntryIconInfo *icon_info = NULL;
- GdkCursor *cursor;
gint i;
for (i = 0; i < MAX_ICONS; i++)
@@ -2829,9 +2824,7 @@ update_cursors (GtkWidget *widget)
(gtk_widget_get_sensitive (icon_info->widget) ||
(icon_info->nonactivatable && icon_info->target_list == NULL)))
{
- cursor = gdk_cursor_new_from_name ("default", NULL);
- gtk_widget_set_cursor (icon_info->widget, cursor);
- g_clear_object (&cursor);
+ gtk_widget_set_cursor_from_name (icon_info->widget, "default");
}
else
{
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index dcbd32e..f23e665 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -4314,26 +4314,16 @@ set_busy_cursor (GtkFileChooserWidget *impl,
{
GtkWidget *widget;
GtkWindow *toplevel;
- GdkDisplay *display;
- GdkCursor *cursor;
toplevel = get_toplevel (GTK_WIDGET (impl));
widget = GTK_WIDGET (toplevel);
if (!toplevel || !gtk_widget_get_realized (widget))
return;
- display = gtk_widget_get_display (widget);
-
if (busy)
- cursor = gdk_cursor_new_from_name ("progress", NULL);
+ gtk_widget_set_cursor_from_name (widget, "progress");
else
- cursor = NULL;
-
- gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
- gdk_display_flush (display);
-
- if (cursor)
- g_object_unref (cursor);
+ gtk_widget_set_cursor (widget, NULL);
}
static void
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 1a82368..9f7a7d6 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3756,24 +3756,17 @@ gtk_label_update_cursor (GtkLabel *label)
if (gtk_widget_get_realized (widget))
{
- GdkCursor *cursor;
-
if (gtk_widget_is_sensitive (widget))
{
if (priv->select_info->active_link)
- cursor = gdk_cursor_new_from_name ("pointer", NULL);
+ gtk_widget_set_cursor_from_name (widget, "pointer");
else if (priv->select_info->selectable)
- cursor = gdk_cursor_new_from_name ("text", NULL);
+ gtk_widget_set_cursor_from_name (widget, "text");
else
- cursor = NULL;
+ gtk_widget_set_cursor (widget, NULL);
}
else
- cursor = NULL;
-
- gtk_widget_set_cursor (widget, cursor);
-
- if (cursor)
- g_object_unref (cursor);
+ gtk_widget_set_cursor (widget, NULL);
}
}
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index 430d427..382776a 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -309,17 +309,10 @@ static void
set_hand_cursor (GtkWidget *widget,
gboolean show_hand)
{
- GdkCursor *cursor;
-
if (show_hand)
- cursor = gdk_cursor_new_from_name ("pointer", NULL);
+ gtk_widget_set_cursor_from_name (widget, "pointer");
else
- cursor = NULL;
-
- gtk_widget_set_cursor (widget, cursor);
-
- if (cursor)
- g_object_unref (cursor);
+ gtk_widget_set_cursor (widget, NULL);
}
static void
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index 66d3485..bf26a46 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -319,15 +319,10 @@ gtk_paned_motion_notify (GtkWidget *widget,
(gdk_rectangle_contains_point (&handle_area, x, y) ||
priv->panning))
{
- GdkCursor *cursor;
-
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- cursor = gdk_cursor_new_from_name ("col-resize", NULL);
+ gtk_widget_set_cursor_from_name (widget, "col-resize");
else
- cursor = gdk_cursor_new_from_name ("row-resize", NULL);
-
- gtk_widget_set_cursor (widget, cursor);
- g_object_unref (cursor);
+ gtk_widget_set_cursor_from_name (widget, "row-resize");
}
else
{
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index bda8b18..405c1a1 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -324,7 +324,6 @@ set_busy_cursor (GtkPlacesView *view,
{
GtkWidget *widget;
GtkWindow *toplevel;
- GdkCursor *cursor;
toplevel = get_toplevel (GTK_WIDGET (view));
widget = GTK_WIDGET (toplevel);
@@ -332,14 +331,9 @@ set_busy_cursor (GtkPlacesView *view,
return;
if (busy)
- cursor = gdk_cursor_new_from_name ("progress", NULL);
+ gtk_widget_set_cursor_from_name (widget, "progress");
else
- cursor = NULL;
-
- gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
-
- if (cursor)
- g_object_unref (cursor);
+ gtk_widget_set_cursor (widget, NULL);
}
/* Activates the given row, with the given flags as parameter */
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index 9f668b3..4480005 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -581,7 +581,6 @@ set_busy_cursor (GtkPrintUnixDialog *dialog,
{
GtkWidget *widget;
GtkWindow *toplevel;
- GdkCursor *cursor;
toplevel = get_toplevel (GTK_WIDGET (dialog));
widget = GTK_WIDGET (toplevel);
@@ -590,14 +589,9 @@ set_busy_cursor (GtkPrintUnixDialog *dialog,
return;
if (busy)
- cursor = gdk_cursor_new_from_name ("progress", NULL);
+ gtk_widget_set_cursor_from_name (widget, "progress");
else
- cursor = NULL;
-
- gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
-
- if (cursor)
- g_object_unref (cursor);
+ gtk_widget_set_cursor (widget, NULL);
}
/* This function handles error messages before printing.
diff --git a/gtk/gtkrecentchooserdefault.c b/gtk/gtkrecentchooserdefault.c
index 41d06e4..4eca2d4 100644
--- a/gtk/gtkrecentchooserdefault.c
+++ b/gtk/gtkrecentchooserdefault.c
@@ -626,25 +626,15 @@ set_busy_cursor (GtkRecentChooserDefault *impl,
gboolean busy)
{
GtkWindow *toplevel;
- GdkDisplay *display;
- GdkCursor *cursor;
toplevel = get_toplevel (GTK_WIDGET (impl));
if (!toplevel || !gtk_widget_get_realized (GTK_WIDGET (toplevel)))
return;
- display = gtk_widget_get_display (GTK_WIDGET (toplevel));
-
if (busy)
- cursor = gdk_cursor_new_from_name ("progress", NULL);
+ gtk_widget_set_cursor_from_name (GTK_WIDGET (toplevel), "progress");
else
- cursor = NULL;
-
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (toplevel)), cursor);
- gdk_display_flush (display);
-
- if (cursor)
- g_object_unref (cursor);
+ gtk_widget_set_cursor (GTK_WIDGET (toplevel), NULL);
}
static void
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 9db5cf1..583e022 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -3194,11 +3194,7 @@ gtk_scrolled_window_allocate_scrollbar (GtkScrolledWindow *scrolled_window,
static void
install_scroll_cursor (GtkScrolledWindow *scrolled_window)
{
- GdkCursor *cursor;
-
- cursor = gdk_cursor_new_from_name ("all-scroll", NULL);
- gtk_widget_set_cursor (GTK_WIDGET (scrolled_window), cursor);
- g_clear_object (&cursor);
+ gtk_widget_set_cursor_from_name (GTK_WIDGET (scrolled_window), "all-scroll");
}
static void
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 680db99..3b83677 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -4507,10 +4507,7 @@ gtk_tree_view_motion (GtkWidget *widget,
if (_gtk_tree_view_column_coords_in_resize_rect (column, x, y))
{
- GdkCursor *cursor = gdk_cursor_new_from_name ("col-resize", NULL);
-
- gtk_widget_set_cursor (widget, cursor);
- g_object_unref (cursor);
+ gtk_widget_set_cursor_from_name (widget, "col-resize");
cursor_set = TRUE;
break;
}
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 3b70e33..579e27b 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -3849,19 +3849,9 @@ set_cursor_from_name (GtkWidget *entry,
GtkWidget *widget)
{
const gchar *name;
- GdkCursor *cursor;
name = gtk_entry_get_text (GTK_ENTRY (entry));
- cursor = gdk_cursor_new_from_name (name, NULL);
-
- if (cursor == NULL)
- {
- name = NULL;
- cursor = gdk_cursor_new_from_name ("none", NULL);
- }
-
- gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
- g_object_unref (cursor);
+ gtk_widget_set_cursor_from_name (widget, name);
g_object_set_data_full (G_OBJECT (widget), "name", g_strdup (name), g_free);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]