4

When I maximize the Emacs frame, it uses the full width of the screen, no background showing. But if I e.g. snap-to-edge (in XFCE), it shows a little "margin" of background outside the frame. And if I drag to resize, it always over- or undershoots the edge – it looks like it wants to always resize by whole lines/characters. Is there a way to have a 50% size Emacs frame that aligns with the edge of the screen?

(I'm using 20170203:93058-ce88155-emacs-25.1~ubuntu16.04.1)

Mousepad can take exactly 50% width and 100%height, with height from the top of the screen down to the panel: mousepad can take exactly 50% width and 100%height

Emacs seems to overshoot/undershoot: emacs overshoots

emacs overshoots on the right too

When I "snap" Emacs to the edges with XFCE, it fits the width on my laptop, but not on my external monitor. It never matches the full height.

  • 2
    Have a look at display-pixel-width and display-pixel-height, set-frame-height, set-frame-width, set-frame-size, set-frame-position -- including the optional PIXELWISE argument for some of the functions : gnu.org/software/emacs/manual/html_node/elisp/… And, of course, the division / function -- i.e., just like a divorce (divide by two). If you want to set this at the outset, have a look at default-frame-alist, initial-frame-alist, and also certain paramaters that can be passed to the make-frame function. Emacs 25 handles this better. – lawlist Feb 3 '17 at 16:25
  • Based on your edit, it appears that you will need to get the bounds in exact pixels of your other windows (e.g., Mousepad) -- and then subtract that pixel width from the Emacs display-pixel-width in the answer below to come up with the exact Emacs frame size -- that assumes the Mousepad is flush right. Or you will need to get the left pixel bound of Mousepad and calculate accordingly. Emacs does not have any function that I am aware of that could search the screen for all other application windows that are present and attempt to adjust its size based on something like Mousepad. – lawlist Feb 4 '17 at 8:08
  • You could also just run a few tests by trial and error subtracting or adding a few pixels to the width value used by set-frame-width to come up with your perfect setting. – lawlist Feb 4 '17 at 8:11
  • I did, and did find the right width, but only after setting frame-resize-pixelwise, which solved the problem in general too :-) – unhammer Feb 4 '17 at 8:26
3

Reading C-h f set-frame-width as mentioned by user @lawlist, I saw a mention of frame-resize-pixelwise. Putting this in .emacs.d/init.el

(setq frame-resize-pixelwise t)

makes the window "snap" to the right height in XFCE (haven't tried on my external monitor yet, so don't know if it gets the exact right width too); it also snaps to the right height when I set the height with my wmctrl scripts.

2

Here is an example using some of the functions mentioned in the comment and link underneath the original question hereinabove:

(let ((frame (selected-frame))
      (one-half-display-pixel-width (/ (display-pixel-width) 2)))
  (set-frame-width frame one-half-display-pixel-width nil 'pixelwise)
  (set-frame-position frame 0 0))

FYI:  Feature request #21415 was incorporated into Emacs 25 -- frame creation may now include a pixel specification -- this includes items such as the initial-frame-alist, default-frame-alist, and the make-frame function.

Example of usage for the width parameter: '(width . (text-pixels . 1900))

Example of usage for the height parameter: '(height . (text-pixels . 1054))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.