summaryrefslogtreecommitdiff
path: root/src/xmenu.c
diff options
context:
space:
mode:
authorAlexander Gramiak <agrambot@gmail.com>2017-06-10 12:28:03 +0300
committerEli Zaretskii <eliz@gnu.org>2017-06-10 12:28:03 +0300
commitbdf41152af3434307218ac2863b737c4486f740e (patch)
treed8c2275a5814aa0c3be2761c1282b30007551bc1 /src/xmenu.c
parent187a71df596a331a23bf86ee314c12035f42aff2 (diff)
downloademacs-bdf41152af3434307218ac2863b737c4486f740e.tar.gz
Fix the placement of GTK menus on multi-monitor systems
menu_position_func did not properly use the current monitor's resolution. Also see commit '2016-02-06 22:12:53 +0100'. * lisp/frame.el (frame-monitor-attribute, frame-monitor-geometry) (frame-monitor-workarea): New functions. * src/xmenu.c (menu_position_func): Take into account the workarea of the monitor that contains the mouse. (Bug#23568)
Diffstat (limited to 'src/xmenu.c')
-rw-r--r--src/xmenu.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/xmenu.c b/src/xmenu.c
index 28052491646..6c8a0c506cc 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -1160,9 +1160,37 @@ menu_position_func (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer
{
struct next_popup_x_y *data = user_data;
GtkRequisition req;
- struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (data->f);
- int disp_width = x_display_pixel_width (dpyinfo);
- int disp_height = x_display_pixel_height (dpyinfo);
+ int max_x = -1;
+ int max_y = -1;
+
+ Lisp_Object frame, workarea;
+
+ XSETFRAME (frame, data->f);
+
+ /* TODO: Get the monitor workarea directly without calculating other
+ items in x-display-monitor-attributes-list. */
+ workarea = call3 (Qframe_monitor_workarea,
+ Qnil,
+ make_number (data->x),
+ make_number (data->y));
+
+ if (CONSP (workarea))
+ {
+ int min_x, min_y;
+
+ min_x = XINT (XCAR (workarea));
+ min_y = XINT (Fnth (make_number (1), workarea));
+ max_x = min_x + XINT (Fnth (make_number (2), workarea));
+ max_y = min_y + XINT (Fnth (make_number (3), workarea));
+ }
+
+ if (max_x < 0 || max_y < 0)
+ {
+ struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (data->f);
+
+ max_x = x_display_pixel_width (dpyinfo);
+ max_y = x_display_pixel_height (dpyinfo);
+ }
*x = data->x;
*y = data->y;
@@ -1170,10 +1198,10 @@ menu_position_func (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer
/* Check if there is room for the menu. If not, adjust x/y so that
the menu is fully visible. */
gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &req);
- if (data->x + req.width > disp_width)
- *x -= data->x + req.width - disp_width;
- if (data->y + req.height > disp_height)
- *y -= data->y + req.height - disp_height;
+ if (data->x + req.width > max_x)
+ *x -= data->x + req.width - max_x;
+ if (data->y + req.height > max_y)
+ *y -= data->y + req.height - max_y;
}
static void
@@ -2361,6 +2389,10 @@ syms_of_xmenu (void)
DEFSYM (Qdebug_on_next_call, "debug-on-next-call");
defsubr (&Smenu_or_popup_active_p);
+#ifdef USE_GTK
+ DEFSYM (Qframe_monitor_workarea, "frame-monitor-workarea");
+#endif
+
#if defined (USE_GTK) || defined (USE_X_TOOLKIT)
defsubr (&Sx_menu_bar_open_internal);
Ffset (intern_c_string ("accelerate-menu"),