wm

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

commit 32f6a73983286069d296035ddaf8ec66bb2a9039
parent 01b8b2b9b01080b5df961068e601ebcb1b96b155
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Sun, 28 Jun 2026 04:12:51 -0300

Squashed commit of the following:

commit 2bfba826fb1b943d29991a8859847cc81dd80c85
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Sun Jun 28 03:52:16 2026 -0300

    Returning to this project

commit e6f7a4be533d3ea8b858ba8786945aae6b0ac3bf
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Tue Jan 7 23:34:06 2025 -0500

    Send WM_DELETE_WINDOW if supported

commit b6babddd30f882a3d16eb57301062630e4fbc08e
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Tue Jan 7 23:30:30 2025 -0500

    Improve logging with hexadecimals

Diffstat:
Mpwm.c | 50+++++++++++++++++++++++++++++++++++++-------------
1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/pwm.c b/pwm.c @@ -123,7 +123,7 @@ int main(void) XSelectInput(dpy, ev.xmaprequest.window, EnterWindowMask | FocusChangeMask | PropertyChangeMask | StructureNotifyMask); } XMapWindow(dpy, ev.xmaprequest.window); - fprintf(stderr, "%d: XMapRequestEvent %lu, num_windows: %d\n", ev.type, ev.xmaprequest.window, num_windows); + fprintf(stderr, "%d: XMapRequestEvent 0x%lx, num_windows: %d\n", ev.type, ev.xmaprequest.window, num_windows); break; case UnmapNotify: for (int i = 0; i < num_windows; i++) { @@ -134,10 +134,11 @@ int main(void) } } current_index = current_index % num_windows; - fprintf(stderr, "%d: XUnmapEvent %lu, num_windows = %d\n", ev.type, ev.xunmap.window, num_windows); + fprintf(stderr, "%d: XUnmapEvent 0x%lx, num_windows = %d\n", ev.type, ev.xunmap.window, num_windows); + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); break; case ClientMessage: - fprintf(stderr, "%d: XClientMessageEvent %lu\n", ev.type, ev.xclient.window); + fprintf(stderr, "%d: XClientMessageEvent 0x%lx\n", ev.type, ev.xclient.window); Atom net_wm_state = XInternAtom(dpy, "_NET_WM_STATE", False); Atom net_wm_state_fullscreen = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); @@ -150,7 +151,7 @@ int main(void) 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 || (action == 2 && !is_fullscreen)) { // _NET_WM_STATE_ADD || _NET_WM_STATE_TOGGLE - fprintf(stderr, "Setting window %lu to fullscreen\n", ev.xclient.window); + fprintf(stderr, "Setting window 0x%lx 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 = { @@ -163,7 +164,7 @@ int main(void) XConfigureWindow(dpy, ev.xclient.window, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc); 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); + fprintf(stderr, "Exiting fullscreen for window 0x%lx\n", ev.xclient.window); XSetWindowBorderWidth(dpy, ev.xclient.window, BORDER_WIDTH); XDeleteProperty(dpy, ev.xclient.window, net_wm_state); XWindowChanges wc = { @@ -188,7 +189,6 @@ int main(void) } else if (ev.xkey.keycode == XKeysymToKeycode(dpy, XStringToKeysym("j"))) { XSetWindowBorder(dpy, windows[current_index], BORDER_COLOR); current_index = (current_index + num_windows - 1) % num_windows; - XSetInputFocus(dpy, windows[current_index], RevertToParent, CurrentTime); XRaiseWindow(dpy, windows[current_index]); XSetWindowBorder(dpy, windows[current_index], 0xAAAAAA); @@ -202,7 +202,7 @@ int main(void) } XFree(protocols); } - printf("supported WM_TAKE_FOCUS = %d\n", exists); + printf("supported WM_TAKE_FOCUS = %d\n", supported); if (supported) { XClientMessageEvent send_ev = { .type = ClientMessage, @@ -213,12 +213,12 @@ int main(void) .data.l[1] = CurrentTime, }; XSendEvent(dpy, windows[current_index], False, NoEventMask, (XEvent *)&send_ev); + } else { + XSetInputFocus(dpy, windows[current_index], RevertToPointerRoot, CurrentTime); } - } else if (ev.xkey.keycode == XKeysymToKeycode(dpy, XStringToKeysym("k"))) { XSetWindowBorder(dpy, windows[current_index], BORDER_COLOR); current_index = (current_index + 1) % num_windows; - XSetInputFocus(dpy, windows[current_index], RevertToParent, CurrentTime); XRaiseWindow(dpy, windows[current_index]); XSetWindowBorder(dpy, windows[current_index], 0xAAAAAA); @@ -232,7 +232,7 @@ int main(void) } XFree(protocols); } - printf("supported WM_TAKE_FOCUS = %d\n", exists); + printf("supported WM_TAKE_FOCUS = %d\n", supported); if (supported) { XClientMessageEvent send_ev = { .type = ClientMessage, @@ -243,6 +243,8 @@ int main(void) .data.l[1] = CurrentTime, }; XSendEvent(dpy, windows[current_index], False, NoEventMask, (XEvent *)&send_ev); + } else { + XSetInputFocus(dpy, windows[current_index], RevertToPointerRoot, CurrentTime); } } else if (ev.xkey.keycode == XKeysymToKeycode(dpy, XStringToKeysym("c"))) { if (wmcheckwin) { @@ -252,7 +254,7 @@ int main(void) wmcheckwin = None; } else { wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0); - fprintf(stderr, "wmcheckwin = %ld\n", wmcheckwin); + fprintf(stderr, "wmcheckwin = 0x%lx\n", wmcheckwin); XChangeProperty(dpy, wmcheckwin, XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False), XA_WINDOW, 32, PropModeReplace, (unsigned char *)&wmcheckwin, 1); XChangeProperty( dpy, wmcheckwin, XInternAtom(dpy, "_NET_WM_NAME", False), XInternAtom(dpy, "UTF8_STRING", False), 8, PropModeReplace, (unsigned char *)"pwm", 3); @@ -281,7 +283,7 @@ int main(void) XGetClassHint(dpy, windows[i], &class_hint); fprintf(stderr, - "%lu: %s - %s - %s - %d - (%d, %d, %d, %d) - " + "0x%lx: %s - %s - %s - %d - (%d, %d, %d, %d) - " "%d(%lu)\n", windows[i], window_name, @@ -308,7 +310,7 @@ int main(void) } XFree(protocols); } - printf("supported WM_DELETE_WINDOW = %d\n", exists); + printf("supported WM_DELETE_WINDOW = %d\n", supported); if (supported) { XClientMessageEvent send_ev = { @@ -377,6 +379,28 @@ int main(void) break; case DestroyNotify: fprintf(stderr, "ev.type = %2d = DestroyNotify, window = 0x%lx\n", ev.type, ev.xdestroywindow.window); + Window focus_destroy; + int revert_to_destroy; + XGetInputFocus(dpy, &focus_destroy, &revert_to_destroy); + fprintf(stderr, "focus = %lx, revert_to = %d\n", focus_destroy, revert_to_destroy); + break; + case FocusIn: + fprintf(stderr, "ev.type = %2d ", ev.type); + fprintf(stderr, "= FocusIn "); + fprintf(stderr, "serial = %lu, send_event = %d, window = 0x%lx, mode = %d, detail = %d\n", ev.xfocus.serial, ev.xfocus.send_event, ev.xfocus.window, ev.xfocus.mode, ev.xfocus.detail); + Window focus_in; + int revert_to_in; + XGetInputFocus(dpy, &focus_in, &revert_to_in); + fprintf(stderr, "focus = %lx, revert_to = %d\n", focus_in, revert_to_in); + break; + case FocusOut: + fprintf(stderr, "ev.type = %2d ", ev.type); + fprintf(stderr, "= FocusOut "); + fprintf(stderr, "serial = %lu, send_event = %d, window = 0x%lx, mode = %d, detail = %d\n", ev.xfocus.serial, ev.xfocus.send_event, ev.xfocus.window, ev.xfocus.mode, ev.xfocus.detail); + Window focus_out; + int revert_to_out; + XGetInputFocus(dpy, &focus_out, &revert_to_out); + fprintf(stderr, "focus = %lx, revert_to = %d\n", focus_out, revert_to_out); break; default: fprintf(stderr, "ev.type = %2d ", ev.type);