exwm icon indicating copy to clipboard operation
exwm copied to clipboard

Floating windows are too big

Open loafofpiecrust opened this issue 4 years ago • 22 comments

When I get floating dialogs, they start out the correct size in the center of the screen. Then, without any interaction they resize to the size of the whole frame (around 1920x1080) with the top-left corner still in place, making floating windows a terrible pain to use. Could this be related to #214? How should I debug this? Maybe there's a hook that I have resetting the window size.

I'm using DOOM with EXWM, and managing workspaces only with persp, rather than separate frames. Emacs version: observed on 27.0.90 and native-comp (28.0.50)

loafofpiecrust avatar Aug 09 '20 14:08 loafofpiecrust

Just wanted to add that I had the same issue but for me it only happened with the Emacs 28 native-comp branch and that is actually the reason why I'm back right now on the "normal" Emacs 28 master branch and not native-comp.

dakra avatar Aug 09 '20 21:08 dakra

Alright! I built Emacs master and it seems to work okay so this must be specific to native-comp. That branch also seems to have similar problems with a posframe window with (parent . nil).

loafofpiecrust avatar Aug 10 '20 15:08 loafofpiecrust

FYI, I recently switched back to the native-comp branch and to avoid this issue you can just not native-compile exwm and xcb as a workaround until this issue is fixed.

  (add-to-list 'comp-deferred-compilation-black-list "/exwm.*\\.el")
  (add-to-list 'comp-deferred-compilation-black-list "/xcb.*\\.el")

dakra avatar Sep 07 '20 07:09 dakra

That sounds like a good solution, but I can't get it to actually fix the problem for me. I switched back to native-comp on doom emacs, and use the following in my packages.el file:

(package! xelb :recipe (:no-byte-compile t :no-native-compile t))
(package! exwm :recipe (:no-byte-compile t :no-native-compile t))

Which I think should equate to the snippet you gave. I also added those two lines to my config.el and init.el to no avail. Popup windows still expand too large.

loafofpiecrust avatar Sep 07 '20 19:09 loafofpiecrust

Check that you actually removed the native-comp files from eln-cache before starting Emacs with the new config.

If the .eln files for exwm/xelb are already there they will still load regardless of the value of comp-deferred-compilation-black-list.

dakra avatar Sep 07 '20 19:09 dakra

After clearing out my emacs directories ~/.config/emacs/.local, and rebuilding all my packages, there are no .elc or .eln files for exwm or xelb. Yet I still have this problem with popups. Maybe there's another way to check whether I have loaded the native compiled version or the elisp version? For reference, I tried with the latest commit to the native-comp branch, and with the latest commit as of August 6.

loafofpiecrust avatar Sep 07 '20 20:09 loafofpiecrust

Hmm, strange. I'm at commit 67c5369156 from September 4th. And just to make sure, my comp-deferred-compilation-black-list looks like: ("init\\.el" "/xcb.*\\.el" "/exwm.*\\.el").

dakra avatar Sep 08 '20 06:09 dakra

I'm also seeing the same behavior and am running the native-comp branch. Setting comp-deferred-compilation-black-list to ("init\\.el" "/xcb.*\\.el" "/exwm.*\\.el") also has not helped me either. I wonder if the generally improved performance of native-comp has perhaps exposed some race condition?

akirakyle avatar Sep 14 '20 01:09 akirakyle

I just tried it again with the latest native-comp master. When I don't exclude both xcb and exwm I get this issue described here but when I don't compile them it works.

Maybe you set the black list too late? I have this in my config

(use-package comp
  :config
  (setq comp-deferred-compilation t)
  ;; Don't try to native compile these files
  (add-to-list 'comp-deferred-compilation-black-list "/exwm.*\\.el")
  (add-to-list 'comp-deferred-compilation-black-list "/xcb.*\\.el")
  (add-to-list 'comp-deferred-compilation-black-list "init\\.el"))

And also make sure that you removed the already compiled .eln files for exwm and xcb. So for me they're currently in .emacs.d/eln-cache/28.0.50-x86_64-pc-linux-gnu-cfb9403e84a6e99e5ac1bea6ab4abade.

Obviously this all is just a work around and would be nice if it gets fixed inside exwm.

dakra avatar Sep 15 '20 13:09 dakra

Just an update that after I upgraded to the new version I also get the same bug now regardless of what's in the black-list :(

dakra avatar Sep 17 '20 08:09 dakra

I also had the same issue and couldn't fix it using all the approaches mentioned here. I will go back to emacs 28 (latest build on master) until this is solved.

dickoa avatar Sep 20 '20 20:09 dickoa

Not sure what changed, but I just updated to the latest commit e5b052d60d905209c6cefcf18c620167ed946301 and I'm not experiencing this issue anymore. I still have exwm*.el and xcb*.el added to comp-deferred-compilation-black-list.

akirakyle avatar Sep 26 '20 01:09 akirakyle

It's also working for me since the commit e5b052d60d905209c6cefcf18c620167ed946301, thanks for pointing this out @akirakyle I'm back to gccemacs now!

dickoa avatar Sep 26 '20 14:09 dickoa

I also have a working version now with the latest commit. And you don't even have to exclude exwm in comp-deferred-compilation-black-list. Works also with native compiled exwm, xcb :)

dakra avatar Sep 30 '20 06:09 dakra

Floats are fine for me on NixOS (emacs native-comp branch) if I install exwm through nix and not through doom

teu5us avatar Oct 07 '20 16:10 teu5us

Hi, I am experiencing the same problem: floatingdialog boxes (like the save file dialog in Firefox) are too big. I can resize them with super + mouse, but I have to do this every time and it is tedious. I am using emacs's master branch and I cofigure it like this ./configure --with-native-compilation --with-xwidgets I have adapted the suggested workaround like this: (setq native-comp-deferred-compilation t) (add-to-list 'native-comp-deferred-compilation-deny-list "/exwm.\.el") (add-to-list 'native-comp-deferred-compilation-deny-list "/xcb.\.el") (add-to-list 'native-comp-deferred-compilation-deny-list "init\.el") I have checked that the compiled files do not appear in the eln-cache directory. But the problem persists. Isn't there a way to force a floating window to have a particular size? Maybe this could be enforced using exwm-floating-setup-hook? Thanks for any idea you may have.

gdindi avatar Jul 04 '22 06:07 gdindi

Isn't there a way to force a floating window to have a particular size? Maybe this could be enforced using exwm-floating-setup-hook?

Perhaps a bit off topic (and feel free to remove this comment if it's too much of a plug), but I have a library that works with floating windows in exwm, and one if it's features is placement rules for windows by name

https://gitlab.com/mtekman/exwm-float.el

mtekman avatar Jul 04 '22 07:07 mtekman

Nice. I'll have a look at it.

gdindi avatar Jul 04 '22 07:07 gdindi

Using exwm-float.el and this

(add-hook 'exwm-floating-setup-hook
          (lambda ()
            (exwm-layout-hide-mode-line)
            (exwm-float-resize 400 400)))

Seems to do the trick for the "save-as" dialog in Firefox. I will experiment with other applications and report if useful.

gdindi avatar Jul 04 '22 11:07 gdindi

Well, actually, it does not work with other applications. And furthermore, if I want to disable tab-bar-mode for floating frames, it does not work at all. I don't understand why. But here is what I found that is OK for my workflow.

I have extracted this from exwm-float.el

(defun my/resize-floating-frame (width height)
  (interactive "nWidth: \nnHeight: ")
    (let ((floating-container (frame-parameter exwm--floating-frame
                                               'exwm-container)))
      (exwm--set-geometry floating-container nil nil width height)
      (exwm--set-geometry exwm--id nil nil width height)
      (xcb:flush exwm--connection)))

(exwm-input-set-key (kbd "s-x r") (lambda () (interactive) (my/resize-floating-frame 500 500)))

With that, I can resize the frames which don't have the right size, and, their size becomes correct the next time the same kind of frame pops up (save as dialogs, file selection, etc.). When I say «correct» size, I dont mean the size I manually selected when calling the function above, but the default size that the application tries to use (as one would get in a floating WM).

It's a shame that I don't understand how this things work!

I can now use the following hook without issues:

(defun my/remove-tab-bar-and-mode-line ()
  (toggle-frame-tab-bar) ;; No tab bars on floating frames
  (exwm-layout-hide-mode-line))

(add-hook 'exwm-floating-setup-hook #'my/remove-tab-bar-and-mode-line)

And I don't need to disable native comp for exwm, xcb or anything else.

I hope this helps anybody who may face similar problems.

gdindi avatar Jul 04 '22 13:07 gdindi

Hello, Just another iteration on this. I have been investigating and I found that in exwm-floating--set-floating line 297 in the call to (set-frame-size frame frame-width frame-height t) sometimes frame-height is greater than my screen size. I sometimes use a dual screen setup with 2 different sizes and one monitor on top of the other, so maybe this is the cause of the mismatch.

Anyway, the workaround that I finally adopted consists in resizing the frame in the exwm-floating-setup-hook like this:

(defun my/adjust-floating-frame-size ()
  "Ensure that the current floating exwm frame does not exceed the size of the screen"
  (let* ((frame (selected-frame))
         (width (frame-pixel-width frame))
         (height (frame-pixel-height frame))
         (w1 (elt (elt exwm-workspace--workareas 0) 2))
         (h1 (elt (elt exwm-workspace--workareas 0) 3))
         (w2 (elt (elt exwm-workspace--workareas 1) 2))
         (h2 (elt (elt exwm-workspace--workareas 1) 3))
         (max-width (min w1 w2))
         (max-height (min h1 h2))
         (final-height (min height max-height))
         (final-width (min width max-width)))
    (set-frame-size frame final-width final-height t)))
(add-hook 'exwm-floating-setup-hook #'my/adjust-floating-frame-size 100)

Note that this has to be the last function in the hook for it to work.

Not pretty, but I can work like that.

However, looking at the code of exwm-floating--set-floating I don't understand why the size is not correctly computed.

gdindi avatar Jul 13 '22 09:07 gdindi

This seems to have been corrected in 0.27.

Hello, Just another iteration on this. I have been investigating and I found that in exwm-floating--set-floating line 297 in the call to (set-frame-size frame frame-width frame-height t) sometimes frame-height is greater than my screen size. I sometimes use a dual screen setup with 2 different sizes and one monitor on top of the other, so maybe this is the cause of the mismatch.

Anyway, the workaround that I finally adopted consists in resizing the frame in the exwm-floating-setup-hook like this:

(defun my/adjust-floating-frame-size ()
  "Ensure that the current floating exwm frame does not exceed the size of the screen"
  (let* ((frame (selected-frame))
         (width (frame-pixel-width frame))
         (height (frame-pixel-height frame))
         (w1 (elt (elt exwm-workspace--workareas 0) 2))
         (h1 (elt (elt exwm-workspace--workareas 0) 3))
         (w2 (elt (elt exwm-workspace--workareas 1) 2))
         (h2 (elt (elt exwm-workspace--workareas 1) 3))
         (max-width (min w1 w2))
         (max-height (min h1 h2))
         (final-height (min height max-height))
         (final-width (min width max-width)))
    (set-frame-size frame final-width final-height t)))
(add-hook 'exwm-floating-setup-hook #'my/adjust-floating-frame-size 100)

Note that this has to be the last function in the hook for it to work.

Not pretty, but I can work like that.

However, looking at the code of exwm-floating--set-floating I don't understand why the size is not correctly computed.

This seems to have been corrected in 0.27.

gdindi avatar Nov 13 '22 16:11 gdindi