Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't force an app to not float by config #91

Open
xpusostomos opened this issue Dec 3, 2024 · 14 comments
Open

Can't force an app to not float by config #91

xpusostomos opened this issue Dec 3, 2024 · 14 comments

Comments

@xpusostomos
Copy link

There doesn't seem to be a way to force an app to not float via configuration. I'm using the Jetbrains toolbox app, which apparently sets preferences to float, but I don't want it to.

There are at least 2 issues I see... firstly, there is a function called exwm-floating-toggle-floating. This is not good practice to only have a function that toggles something, rather than having a function which explicitely says true or false to floating... And this leads into the second problem...

If I set a hook to attempt to force it to float...

(add-hook 'exwm-manage-finish-hook
          (lambda ()
	    (if exwm-class-name
		(cond 
		 ((string= exwm-class-name "jetbrains-toolbox")
		  (exwm-floating-toggle-floating))))))

It doesn't work. I suspect it might be a timing issue in that the slow opening of the window, doesn't give it time to tell it what to do..

The reason I say this, is that jetbrains-toolbox is helpfully coded to only allow one instance to run at once. So if you try and run it twice, it seems to look and see, hey it's already running, and exit.

HOWEVER, the interesting thing is, if you try running a second instance, the existing instance will THEN toggle to a non-floating frame.

Then if you try and run a 3rd time, it will toggle again back to floating, ad infinitum. And that's why I'm guessing that the problem here is one of timing, that exwm is capable of telling the window how to open non-floating, but only if it opens quick enough. That's my guess anyway.

I'm not enough of an emacs guru to know if maybe there's a way to set some kind of timer to force it to do it. However, even if I could do something like that, the issue of the function toggling, rather than asserting what state it wants, is bound to lead to issues again.

I have seen around the web some old code which seemed to use undocumented variables to try and get around the toggling behaviour, but it didn't work for me, and in any case we should have a documented function to set floating positively, rather than toggling.

@walseb
Copy link
Contributor

walseb commented Dec 3, 2024

Maybe you could set exwm-manage-force-tiling to t right before you launch the app and then set it back when it's launched? That doesn't seem like a solid solution however.

Perhaps we should add a predicate variable here to make this possible: https://github.com/emacs-exwm/exwm/blob/master/exwm-manage.el#L402

For the moment, think I would simply advice exwm-floating--set-floating and have it not run if the exwm-class-name is jetbrains-toolbox. Something like this:

(advice-add 'exwm-floating--set-floating :around
            (defun my/lambda-1719660754 (orig-func &rest args)
              (when (not (string= exwm-class-name "jetbrains-toolbox"))
                (apply orig-func args))))

But perhaps the exwm-class-name isn't set by the time that code runs?

@Stebalien
Copy link
Contributor

You should be able to use exwm-manage-configurations. Something like:

(push '((string= exwm-class-name "jetbrains-toolbox") floating nil)) exwm-manage-configurations)

@xpusostomos
Copy link
Author

@Stebalien I've seen code around that uses exwm-manage-configurations, and I'm confused when to use it vs exwm-manage-finish-hook .... Also it doesn't seem documented.

@Stebalien
Copy link
Contributor

In general:

  1. Use this variable to specify window defaults. It's documented through the customize interface (I recommend going through M-x customize-group RET exwm RET). There are also a few examples in https://github.com/emacs-exwm/exwm/wiki.
  2. Use the manage finish hook if you need to do something every time EXWM adopts a new window. I don't actually use this hook in my own config.

Although I'm not entirely sure why your initial code isn't working...

@xpusostomos
Copy link
Author

Question: I've noticed some other annoying behaviors. Are they expected?

Firstly, if I open a floating window (jetbrains-toolbox), hide the window, then switch to another workspace, and back again, the floating window comes back. It won't stay hidden.

Secondly, if I select a floating window from the buffer menu, it stays hidden. I would have thought that would be the obvious way to bring a hidden window back.

Thirdly, when I stop jetbrains toolbox from floating and make it a full frame, I can't switch away from it with say, C-x C-b. No emacs input is accepted. I assume what I'm supposed to do then is s-r (exwm-reset). The trouble is, that makes it float again. why?

Fourthly, when I turn off floating (exwm-floating-toggle-floating), and I have say, 4 windows open on the screen, I would have thought it should either grab one of the 4 windows, or else disappear into the buffer list... however what it does in fact is go full screen. So it's impossible to get it into a frame, because after it's full screen, it won't accept emacs input, I have to exwm-reset, and it goes floating again.

@Stebalien
Copy link
Contributor

I've never used the "hide floating window" feature (didn't even know it existed). You're right, that looks pretty buggy. Can you file a separate issue for that?

Thirdly, when I stop jetbrains toolbox from floating and make it a full frame, I can't switch away from it with say, C-x C-b. No emacs input is accepted. I assume what I'm supposed to do then is s-r (exwm-reset). The trouble is, that makes it float again. why?

