diff --git a/lisp/frame.el b/lisp/frame.el index 02871e0551..d0ac29694c 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -1498,6 +1498,75 @@ frame-monitor-attributes for frames = (cdr (assq 'frames attributes)) if (memq frame frames) return attributes)) +(defun frame-monitor-attribute (attribute &optional frame x y) + "Return the value of the ATTRIBUTE of the current monitor. +If FRAME is omitted or nil, use currently selected frame. + +By default, the current monitor is said to be the physical +monitor dominating FRAME. A frame is dominated by a physical +monitor when either the largest area of the frame resides in the +monitor, or the monitor is the closest to the frame if the frame +does not intersect any physical monitors. + +If X and Y are both numbers, then ignore the value of FRAME; the +current monitor is determined to be the physical monitor that +contains the pixel coordinate (X, Y). + +See `display-monitor-attributes-list' for the list of attribute +keys and their meanings." + (if (and (numberp x) + (numberp y)) + (cl-loop for monitor in (display-monitor-attributes-list) + for geometry = (alist-get 'geometry monitor) + for min-x = (pop geometry) + for min-y = (pop geometry) + for max-x = (+ min-x (pop geometry)) + for max-y = (+ min-y (car geometry)) + when (and (<= min-x x) + (< x max-x) + (<= min-y y) + (< y max-y)) + return (alist-get attribute monitor)) + (alist-get attribute (frame-monitor-attributes frame)))) + +(defun frame-monitor-geometry (&optional frame x y) + "Return the geometry of the current monitor. +FRAME can be a frame name, a terminal name, or a frame. +If FRAME is omitted or nil, use the currently selected frame. + +By default, the current monitor is said to be the physical +monitor dominating FRAME. A frame is dominated by a physical +monitor when either the largest area of the frame resides in the +monitor, or the monitor is the closest to the frame if the frame +does not intersect any physical monitors. + +If X and Y are both numbers, then ignore the value of FRAME; the +current monitor is determined to be the physical monitor that +contains the pixel coordinate (X, Y). + +See `display-monitor-attributes-list' for information on the +geometry attribute." + (frame-monitor-attribute 'geometry frame x y)) + +(defun frame-monitor-workarea (&optional frame x y) + "Return the workarea of the current monitor. +FRAME can be a frame name, a terminal name, or a frame. +If FRAME is omitted or nil, use currently selected frame. + +By default, the current monitor is said to be the physical +monitor dominating FRAME. A frame is dominated by a physical +monitor when either the largest area of the frame resides in the +monitor, or the monitor is the closest to the frame if the frame +does not intersect any physical monitors. + +If X and Y are both numbers, then ignore the value of FRAME; the +current monitor is determined to be the physical monitor that +contains the pixel coordinate (X, Y). + +See `display-monitor-attributes-list' for information on the +workarea attribute." + (frame-monitor-attribute 'workarea frame x y)) + (declare-function x-frame-list-z-order "xfns.c" (&optional display)) (declare-function w32-frame-list-z-order "w32fns.c" (&optional display)) (declare-function ns-frame-list-z-order "nsfns.m" (&optional display)) diff --git a/src/xmenu.c b/src/xmenu.c index 2805249164..5aee85360d 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -1160,9 +1160,33 @@ 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 disp_width = -1; + int disp_height = -1; + + Lisp_Object frame, geometry; + + XSETFRAME (frame, data->f); + geometry = call3 (Qdisplay_monitor_geometry, + Qnil, + make_number (data->x), + make_number (data->y)); + + if (CONSP (geometry)) + { + int min_x, min_y; + + min_x = XINT (XCAR (geometry)); + min_y = XINT (Fnth (make_number (1), geometry)); + disp_width = min_x + XINT (Fnth (make_number (2), geometry)); + disp_height = min_y + XINT (Fnth (make_number (3), geometry)); + } + if ( disp_width < 0 || disp_height < 0 ) + { + struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (data->f); + + disp_width = x_display_pixel_width (dpyinfo); + disp_height = x_display_pixel_height (dpyinfo); + } *x = data->x; *y = data->y; @@ -2361,6 +2385,10 @@ syms_of_xmenu (void) DEFSYM (Qdebug_on_next_call, "debug-on-next-call"); defsubr (&Smenu_or_popup_active_p); +#ifdef USE_GTK + DEFSYM (Qdisplay_monitor_geometry, "display-monitor-geometry"); +#endif + #if defined (USE_GTK) || defined (USE_X_TOOLKIT) defsubr (&Sx_menu_bar_open_internal); Ffset (intern_c_string ("accelerate-menu"),