winit icon indicating copy to clipboard operation
winit copied to clipboard

Support floating hint for tiling window managers

Open inodentry opened this issue 6 years ago • 12 comments
trafficstars

On X11 (and I think Wayland too?) there is a standard to provide extra hints to the window manager when creating a window. One of the things this allows is requesting that a tiling/dynamic window manager not tile the window (open it in floating mode instead).

This is an important feature in order to provide a good user experience for people using such window managers, as there are many kinds of application windows which should be opened this way (games should work this way when not fullscreen and normal GUI apps should use this for dialogs, settings windows, floating toolbars, etc.).

AFAIK winit does not currently support this. Please consider adding support.

inodentry avatar May 07 '19 12:05 inodentry

i3 determines if a window should be floating by the _NET_WM_WINDOW_TYPE. It is my understanding that the following variants are floats by default:

  • dialog,
  • utility,
  • toolbar,
  • splash

Also, I'm not sure this is X11 specific, although I don't know how, for example, sway handles this.

SlavojZizekIsASnack avatar Jun 08 '19 22:06 SlavojZizekIsASnack

(and I think Wayland too?)

I'm not aware of any relatively standard mechanism for doing so, sadly. AFAIK sway does some guesswork to decide whether to tile a window.

elinorbgr avatar Jun 10 '19 11:06 elinorbgr

This is how GLFW does it: https://github.com/glfw/glfw/blob/1adfbde4d7fb862bb36d4a20e05d16bf712170f3/src/x11_window.c#L2635

agorgl avatar Dec 29 '20 10:12 agorgl

Setting fixed window size and making it not resizable seems to force floating window on i3 and dwm. Some standard would be nice.

ardijanr avatar Jan 06 '21 13:01 ardijanr

Can confirm

agorgl avatar Jan 06 '21 16:01 agorgl

Setting fixed window size and making it not resizable seems to force floating window on i3 and dwm. Some standard would be nice.

This also works on sway; one can also enable resizing after it's drawn. If someone is interested in getting a standard feature it has been suggested to make a PR in the wayland-protocols repo.

akvadrako avatar Mar 19 '21 12:03 akvadrako

If anyone is interested, here is the relevant Sway source code for Wayland clients: https://github.com/swaywm/sway/blob/bc258a3be2f946c1c93bcbe40735b2db068e0ea8/sway/desktop/xdg_shell.c#L221-L225

So the only way to force a window to be floating by default, is to set maximum and minimum width (or alternatively height) to the same non-zero value (i.e. make the window non-resizable).

It seems there is no way on Wayland to have a resizable window be floating by default, which is rather unfortunate.

Here is the source code for XWayland clients: https://github.com/swaywm/sway/blob/bc258a3be2f946c1c93bcbe40735b2db068e0ea8/sway/desktop/xwayland.c#L324-L327

So for X11 we luckily have the window type property, and sway (and most X11 tiling WMs) will additionally float a client, if it is set to one of the following values:

  • NET_WM_WINDOW_TYPE_DIALOG
  • NET_WM_WINDOW_TYPE_UTILITY
  • NET_WM_WINDOW_TYPE_TOOLBAR
  • NET_WM_WINDOW_TYPE_SPLASH

Unless Wayland adds support for something similar to this basic feature, it is impossible to set a hint that signals "do not tile this window" while also allowing to resize the window.

vimpostor avatar Apr 10 '24 14:04 vimpostor

You on wayland control the size yourself, you can resize however you want, it's just entirely up to you to handle all of that.

kchibisov avatar Apr 10 '24 15:04 kchibisov

you can resize however you want, it's just entirely up to you to handle all of that.

Right, if you use non-resizable mode, you can effectively simulate support for resizing by adding your own mouse handlers that always update maximumWidth == minimumWidth and maximumHeight == minimumHeight to some new value.

That is a ridiculous workaround though and would mean reimplementing basic resizing logic just to be able to have a window be floating by default on sway.

vimpostor avatar Apr 10 '24 15:04 vimpostor

Another workaround is to initially set the window to fixed size. Sway will make it float. After it displays (under a second later) you can make it resizable. I've done this before and it works, though it's pretty hacky.

akvadrako avatar Apr 10 '24 21:04 akvadrako

What's the end goal here btw? If to show dialog, there's a new protocol https://wayland.app/protocols/xdg-dialog-v1 for them which we may utilize.

kchibisov avatar Apr 10 '24 21:04 kchibisov

What's the end goal here btw?

What the issue description above says, i.e. float a window.

there's a new protocol https://wayland.app/protocols/xdg-dialog-v1

It's quite limited and doesn't work for top-level windows. Some windows for system utilities might want to be floating by default, but they are not a dialog so your protocol is no use for them.

vimpostor avatar Apr 10 '24 23:04 vimpostor