By "a full frame" do you mean C-x C-b 1 or exwm-layout-set-fullscreen?

Anyways, I'm guessing this is a line-mode/char-mode issue. The window is probably in char-mode and should be in line-mode (you can call exwm-input-grab-keyboard to switch back to line-mode).

Fourthly, when I turn off floating (exwm-floating-toggle-floating), and I have say, 4 windows open on the screen, I would have thought it should either grab one of the 4 windows, or else disappear into the buffer list... however what it does in fact is go full screen. So it's impossible to get it into a frame, because after it's full screen, it won't accept emacs input, I have to exwm-reset, and it goes floating again.

By this I assume you mean really full-screen (no mode line, etc.)? Honestly, it sounds like Jetbrains is setting some interesting window properties. Can you use xprop to get the window properties and post them here?

@xpusostomos
Copy link
Author

You ask what I mean by full frame. I don't know because all I was doing was exwm-floating-toggle-floating. I wasn't aiming for full frame, that's what it forced on me. I would have expected it should either grab a window, or else go away to the buffer list so I could retrieve it to a window. But instead it grabs the whole screen.

You suggest exwm-input-grab-keyboard. Difficult, since no emacs keys work at that point. I tried assigning that function to a hot key, but that didn't do anything either. All that did anything was s-r, which is exwm-reset. At that point it floated again. So it was impossible to get it into a window.

I can create more issues, how many of the 4 points do you think this warrants? (BTW, are you a maintainer here?)

@Stebalien
Copy link
Contributor

I mean:

  1. Full-frame as in a full emacs window.
  2. Full-screen as in you can't even see emacs.

It sounds like the latter.


BTW, are you a maintainer here

One of them, yes.

I can create more issues

  1. One for the issues related to the "hide floating window" setting (your first/second points).
  2. One for the issue where the Jetbrains window goes fullscreen when switching from floating to tiling. For that one, we'll need to see the output of xprop when clicking on the window (when it's floating) and it would be helpful to get a screenshot of what it looks like when it goes full screen.

@xpusostomos
Copy link
Author

Yes, you're right I can't even see emacs at that point. I have a key mapped to exwm-floating-toggle-floating and it goes full screen such that I can't see emacs, and that's not what I would have expected.

@xpusostomos
Copy link
Author

@Stebalien I tried your suggestion, and put this in my config:

(setq exwm-manage-configurations '(((string= exwm-class-name "jetbrains-toolbox")
                                   floating nil)))

but it didn't work. Puzzled, I put this in to try:

 (setq exwm-manage-configurations '((t floating nil)))

And then nothing floats, including jetbrains-toolbox, which is corect. So it's puzzling why the first code doesn't work.

Then I noticed that if I put the first version of the code back, restarted... then started toolbox, killed toolbox, then started it a 2nd time, it worked then! 3rd time works, 4th time works, but 1st time no. So that's strange, I don't know if it's some kind of race condition or what. But it does seem consistent that the 1st time never works.

@Stebalien
Copy link
Contributor

I'm not 100% sure, maybe Jetbrains is mapping the window before setting the class name? You'd have to log inside a exwm-manage-finish-hook. That would also explain why using the manage finish hook wasn't working.

@ezemtsov
Copy link

@xpusostomos could that be related to _JAVA_AWT_WM_NONREPARENTING? Try setting the env variable to 1.

I had similar issues with the Rider, it might solve it for you.

@xpusostomos
Copy link
Author

I have since set _JAVA_AWT_WM_NONREPARENTING, because it was needed to get squirrel-sql to work. I think it might have had some effect. It doesn't grab the whole screen anymore when I turn off floating. However trying to stop floating in the exwm-manage-finish-hook still doesn't work. I haven't got around yet to trying exwm-manage-configurations. However something also got worse, hiding the floating window doesn't seem to work at all. Sometimes it blinks for a fraction of a second, but it doesn't disappear. Hmm.... Hiding a floating Chrome doesn't work either now, so maybe not related to that. Not sure what's going on there.

@xpusostomos
Copy link
Author

I figured out a clue... I noticed the first time I run Toolbox, its class name in the buffer list is "com-jetbrains-toolbox-entry-ToolboxEntry" ... despite xprop saying it is "jetbrains-toolbox" ... on subsequent runs, it correctly is reported as "jetbrains-toolbox". I don't know if the program is changing its window classname early in its startup sequence, or whether there is a bug in exwm. It's certainly odd that the first run is different, and that xprop returns the right thing. If the program was doing something odd, why only the first time? Makes me think exwm is to blame. Anyway I am able to get around it by naming both possibilities...

(setq exwm-manage-configurations '(((or (string= exwm-class-name "jetbrains-toolbox")
				        (string= exwm-class-name "com-jetbrains-toolbox-entry-ToolboxEntry"))
                                    floating nil)))
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants