Dobrý den,
co jiného může být lepším základem pro vlastní XWindowManager, než TinyWM... :) (50 řádků kódu...) V C to jede:
https://github.com/…ter/tinywm.c
Ale přepis do D:
import std.c.linux.X11.Xlib;
import std.c.linux.X11.X;
// gdc ./main.d /usr/include/d2/4.6/std/c/linux/X11/Xlib.d -o refuja -lX11
int main()
{
Display *display0 = XOpenDisplay(cast(char*)0);
XWindowAttributes winAttributes;
XButtonEvent start;
XEvent xEvent;
if(!display0)
return 1;
XGrabKey(display0, XKeysymToKeycode(display0, XStringToKeysym(cast(char*)"F1")), KeyMask.Mod1Mask, DefaultRootWindow(display0), cast(Bool)true, GrabMode.GrabModeAsync, GrabMode.GrabModeAsync);
XGrabButton(display0, 1, KeyMask.Mod1Mask, DefaultRootWindow(display0), cast(Bool)true, EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionMask, GrabMode.GrabModeAsync, GrabMode.GrabModeAsync, None, None);
XGrabButton(display0, 3, KeyMask.Mod1Mask, DefaultRootWindow(display0), cast(Bool)true, EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionMask, GrabMode.GrabModeAsync, GrabMode.GrabModeAsync, None, None);
start.subwindow = None;
while(true)
{
XNextEvent(display0, &xEvent);
if(xEvent.type == EventType.KeyPress && xEvent.xkey.subwindow != None)
XRaiseWindow(display0, xEvent.xkey.subwindow);
else if(xEvent.type == EventType.ButtonPress && xEvent.xbutton.subwindow != None)
{
XGetWindowAttributes(display0, xEvent.xbutton.subwindow, &winAttributes);
start = xEvent.xbutton;
}
else if(xEvent.type == EventType.MotionNotify && start.subwindow != None)
{
int xdiff = xEvent.xbutton.x_root - start.x_root,
ydiff = xEvent.xbutton.y_root - start.y_root;
XMoveResizeWindow(display0, start.subwindow,
winAttributes.x + (start.button==1 ? xdiff : 0),
winAttributes.y + (start.button==1 ? ydiff : 0),
Max(1, winAttributes.width + (start.button == 3 ? xdiff : 0)),
Max(1, winAttributes.height + (start.button == 3 ? ydiff : 0)));
}
else if(xEvent.type == EventType.ButtonRelease)
start.subwindow = None;
}
}
int Max(int a, int b)
{
return (a > b ? a : b);
}
Jen problikne a konec. Smím vědět proč? :)
Děkuji.