git.strcat.st

/strcat/wm.git/ - summarytreelogarchivereleases

subject
inital commit
commit
230122cb4a6c1c33d8ed5c8ac65e6a21da60e410
date
2026-04-20T17:45:49Z
message
diff
 wm.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/wm.c b/wm.c
new file mode 100644
index 0000000..ee4c746
--- /dev/null
+++ b/wm.c
@@ -0,0 +1,52 @@
+#include <X11/Xlib.h>
+
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+int main()
+{
+    Display * dpy;
+    Window root;
+    XWindowAttributes attr;
+    XButtonEvent start;
+    XEvent ev;
+
+    if(!(dpy = XOpenDisplay(0x0))) return 1;
+
+    root = DefaultRootWindow(dpy);
+
+    XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("F1")), Mod1Mask, root,
+            True, GrabModeAsync, GrabModeAsync);
+    XGrabButton(dpy, 1, Mod1Mask, root, True, ButtonPressMask, GrabModeAsync,
+            GrabModeAsync, None, None);
+    XGrabButton(dpy, 3, Mod1Mask, root, True, ButtonPressMask, GrabModeAsync,
+            GrabModeAsync, None, None);
+
+    for(;;)
+    {
+        XNextEvent(dpy, &ev);
+        if(ev.type == KeyPress && ev.xkey.subwindow != None)
+            XRaiseWindow(dpy, ev.xkey.subwindow);
+        else if(ev.type == ButtonPress && ev.xbutton.subwindow != None)
+        {
+            XGrabPointer(dpy, ev.xbutton.subwindow, True,
+                    PointerMotionMask|ButtonReleaseMask, GrabModeAsync,
+                    GrabModeAsync, None, None, CurrentTime);
+            XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr);
+            start = ev.xbutton;
+        }
+        else if(ev.type == MotionNotify)
+        {
+            int xdiff, ydiff;
+            while(XCheckTypedEvent(dpy, MotionNotify, &ev));
+            xdiff = ev.xbutton.x_root - start.x_root;
+            ydiff = ev.xbutton.y_root - start.y_root;
+            XMoveResizeWindow(dpy, ev.xmotion.window,
+                attr.x + (start.button==1 ? xdiff : 0),
+                attr.y + (start.button==1 ? ydiff : 0),
+                MAX(1, attr.width + (start.button==3 ? xdiff : 0)),
+                MAX(1, attr.height + (start.button==3 ? ydiff : 0)));
+        }
+        else if(ev.type == ButtonRelease)
+            XUngrabPointer(dpy, CurrentTime);
+    }
+}