72 lines
2.7 KiB
Odin
72 lines
2.7 KiB
Odin
package wm
|
|
|
|
import fmt "core:fmt"
|
|
import "core:os"
|
|
import "core:log"
|
|
import "core:math"
|
|
import "core:strings"
|
|
import x "vendor:x11/xlib"
|
|
|
|
|
|
main :: proc () {
|
|
display: ^x.Display
|
|
root: x.Window
|
|
attr: x.XWindowAttributes
|
|
start: x.XButtonEvent
|
|
|
|
display = x.OpenDisplay(nil)
|
|
if display == nil {
|
|
fmt.println("Could not open display")
|
|
os.exit(1)
|
|
}
|
|
|
|
x.GrabKey(display, i32(x.KeysymToKeycode(display, x.StringToKeysym("F1"))), {.Mod1Mask},
|
|
x.DefaultRootWindow(display), true, .GrabModeAsync, .GrabModeAsync);
|
|
// x.GrabButton(display, 1, Mod1Mask, DefaultRootWindow(dpy), true,
|
|
// ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
|
// XGrabButton(display, 3, Mod1Mask, DefaultRootWindow(display), true,
|
|
// ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
|
// x.SelectInput
|
|
// display,
|
|
// root,
|
|
// {.SubstructureRedirect, .SubstructureNotify});
|
|
// x.Synchronize(display, false);
|
|
|
|
for {
|
|
e: x.XEvent
|
|
x.NextEvent(display, &e)
|
|
fmt.println("Received Event: ", e)
|
|
|
|
#partial switch e.type {
|
|
case .KeyPress:
|
|
x.RaiseWindow(display, e.xkey.subwindow)
|
|
case .ButtonPress:
|
|
x.GetWindowAttributes(display, e.xbutton.subwindow, &attr)
|
|
start = e.xbutton
|
|
case .MotionNotify:
|
|
xdiff := e.xbutton.x_root - start.x_root;
|
|
ydiff := e.xbutton.y_root - start.y_root;
|
|
xpos := attr.x + (start.button==.Button1 ? xdiff : 0)
|
|
ypos := attr.y + (start.button==.Button1 ? ydiff : 0)
|
|
width := u32(max(1, attr.width + (start.button==.Button2 ? xdiff : 0)))
|
|
height := u32(max(1, attr.height + (start.button==.Button2 ? ydiff : 0)))
|
|
x.MoveResizeWindow(display, start.subwindow, xpos, ypos, width, height)
|
|
case .ButtonRelease:
|
|
// start.subwindow = nil;
|
|
}
|
|
// else if(ev.xbutton.subwindow != None)
|
|
// else if(ev.type == MotionNotify && start.subwindow != None)
|
|
// {
|
|
// int xdiff = ev.xbutton.x_root - start.x_root;
|
|
// int ydiff = ev.xbutton.y_root - start.y_root;
|
|
// XMoveResizeWindow(dpy, start.subwindow,
|
|
// 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)
|
|
// start.subwindow = None;
|
|
}
|
|
}
|