2

When I start emacs, it is always fullscreen. I can't find the configuration to have emacs start not in fullscreen (maximized). I'm not the only one with this problem:

http://ubuntuforums.org/showthread.php?t=2282182

System:

  • Dell XPS 15
  • Ubuntu 14.04 (factory installed)
  • Emacs 24.3.1 (factory installed, updated)

I've tried the --geometry option, and it works from the command line, but doesn't change the behavior of the dock icon. Even when I remove the icon, start from the command line with custom --geometry, and lock the new icon -- it just starts in full screen again. I haven't had any luck with *-frame-alist settings either. What other configuration could be doing this?

  • My emacs24 goes into/out of fullscreen when I drag it to/away from the top of screen, or type Ctrl-Windows-UPArrow Ctrl-Windows-DownArrow. Neither action is visible to the emacs describe-key function. Try Right-Clicking on the title bar, and checking there, too. – waltinator Oct 13 '15 at 21:45
  • 1
    Yes, these work for me too -- I see now that my complaint "I can't make it stop" was unclear :/ My question is how to make emacs not be maximized at startup, and I've clarified it now. – Niles Oct 14 '15 at 12:16
  • 1
    Ensure your emacs's initial window position does not overlap the "maximize me" region at the top of the screen. – waltinator Oct 16 '15 at 5:47
1

I also have a Dell XPS with a HiDPI screen and I had the same problem. Turns out Emacs wanted to occupy more screen space than was available because in my Emacs startup files I was setting a frame width of 88 characters, which was being doubled because I set my UI scale-factor to 2 to make things readable on the HiDPI display. So the window manager (rightly) opened Emacs in full screen mode instead. I figured it out when when I tried ennob's solution on http://ubuntuforums.org/showthread.php?t=2282182. In ennob's code the frame size is 40 x 25 characters, which resulted in a frame size of 80x50 on my system. A little experimentation confirmed that Emacs multiplies the requested text width and height by the scale factor when setting the actual width and height of the frame.

You can get the scale factor from dconf:

dconf read /com/ubuntu/user-interface/scale-factor

which on my system returns {'eDP1': 16}. A scale factor of 1 gives {'eDP1': 8}. So I generalized ennob's code and added this to my Emacs startup file (for me, ~/.emacs.d/init.el):

(defun my:window-setup-hook ()
  (when (and (string= system-type "gnu/linux") window-system)
    (toggle-frame-maximized)
    (let* ((dconf-entry
            (shell-command-to-string
             "dconf read /com/ubuntu/user-interface/scale-factor"))
           (scale-factor (progn (string-match "'[eD][FD]P1': \\([0-9]+\\)[,\}]"
                                              dconf-entry)
                                (string-to-int (match-string 1 dconf-entry))))
           (text-width (truncate (/ desired-width (/ scale-factor 8.0))))
           (text-height (truncate (/ desired-height (/ scale-factor 8.0)))))
      (message "set-frame-size is %dx%d, scale-factor is %s"
               text-width text-height scale-factor)
      (set-frame-size (selected-frame) text-width text-height))))

(setq window-setup-hook 'my:window-setup-hook)

This works for me for scale factors >= 2 and when my default font is 14 pt ((set-face-attribute 'default nil :height 140)). So I still don't understand the myriad factors at play, but my immediate problem is solved and I hope this helps you too.

|improve this answer|||||
  • Excellent! This didn't quite work, because for some reason the function toggle-frame-maximized isn't available in my emacs. Reading through some instructions at EmacsWiki, I see that this function is defined by default on Windows, but maybe not other OS? In any case, I discovered a solution for X11: also add the function toggle-fullscreen and use that instead. (See my answer below for the code.) – Niles Jan 4 '16 at 13:53
1

The answer from @chris-simpkins almost worked for me, but the function to toggle fullscreen didn't work for some reason :/ As per my comment, here is the code that does work for me (I prefer a narrower screen):

(defun toggle-fullscreen-x11 ()
  "Toggle full screen on X11"
  (interactive)
  (when (eq window-system 'x)
    (set-frame-parameter
     nil 'fullscreen
     (when (not (frame-parameter nil 'fullscreen)) 'fullboth))))

(defun my:window-setup-hook ()
  (toggle-fullscreen-x11)
  (when window-system
    (let* ((dconf-entry
            (shell-command-to-string
             "dconf read /com/ubuntu/user-interface/scale-factor"))
           (scale-factor (progn (string-match "{'eDP1': \\([0-9]+\\)}"
                                              dconf-entry)
                                (string-to-int (match-string 1 dconf-entry))))
           ;; text-width make room for gutter and fringes
           (text-width (truncate (/ 48 (/ scale-factor 8.0))))
           (text-height (truncate (/ 50 (/ scale-factor 8.0)))))
      (set-frame-size (selected-frame) text-width text-height))))
(setq window-setup-hook 'my:window-setup-hook)
|improve this answer|||||
  • I don't know why neither Chris's nor your answer are working for me; I'm using a newly installed emacs 25.3.2 on a new ubuntu 16.04.4. Only other thing I've set up so far in my .emacs is (require 'package). When starting emacs with no options I see in the status line: Arithmetic range error: "truncate", 1.0e+INF This would seem to indicate, obviously, something wrong in how the truncate or division clauses are done, but your example is clear and I cut and pasted it directly, so... I'm stumped. – cdaddr Mar 12 '18 at 4:24

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.