From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: Emacs's set-frame-size can not work well with gnome-shell? Date: Tue, 31 Mar 2020 19:04:11 +0200 Message-ID: <9b0577e5-61e2-e4fa-8c95-0a08a7392e5a@gmx.at> References: <2056a194.3971.16f8d4dd4c5.Coremail.tumashu@163.com> <4b114f01-d8d9-2c33-6312-1e2e60a5d462@yandex.ru> <127bb534-e77c-bad0-683b-92c206feeba1@yandex.ru> <2af76486-f976-eef0-683c-45b7ea6c54eb@gmx.at> <090b65ce-f90a-c959-c72b-be73d5a2eb19@yandex.ru> <15b20ca9-b684-1ad5-3a25-822a00736c69@yandex.ru> <945fb9b8-1563-d650-ea47-4edd42d69d5f@yandex.ru> <2855252a-b9e2-47d0-6d7a-d44fa32db36c@gmx.at> <9cb2f0f2-2f9a-5122-1813-742972ee25d2@yandex.ru> <87783b28-9998-3b92-60e4-5aa328e4967a@gmx.at> <02f9fa71-308c-c613-5039-a13005ffd48f@yandex.ru> <384dd180-b194-d2b7-0a2b-2725bf2a1360@yandex.ru> <5b27dc36-df18-d188-eab3-8bf546a8c24a@gmx.at> <6668f932-62d6-6eca-190d-d270e6999d65@yandex.ru> <033361f9-eb1c-c7e6-1473-04532d0eb88e@gmx.at> <9eda9f71-2719-bb97-db4a-5b1d4a1c2087@yandex.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------4AD11D60E7E48AC51911F0A5" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="68803"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "emacs-devel@gnu.org" To: Dmitry Gutov , tumashu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 31 19:07:52 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJKMh-000Hm0-Ph for ged-emacs-devel@m.gmane-mx.org; Tue, 31 Mar 2020 19:07:52 +0200 Original-Received: from localhost ([::1]:41946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJKMg-00053M-Kt for ged-emacs-devel@m.gmane-mx.org; Tue, 31 Mar 2020 13:07:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47114) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJKJT-0003UF-8B for emacs-devel@gnu.org; Tue, 31 Mar 2020 13:04:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJKJM-0000PW-BU for emacs-devel@gnu.org; Tue, 31 Mar 2020 13:04:29 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:49547) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJKJL-0000Ov-Kc for emacs-devel@gnu.org; Tue, 31 Mar 2020 13:04:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1585674253; bh=Rm55mwBpx0RxGefKlUTsQbW/Mcy1g6wVbpHDuebhhAU=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=NokNnqDf4rpovCnoPv34Ga9GL/PhpBcXNqZRTl650FXKJ3dwGpXyfZazA85tVz9T4 oFmn00DXfK1I8ixxau6davL8xIT4Tne1r5n55llqJq8TQ6peXzBHxzeLxDSQlZqphn llsnMNHQCYsZBPw0T56ktPARKtAVgbRIcn0rGpGQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [192.168.1.101] ([212.95.5.250]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N17UQ-1jCCpC3TIo-012bDJ; Tue, 31 Mar 2020 19:04:13 +0200 In-Reply-To: <9eda9f71-2719-bb97-db4a-5b1d4a1c2087@yandex.ru> Content-Language: en-US X-Provags-ID: V03:K1:r/8n9JS2G87IXimpDKEeSd1mAIeelDr7h8FrpSSjiK3aXs6nl0k TVC3mFJtWBLdKQ4OGXyq+er9UvRWeiOu2Rv9g0l49an1WrIz2nzwVqmDNpS2TPJDW39G2kC xYUSJ62ctIK9476Dr3Q6DV/76sXhs71VAXegFa5ftpfp8f289tZwj32H1W48SPqAYHtEhyy zx1DOCJnwSfK27XGspLyw== X-UI-Out-Filterresults: notjunk:1;V03:K0:cwjSlHonAQo=:+jV/JPHRHyTRrw+zx++uBr s4FY7/J15gtM8eFlRM13dUp9dx1MgdGoc3+b1kdGqHviagjggB7KujBAgkLog8zbNIXSHrwJe DBpFJAqcaKmF+JCQwMaBq+6zCYrenFr6ZS/PRV2CYbZcPw7c7Q+KOyUWQdShp7qQ54otNawkq XDfamhuUivtfcR6voSKljQoMcTVTBC5Cikm5ShYW9NVUd5lYUe6nyJt5pTbyG+gUTAmoZtAR/ m4ukFI3U8D4nVBlde+ipnDTWwOupG8zDBexnQxh4qT7uU1+MXrTPQ7I1CKIyxTeHxa7R7Mp2M +q08IG94I+oShH7Ykdfibx5JjHM/Ti+asWkWNYuWXQ1kGCqziUJoWrPk2pa9l49yU2sQmHJy0 AJWVy77/G8FOMjKNkLX0JsWkggdLJF0uj4Yfo+kTc9cTkujBz8HrF9LM3sSsos2BJDK6x6hF8 CMLuYEhmP4DZHIM7nlVDGTctpmbFWWiAsjhLrYXJnBvtaYw6y0bi789gK4Iposgi0eZ8gZKAe XmFVKClUMSv9gs0HE8vvBse7ITDluGWVSH7s8mJ2xzHDE5FdL5uB4fdI1U1rbYQnrXeVxqExG 1HS/sW9rzKJ9IFITBS0OkEiYdSbrgWzwPhBt1TLbztJ80VnTLMT04LhsZISIIwCCKFIK1A6gk igBrZEYL6BUiB3hQXPe8wSErCeXhjGtw3bLGESobb+83RIrmaGf2+3Ti7ovyTrl83D0BZR53i LIvPbdyZwzlnixFgSYwZIykky9gnt0v4faop1XiW0Yf1GcknXTLU1wy7kji35mWF2ncE6Qgi X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.21 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:246124 Archived-At: This is a multi-part message in MIME format. --------------4AD11D60E7E48AC51911F0A5 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit OK. Eli, I would like to install the attached patch for Emacs 27. All changes affect the resizing and moving of child frames only, normal frames are not affected. The Change Log below tries to explain why they are needed. One change (the addition of Fx_gtk_debug) is not needed but might be useful in order to debug GTK issues from inside Emacs if and when we receive more bug reports in this area. martin Fix problems with moving and resizing child frames (1) Re-implement 'mouse-drag-frame' via two new functions 'mouse-drag-frame-resize' and 'mouse-drag-frame-move'. This is needed because with some toolkits the notifications for frame movement and resizing arrive asynchronously, breaking any calculations using intermediate frame sizes and positions. (2) Provide new option 'x-gtk-resize-child-frames' which allows to either hide a child frame during resizing or asks GTK to resize it "immediately". This is needed because desktops like GNOME shell otherwise won't allow resizing child frames at all. (3) Do not try to synchronize the position of a child frame after moving it. Needed because the present implementation introduces a 0.5 secs delay which makes dragging child frames virtually impossible with Lucid and Motif toolkits on desktops like GNOME shell that use invisible outer frame borders. For further information see the thread starting with https://lists.gnu.org/archive/html/emacs-devel/2020-01/msg00343.html * lisp/mouse.el (mouse-drag-mode-line, mouse-drag-left-edge) (mouse-drag-top-left-corner, mouse-drag-top-edge) (mouse-drag-top-right-corner, mouse-drag-right-edge) (mouse-drag-bottom-right-corner, mouse-drag-bottom-edge) (mouse-drag-bottom-left-corner): Call 'mouse-drag-frame-resize' instead of 'mouse-drag-frame'. (mouse-drag-frame): Split into two new functions - 'mouse-drag-frame-move' and 'mouse-drag-frame-resize'. (mouse-drag-frame-resize, mouse-drag-frame-move): New functions to implement functionality of the removed 'mouse-drag-frame'. * src/frame.c (syms_of_frame): New symbol Qxg_frame_set_char_size_4 * src/gtkutil.c (xg_frame_set_char_size): Hide frame during resizing when 'x-gtk-resize-child-frames' equals 'hide'. * src/xfns.c (x_set_parent_frame, Fx_create_frame): Set gtk_container_resize_mode to GTK_RESIZE_IMMEDIATE when'x-gtk-resize-child-frames' equals 'resize-mode'. (Fx_gtk_debug): New function to toggle interactive GTK debugging from within Emacs. (syms_of_xfns): New symbols Qhide and Qresize_mode. (x-gtk-resize-child-frames): New option that allows to resize child frames on desktops like GNOME shell (with the mutter WM) that generally refuse to resize them. * src/xterm.c (x_set_offset): Don't x_sync_with_move for child frames, it makes moving child frames virtually impossible with the Lucid and Motif toolkits. --------------4AD11D60E7E48AC51911F0A5 Content-Type: text/x-patch; name="x-gtk-resize-child-frames.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x-gtk-resize-child-frames.diff" diff --git a/lisp/mouse.el b/lisp/mouse.el index e58a2e6da1..9703d957d5 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -552,7 +552,7 @@ mouse-drag-mode-line (not (eq (window-frame minibuffer-window) frame)))) ;; Drag frame when the window is on the bottom of its frame and ;; there is no minibuffer window below. - (mouse-drag-frame start-event 'move))))) + (mouse-drag-frame-move start-event))))) =20 (defun mouse-drag-header-line (start-event) "Change the height of a window by dragging on its header line. @@ -569,7 +569,7 @@ mouse-drag-header-line (mouse-drag-line start-event 'header) (let ((frame (window-frame window))) (when (frame-parameter frame 'drag-with-header-line) - (mouse-drag-frame start-event 'move)))))) + (mouse-drag-frame-move start-event)))))) =20 (defun mouse-drag-vertical-line (start-event) "Change the width of a window by dragging on a vertical line. @@ -577,46 +577,7 @@ mouse-drag-vertical-line (interactive "e") (mouse-drag-line start-event 'vertical)) =0C -(defun mouse-resize-frame (frame x-diff y-diff &optional x-move y-move) - "Helper function for `mouse-drag-frame'." - (let* ((frame-x-y (frame-position frame)) - (frame-x (car frame-x-y)) - (frame-y (cdr frame-x-y)) - alist) - (if (> x-diff 0) - (when x-move - (setq x-diff (min x-diff frame-x)) - (setq x-move (- frame-x x-diff))) - (let* ((min-width (frame-windows-min-size frame t nil t)) - (min-diff (max 0 (- (frame-inner-width frame) min-width))))= - (setq x-diff (max x-diff (- min-diff))) - (when x-move - (setq x-move (+ frame-x (- x-diff)))))) - - (if (> y-diff 0) - (when y-move - (setq y-diff (min y-diff frame-y)) - (setq y-move (- frame-y y-diff))) - (let* ((min-height (frame-windows-min-size frame nil nil t)) - (min-diff (max 0 (- (frame-inner-height frame) min-height))= )) - (setq y-diff (max y-diff (- min-diff))) - (when y-move - (setq y-move (+ frame-y (- y-diff)))))) - - (unless (zerop x-diff) - (when x-move - (push `(left . ,x-move) alist)) - (push `(width . (text-pixels . ,(+ (frame-text-width frame) x-diff= ))) - alist)) - (unless (zerop y-diff) - (when y-move - (push `(top . ,y-move) alist)) - (push `(height . (text-pixels . ,(+ (frame-text-height frame) y-di= ff))) - alist)) - (when alist - (modify-frame-parameters frame alist)))) - -(defun mouse-drag-frame (start-event part) +(defun mouse-drag-frame-resize (start-event part) "Drag a frame or one of its edges with the mouse. START-EVENT is the starting mouse event of the drag action. Its position window denotes the frame that will be dragged. @@ -635,9 +596,144 @@ mouse-drag-frame (frame (if (window-live-p window) (window-frame window) window)) - (width (frame-native-width frame)) - (height (frame-native-height frame)) - ;; PARENT is the parent frame of FRAME or, if FRAME is a + ;; Initial "first" frame position and size. While dragging we + ;; base all calculations against that size and position. + (first-pos (frame-position frame)) + (first-left (car first-pos)) + (first-top (cdr first-pos)) + (first-width (frame-text-width frame)) + (first-height (frame-text-height frame)) + ;; Don't let FRAME become less large than the size needed to + ;; fit all of its windows. + (min-text-width + (+ (frame-windows-min-size frame t nil t) + (- (frame-inner-width frame) first-width))) + (min-text-height + (+ (frame-windows-min-size frame nil nil t) + (- (frame-inner-height frame) first-height))) + ;; PARENT is the parent frame of FRAME or, if FRAME is a + ;; top-level frame, FRAME's workarea. + (parent (frame-parent frame)) + (parent-edges + (if parent + (frame-edges parent) + (let* ((attributes + (car (display-monitor-attributes-list))) + (workarea (assq 'workarea attributes))) + (and workarea + `(,(nth 1 workarea) ,(nth 2 workarea) + ,(+ (nth 1 workarea) (nth 3 workarea)) + ,(+ (nth 2 workarea) (nth 4 workarea))))))) + (parent-left (and parent-edges (nth 0 parent-edges))) + (parent-top (and parent-edges (nth 1 parent-edges))) + (parent-right (and parent-edges (nth 2 parent-edges))) + (parent-bottom (and parent-edges (nth 3 parent-edges))) + ;; Drag types. drag-left/drag-right and drag-top/drag-bottom + ;; are mutually exclusive. + (drag-left (memq part '(bottom-left left top-left))) + (drag-top (memq part '(top-left top top-right))) + (drag-right (memq part '(top-right right bottom-right))) + (drag-bottom (memq part '(bottom-right bottom bottom-left))) + ;; Initial "first" mouse position. While dragging we base all + ;; calculations against that position. + (first-x-y (mouse-absolute-pixel-position)) + (first-x (car first-x-y)) + (first-y (cdr first-x-y)) + (exitfun nil) + (move + (lambda (event) + (interactive "e") + (when (consp event) + (let* ((last-x-y (mouse-absolute-pixel-position)) + (last-x (car last-x-y)) + (last-y (cdr last-x-y)) + (left (- last-x first-x)) + (top (- last-y first-y)) + alist) + ;; We never want to warp the mouse position here. When + ;; moving the mouse leftward or upward, then with a wide= + ;; border the calculated left or top position of the + ;; frame could drop to a value less than zero depending + ;; on where precisely the mouse within the border. We + ;; guard against this by never allowing the frame to + ;; move to a position less than zero here. No such + ;; precautions are used for the right and bottom borders= + ;; so with a large internal border parts of that border + ;; may disappear. + (when (and drag-left (>=3D last-x parent-left) + (>=3D (- first-width left) min-text-width))= + (push `(left . ,(max (+ first-left left) 0)) alist) + (push `(width . (text-pixels . ,(- first-width left))) + alist)) + (when (and drag-top (>=3D last-y parent-top) + (>=3D (- first-height top) min-text-height)= ) + (push `(top . ,(max 0 (+ first-top top))) alist) + (push `(height . (text-pixels . ,(- first-height top))) + alist)) + (when (and drag-right (<=3D last-x parent-right) + (>=3D (+ first-width left) min-text-width))= + (push `(width . (text-pixels . ,(+ first-width left))) + alist)) + (when (and drag-bottom (<=3D last-y parent-bottom) + (>=3D (+ first-height top) min-text-height)= ) + (push `(height . (text-pixels . ,(+ first-height top))) + alist)) + (modify-frame-parameters frame alist))))) + (old-track-mouse track-mouse)) + ;; Start tracking. The special value 'dragging' signals the + ;; display engine to freeze the mouse pointer shape for as long + ;; as we drag. + (setq track-mouse 'dragging) + ;; Loop reading events and sampling the position of the mouse. + (setq exitfun + (set-transient-map + (let ((map (make-sparse-keymap))) + (define-key map [switch-frame] #'ignore) + (define-key map [select-window] #'ignore) + (define-key map [scroll-bar-movement] #'ignore) + (define-key map [mouse-movement] move) + ;; Swallow drag-mouse-1 events to avoid selecting some othe= r window. + (define-key map [drag-mouse-1] + (lambda () (interactive) (funcall exitfun))) + ;; Some of the events will of course end up looked up + ;; with a mode-line, header-line or vertical-line prefix ..= =2E + (define-key map [mode-line] map) + (define-key map [header-line] map) + (define-key map [vertical-line] map) + ;; ... and some maybe even with a right- or bottom-divider + ;; prefix. + (define-key map [right-divider] map) + (define-key map [bottom-divider] map) + map) + t (lambda () (setq track-mouse old-track-mouse)))))) + +(defun mouse-drag-frame-move (start-event) + "Drag a frame or one of its edges with the mouse. +START-EVENT is the starting mouse event of the drag action. Its +position window denotes the frame that will be dragged. + +PART specifies the part that has been dragged and must be one of +the symbols `left', `top', `right', `bottom', `top-left', +`top-right', `bottom-left', `bottom-right' to drag an internal +border or edge. If PART equals `move', this means to move the +frame with the mouse." + ;; Give temporary modes such as isearch a chance to turn off. + (run-hooks 'mouse-leave-buffer-hook) + (let* ((echo-keystrokes 0) + (start (event-start start-event)) + (window (posn-window start)) + ;; FRAME is the frame to drag. + (frame (if (window-live-p window) + (window-frame window) + window)) + (native-width (frame-native-width frame)) + (native-height (frame-native-height frame)) + ;; Initial "first" frame position and size. While dragging we + ;; base all calculations against that size and position. + (first-pos (frame-position frame)) + (first-left (car first-pos)) + (first-top (cdr first-pos)) + ;; PARENT is the parent frame of FRAME or, if FRAME is a ;; top-level frame, FRAME's workarea. (parent (frame-parent frame)) (parent-edges @@ -654,19 +750,16 @@ mouse-drag-frame (parent-top (and parent-edges (nth 1 parent-edges))) (parent-right (and parent-edges (nth 2 parent-edges))) (parent-bottom (and parent-edges (nth 3 parent-edges))) - ;; `pos-x' and `pos-y' record the x- and y-coordinates of the - ;; last sampled mouse position. Note that we sample absolute - ;; mouse positions to avoid that moving the mouse from one - ;; frame into another gets into our way. `last-x' and `last-y' - ;; records the x- and y-coordinates of the previously sampled - ;; position. The differences between `last-x' and `pos-x' as - ;; well as `last-y' and `pos-y' determine the amount the mouse - ;; has been dragged between the last two samples. - pos-x-y pos-x pos-y - (last-x-y (mouse-absolute-pixel-position)) - (last-x (car last-x-y)) - (last-y (cdr last-x-y)) - ;; `snap-x' and `snap-y' record the x- and y-coordinates of the= + ;; Initial "first" mouse position. While dragging we base all + ;; calculations against that position. + (first-x-y (mouse-absolute-pixel-position)) + (first-x (car first-x-y)) + (first-y (cdr first-x-y)) + ;; `snap-width' (maybe also a yet to be provided `snap-height')= + ;; could become floats to handle proportionality wrt PARENT. + ;; We don't do any checks on this parameter so far. + (snap-width (frame-parameter frame 'snap-width)) + ;; `snap-x' and `snap-y' record the x- and y-coordinates of the ;; mouse position when FRAME snapped. As soon as the ;; difference between `pos-x' and `snap-x' (or `pos-y' and ;; `snap-y') exceeds the value of FRAME's `snap-width' @@ -678,176 +771,141 @@ mouse-drag-frame (lambda (event) (interactive "e") (when (consp event) - (setq pos-x-y (mouse-absolute-pixel-position)) - (setq pos-x (car pos-x-y)) - (setq pos-y (cdr pos-x-y)) - (cond - ((eq part 'left) - (mouse-resize-frame frame (- last-x pos-x) 0 t)) - ((eq part 'top) - (mouse-resize-frame frame 0 (- last-y pos-y) nil t)) - ((eq part 'right) - (mouse-resize-frame frame (- pos-x last-x) 0)) - ((eq part 'bottom) - (mouse-resize-frame frame 0 (- pos-y last-y))) - ((eq part 'top-left) - (mouse-resize-frame - frame (- last-x pos-x) (- last-y pos-y) t t)) - ((eq part 'top-right) - (mouse-resize-frame - frame (- pos-x last-x) (- last-y pos-y) nil t)) - ((eq part 'bottom-left) - (mouse-resize-frame - frame (- last-x pos-x) (- pos-y last-y) t)) - ((eq part 'bottom-right) - (mouse-resize-frame - frame (- pos-x last-x) (- pos-y last-y))) - ((eq part 'move) - (let* ((old-position (frame-position frame)) - (old-left (car old-position)) - (old-top (cdr old-position)) - (left (+ old-left (- pos-x last-x))) - (top (+ old-top (- pos-y last-y))) - right bottom - ;; `snap-width' (maybe also a yet to be provided - ;; `snap-height') could become floats to handle - ;; proportionality wrt PARENT. We don't do any - ;; checks on this parameter so far. - (snap-width (frame-parameter frame 'snap-width)))= - ;; Docking and constraining. - (when (and (numberp snap-width) parent-edges) + (let* ((last-x-y (mouse-absolute-pixel-position)) + (last-x (car last-x-y)) + (last-y (cdr last-x-y)) + (left (- last-x first-x)) + (top (- last-y first-y)) + right bottom) + (setq left (+ first-left left)) + (setq top (+ first-top top)) + ;; Docking and constraining. + (when (and (numberp snap-width) parent-edges) + (cond + ;; Docking at the left parent edge. + ((< last-x first-x) (cond - ;; Docking at the left parent edge. - ((< pos-x last-x) - (cond - ((and (> left parent-left) - (<=3D (- left parent-left) snap-width)) - ;; Snap when the mouse moved leftward and - ;; FRAME's left edge would end up within - ;; `snap-width' pixels from PARENT's left edge. - (setq snap-x pos-x) - (setq left parent-left)) - ((and (<=3D left parent-left) - (<=3D (- parent-left left) snap-width) - snap-x (<=3D (- snap-x pos-x) snap-width)) - ;; Stay snapped when the mouse moved leftward - ;; but not more than `snap-width' pixels from - ;; the time FRAME snapped. - (setq left parent-left)) - (t - ;; Unsnap when the mouse moved more than - ;; `snap-width' pixels leftward from the time - ;; FRAME snapped. - (setq snap-x nil)))) - ((> pos-x last-x) - (setq right (+ left width)) - (cond - ((and (< right parent-right) - (<=3D (- parent-right right) snap-width)) - ;; Snap when the mouse moved rightward and - ;; FRAME's right edge would end up within - ;; `snap-width' pixels from PARENT's right edge.= - (setq snap-x pos-x) - (setq left (- parent-right width))) - ((and (>=3D right parent-right) - (<=3D (- right parent-right) snap-width) - snap-x (<=3D (- pos-x snap-x) snap-width)) - ;; Stay snapped when the mouse moved rightward - ;; but not more more than `snap-width' pixels - ;; from the time FRAME snapped. - (setq left (- parent-right width))) - (t - ;; Unsnap when the mouse moved rightward more - ;; than `snap-width' pixels from the time FRAME - ;; snapped. - (setq snap-x nil))))) - + ((and (> left parent-left) + (<=3D (- left parent-left) snap-width)) + ;; Snap when the mouse moved leftward and FRAME's + ;; left edge would end up within `snap-width' + ;; pixels from PARENT's left edge. + (setq snap-x last-x) + (setq left parent-left)) + ((and (<=3D left parent-left) + (<=3D (- parent-left left) snap-width) + snap-x (<=3D (- snap-x last-x) snap-width)) + ;; Stay snapped when the mouse moved leftward but + ;; not more than `snap-width' pixels from the time= + ;; FRAME snapped. + (setq left parent-left)) + (t + ;; Unsnap when the mouse moved more than + ;; `snap-width' pixels leftward from the time + ;; FRAME snapped. + (setq snap-x nil)))) + ((> last-x first-x) + (setq right (+ left native-width)) (cond - ((< pos-y last-y) - (cond - ((and (> top parent-top) - (<=3D (- top parent-top) snap-width)) - ;; Snap when the mouse moved upward and FRAME's - ;; top edge would end up within `snap-width' - ;; pixels from PARENT's top edge. - (setq snap-y pos-y) - (setq top parent-top)) - ((and (<=3D top parent-top) - (<=3D (- parent-top top) snap-width) - snap-y (<=3D (- snap-y pos-y) snap-width)) - ;; Stay snapped when the mouse moved upward but - ;; not more more than `snap-width' pixels from - ;; the time FRAME snapped. - (setq top parent-top)) - (t - ;; Unsnap when the mouse moved upward more than - ;; `snap-width' pixels from the time FRAME - ;; snapped. - (setq snap-y nil)))) - ((> pos-y last-y) - (setq bottom (+ top height)) - (cond - ((and (< bottom parent-bottom) - (<=3D (- parent-bottom bottom) snap-width))= - ;; Snap when the mouse moved downward and - ;; FRAME's bottom edge would end up within - ;; `snap-width' pixels from PARENT's bottom - ;; edge. - (setq snap-y pos-y) - (setq top (- parent-bottom height))) - ((and (>=3D bottom parent-bottom) - (<=3D (- bottom parent-bottom) snap-width) - snap-y (<=3D (- pos-y snap-y) snap-width)) - ;; Stay snapped when the mouse moved downward - ;; but not more more than `snap-width' pixels - ;; from the time FRAME snapped. - (setq top (- parent-bottom height))) - (t - ;; Unsnap when the mouse moved downward more - ;; than `snap-width' pixels from the time FRAME - ;; snapped. - (setq snap-y nil)))))) - - ;; If requested, constrain FRAME's draggable areas to - ;; PARENT's edges. The `top-visible' parameter should= - ;; be set when FRAME has a draggable header-line. If - ;; set to a number, it ascertains that the top of - ;; FRAME is always constrained to the top of PARENT - ;; and that at least as many pixels of FRAME as - ;; specified by that number are visible on each of the= - ;; three remaining sides of PARENT. - ;; - ;; The `bottom-visible' parameter should be set when - ;; FRAME has a draggable mode-line. If set to a - ;; number, it ascertains that the bottom of FRAME is - ;; always constrained to the bottom of PARENT and that= - ;; at least as many pixels of FRAME as specified by - ;; that number are visible on each of the three - ;; remaining sides of PARENT. - (let ((par (frame-parameter frame 'top-visible)) - bottom-visible) - (unless par - (setq par (frame-parameter frame 'bottom-visible))= - (setq bottom-visible t)) - (when (and (numberp par) parent-edges) - (setq left - (max (min (- parent-right par) left) - (+ (- parent-left width) par))) - (setq top - (if bottom-visible - (min (max top (- parent-top (- height pa= r))) - (- parent-bottom height)) - (min (max top parent-top) - (- parent-bottom par)))))) - - ;; Use `modify-frame-parameters' since `left' and - ;; `top' may want to move FRAME out of its PARENT. - (modify-frame-parameters - frame - `((left . (+ ,left)) (top . (+ ,top))))))) - (setq last-x pos-x) - (setq last-y pos-y)))) - (old-track-mouse track-mouse)) + ((and (< right parent-right) + (<=3D (- parent-right right) snap-width)) + ;; Snap when the mouse moved rightward and FRAME's= + ;; right edge would end up within `snap-width' + ;; pixels from PARENT's right edge. + (setq snap-x last-x) + (setq left (- parent-right native-width))) + ((and (>=3D right parent-right) + (<=3D (- right parent-right) snap-width) + snap-x (<=3D (- last-x snap-x) snap-width)) + ;; Stay snapped when the mouse moved rightward but= + ;; not more more than `snap-width' pixels from the= + ;; time FRAME snapped. + (setq left (- parent-right native-width))) + (t + ;; Unsnap when the mouse moved rightward more than= + ;; `snap-width' pixels from the time FRAME + ;; snapped. + (setq snap-x nil))))) + (cond + ((< last-y first-y) + (cond + ((and (> top parent-top) + (<=3D (- top parent-top) snap-width)) + ;; Snap when the mouse moved upward and FRAME's + ;; top edge would end up within `snap-width' + ;; pixels from PARENT's top edge. + (setq snap-y last-y) + (setq top parent-top)) + ((and (<=3D top parent-top) + (<=3D (- parent-top top) snap-width) + snap-y (<=3D (- snap-y last-y) snap-width)) + ;; Stay snapped when the mouse moved upward but + ;; not more more than `snap-width' pixels from the= + ;; time FRAME snapped. + (setq top parent-top)) + (t + ;; Unsnap when the mouse moved upward more than + ;; `snap-width' pixels from the time FRAME + ;; snapped. + (setq snap-y nil)))) + ((> last-y first-y) + (setq bottom (+ top native-height)) + (cond + ((and (< bottom parent-bottom) + (<=3D (- parent-bottom bottom) snap-width)) + ;; Snap when the mouse moved downward and FRAME's + ;; bottom edge would end up within `snap-width' + ;; pixels from PARENT's bottom edge. + (setq snap-y last-y) + (setq top (- parent-bottom native-height))) + ((and (>=3D bottom parent-bottom) + (<=3D (- bottom parent-bottom) snap-width) + snap-y (<=3D (- last-y snap-y) snap-width)) + ;; Stay snapped when the mouse moved downward but + ;; not more more than `snap-width' pixels from the= + ;; time FRAME snapped. + (setq top (- parent-bottom native-height))) + (t + ;; Unsnap when the mouse moved downward more than + ;; `snap-width' pixels from the time FRAME + ;; snapped. + (setq snap-y nil)))))) + + ;; If requested, constrain FRAME's draggable areas to + ;; PARENT's edges. The `top-visible' parameter should + ;; be set when FRAME has a draggable header-line. If + ;; set to a number, it ascertains that the top of FRAME + ;; is always constrained to the top of PARENT and that + ;; at least as many pixels of FRAME as specified by that= + ;; number are visible on each of the three remaining + ;; sides of PARENT. + ;; + ;; The `bottom-visible' parameter should be set when + ;; FRAME has a draggable mode-line. If set to a number,= + ;; it ascertains that the bottom of FRAME is always + ;; constrained to the bottom of PARENT and that at least= + ;; as many pixels of FRAME as specified by that number + ;; are visible on each of the three remaining sides of + ;; PARENT. + (let ((par (frame-parameter frame 'top-visible)) + bottom-visible) + (unless par + (setq par (frame-parameter frame 'bottom-visible)) + (setq bottom-visible t)) + (when (and (numberp par) parent-edges) + (setq left + (max (min (- parent-right par) left) + (+ (- parent-left native-width) par))) + (setq top + (if bottom-visible + (min (max top (- parent-top (- native-heig= ht par))) + (- parent-bottom native-height)) + (min (max top parent-top) + (- parent-bottom par)))))) + ;; Use `modify-frame-parameters' since `left' and `top' + ;; may want to move FRAME out of its PARENT. + (modify-frame-parameters frame `((left . (+ ,left)) (top= . (+ ,top)))))))) + (old-track-mouse track-mouse)) ;; Start tracking. The special value 'dragging' signals the ;; display engine to freeze the mouse pointer shape for as long ;; as we drag. @@ -879,49 +937,49 @@ mouse-drag-left-edge "Drag left edge of a frame with the mouse. START-EVENT is the starting mouse event of the drag action." (interactive "e") - (mouse-drag-frame start-event 'left)) + (mouse-drag-frame-resize start-event 'left)) =20 (defun mouse-drag-top-left-corner (start-event) "Drag top left corner of a frame with the mouse. START-EVENT is the starting mouse event of the drag action." (interactive "e") - (mouse-drag-frame start-event 'top-left)) + (mouse-drag-frame-resize start-event 'top-left)) =20 (defun mouse-drag-top-edge (start-event) "Drag top edge of a frame with the mouse. START-EVENT is the starting mouse event of the drag action." (interactive "e") - (mouse-drag-frame start-event 'top)) + (mouse-drag-frame-resize start-event 'top)) =20 (defun mouse-drag-top-right-corner (start-event) "Drag top right corner of a frame with the mouse. START-EVENT is the starting mouse event of the drag action." (interactive "e") - (mouse-drag-frame start-event 'top-right)) + (mouse-drag-frame-resize start-event 'top-right)) =20 (defun mouse-drag-right-edge (start-event) "Drag right edge of a frame with the mouse. START-EVENT is the starting mouse event of the drag action." (interactive "e") - (mouse-drag-frame start-event 'right)) + (mouse-drag-frame-resize start-event 'right)) =20 (defun mouse-drag-bottom-right-corner (start-event) "Drag bottom right corner of a frame with the mouse. START-EVENT is the starting mouse event of the drag action." (interactive "e") - (mouse-drag-frame start-event 'bottom-right)) + (mouse-drag-frame-resize start-event 'bottom-right)) =20 (defun mouse-drag-bottom-edge (start-event) "Drag bottom edge of a frame with the mouse. START-EVENT is the starting mouse event of the drag action." (interactive "e") - (mouse-drag-frame start-event 'bottom)) + (mouse-drag-frame-resize start-event 'bottom)) =20 (defun mouse-drag-bottom-left-corner (start-event) "Drag bottom left corner of a frame with the mouse. START-EVENT is the starting mouse event of the drag action." (interactive "e") - (mouse-drag-frame start-event 'bottom-left)) + (mouse-drag-frame-resize start-event 'bottom-left)) =20 (defcustom mouse-select-region-move-to-beginning nil "Effect of selecting a region extending backward from double click. diff --git a/src/frame.c b/src/frame.c index 88d6f22fc0..9ec5c24b22 100644 --- a/src/frame.c +++ b/src/frame.c @@ -5941,6 +5941,7 @@ syms_of_frame (void) DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1"); DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2"); DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3"); + DEFSYM (Qxg_frame_set_char_size_4, "xg-frame-set-char-size-4"); DEFSYM (Qx_set_window_size_1, "x-set-window-size-1"); DEFSYM (Qx_set_window_size_2, "x-set-window-size-2"); DEFSYM (Qx_set_window_size_3, "x-set-window-size-3"); diff --git a/src/gtkutil.c b/src/gtkutil.c index 6308c38f16..4cab8a5706 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -940,9 +940,8 @@ xg_frame_resized (struct frame *f, int pixelwidth, in= t pixelheight) } } =20 -/* Resize the outer window of frame F after changing the height. - COLUMNS/ROWS is the size the edit area shall have after the resize. = */ - +/** Resize the outer window of frame F. WIDTH and HEIGHT are the new + pixel sizes of F's text area. */ void xg_frame_set_char_size (struct frame *f, int width, int height) { @@ -953,6 +952,7 @@ xg_frame_set_char_size (struct frame *f, int width, i= nt height) int totalheight =3D pixelheight + FRAME_TOOLBAR_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f= ); int totalwidth =3D pixelwidth + FRAME_TOOLBAR_WIDTH (f); + bool was_visible =3D false; =20 if (FRAME_PIXEL_HEIGHT (f) =3D=3D 0) return; @@ -995,12 +995,35 @@ xg_frame_set_char_size (struct frame *f, int width,= int height) gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), totalwidth, gheight); } + else if (FRAME_PARENT_FRAME (f) && FRAME_VISIBLE_P (f) + && EQ (x_gtk_resize_child_frames, Qhide)) + { + was_visible =3D true; + + if (totalwidth !=3D gwidth || totalheight !=3D gheight) + { + frame_size_history_add + (f, Qxg_frame_set_char_size_4, width, height, + list2i (totalwidth, totalheight)); + block_input (); + gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f)); + unblock_input (); + + gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), + totalwidth, totalheight); + + block_input (); + gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f)); + unblock_input (); + + fullscreen =3D Qnil; + } + } else { frame_size_history_add (f, Qxg_frame_set_char_size_3, width, height, list2i (totalwidth, totalheight)); - gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), totalwidth, totalheight); fullscreen =3D Qnil; @@ -1016,7 +1039,7 @@ xg_frame_set_char_size (struct frame *f, int width,= int height) size as fast as possible. For unmapped windows, we can set rows/cols. When the frame is mapped again we will (hopefully) get the correct size.= */ - if (FRAME_VISIBLE_P (f)) + if (FRAME_VISIBLE_P (f) && !was_visible) { /* Must call this to flush out events */ (void)gtk_events_pending (); diff --git a/src/xfns.c b/src/xfns.c index 276ea1c393..f32056ff03 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -861,6 +861,12 @@ x_set_parent_frame (struct frame *f, Lisp_Object new= _value, Lisp_Object old_valu (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), p ? FRAME_X_WINDOW (p) : DefaultRootWindow (FRAME_X_DISPLAY (f)), f->left_pos, f->top_pos); +#ifdef USE_GTK + if (EQ (x_gtk_resize_child_frames, Qresize_mode)) + gtk_container_set_resize_mode + (GTK_CONTAINER (FRAME_GTK_OUTER_WIDGET (f)), + p ? GTK_RESIZE_IMMEDIATE : GTK_RESIZE_QUEUE); +#endif unblock_input (); =20 fset_parent_frame (f, new_value); @@ -4084,6 +4090,11 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_creat= e_frame, block_input (); XReparentWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), FRAME_X_WINDOW (p), f->left_pos, f->top_pos); +#ifdef USE_GTK + if (EQ (x_gtk_resize_child_frames, Qresize_mode)) + gtk_container_set_resize_mode + (GTK_CONTAINER (FRAME_GTK_OUTER_WIDGET (f)), GTK_RESIZE_IMMEDIATE); +#endif unblock_input (); } =20 @@ -7742,6 +7753,22 @@ frames (each of which corresponds to one page). E= ach frame should be #endif /* USE_GTK */ #endif /* USE_CAIRO */ =20 +#ifdef USE_GTK +#ifdef HAVE_GTK3 +DEFUN ("x-gtk-debug", Fx_gtk_debug, Sx_gtk_debug, 1, 1, 0, + doc: /* Toggle interactive GTK debugging. */) + (Lisp_Object enable) +{ + gboolean enable_debug =3D !NILP (enable); + + block_input (); + gtk_window_set_interactive_debugging (enable_debug); + unblock_input (); + + return NILP (enable) ? Qnil : Qt; +} +#endif /* HAVE_GTK3 */ +#endif /* USE_GTK */ =0C /***********************************************************************= Initialization @@ -7810,6 +7837,8 @@ syms_of_xfns (void) DEFSYM (Qfont_parameter, "font-parameter"); DEFSYM (Qmono, "mono"); DEFSYM (Qassq_delete_all, "assq-delete-all"); + DEFSYM (Qhide, "hide"); + DEFSYM (Qresize_mode, "resize-mode"); =20 #ifdef USE_CAIRO DEFSYM (Qpdf, "pdf"); @@ -7986,6 +8015,28 @@ syms_of_xfns (void) When using Gtk+ tooltips, the tooltip face is not used. */); x_gtk_use_system_tooltips =3D true; =20 + DEFVAR_LISP ("x-gtk-resize-child-frames", x_gtk_resize_child_frames, + doc: /* If non-nil, resize child frames specially with GTK builds. +If this is nil, resize child frames like any other frames. This is the +default and usually works with most desktops. Some desktop environments= +(GNOME shell in particular when using the mutter window manager), +however, may refuse to resize a child frame when Emacs is built with +GTK3. For those environments, the two settings below are provided. + +If this equals the symbol 'hide', Emacs temporarily hides the child +frame during resizing. This approach seems to work reliably, may +however induce some flicker when the frame is made visible again. + +If this equals the symbol 'resize-mode', Emacs uses GTK's resize mode to= +always trigger an immediate resize of the child frame. This method is +deprecated by GTK and may not work in future versions of that toolkit. +It also may freeze Emacs when used with other desktop environments. It +avoids, however, the unpleasent flicker induced by the hiding approach. + +This variable is considered a temporary workaround and will be hopefully= +eliminated in future versions of Emacs. */); + x_gtk_resize_child_frames =3D Qnil; + /* Tell Emacs about this window system. */ Fprovide (Qx, Qnil); =20 @@ -8101,4 +8152,9 @@ syms_of_xfns (void) defsubr (&Sx_print_frames_dialog); #endif #endif +#ifdef USE_GTK +#ifdef HAVE_GTK3 + defsubr (&Sx_gtk_debug); +#endif +#endif } diff --git a/src/xterm.c b/src/xterm.c index 21d99f0c7b..971f374764 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -10612,26 +10612,29 @@ x_set_offset (struct frame *f, register int xof= f, register int yoff, int change_ modified_left, modified_top); #endif =20 - x_sync_with_move (f, f->left_pos, f->top_pos, - FRAME_DISPLAY_INFO (f)->wm_type =3D=3D X_WMTYPE_UNKN= OWN); - - /* change_gravity is non-zero when this function is called from Lisp t= o - programmatically move a frame. In that case, we call - x_check_expected_move to discover if we have a "Type A" or "Type B"= - window manager, and, for a "Type A" window manager, adjust the posi= tion - of the frame. - - We call x_check_expected_move if a programmatic move occurred, and - either the window manager type (A/B) is unknown or it is Type A but= we - need to compute the top/left offset adjustment for this frame. */ - - if (change_gravity !=3D 0 - && !FRAME_PARENT_FRAME (f) - && (FRAME_DISPLAY_INFO (f)->wm_type =3D=3D X_WMTYPE_UNKNOWN - || (FRAME_DISPLAY_INFO (f)->wm_type =3D=3D X_WMTYPE_A - && (FRAME_X_OUTPUT (f)->move_offset_left =3D=3D 0 - && FRAME_X_OUTPUT (f)->move_offset_top =3D=3D 0)))) - x_check_expected_move (f, modified_left, modified_top); + /* 'x_sync_with_move' is too costly for dragging child frames. */ + if (!FRAME_PARENT_FRAME (f)) + { + x_sync_with_move (f, f->left_pos, f->top_pos, + FRAME_DISPLAY_INFO (f)->wm_type =3D=3D X_WMTYPE_UNKNOWN); + + /* change_gravity is non-zero when this function is called from Li= sp to + programmatically move a frame. In that case, we call + x_check_expected_move to discover if we have a "Type A" or "Type B" + window manager, and, for a "Type A" window manager, adjust the positio= n + of the frame. + + We call x_check_expected_move if a programmatic move occurred, and + either the window manager type (A/B) is unknown or it is Type A but we= + need to compute the top/left offset adjustment for this frame. */ + + if (change_gravity !=3D 0 + && (FRAME_DISPLAY_INFO (f)->wm_type =3D=3D X_WMTYPE_UNKNOWN + || (FRAME_DISPLAY_INFO (f)->wm_type =3D=3D X_WMTYPE_A + && (FRAME_X_OUTPUT (f)->move_offset_left =3D=3D 0 + && FRAME_X_OUTPUT (f)->move_offset_top =3D=3D 0)))) + x_check_expected_move (f, modified_left, modified_top); + } =20 unblock_input (); } --------------4AD11D60E7E48AC51911F0A5--