wm

My window manager
git clone git://pcardenasb.com/wm
Log | Files | Refs

commit 85f5edd9f82508eced70d069d39a2185e03333c6
parent f6f6a4f70db514d79204e64c06d7ddd2c2e12b5e
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Sat,  4 Jan 2025 16:26:19 -0500

Supports _NET_WM_STATE_TOGGLE

Diffstat:
Mpwm.c | 20++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/pwm.c b/pwm.c @@ -97,6 +97,8 @@ int main(void) // Main Loop // /////////////// XWindowAttributes pressed_wa; + XWindowAttributes fullscreen_wa; + bool is_fullscreen = 0; XButtonEvent start = {.subwindow = None}; XSync(dpy, False); @@ -140,15 +142,17 @@ int main(void) Atom net_wm_state_fullscreen = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); fprintf(stderr, "ev.xclient.message_type = %lu = %s\n", ev.xclient.message_type, XGetAtomName(dpy, ev.xclient.message_type)); + // https://specifications.freedesktop.org/wm-spec/1.3/ar01s05.html#id-1.6.8 if (ev.xclient.message_type == net_wm_state) { Atom action = ev.xclient.data.l[0]; Atom property = (Atom)ev.xclient.data.l[1]; fprintf(stderr, "ev.xclient.data.l[0] = %lu\n", ev.xclient.data.l[0]); fprintf(stderr, "ev.xclient.data.l[1] = %lu = %s\n", ev.xclient.data.l[1], XGetAtomName(dpy, ev.xclient.data.l[1])); if (property == net_wm_state_fullscreen) { - if (action == 1) { // _NET_WM_STATE_ADD + if (action == 1 || (action == 2 && !is_fullscreen)) { // _NET_WM_STATE_ADD || _NET_WM_STATE_TOGGLE fprintf(stderr, "Setting window %lu to fullscreen\n", ev.xclient.window); XChangeProperty(dpy, ev.xclient.window, net_wm_state, XA_ATOM, 32, PropModeReplace, (unsigned char *)&net_wm_state_fullscreen, 1); + XGetWindowAttributes(dpy, ev.xclient.window, &fullscreen_wa); XWindowChanges wc = { .x = 0, .y = 0, @@ -157,12 +161,20 @@ int main(void) .border_width = 0, }; XConfigureWindow(dpy, ev.xclient.window, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc); - XSync(dpy, False); - } else if (action == 0) { // _NET_WM_STATE_REMOVE + is_fullscreen = 1; + } else if (action == 0 || (action == 2 && is_fullscreen)) { // _NET_WM_STATE_REMOVE || _NET_WM_STATE_TOGGLE fprintf(stderr, "Exiting fullscreen for window %lu\n", ev.xclient.window); XSetWindowBorderWidth(dpy, ev.xclient.window, BORDER_WIDTH); XDeleteProperty(dpy, ev.xclient.window, net_wm_state); - // Restore window to its previous size and position here + XWindowChanges wc = { + .x = fullscreen_wa.x, + .y = fullscreen_wa.y, + .height = fullscreen_wa.height, + .width = fullscreen_wa.width, + .border_width = fullscreen_wa.border_width, + }; + XConfigureWindow(dpy, ev.xclient.window, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc); + is_fullscreen = 0; } } }