/pidgin/main: a6493d38dc28: Use GdkDevice instead of keyboard an...

Elliott Sales de Andrade qulogic at pidgin.im
Wed Aug 15 04:28:34 EDT 2012


Changeset: a6493d38dc287f6d1e2472c70bd806f04962c8e2
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2012-08-15 03:12 -0400
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/a6493d38dc28

Description:

Use GdkDevice instead of keyboard and pointer grabs.

diffstat:

 pidgin/gtkconv.c                      |   37 ++++++++++--
 pidgin/gtkstatusbox.c                 |  101 ++++++++++++++++++++++-----------
 pidgin/gtkwhiteboard.c                |    5 +
 pidgin/plugins/gestures/stroke-draw.c |   16 +++++-
 4 files changed, 117 insertions(+), 42 deletions(-)

diffs (truncated from 389 to 300 lines):

diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -9021,9 +9021,12 @@ focus_win_cb(GtkWidget *w, GdkEventFocus
 }
 
 static void
-notebook_init_grab(PidginWindow *gtkwin, GtkWidget *widget)
+notebook_init_grab(PidginWindow *gtkwin, GtkWidget *widget, GdkEvent *event)
 {
 	static GdkCursor *cursor = NULL;
+#if GTK_CHECK_VERSION(3,0,0)
+	GdkDevice *device;
+#endif
 
 	gtkwin->in_drag = TRUE;
 
@@ -9038,6 +9041,14 @@ notebook_init_grab(PidginWindow *gtkwin,
 
 	/* Grab the pointer */
 	gtk_grab_add(gtkwin->notebook);
+#if GTK_CHECK_VERSION(3,0,0)
+	device = gdk_event_get_device(event);
+	if (!gdk_display_device_is_grabbed(gdk_device_get_display(device), device))
+		gdk_device_grab(device, gtk_widget_get_window(gtkwin->notebook),
+		                GDK_OWNERSHIP_WINDOW, FALSE,
+		                GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
+		                cursor, gdk_event_get_time(event));
+#else
 #ifndef _WIN32
 	/* Currently for win32 GTK+ (as of 2.2.1), gdk_pointer_is_grabbed will
 	   always be true after a button press. */
@@ -9045,7 +9056,8 @@ notebook_init_grab(PidginWindow *gtkwin,
 #endif
 		gdk_pointer_grab(gtk_widget_get_window(gtkwin->notebook), FALSE,
 		                 GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
-		                 NULL, cursor, GDK_CURRENT_TIME);
+		                 NULL, cursor, gdk_event_get_time(event));
+#endif
 }
 
 static gboolean
@@ -9063,7 +9075,7 @@ notebook_motion_cb(GtkWidget *widget, Gd
 		    e->y_root >= win->drag_max_y) {
 
 			    win->in_predrag = FALSE;
-			    notebook_init_grab(win, widget);
+			    notebook_init_grab(win, widget, (GdkEvent *)e);
 		    }
 	}
 	else { /* Otherwise, draw the arrows. */
@@ -9139,9 +9151,9 @@ notebook_leave_cb(GtkWidget *widget, Gdk
 	    e->y_root <  win->drag_min_y ||
 	    e->y_root >= win->drag_max_y) {
 
-		    win->in_predrag = FALSE;
-		    notebook_init_grab(win, widget);
-	    }
+		win->in_predrag = FALSE;
+		notebook_init_grab(win, widget, (GdkEvent *)e);
+	}
 
 	return TRUE;
 }
