rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.71k stars 887 forks source link

Support floating hint for tiling window managers #862

Open inodentry opened 5 years ago

inodentry commented 5 years ago

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.

SlavojZizekIsASnack commented 5 years ago

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:

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

elinorbgr commented 5 years ago

(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.

agorgl commented 3 years ago

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

ardijanr commented 3 years ago

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

agorgl commented 3 years ago

Can confirm

akvadrako commented 3 years ago

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.

vimpostor commented 5 months ago

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:

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.

kchibisov commented 5 months ago

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.

vimpostor commented 5 months ago

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.

akvadrako commented 5 months ago

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.

kchibisov commented 5 months ago

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.

vimpostor commented 5 months ago

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.