finish tinywm and change directory structure
This commit is contained in:
parent
92751b3efd
commit
3baf563d0a
4 changed files with 53 additions and 44 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1 @@
|
||||||
bin/*
|
wm
|
13
Makefile
13
Makefile
|
@ -1,15 +1,10 @@
|
||||||
SRC_DIR=src
|
|
||||||
BIN_DIR=bin
|
|
||||||
WM_SOURCES_MAIN=$(SRC_DIR)/main.c
|
|
||||||
WM_SOURCES=$(WM_SOURCES_MAIN)
|
|
||||||
|
|
||||||
PREFIX?=/usr/X11R6
|
PREFIX?=/usr/X11R6
|
||||||
CFLAGS?=-Os -pedantic -Wall
|
CFLAGS?=-Os -pedantic -Wall
|
||||||
|
|
||||||
all: $(WM_SOURCES) wm
|
all: wm
|
||||||
|
|
||||||
wm: $(WM_SOURCES_MAIN)
|
wm: wm.c
|
||||||
$(CC) $(CFLAGS) -I$(PREFIX)/include $< -L$(PREFIX)/lib -lX11 -o $(BIN_DIR)/wm
|
$(CC) $(CFLAGS) -I$(PREFIX)/include wm.c -L$(PREFIX)/lib -lX11 -o wm
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(BIN_DIR)/*
|
rm -f wm
|
34
src/main.c
34
src/main.c
|
@ -1,34 +0,0 @@
|
||||||
// Some things taken from https://github.com/mackstann/tinywm
|
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
|
|
||||||
#define MODMASK Mod1Mask
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
Display* display;
|
|
||||||
XWindowAttributes attr;
|
|
||||||
|
|
||||||
// Used to store the state of the cursor when resizing
|
|
||||||
XButtonEvent start;
|
|
||||||
|
|
||||||
XEvent ev;
|
|
||||||
|
|
||||||
bool isRunning = true;
|
|
||||||
|
|
||||||
|
|
||||||
if(!(dpy = XOpenDisplay(0x0))) return 1;
|
|
||||||
|
|
||||||
XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("F1")), MODMASK, DefaultRootWindow(dpy), True, GrabModeAsync, GrabModeAsync);
|
|
||||||
XGrabButton(dpy, 1, MODMASK, DefaultRootWindow(dpy), True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
|
||||||
XGrabButton(dpy, 3, MODMASK, DefaultRootWindow(dpy), True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
|
||||||
|
|
||||||
start.subwindow = None;
|
|
||||||
|
|
||||||
while(isRunning) {
|
|
||||||
XNextEvent(dpy, &ev);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
48
wm.c
Normal file
48
wm.c
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
// Taken from https://github.com/mackstann/tinywm
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
#define MODMASK Mod1Mask
|
||||||
|
|
||||||
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Display* dpy;
|
||||||
|
XWindowAttributes attr;
|
||||||
|
|
||||||
|
// Used to store the state of the cursor when resizing
|
||||||
|
XButtonEvent start;
|
||||||
|
|
||||||
|
XEvent ev;
|
||||||
|
|
||||||
|
if(!(dpy = XOpenDisplay(0x0))) return 1;
|
||||||
|
|
||||||
|
XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("F1")), MODMASK, DefaultRootWindow(dpy), True, GrabModeAsync, GrabModeAsync);
|
||||||
|
XGrabButton(dpy, 1, MODMASK, DefaultRootWindow(dpy), True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
||||||
|
XGrabButton(dpy, 3, MODMASK, DefaultRootWindow(dpy), True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
||||||
|
|
||||||
|
start.subwindow = 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) {
|
||||||
|
XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr);
|
||||||
|
start = ev.xbutton;
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in a new issue