@@ -9311,6 +9323,9 @@ notebook_release_cb(GtkWidget *widget, G
 	gint dest_page_num = 0;
 	gboolean new_window = FALSE;
 	gboolean to_right = FALSE;
+#if GTK_CHECK_VERSION(3,0,0)
+	GdkDevice *device;
+#endif
 
 	/*
 	* Don't check to make sure that the event's window matches the
@@ -9320,10 +9335,18 @@ notebook_release_cb(GtkWidget *widget, G
 	if (e->button != 1 && e->type != GDK_BUTTON_RELEASE)
 		return FALSE;
 
+#if GTK_CHECK_VERSION(3,0,0)
+	device = gdk_event_get_device((GdkEvent *)e);
+	if (gdk_display_device_is_grabbed(gdk_device_get_display(device), device)) {
+		gdk_device_ungrab(device, gdk_event_get_time((GdkEvent *)e));
+		gtk_grab_remove(widget);
+	}
+#else
 	if (gdk_pointer_is_grabbed()) {
-		gdk_pointer_ungrab(GDK_CURRENT_TIME);
+		gdk_pointer_ungrab(gdk_event_get_time((GdkEvent *)e));
 		gtk_grab_remove(widget);
 	}
+#endif
 
 	if (!win->in_predrag && !win->in_drag)
 		return FALSE;
diff --git a/pidgin/gtkstatusbox.c b/pidgin/gtkstatusbox.c
--- a/pidgin/gtkstatusbox.c
+++ b/pidgin/gtkstatusbox.c
@@ -95,8 +95,8 @@ static gboolean pidgin_status_box_expose
 static void pidgin_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
 static void pidgin_status_box_redisplay_buddy_icon(PidginStatusBox *status_box);
 static void pidgin_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data);
-static void pidgin_status_box_popup(PidginStatusBox *box);
-static void pidgin_status_box_popdown(PidginStatusBox *box);
+static void pidgin_status_box_popup(PidginStatusBox *box, GdkEvent *event);
+static void pidgin_status_box_popdown(PidginStatusBox *box, GdkEvent *event);
 
 static void do_colorshift (GdkPixbuf *dest, GdkPixbuf *src, int shift);
 static void icon_choose_cb(const char *filename, gpointer data);
@@ -1136,7 +1136,7 @@ pidgin_status_box_regenerate(PidginStatu
 static gboolean
 combo_box_scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkWebView *webview)
 {
-	pidgin_status_box_popup(PIDGIN_STATUS_BOX(w));
+	pidgin_status_box_popup(PIDGIN_STATUS_BOX(w), (GdkEvent *)event);
 	return TRUE;
 }
 
@@ -1381,28 +1381,52 @@ pidgin_status_box_list_position (PidginS
 }
 
 static gboolean
-popup_grab_on_window (GdkWindow *window,
-		      guint32    activate_time)
+popup_grab_on_window(GdkWindow *window, GdkEvent *event)
 {
-	if ((gdk_pointer_grab (window, TRUE,
-			 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
-			 GDK_POINTER_MOTION_MASK,
-			 NULL, NULL, activate_time) == 0))
+	guint32 activate_time = gdk_event_get_time(event);
+#if GTK_CHECK_VERSION(3,0,0)
+	GdkDevice *device = gdk_event_get_device(event);
+	GdkGrabStatus status;
+
+	status = gdk_device_grab(device, window, GDK_OWNERSHIP_WINDOW, TRUE,
+	                         GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+	                         GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK |
+	                         GDK_KEY_RELEASE_MASK, NULL, activate_time);
+	if (status == GDK_GRAB_SUCCESS) {
+		status = gdk_device_grab(gdk_device_get_associated_device(device),
+		                         window, GDK_OWNERSHIP_WINDOW, TRUE,
+		                         GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+		                         GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK |
+		                         GDK_KEY_RELEASE_MASK, NULL, activate_time);
+		if (status == GDK_GRAB_SUCCESS)
+			return TRUE;
+		else
+			gdk_device_ungrab(device, activate_time);
+	}
+
+	return FALSE;
+#else
+	if ((gdk_pointer_grab(window, TRUE,
+	                      GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+	                      GDK_POINTER_MOTION_MASK,
+	                      NULL, NULL, activate_time) == 0))
 	{
-		if (gdk_keyboard_grab (window, TRUE, activate_time) == 0)
+		if (gdk_keyboard_grab(window, TRUE, activate_time) == 0)
 			return TRUE;
 		else {
-			gdk_display_pointer_ungrab (gdk_window_get_display (window), activate_time);
+			gdk_display_pointer_ungrab(gdk_window_get_display(window),
+			                           activate_time);
 			return FALSE;
 		}
 	}
 
 	return FALSE;
+#endif
 }
 
 
 static void
-pidgin_status_box_popup(PidginStatusBox *box)
+pidgin_status_box_popup(PidginStatusBox *box, GdkEvent *event)
 {
 	int width, height, x, y;
 	pidgin_status_box_list_position (box, &x, &y, &width, &height);
@@ -1411,8 +1435,7 @@ pidgin_status_box_popup(PidginStatusBox 
 	gtk_window_move (GTK_WINDOW (box->popup_window), x, y);
 	gtk_widget_show(box->popup_window);
 	gtk_widget_grab_focus (box->tree_view);
-	if (!popup_grab_on_window (gtk_widget_get_window(box->popup_window),
-				   GDK_CURRENT_TIME)) {
+	if (!popup_grab_on_window(gtk_widget_get_window(box->popup_window), event)) {
 		gtk_widget_hide (box->popup_window);
 		return;
 	}
@@ -1429,15 +1452,25 @@ pidgin_status_box_popup(PidginStatusBox 
 }
 
 static void
-pidgin_status_box_popdown(PidginStatusBox *box)
+pidgin_status_box_popdown(PidginStatusBox *box, GdkEvent *event)
 {
+	guint32 time;
+#if GTK_CHECK_VERSION(3,0,0)
+	GdkDevice *device;
+#endif
 	gtk_widget_hide(box->popup_window);
 	box->popup_in_progress = FALSE;
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (box->toggle_button),
-				      FALSE);
-	gtk_grab_remove (box->popup_window);
-	gdk_pointer_ungrab(GDK_CURRENT_TIME);
-	gdk_keyboard_ungrab(GDK_CURRENT_TIME);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box->toggle_button), FALSE);
+	gtk_grab_remove(box->popup_window);
+	time = gdk_event_get_time(event);
+#if GTK_CHECK_VERSION(3,0,0)
+	device = gdk_event_get_device(event);
+	gdk_device_ungrab(device, time);
+	gdk_device_ungrab(gdk_device_get_associated_device(device), time);
+#else
+	gdk_pointer_ungrab(time);
+	gdk_keyboard_ungrab(time);
+#endif
 }
 
 static gboolean
@@ -1449,10 +1482,10 @@ toggle_key_press_cb(GtkWidget *widget, G
 		case GDK_KEY_KP_Space:
 		case GDK_KEY_space:
 			if (!box->popup_in_progress) {
-				pidgin_status_box_popup (box);
+				pidgin_status_box_popup(box, (GdkEvent *)event);
 				box->popup_in_progress = TRUE;
 			} else {
-				pidgin_status_box_popdown(box);
+				pidgin_status_box_popdown(box, (GdkEvent *)event);
 			}
 			return TRUE;
 		default:
@@ -1464,9 +1497,9 @@ static gboolean
 toggled_cb(GtkWidget *widget, GdkEventButton *event, PidginStatusBox *box)
 {
 	if (!box->popup_in_progress)
-		pidgin_status_box_popup (box);
+		pidgin_status_box_popup(box, (GdkEvent *)event);
 	else
-		pidgin_status_box_popdown(box);
+		pidgin_status_box_popdown(box, (GdkEvent *)event);
 	return TRUE;
 }
 
@@ -1574,13 +1607,13 @@ update_buddyicon_cb(const char *name, Pu
 }
 
 static void
-treeview_activate_current_selection(PidginStatusBox *status_box, GtkTreePath *path)
+treeview_activate_current_selection(PidginStatusBox *status_box, GtkTreePath *path, GdkEvent *event)
 {
 	if (status_box->active_row)
 		gtk_tree_row_reference_free(status_box->active_row);
 
 	status_box->active_row = gtk_tree_row_reference_new(GTK_TREE_MODEL(status_box->dropdown_store), path);
-	pidgin_status_box_popdown (status_box);
+	pidgin_status_box_popdown(status_box, event);
 	pidgin_status_box_changed(status_box);
 }
 
@@ -1596,7 +1629,7 @@ static void tree_view_delete_current_sel
 }
 
 static void
-tree_view_delete_current_selection(PidginStatusBox *status_box, GtkTreePath *path)
+tree_view_delete_current_selection(PidginStatusBox *status_box, GtkTreePath *path, GdkEvent *event)
 {
 	GtkTreeIter iter;
 	gpointer data;
@@ -1631,7 +1664,7 @@ tree_view_delete_current_selection(Pidgi
 
 	g_free(msg);
 
-	pidgin_status_box_popdown(status_box);
+	pidgin_status_box_popdown(status_box, event);
 }
 
 static gboolean
@@ -1645,7 +1678,7 @@ treeview_button_release_cb(GtkWidget *wi
 		if (ewidget == status_box->toggle_button &&
 		    status_box->popup_in_progress &&
 		    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (status_box->toggle_button))) {
-			pidgin_status_box_popdown (status_box);
+			pidgin_status_box_popdown(status_box, (GdkEvent *)event);
 			return TRUE;
 		} else if (ewidget == status_box->toggle_button) {
 			status_box->popup_in_progress = TRUE;
@@ -1653,7 +1686,7 @@ treeview_button_release_cb(GtkWidget *wi
 
 		/* released outside treeview */
 		if (ewidget != status_box->toggle_button) {
-				pidgin_status_box_popdown (status_box);
+				pidgin_status_box_popdown(status_box, (GdkEvent *)event);
 				return TRUE;
 		}
 
@@ -1668,7 +1701,7 @@ treeview_button_release_cb(GtkWidget *wi
 	if (!ret)



More information about the Commits mailing list