6

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.

unhammer
  • 1,127
  • 8
  • 22
  • 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 : https://www.gnu.org/software/emacs/manual/html_node/elisp/Size-and-Position.html 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 03 '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 04 '17 at 08: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 04 '17 at 08: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 04 '17 at 08:26

3 Answers3

6

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.

unhammer
  • 1,127
  • 8
  • 22
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))

lawlist
  • 18,826
  • 5
  • 37
  • 118
1

Functions moom-fill-left and moom-fill-right in moom package resizes the frame to exactly half of the screen: https://github.com/takaxp/moom

AhLeung
  • 1,083
  • 5
  • 14
  • Please clarify in which way this package answers the question. Link-only answers are not very valuable since the link may go stale. – Stefan May 03 '20 at 04:38
  • In addition to explaining your answer in more detail, please do not post [duplicate answers](https://emacs.stackexchange.com/a/58246) to multiple questions. – Dan May 03 '20 at 09:32
  • 1
    Modified the answer to reply the question. – AhLeung May 04 '20 at 05:27
  • However, moom also resizes the fonts (which on my 4k monitor makes them "huge"). Moom-fill-left also resizes the screen height, which means on WSL the windows task bar covers the emacs echo area. – intel_chris Jul 19 '21 at 14:19