From ed4707d50588917c9dfc59bdeb8e5e8d34b394ed Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 6 Jul 2004 06:02:57 +0000 Subject: [PATCH] Improve positioning of keyboard-activated menus with Xinerama. Tue Jul 6 02:00:28 2004 Matthias Clasen * gtk/gtkfilechooserdefault.c (popup_position_func): * gtk/gtkentry.c (popup_position_func): * gtk/gtktextview.c (popup_position_func): Improve positioning of keyboard-activated menus with Xinerama. --- ChangeLog | 7 +++++ ChangeLog.pre-2-10 | 7 +++++ ChangeLog.pre-2-6 | 7 +++++ ChangeLog.pre-2-8 | 7 +++++ gtk/gtkentry.c | 16 ++++++++--- gtk/gtkfilechooserdefault.c | 55 ++++++++++++++++++++++++++++--------- gtk/gtktextview.c | 16 ++++++++--- 7 files changed, 94 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b0adc35b0..71369b7681 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Jul 6 02:00:28 2004 Matthias Clasen + + * gtk/gtkfilechooserdefault.c (popup_position_func): + * gtk/gtkentry.c (popup_position_func): + * gtk/gtktextview.c (popup_position_func): Improve positioning + of keyboard-activated menus with Xinerama. + Tue Jul 6 00:29:03 2004 Matthias Clasen * gtk/gtkuimanager.c (do_updates): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 1b0adc35b0..71369b7681 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Tue Jul 6 02:00:28 2004 Matthias Clasen + + * gtk/gtkfilechooserdefault.c (popup_position_func): + * gtk/gtkentry.c (popup_position_func): + * gtk/gtktextview.c (popup_position_func): Improve positioning + of keyboard-activated menus with Xinerama. + Tue Jul 6 00:29:03 2004 Matthias Clasen * gtk/gtkuimanager.c (do_updates): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 1b0adc35b0..71369b7681 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Tue Jul 6 02:00:28 2004 Matthias Clasen + + * gtk/gtkfilechooserdefault.c (popup_position_func): + * gtk/gtkentry.c (popup_position_func): + * gtk/gtktextview.c (popup_position_func): Improve positioning + of keyboard-activated menus with Xinerama. + Tue Jul 6 00:29:03 2004 Matthias Clasen * gtk/gtkuimanager.c (do_updates): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 1b0adc35b0..71369b7681 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Tue Jul 6 02:00:28 2004 Matthias Clasen + + * gtk/gtkfilechooserdefault.c (popup_position_func): + * gtk/gtkentry.c (popup_position_func): + * gtk/gtktextview.c (popup_position_func): Improve positioning + of keyboard-activated menus with Xinerama. + Tue Jul 6 00:29:03 2004 Matthias Clasen * gtk/gtkuimanager.c (do_updates): diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index ff9919870a..2a7ec896a8 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -4150,18 +4150,26 @@ popup_position_func (GtkMenu *menu, GtkWidget *widget = GTK_WIDGET (entry); GdkScreen *screen = gtk_widget_get_screen (widget); GtkRequisition req; + gint monitor_num; + GdkRectangle monitor; g_return_if_fail (GTK_WIDGET_REALIZED (entry)); - gdk_window_get_origin (widget->window, x, y); - + gdk_window_get_origin (widget->window, x, y); + gtk_widget_size_request (entry->popup_menu, &req); *x += widget->allocation.width / 2; *y += widget->allocation.height; - *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width)); - *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height)); + monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y); + gtk_menu_set_monitor (menu, monitor_num); + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + + *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width)); + *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height)); + + *push_in = FALSE; } diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 19708c7d1d..9d690f24a2 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -2713,28 +2713,57 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) G_CALLBACK (show_hidden_toggled_cb), impl); } +static void +popup_position_func (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data) +{ + GtkWidget *widget = GTK_WIDGET (user_data); + GdkScreen *screen = gtk_widget_get_screen (widget); + GtkRequisition req; + gint monitor_num; + GdkRectangle monitor; + + g_return_if_fail (GTK_WIDGET_REALIZED (widget)); + + gdk_window_get_origin (widget->window, x, y); + + gtk_widget_size_request (GTK_WIDGET (menu), &req); + + *x += (widget->allocation.width - req.width) / 2; + *y += (widget->allocation.height - req.height) / 2; + + monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y); + gtk_menu_set_monitor (menu, monitor_num); + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + + *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width)); + *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height)); + + *push_in = FALSE; +} + static void file_list_popup_menu (GtkFileChooserDefault *impl, GdkEventButton *event) { - int button; - guint32 timestamp; - + file_list_build_popup_menu (impl); if (event) - { - button = event->button; - timestamp = event->time; - } + gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu), + NULL, NULL, NULL, NULL, + event->button, event->time); else { - button = 0; - timestamp = GDK_CURRENT_TIME; + gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu), + NULL, NULL, + popup_position_func, impl->browse_files_tree_view, + 0, GDK_CURRENT_TIME); + gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_files_popup_menu), + FALSE); } - file_list_build_popup_menu (impl); - gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu), - NULL, NULL, NULL, NULL, - button, timestamp); } /* Callback used for the GtkWidget::popup-menu signal of the file list */ diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 2c649ca4a0..84763ca3ba 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -6790,7 +6790,9 @@ popup_position_func (GtkMenu *menu, GtkTextIter iter; GtkRequisition req; GdkScreen *screen; - + gint monitor_num; + GdkRectangle monitor; + text_view = GTK_TEXT_VIEW (user_data); widget = GTK_WIDGET (text_view); @@ -6832,13 +6834,19 @@ popup_position_func (GtkMenu *menu, *x = root_x + (widget->allocation.width / 2 - req.width / 2); *y = root_y + (widget->allocation.height / 2 - req.height / 2); } - + /* Ensure sanity */ *x = CLAMP (*x, root_x, (root_x + widget->allocation.width)); *y = CLAMP (*y, root_y, (root_y + widget->allocation.height)); - *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width)); - *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height)); + monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y); + gtk_menu_set_monitor (menu, monitor_num); + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + + *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width)); + *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height)); + + *push_in = FALSE; } typedef struct