docs: update

This commit is contained in:
Dylan Araps committed 2019-10-14 08:18:08 +03:00
1 parent e1cc06c8fd
commit a5d6bb9f47
1 file changed
+47 -47
+47 -47
View File
@@ -10,7 +10,7 @@
#include <unistd.h> #include <unistd.h>
#define WIN (c=list;c;c=c->next) #define WIN (c=list;c;c=c->next)
#define FOC(W) XSetInputFocus(dis, W, RevertToParent, CurrentTime); #define FOC(W) XSetInputFocus(d, W, RevertToParent, CurrentTime);
typedef union { typedef union {
const char** com; const char** com;
@@ -27,7 +27,7 @@ struct key {
typedef struct client client; typedef struct client client;
struct client{ struct client{
client *next, *prev; client *next, *prev;
Window win; Window w;
XWindowAttributes a; XWindowAttributes a;
int f; int f;
}; };
@@ -62,7 +62,7 @@ static client *list = { 0 };
static ws ws_list[10]; static ws ws_list[10];
static int desk = 1, sh, sw, s, j; static int desk = 1, sh, sw, s, j;
static Display *dis; static Display *d;
static Window root, cur; static Window root, cur;
static XButtonEvent start; static XButtonEvent start;
static XWindowAttributes attr; static XWindowAttributes attr;
@@ -83,7 +83,7 @@ static void (*events[LASTEvent])(XEvent *e) = {
void notify_destroy(XEvent *e) { void notify_destroy(XEvent *e) {
win_del(e->xdestroywindow.window); win_del(e->xdestroywindow.window);
if (list) FOC(list->win); if (list) FOC(list->w);
} }
void notify_enter(XEvent *e) { void notify_enter(XEvent *e) {
@@ -97,29 +97,29 @@ void notify_motion(XEvent *e) {
int xd = e->xbutton.x_root - start.x_root; int xd = e->xbutton.x_root - start.x_root;
int yd = e->xbutton.y_root - start.y_root; int yd = e->xbutton.y_root - start.y_root;
while(XCheckTypedEvent(dis, MotionNotify, e)); while(XCheckTypedEvent(d, MotionNotify, e));
XMoveResizeWindow(dis, start.subwindow, XMoveResizeWindow(d, start.subwindow,
attr.x + (start.button==1 ? xd : 0), attr.x + (start.button==1 ? xd : 0),
attr.y + (start.button==1 ? yd : 0), attr.y + (start.button==1 ? yd : 0),
attr.width + (start.button==3 ? xd : 0), attr.width + (start.button==3 ? xd : 0),
attr.height + (start.button==3 ? yd : 0)); attr.height + (start.button==3 ? yd : 0));
} }
for WIN if (c->win == start.subwindow) c->f = 0; for WIN if (c->w == start.subwindow) c->f = 0;
} }
void key_grab() { void key_grab() {
KeyCode code; KeyCode code;
for (int i=0; i < sizeof(keys)/sizeof(*keys); ++i) for (int i=0; i < sizeof(keys)/sizeof(*keys); ++i)
if ((code = XKeysymToKeycode(dis, keys[i].keysym))) if ((code = XKeysymToKeycode(d, keys[i].keysym)))
XGrabKey(dis, code, keys[i].mod, root, XGrabKey(d, code, keys[i].mod, root,
True, GrabModeAsync, GrabModeAsync); True, GrabModeAsync, GrabModeAsync);
} }
void key_press(XEvent *e) { void key_press(XEvent *e) {
KeySym keysym = XKeycodeToKeysym(dis, e->xkey.keycode, 0); KeySym keysym = XKeycodeToKeysym(d, e->xkey.keycode, 0);
for (int i=0; i < sizeof(keys)/sizeof(*keys); ++i) for (int i=0; i < sizeof(keys)/sizeof(*keys); ++i)
if (keys[i].keysym == keysym && keys[i].mod == e->xkey.state) if (keys[i].keysym == keysym && keys[i].mod == e->xkey.state)
@@ -129,8 +129,8 @@ void key_press(XEvent *e) {
void button_press(XEvent *e) { void button_press(XEvent *e) {
if (e->xbutton.subwindow == None) return; if (e->xbutton.subwindow == None) return;
XGetWindowAttributes(dis, e->xbutton.subwindow, &attr); XGetWindowAttributes(d, e->xbutton.subwindow, &attr);
XRaiseWindow(dis, e->xbutton.subwindow); XRaiseWindow(d, e->xbutton.subwindow);
start = e->xbutton; start = e->xbutton;
} }
@@ -139,7 +139,7 @@ void button_release() {
} }
Window win_current() { Window win_current() {
XGetInputFocus(dis, &cur, &j); XGetInputFocus(d, &cur, &j);
return cur; return cur;
} }
@@ -152,7 +152,7 @@ void win_add(Window w) {
if (!list) { if (!list) {
c->next = 0; c->next = 0;
c->prev = 0; c->prev = 0;
c->win = w; c->w = w;
list = c; list = c;
} else { } else {
@@ -160,7 +160,7 @@ void win_add(Window w) {
c->next = 0; c->next = 0;
c->prev = t; c->prev = t;
c->win = w; c->w = w;
t->next = c; t->next = c;
} }
@@ -170,7 +170,7 @@ void win_add(Window w) {
void win_del(Window w) { void win_del(Window w) {
client *c; client *c;
for WIN if (c->win == w) { for WIN if (c->w == w) {
if (!c->prev && !c->next) { if (!c->prev && !c->next) {
free(list); free(list);
list = 0; list = 0;
@@ -199,26 +199,26 @@ void win_del(Window w) {
void win_kill() { void win_kill() {
win_current(); win_current();
if (cur != root) XKillClient(dis, cur); if (cur != root) XKillClient(d, cur);
} }
void win_center(Window w) { void win_center(Window w) {
XGetWindowAttributes(dis, w, &attr); XGetWindowAttributes(d, w, &attr);
XMoveWindow(dis, w, sw / 2 - attr.width / 2, XMoveWindow(d, w, sw / 2 - attr.width / 2,
sh / 2 - attr.height / 2); sh / 2 - attr.height / 2);
} }
void win_fs(Window w) { void win_fs(Window w) {
client *c; client *c;
for WIN if (c->win == w) { for WIN if (c->w == w) {
if ((c->f = c->f == 0 ? 1 : 0)) { if ((c->f = c->f == 0 ? 1 : 0)) {
XGetWindowAttributes(dis, w, &c->a); XGetWindowAttributes(d, w, &c->a);
XMoveResizeWindow(dis, w, 0, 0, sw, sh); XMoveResizeWindow(d, w, 0, 0, sw, sh);
} else } else
XMoveResizeWindow(dis, w, c->a.x, c->a.y, c->a.width, c->a.height); XMoveResizeWindow(d, w, c->a.x, c->a.y, c->a.width, c->a.height);
} }
} }
@@ -234,10 +234,10 @@ void win_to_ws(const Arg arg) {
ws_sel(tmp); ws_sel(tmp);
win_del(cur); win_del(cur);
XUnmapWindow(dis, cur); XUnmapWindow(d, cur);
ws_save(tmp); ws_save(tmp);
if (list) FOC(list->win); if (list) FOC(list->w);
} }
void win_next() { void win_next() {
@@ -245,12 +245,12 @@ void win_next() {
client *c; client *c;
if (list) { if (list) {
for WIN if (c->win == cur) break; for WIN if (c->w == cur) break;
c = c->next ? c->next : list; c = c->next ? c->next : list;
FOC(c->win); FOC(c->w);
XRaiseWindow(dis, c->win); XRaiseWindow(d, c->w);
} }
} }
@@ -271,15 +271,15 @@ void ws_go(const Arg arg) {
ws_save(desk); ws_save(desk);
ws_sel(arg.i); ws_sel(arg.i);
if (list) for WIN XMapWindow(dis, c->win); if (list) for WIN XMapWindow(d, c->w);
ws_sel(tmp); ws_sel(tmp);
if (list) for WIN XUnmapWindow(dis, c->win); if (list) for WIN XUnmapWindow(d, c->w);
ws_sel(arg.i); ws_sel(arg.i);
if (list) FOC(list->win); if (list) FOC(list->w);
} }
void ws_save(int i) { void ws_save(int i) {
@@ -302,44 +302,44 @@ void configure_request(XEvent *e) {
wc.sibling = ev->above; wc.sibling = ev->above;
wc.stack_mode = ev->detail; wc.stack_mode = ev->detail;
XConfigureWindow(dis, ev->window, ev->value_mask, &wc); XConfigureWindow(d, ev->window, ev->value_mask, &wc);
} }
void map_request(XEvent *e) { void map_request(XEvent *e) {
Window w = e->xmaprequest.window; Window w = e->xmaprequest.window;
XSelectInput(dis, w, PropertyChangeMask|StructureNotifyMask| XSelectInput(d, w, PropertyChangeMask|StructureNotifyMask|
EnterWindowMask|FocusChangeMask); EnterWindowMask|FocusChangeMask);
win_center(w); win_center(w);
XMapWindow(dis, w); XMapWindow(d, w);
FOC(w); FOC(w);
win_add(w); win_add(w);
} }
void run(const Arg arg) { void run(const Arg arg) {
if (fork()) return; if (fork()) return;
if (dis) close(ConnectionNumber(dis)); if (d) close(ConnectionNumber(d));
setsid(); setsid();
execvp((char*)arg.com[0], (char**)arg.com); execvp((char*)arg.com[0], (char**)arg.com);
} }
int xerror(Display *dis, XErrorEvent *ee) { int xerror(Display *d, XErrorEvent *e) {
return 0; return 0;
} }
int main(void) { int main(void) {
XEvent ev; XEvent ev;
if (!(dis = XOpenDisplay(0x0))) return 0; if (!(d = XOpenDisplay(0x0))) return 0;
signal(SIGCHLD, SIG_IGN); signal(SIGCHLD, SIG_IGN);
XSetErrorHandler(xerror); XSetErrorHandler(xerror);
s = DefaultScreen(dis); s = DefaultScreen(d);
root = RootWindow(dis, s); root = RootWindow(d, s);
sw = XDisplayWidth(dis, s); sw = XDisplayWidth(d, s);
sh = XDisplayHeight(dis, s); sh = XDisplayHeight(d, s);
key_grab(); key_grab();
@@ -348,17 +348,17 @@ int main(void) {
ws_go((Arg){.i = 1}); ws_go((Arg){.i = 1});
XSelectInput(dis, root, SubstructureNotifyMask| XSelectInput(d, root, SubstructureNotifyMask|
SubstructureRedirectMask|EnterWindowMask|LeaveWindowMask); SubstructureRedirectMask|EnterWindowMask|LeaveWindowMask);
XGrabButton(dis, 1, Mod4Mask, root, True, XGrabButton(d, 1, Mod4Mask, root, True,
ButtonPressMask|ButtonReleaseMask|PointerMotionMask, ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, None); GrabModeAsync, GrabModeAsync, None, None);
XGrabButton(dis, 3, Mod4Mask, root, True, XGrabButton(d, 3, Mod4Mask, root, True,
ButtonPressMask|ButtonReleaseMask|PointerMotionMask, ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, None); GrabModeAsync, GrabModeAsync, None, None);
while(1 && !XNextEvent(dis, &ev)) while(1 && !XNextEvent(d, &ev))
if (events[ev.type]) events[ev.type](&ev); if (events[ev.type]) events[ev.type](&ev);
} }