9fans / plan9port

Plan 9 from User Space
https://9fans.github.io/plan9port/
Other
1.64k stars 326 forks source link

devdraw: X11: fullscreen is not portable between WMs #220

Open wgrr opened 5 years ago

wgrr commented 5 years ago

if devdraw was supposed to be used under rio in X11 systems, ignore this issue.

most of windows managers wont let client draw over the window decorations, so you cannot fullscreen on these, some like rio will. for me, i did what this freedesktop spec suggests, sent an event atom "_NET_WM_STATE_FULLSCREEN" and it works as expected.

diff --git a/src/cmd/devdraw/x11-memdraw.h b/src/cmd/devdraw/x11-memdraw.h
index d2cab13b..2739380e 100644
--- a/src/cmd/devdraw/x11-memdraw.h
+++ b/src/cmd/devdraw/x11-memdraw.h
@@ -101,7 +101,7 @@ extern char*        _xgetsnarf(void);
 extern void        _xputsnarf(char *data);
 extern void        _xtopwindow(void);
 extern void        _xresizewindow(Rectangle);
-extern void        _xmovewindow(Rectangle);
+extern void        _xmovewindow(void);
 extern int     _xreplacescreenimage(void);

 #define MouseMask (\
diff --git a/src/cmd/devdraw/x11-wsys.c b/src/cmd/devdraw/x11-wsys.c
index 9095c950..aa7dd4cd 100644
--- a/src/cmd/devdraw/x11-wsys.c
+++ b/src/cmd/devdraw/x11-wsys.c
@@ -29,18 +29,22 @@ _xresizewindow(Rectangle r)
 }

 void
-_xmovewindow(Rectangle r)
+_xmovewindow(void)
 {
-   XWindowChanges e;
-   int value_mask;
+   Atom st, fs;
+   XEvent ev;

-   memset(&e, 0, sizeof e);
-   value_mask = CWX|CWY|CWWidth|CWHeight;
-   e.x = r.min.x;
-   e.y = r.min.y;
-   e.width = Dx(r);
-   e.height = Dy(r);
-   XConfigureWindow(_x.display, _x.drawable, value_mask, &e);
+   st = XInternAtom(_x.display, "_NET_WM_STATE", False);
+   fs = XInternAtom(_x.display, "_NET_WM_STATE_FULLSCREEN", False);
+   memset(&ev, 0, sizeof ev);
+   ev.type = ClientMessage;
+   ev.xclient.window = _x.drawable;
+   ev.xclient.message_type = st;
+   ev.xclient.format = 32;
+   ev.xclient.data.l[0] = 2;
+   ev.xclient.data.l[1] = fs;
+   ev.xclient.data.l[2] = 0;
+   XSendEvent(_x.display, DefaultRootWindow(_x.display), False, 
+       SubstructureRedirectMask|SubstructureNotifyMask, &ev);
    XFlush(_x.display);
 }
-
gdiazlo commented 5 years ago

Thanks! this patch worked fine for me! would you contribute a PR?

wgrr commented 5 years ago

@gdiazlo well, i could, but first i need to make it work on rio, rio just ignore NET_WM_STATE_FULLSCREEN messages, this patch breaks devdraw on rio.

eekee commented 4 years ago

Wow... It's rio which should be fixed, NET_WM_STATE_FULLSCREEN must be nearly 20 years old. It doesn't look complicated: "_NET_WM_STATE_FULLSCREEN indicates that the window should fill the entire screen and have no window decorations. Additionally the Window Manager is responsible for restoring the original geometry after a switch from fullscreen back to normal window." -- https://specifications.freedesktop.org/wm-spec/1.3/ar01s05.html

Alternative: Use just-about any other window manager. There's even a rio-like compositor for Wayland; it's called wio.

nsajko commented 4 years ago

I think _NET_WM_STATE_FULLSCREEN and its specification, "Extended Window Manager Hints", are just Freedesktop's preference. Thus it may be preferable to stick to the standard, ICCCM, if possible, and pretend EWMH does not exist.

nsajko commented 4 years ago

To clarify, I am not really familiar with EWMH, but it is my understanding that it is somewhat geared towards the "big" "desktop environments" like Gnome, KDE, etc.; and thus I fear that relying on it too much might be harmful to users like me who use simple window managers.

rsc commented 4 years ago

Can we just do both?

rsc commented 4 years ago

That is, can we just do the XConfigureWindow call and the NET_WM_STATE_FULLSCREEN call?

eekee commented 4 years ago

@nsajko: EWMH doesn't seem very large and part of the reason for its existence is clarifying the notoriously difficult and obscure ICCCM. I'm no fan of freedesktop.org, but I think they did good with EWMH; I recall things started working better with its introduction.

@rsc: I can hardly find anything on it; even more so than usual for my searches. Is it possible to test if the window manager supports _NET_WM_STATE_FULLSCREEN? If yes, then we have a way to fall back to XConfigureWindow.

dwm's source came up, which might be helpful if fixing rio. I used to follow its development, they had quite a discussion on getting fullscreen working properly.