From 6f213290fe740621fc4d3f8bf20cbc6b47f5ea0c Mon Sep 17 00:00:00 2001 From: ZenWalker Date: Fri, 18 Aug 2017 02:57:02 +0200 Subject: gtk 3.22: avoid deprecated gdk_screen_get_monitor... functions: avoid deprecated: gdk_screen_get_monitor_geometry gdk_screen_get_monitor_at_window --- drivemount/drive-button.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'drivemount/drive-button.c') diff --git a/drivemount/drive-button.c b/drivemount/drive-button.c index 2c93ce75..6bc598a5 100644 --- a/drivemount/drive-button.c +++ b/drivemount/drive-button.c @@ -176,6 +176,25 @@ drive_button_unrealize (GtkWidget *widget) } #endif /* 0 */ +#if GTK_CHECK_VERSION(3, 22, 0) +static int +_gtk_get_monitor_num (GdkMonitor *monitor) +{ + GdkDisplay *display; + int n_monitors, i; + + display = gdk_monitor_get_display(monitor); + n_monitors = gdk_display_get_n_monitors(display); + + for(i = 0; i < n_monitors; i++) + { + if(gdk_display_get_monitor(display, i) == monitor) return i; + } + + return -1; +} +#endif + /* the following function is adapted from gtkmenuitem.c */ static void position_menu (GtkMenu *menu, gint *x, gint *y, @@ -188,7 +207,12 @@ position_menu (GtkMenu *menu, gint *x, gint *y, GtkRequisition requisition; GtkTextDirection direction; GdkRectangle monitor; +#if GTK_CHECK_VERSION (3, 22, 0) + GdkMonitor *monitor_num; + GdkDisplay *display; +#else gint monitor_num; +#endif g_return_if_fail (menu != NULL); g_return_if_fail (x != NULL); @@ -203,9 +227,17 @@ position_menu (GtkMenu *menu, gint *x, gint *y, theight = requisition.height; screen = gtk_widget_get_screen (GTK_WIDGET (menu)); +#if GTK_CHECK_VERSION (3, 22, 0) + display =gdk_screen_get_display (screen); + monitor_num = gdk_display_get_monitor_at_window (display, gtk_widget_get_window (widget)); + if (monitor_num == NULL) + monitor_num = gdk_display_get_monitor (display, 0); + gdk_monitor_get_geometry (monitor_num, &monitor); +#else monitor_num = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (widget)); if (monitor_num < 0) monitor_num = 0; gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); +#endif if (!gdk_window_get_origin (gtk_widget_get_window (widget), &tx, &ty)) { g_warning ("Menu not on screen"); @@ -230,7 +262,12 @@ position_menu (GtkMenu *menu, gint *x, gint *y, *x = CLAMP (tx, monitor.x, MAX (monitor.x, monitor.x + monitor.width - twidth)); *y = ty; + +#if GTK_CHECK_VERSION (3, 22, 0) + gtk_menu_set_monitor (menu, _gtk_get_monitor_num (monitor_num)); +#else gtk_menu_set_monitor (menu, monitor_num); +#endif } static gboolean -- cgit v1.2.1