* bug#21480: 25.0.50; Frame width gets set to 16 pixels wider than the provided width in the args
@ 2015-09-14 21:13 Kaushal Modi
2015-09-14 21:21 ` Kaushal Modi
2015-09-15 8:27 ` martin rudalics
0 siblings, 2 replies; 6+ messages in thread
From: Kaushal Modi @ 2015-09-14 21:13 UTC (permalink / raw)
To: 21480
[-- Attachment #1: Type: text/plain, Size: 4942 bytes --]
Hi,
I have been using a hack to deal with this bug for over a year now. I
believe I am seeing this problem ever since I starting understanding more
and more of elisp, around emacs 24.3.
Problem:
- I save the frame width using `frame-pixel-width' to a defvar.
- I then set the frame size using `set-frame-size' with that defvar as one
of the args
- I notice that the frame had got wider! When I do a readback using
`frame-pixel-width', it is exactly 16 pixels wider than expected.
I have seen this problem on emacsen built earlier on RHEL 5 and now on RHEL
6 too.
Evaluate the below code in the scratch buffer in an emacs -Q session. Then
when you keep on hitting F2, you will see that the frame keeps on getting
wider.
Now if you uncomment the line with the "<-- HACK" comment, reeval the code
and then keep on hitting F2, the frame width will stay the same (which was
the end goal of the below code).
(defvar bkp--frame-height-px nil)
(defvar bkp--frame-width-px nil)
(defun modi/toggle-menu-bar ()
"Toggle the menu bar.
Also restore the original frame size when disabling the menu bar."
(interactive)
(let ((frame-resize-pixelwise t))
;; If the menu bar is hidden currently, take a backup of the frame
height.
(when (null menu-bar-mode)
(setq bkp--frame-height-px (frame-pixel-height))
(setq bkp--frame-width-px (frame-pixel-width))
;; ;; `frame-pixel-width' is returning a value higher by 16 pixels
compared
;; ;; to that set using `set-frame-size'. So the below adjustment has
to be made.
;; (setq bkp--frame-width-px (- (frame-pixel-width) 16))) ; <-- HACK
(menu-bar-mode 'toggle)
;; Restore frame size if menu bar is hidden after toggle
(when (null menu-bar-mode)
(set-frame-size nil bkp--frame-width-px bkp--frame-height-px
:pixelwise))))
(global-set-key (kbd "<f2>") #'modi/toggle-menu-bar)
-----------------------------------------------------------------------------------------------------
In GNU Emacs 25.0.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.23)
of 2015-09-14
Repository revision: 1ee47d477ddb9c567eaf63154f78fad5d5826b78
Windowing system distributor 'The X.Org Foundation', version 11.0.60900000
System Description: Red Hat Enterprise Linux Workstation release 6.6
(Santiago)
Configured using:
'configure --prefix=/home/kmodi/usr_local/apps/6/emacs/master
'CPPFLAGS=-fgnu89-inline -I/home/kmodi/usr_local/6/include
-I/usr/include/freetype2 -I/usr/include'
'LDFLAGS=-L/home/kmodi/usr_local/6/lib
-L/home/kmodi/usr_local/6/lib64''
Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK2 X11
Important settings:
value of $LANG: en_US.UTF-8
value of $XMODIFIERS: @im=none
locale-coding-system: utf-8-unix
Major mode: Lisp Interaction
Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark activated
next-line: End of buffer
Load-path shadows:
None found.
Features:
(shadow sort gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns help-mode easymenu mail-prsvr mail-utils edmacro kmacro
cl-loaddefs pcase cl-lib time-date mule-util tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
dbusbind inotify dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)
Memory information:
((conses 16 82449 9769)
(symbols 48 19499 0)
(miscs 40 49 185)
(strings 32 13474 4382)
(string-bytes 1 404277)
(vectors 16 10887)
(vector-slots 8 418983 6570)
(floats 8 131 201)
(intervals 56 356 10)
(buffers 976 11)
(heap 1024 30054 843))
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 14205 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#21480: 25.0.50; Frame width gets set to 16 pixels wider than the provided width in the args
2015-09-14 21:13 bug#21480: 25.0.50; Frame width gets set to 16 pixels wider than the provided width in the args Kaushal Modi
@ 2015-09-14 21:21 ` Kaushal Modi
2015-09-15 8:29 ` martin rudalics
2015-09-15 8:27 ` martin rudalics
1 sibling, 1 reply; 6+ messages in thread
From: Kaushal Modi @ 2015-09-14 21:21 UTC (permalink / raw)
To: 21480
[-- Attachment #1: Type: text/plain, Size: 6679 bytes --]
I messed up the parentheses in the example code. Here is the code again:
(defvar bkp--frame-height-px nil)
(defvar bkp--frame-width-px nil)
(defun modi/toggle-menu-bar ()
"Toggle the menu bar.
Also restore the original frame size when disabling the menu bar."
(interactive)
(let ((frame-resize-pixelwise t))
;; If the menu bar is hidden currently, take a backup of the frame
height.
(when (null menu-bar-mode)
(setq bkp--frame-height-px (frame-pixel-height))
(setq bkp--frame-width-px (frame-pixel-width))
;; `frame-pixel-width' is returning a value higher by 16 pixels
compared
;; to that set using `set-frame-size'. So the below adjustment has to
be made.
;; (setq bkp--frame-width-px (- (frame-pixel-width) 16))
)
(menu-bar-mode 'toggle)
;; Restore frame size if menu bar is hidden after toggle
(when (null menu-bar-mode)
(set-frame-size nil bkp--frame-width-px bkp--frame-height-px
:pixelwise))))
(global-set-key (kbd "<f2>") #'modi/toggle-menu-bar)
I noticed one more thing.. In my emacs setup, I need the adjustment of 16
pixels (as shown in the code above).
But in an emacs -Q session, I need an adj of 32 pixels. That might probably
help narrow down the problem.
Does it have to do with the fonts I use? Because emacs -Q starts with
Dejavu Sans Mono font. Whereas my configured emacs uses PragmataPro font.
On Mon, Sep 14, 2015 at 5:13 PM Kaushal Modi <kaushal.modi@gmail.com> wrote:
> Hi,
>
> I have been using a hack to deal with this bug for over a year now. I
> believe I am seeing this problem ever since I starting understanding more
> and more of elisp, around emacs 24.3.
>
> Problem:
> - I save the frame width using `frame-pixel-width' to a defvar.
> - I then set the frame size using `set-frame-size' with that defvar as one
> of the args
> - I notice that the frame had got wider! When I do a readback using
> `frame-pixel-width', it is exactly 16 pixels wider than expected.
>
> I have seen this problem on emacsen built earlier on RHEL 5 and now on
> RHEL 6 too.
>
> Evaluate the below code in the scratch buffer in an emacs -Q session. Then
> when you keep on hitting F2, you will see that the frame keeps on getting
> wider.
>
> Now if you uncomment the line with the "<-- HACK" comment, reeval the code
> and then keep on hitting F2, the frame width will stay the same (which was
> the end goal of the below code).
>
>
>
> (defvar bkp--frame-height-px nil)
> (defvar bkp--frame-width-px nil)
>
> (defun modi/toggle-menu-bar ()
> "Toggle the menu bar.
> Also restore the original frame size when disabling the menu bar."
> (interactive)
> (let ((frame-resize-pixelwise t))
> ;; If the menu bar is hidden currently, take a backup of the frame
> height.
> (when (null menu-bar-mode)
> (setq bkp--frame-height-px (frame-pixel-height))
> (setq bkp--frame-width-px (frame-pixel-width))
>
> ;; ;; `frame-pixel-width' is returning a value higher by 16 pixels
> compared
> ;; ;; to that set using `set-frame-size'. So the below adjustment
> has to be made.
> ;; (setq bkp--frame-width-px (- (frame-pixel-width) 16))) ; <-- HACK
>
> (menu-bar-mode 'toggle)
> ;; Restore frame size if menu bar is hidden after toggle
> (when (null menu-bar-mode)
> (set-frame-size nil bkp--frame-width-px bkp--frame-height-px
> :pixelwise))))
>
> (global-set-key (kbd "<f2>") #'modi/toggle-menu-bar)
>
>
>
>
> -----------------------------------------------------------------------------------------------------
>
>
> In GNU Emacs 25.0.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.23)
> of 2015-09-14
> Repository revision: 1ee47d477ddb9c567eaf63154f78fad5d5826b78
> Windowing system distributor 'The X.Org Foundation', version 11.0.60900000
> System Description: Red Hat Enterprise Linux Workstation release 6.6
> (Santiago)
>
> Configured using:
> 'configure --prefix=/home/kmodi/usr_local/apps/6/emacs/master
> 'CPPFLAGS=-fgnu89-inline -I/home/kmodi/usr_local/6/include
> -I/usr/include/freetype2 -I/usr/include'
> 'LDFLAGS=-L/home/kmodi/usr_local/6/lib
> -L/home/kmodi/usr_local/6/lib64''
>
> Configured features:
> XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
> NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE LIBOTF XFT ZLIB
> TOOLKIT_SCROLL_BARS GTK2 X11
>
> Important settings:
> value of $LANG: en_US.UTF-8
> value of $XMODIFIERS: @im=none
> locale-coding-system: utf-8-unix
>
> Major mode: Lisp Interaction
>
> Minor modes in effect:
> tooltip-mode: t
> global-eldoc-mode: t
> electric-indent-mode: t
> mouse-wheel-mode: t
> tool-bar-mode: t
> menu-bar-mode: t
> file-name-shadow-mode: t
> global-font-lock-mode: t
> font-lock-mode: t
> blink-cursor-mode: t
> auto-composition-mode: t
> auto-encryption-mode: t
> auto-compression-mode: t
> line-number-mode: t
> transient-mark-mode: t
>
> Recent messages:
> For information about GNU Emacs and the GNU system, type C-h C-a.
> Mark activated
> next-line: End of buffer
>
> Load-path shadows:
> None found.
>
> Features:
> (shadow sort gnus-util mail-extr emacsbug message dired format-spec
> rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
> mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
> mm-util help-fns help-mode easymenu mail-prsvr mail-utils edmacro kmacro
> cl-loaddefs pcase cl-lib time-date mule-util tooltip eldoc electric
> uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win
> term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
> tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
> menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
> syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
> misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
> cp51932 hebrew greek romanian slovak czech european ethiopic indian
> cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help
> simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces
> cus-face macroexp files text-properties overlay sha1 md5 base64 format
> env code-pages mule custom widget hashtable-print-readable backquote
> dbusbind inotify dynamic-setting system-font-setting font-render-setting
> move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)
>
> Memory information:
> ((conses 16 82449 9769)
> (symbols 48 19499 0)
> (miscs 40 49 185)
> (strings 32 13474 4382)
> (string-bytes 1 404277)
> (vectors 16 10887)
> (vector-slots 8 418983 6570)
> (floats 8 131 201)
> (intervals 56 356 10)
> (buffers 976 11)
> (heap 1024 30054 843))
>
>
> --
> Kaushal Modi
>
[-- Attachment #2: Type: text/html, Size: 15406 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#21480: 25.0.50; Frame width gets set to 16 pixels wider than the provided width in the args
2015-09-14 21:13 bug#21480: 25.0.50; Frame width gets set to 16 pixels wider than the provided width in the args Kaushal Modi
2015-09-14 21:21 ` Kaushal Modi
@ 2015-09-15 8:27 ` martin rudalics
2015-09-15 8:33 ` martin rudalics
1 sibling, 1 reply; 6+ messages in thread
From: martin rudalics @ 2015-09-15 8:27 UTC (permalink / raw)
To: Kaushal Modi, 21480
> - I save the frame width using `frame-pixel-width' to a defvar.
> - I then set the frame size using `set-frame-size' with that defvar as one
> of the args
> - I notice that the frame had got wider! When I do a readback using
> `frame-pixel-width', it is exactly 16 pixels wider than expected.
‘set-frame-size’ expects a "text width" as argument. Hence the
following
(setq frame-resize-pixelwise t)
(let ((width (frame-pixel-width)))
(set-frame-width nil (+ width 20) nil t)
(sit-for 2)
(set-frame-width nil width nil t)
(sit-for 2)
(message "%s" (cons width (frame-pixel-width))))
is wrong. The difference you see should be the sum of a scroll bar
width and the width of the fringes. This
(setq frame-resize-pixelwise t)
(let ((width (frame-text-width)))
(set-frame-width nil (+ width 20) nil t)
(sit-for 2)
(set-frame-width nil width nil t)
(message "%s" (cons width (frame-text-width))))
should do what you want.
martin
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#21480: 25.0.50; Frame width gets set to 16 pixels wider than the provided width in the args
2015-09-14 21:21 ` Kaushal Modi
@ 2015-09-15 8:29 ` martin rudalics
0 siblings, 0 replies; 6+ messages in thread
From: martin rudalics @ 2015-09-15 8:29 UTC (permalink / raw)
To: Kaushal Modi, 21480
> (defvar bkp--frame-height-px nil)
> (defvar bkp--frame-width-px nil)
>
> (defun modi/toggle-menu-bar ()
> "Toggle the menu bar.
> Also restore the original frame size when disabling the menu bar."
> (interactive)
> (let ((frame-resize-pixelwise t))
> ;; If the menu bar is hidden currently, take a backup of the frame
> height.
> (when (null menu-bar-mode)
> (setq bkp--frame-height-px (frame-pixel-height))
> (setq bkp--frame-width-px (frame-pixel-width))
Here you use "pixel sizes" again. You have to use the "text sizes".
> ;; `frame-pixel-width' is returning a value higher by 16 pixels
> compared
> ;; to that set using `set-frame-size'. So the below adjustment has to
> be made.
> ;; (setq bkp--frame-width-px (- (frame-pixel-width) 16))
> )
> (menu-bar-mode 'toggle)
> ;; Restore frame size if menu bar is hidden after toggle
> (when (null menu-bar-mode)
> (set-frame-size nil bkp--frame-width-px bkp--frame-height-px
> :pixelwise))))
>
> (global-set-key (kbd "<f2>") #'modi/toggle-menu-bar)
>
> I noticed one more thing.. In my emacs setup, I need the adjustment of 16
> pixels (as shown in the code above).
> But in an emacs -Q session, I need an adj of 32 pixels. That might probably
> help narrow down the problem.
>
> Does it have to do with the fonts I use? Because emacs -Q starts with
> Dejavu Sans Mono font. Whereas my configured emacs uses PragmataPro font.
This means that the scroll bar + fringes widths differ in these setups.
BTW, setting ‘frame-inhibit-implied-resize’ to '(menu-bar-lines) should
allow to toggle the menu bar without any resize of the outer frame.
martin
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#21480: 25.0.50; Frame width gets set to 16 pixels wider than the provided width in the args
2015-09-15 8:27 ` martin rudalics
@ 2015-09-15 8:33 ` martin rudalics
2015-09-15 13:39 ` Kaushal Modi
0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2015-09-15 8:33 UTC (permalink / raw)
To: Kaushal Modi, 21480
> (set-frame-width nil width nil t)
> (message "%s" (cons width (frame-text-width))))
Sorry. Without the ‘sit-for’ this is confusing. So this
(let ((width (frame-pixel-width)))
(setq frame-resize-pixelwise t)
(set-frame-width nil (+ width 20) nil t)
(sit-for 2)
(set-frame-width nil width nil t)
(sit-for 2)
(message "%s" (cons width (frame-pixel-width))))
is bad while this
(let ((width (frame-text-width)))
(setq frame-resize-pixelwise t)
(set-frame-width nil (+ width 20) nil t)
(sit-for 2)
(set-frame-width nil width nil t)
(sit-for 2)
(message "%s" (cons width (frame-text-width))))
should do what you want.
martin
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#21480: 25.0.50; Frame width gets set to 16 pixels wider than the provided width in the args
2015-09-15 8:33 ` martin rudalics
@ 2015-09-15 13:39 ` Kaushal Modi
0 siblings, 0 replies; 6+ messages in thread
From: Kaushal Modi @ 2015-09-15 13:39 UTC (permalink / raw)
To: martin rudalics, 21480-done
[-- Attachment #1: Type: text/plain, Size: 1311 bytes --]
Hi Martin,
This was a great "today-I-learned" thread.
Both of your suggested solutions work:
- Using frame-text-width/height instead of frame-pixel-width/height is the
right thing to do. I misunderstood frame-text-* fns to return the
parameters in text char widths and frame-pixel-* fns to return the
parameters in pixels.
- In emacs 25+, frame-inhibit-implied-resize can be set to
'(menu-bar-lines) to prevent frame resize when toggling the menu bar.
Thank you!
On Tue, Sep 15, 2015 at 4:33 AM martin rudalics <rudalics@gmx.at> wrote:
> > (set-frame-width nil width nil t)
> > (message "%s" (cons width (frame-text-width))))
>
> Sorry. Without the ‘sit-for’ this is confusing. So this
>
> (let ((width (frame-pixel-width)))
> (setq frame-resize-pixelwise t)
> (set-frame-width nil (+ width 20) nil t)
> (sit-for 2)
> (set-frame-width nil width nil t)
> (sit-for 2)
> (message "%s" (cons width (frame-pixel-width))))
>
> is bad while this
>
> (let ((width (frame-text-width)))
> (setq frame-resize-pixelwise t)
> (set-frame-width nil (+ width 20) nil t)
> (sit-for 2)
> (set-frame-width nil width nil t)
> (sit-for 2)
> (message "%s" (cons width (frame-text-width))))
>
> should do what you want.
>
> martin
>
>
[-- Attachment #2: Type: text/html, Size: 1764 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-09-15 13:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-14 21:13 bug#21480: 25.0.50; Frame width gets set to 16 pixels wider than the provided width in the args Kaushal Modi
2015-09-14 21:21 ` Kaushal Modi
2015-09-15 8:29 ` martin rudalics
2015-09-15 8:27 ` martin rudalics
2015-09-15 8:33 ` martin rudalics
2015-09-15 13:39 ` Kaushal Modi
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).