X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=sys-x11.c;h=69b5bcbd97edc502c0ce010b43a053e160f821d8;hb=c7b78a6e35dddf23951730bca13f647b7ad1ae85;hp=e60b97c7e94f4f47e1ef2a5e8f9751d74b9075ce;hpb=6f9eafa3b63b7b95af52187bc550d0d4527c1f23;p=wmpus diff --git a/sys-x11.c b/sys-x11.c index e60b97c..69b5bcb 100644 --- a/sys-x11.c +++ b/sys-x11.c @@ -4,6 +4,7 @@ #include #include +#include #include #include "util.h" @@ -14,6 +15,9 @@ struct win_sys { Window xid; Display *dpy; + struct { + int left, right, top, bottom; + } strut; }; typedef struct { @@ -22,7 +26,7 @@ typedef struct { } keymap_t; typedef enum { - wm_proto, wm_focus, natoms + wm_proto, wm_focus, net_strut, natoms } atom_t; /* Global data */ @@ -103,6 +107,7 @@ static ptr_t x2ptr(XEvent *_ev) XKeyEvent *ev = &_ev->xkey; return (ptr_t){ev->x, ev->y, ev->x_root, ev->y_root}; } + static Window getfocus(win_t *root, XEvent *event) { int revert; @@ -116,6 +121,54 @@ static Window getfocus(win_t *root, XEvent *event) return focus; } +/* Helpers */ +static int add_strut(win_t *root, win_t *win) +{ + /* Get X11 strut data */ + Atom ret_type; + int ret_size; + unsigned long ret_items, bytes_left; + unsigned char *xdata; + int status = XGetWindowProperty(win->sys->dpy, win->sys->xid, + atoms[net_strut], 0L, 4L, False, XA_CARDINAL, + &ret_type, &ret_size, &ret_items, &bytes_left, &xdata); + if (status != Success || ret_size != 32 || ret_items != 4) + return 0; + + int left = ((int*)xdata)[0]; + int right = ((int*)xdata)[1]; + int top = ((int*)xdata)[2]; + int bottom = ((int*)xdata)[3]; + if (left == 0 && right == 0 && top == 0 && bottom == 0) + return 0; + + win->sys->strut.left = left; + win->sys->strut.right = right; + win->sys->strut.top = top; + win->sys->strut.bottom = bottom; + root->x += left; + root->y += top; + root->w -= left+right; + root->h -= top+bottom; + return 1; +} + +static int del_strut(win_t *root, win_t *win) +{ + int left = win->sys->strut.left; + int right = win->sys->strut.right; + int top = win->sys->strut.top; + int bottom = win->sys->strut.bottom; + if (left == 0 && right == 0 && top == 0 && bottom == 0) + return 0; + + root->x -= left; + root->y -= top; + root->w += left+right; + root->h += top+bottom; + return 1; +} + /* Window functions */ static win_t *win_new(Display *dpy, Window xid) { @@ -205,9 +258,18 @@ static void process_event(int type, XEvent *ev, win_t *root) //printf("release: %d\n", type); } else if (type == ButtonPress) { - wm_handle_key(win, x2btn(ev->xbutton.button), mod, ptr); - XGrabPointer(dpy, ev->xbutton.root, True, PointerMotionMask|ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, None, CurrentTime); + if (wm_handle_key(win, x2btn(ev->xbutton.button), mod, ptr)) + XGrabPointer(dpy, ev->xbutton.root, True, PointerMotionMask|ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, None, CurrentTime); + else { + printf("resending event\n"); + XSendEvent(win->sys->dpy, ev->xbutton.window, True, NoEventMask, ev); + XSendEvent(win->sys->dpy, ev->xbutton.window, False, NoEventMask, ev); + XSendEvent(win->sys->dpy, ev->xbutton.root, True, NoEventMask, ev); + XSendEvent(win->sys->dpy, ev->xbutton.root, False, NoEventMask, ev); + XSendEvent(win->sys->dpy, ev->xbutton.subwindow, True, NoEventMask, ev); + XSendEvent(win->sys->dpy, ev->xbutton.subwindow, False, NoEventMask, ev); + } } else if (type == ButtonRelease) { XUngrabPointer(dpy, CurrentTime); @@ -237,26 +299,39 @@ static void process_event(int type, XEvent *ev, win_t *root) } else if (type == UnmapNotify) { //printf("unmap: %d\n", type); - if ((win = win_find(dpy,ev->xmap.window,0))) { - wm_remove(win); + if ((win = win_find(dpy,ev->xunmap.window,0))) { + if (!del_strut(root, win)) + wm_remove(win); + else + wm_update(); win_remove(win); } } else if (type == ConfigureRequest) { XConfigureRequestEvent *cre = &ev->xconfigurerequest; - XWindowChanges wc = { - .x = cre->x, .y = cre->y, - .width = cre->width, .height = cre->height, - }; printf("configure_req: %d - %x, (0x%lx) %dx%d @ %d,%d\n", type, (int)cre->window, cre->value_mask, cre->height, cre->width, cre->x, cre->y); - XConfigureWindow(dpy, cre->window, cre->value_mask, &wc); + XConfigureWindow(dpy, cre->window, cre->value_mask, &(XWindowChanges){ + .x = cre->x, + .y = cre->y, + .width = cre->width, + .height = cre->height, + }); + + /* This seems necessasairy for, but causes flicker + * there could be a better way to do this */ + if ((win = win_find(dpy,ev->xmaprequest.window,0))) + sys_move(win, win->x, win->y, win->w, win->h); } else if (type == MapRequest) { printf("map_req: %d\n", type); - if ((win = win_find(dpy,ev->xmaprequest.window,1))) - wm_insert(win); + if ((win = win_find(dpy,ev->xmaprequest.window,1))) { + if (!add_strut(root, win)) + wm_insert(win); + else + wm_update(); + } XMapWindow(dpy,ev->xmaprequest.window); } else { @@ -307,19 +382,16 @@ void sys_raise(win_t *win) void sys_focus(win_t *win) { printf("sys_focus: %p\n", win); - XEvent ev = { + XSetInputFocus(win->sys->dpy, win->sys->xid, + RevertToPointerRoot, CurrentTime); + XSendEvent(win->sys->dpy, win->sys->xid, False, NoEventMask, &(XEvent){ .type = ClientMessage, .xclient.window = win->sys->xid, .xclient.message_type = atoms[wm_proto], .xclient.format = 32, .xclient.data.l[0] = atoms[wm_focus], .xclient.data.l[1] = CurrentTime, - }; - XSetInputFocus(win->sys->dpy, win->sys->xid, - RevertToPointerRoot, CurrentTime); - //XSetInputFocus(win->sys->dpy, PointerRoot, - // RevertToPointerRoot, CurrentTime); - XSendEvent(win->sys->dpy, win->sys->xid, False, NoEventMask, &ev); + }); } void sys_watch(win_t *win, Key_t key, mod_t mod) @@ -329,7 +401,7 @@ void sys_watch(win_t *win, Key_t key, mod_t mod) XGetWindowAttributes(win->sys->dpy, win->sys->xid, &attr); long mask = attr.your_event_mask; if (key_mouse0 <= key && key <= key_mouse7) - XGrabButton(win->sys->dpy, btn2x(key), mod2x(mod), win->sys->xid, True, + XGrabButton(win->sys->dpy, btn2x(key), mod2x(mod), win->sys->xid, False, mod.up ? ButtonReleaseMask : ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None); else if (key == key_enter) @@ -343,6 +415,12 @@ void sys_watch(win_t *win, Key_t key, mod_t mod) mod2x(mod), win->sys->xid, True, GrabModeAsync, GrabModeAsync); } +void sys_unwatch(win_t *win, Key_t key, mod_t mod) +{ + if (key_mouse0 <= key && key <= key_mouse7) + XUngrabButton(win->sys->dpy, btn2x(key), mod2x(mod), win->sys->xid); +} + win_t *sys_init(void) { Display *dpy; @@ -351,8 +429,9 @@ win_t *sys_init(void) error("Unable to get display"); if (!(xid = DefaultRootWindow(dpy))) error("Unable to get root window"); - atoms[wm_proto] = XInternAtom(dpy, "WM_PROTOCOLS", False); - atoms[wm_focus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False); + atoms[wm_proto] = XInternAtom(dpy, "WM_PROTOCOLS", False); + atoms[wm_focus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False); + atoms[net_strut] = XInternAtom(dpy, "_NET_WM_STRUT", False); XSelectInput(dpy, xid, SubstructureRedirectMask|SubstructureNotifyMask); XSetInputFocus(dpy, None, RevertToNone, CurrentTime); xerrorxlib = XSetErrorHandler(xerror); @@ -368,9 +447,10 @@ void sys_run(win_t *root) &par, &xid, &kids, &nkids)) for(int i = 0; i < nkids; i++) { win_t *win = win_find(root->sys->dpy, kids[i], 1); - if (win && win_viewable(win)) + if (win && win_viewable(win) && !add_strut(root,win)) wm_insert(win); } + wm_update(); // For struts /* Main loop */ for(;;)