]> Pileus Git - wmpus/blobdiff - sys-x11.c
Cleanup output messages
[wmpus] / sys-x11.c
index 3ea7ded09edfad989c40657e102b51d84499ae5b..fa66a31d83a2fedffbb78efc65931008ad6c3dbe 100644 (file)
--- a/sys-x11.c
+++ b/sys-x11.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Andy Spencer <andy753421@gmail.com>
+ * Copyright (c) 2011-2012, Andy Spencer <andy753421@gmail.com>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -63,6 +63,7 @@ static Atom atoms[NATOMS];
 static int (*xerrorxlib)(Display *, XErrorEvent *);
 static unsigned long colors[NCOLORS];
 static list_t *screens;
+static list_t *struts;
 
 /* Conversion functions */
 static event_map_t ev2sym[] = {
@@ -186,6 +187,7 @@ static int strut_add(win_t *root, win_t *win)
        win->sys->strut.right  = ((int*)xdata)[1];
        win->sys->strut.top    = ((int*)xdata)[2];
        win->sys->strut.bottom = ((int*)xdata)[3];
+       struts = list_insert(struts, win);
        for (list_t *cur = screens; cur; cur = cur->next)
                strut_copy(cur->data, win, 1);
        return strut_copy(root, win, 1);
@@ -193,6 +195,9 @@ static int strut_add(win_t *root, win_t *win)
 
 static int strut_del(win_t *root, win_t *win)
 {
+       list_t *lwin = list_find(struts, win);
+       if (lwin)
+               struts = list_remove(struts, lwin, 0);
        for (list_t *cur = screens; cur; cur = cur->next)
                strut_copy(cur->data, win, -1);
        return strut_copy(root, win, -1);
@@ -308,15 +313,8 @@ static void process_event(int type, XEvent *xe, win_t *root)
                if (wm_handle_event(win, xb2ev(xe->xbutton.button), mod, ptr))
                        XGrabPointer(dpy, xe->xbutton.root, True, PointerMotionMask|ButtonReleaseMask,
                                        GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
-               else {
-                       printf("resending event\n");
-                       XSendEvent(win->sys->dpy, xe->xbutton.window,    True,  NoEventMask, xe);
-                       XSendEvent(win->sys->dpy, xe->xbutton.window,    False, NoEventMask, xe);
-                       XSendEvent(win->sys->dpy, xe->xbutton.root,      True,  NoEventMask, xe);
-                       XSendEvent(win->sys->dpy, xe->xbutton.root,      False, NoEventMask, xe);
-                       XSendEvent(win->sys->dpy, xe->xbutton.subwindow, True,  NoEventMask, xe);
-                       XSendEvent(win->sys->dpy, xe->xbutton.subwindow, False, NoEventMask, xe);
-               }
+               else
+                       XAllowEvents(win->sys->dpy, ReplayPointer, CurrentTime);
        }
        else if (type == ButtonRelease) {
                XUngrabPointer(dpy, CurrentTime);
@@ -327,7 +325,7 @@ static void process_event(int type, XEvent *xe, win_t *root)
                wm_handle_ptr(win, ptr);
        }
        else if (type == EnterNotify || type == LeaveNotify) {
-               printf("enter: %d\n", type);
+               printf("%s: %d\n", type==EnterNotify?"enter":"leave", type);
                event_t ev = EnterNotify ? EV_ENTER : EV_LEAVE;
                if ((win = win_find(dpy,xe->xcrossing.window,0)))
                        wm_handle_event(win, ev, MOD(), PTR());
@@ -364,17 +362,19 @@ static void process_event(int type, XEvent *xe, win_t *root)
                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, &(XWindowChanges){
-                       .x      = cre->x,
-                       .y      = cre->y,
-                       .width  = cre->width,
-                       .height = cre->height,
-               });
-
-               /* This seems necessary for, but causes flicker
-                * there could be a better way to do this */
-               if ((win = win_find(dpy,xe->xmaprequest.window,0)))
-                       sys_move(win, win->x, win->y, win->w, win->h);
+               if ((win = win_find(dpy,xe->xmaprequest.window,1))) {
+                       XSendEvent(dpy, cre->window, False, StructureNotifyMask, &(XEvent){
+                               .xconfigure.type              = ConfigureNotify,
+                               .xconfigure.display           = win->sys->dpy,
+                               .xconfigure.event             = win->sys->xid,
+                               .xconfigure.window            = win->sys->xid,
+                               .xconfigure.x                 = win->x,
+                               .xconfigure.y                 = win->y,
+                               .xconfigure.width             = win->w,
+                               .xconfigure.height            = win->h,
+                       });
+                       XSync(win->sys->dpy, False);
+               }
        }
        else if (type == MapRequest) {
                printf("map_req: %d\n", type);
@@ -384,7 +384,7 @@ static void process_event(int type, XEvent *xe, win_t *root)
                        else
                                wm_update();
                }
-               XMapWindow(dpy,xe->xmaprequest.window);
+               XMapWindow(dpy, xe->xmaprequest.window);
        }
        else {
                printf("unknown event: %d\n", type);
@@ -403,6 +403,8 @@ static int xerror(Display *dpy, XErrorEvent *err)
            (err->request_code == X_GrabKey           && err->error_code == BadAccess  ) ||
            (err->request_code == X_CopyArea          && err->error_code == BadDrawable))
                return 0;
+       if (err->request_code == X_ChangeWindowAttributes && err->error_code == BadAccess)
+               error("Another window manager is already running");
        return xerrorxlib(dpy, err);
 }
 
@@ -430,6 +432,9 @@ void sys_raise(win_t *win)
 {
        //printf("sys_raise: %p\n", win);
        XRaiseWindow(win->sys->dpy, win->sys->xid);
+       for (list_t *cur = struts; cur; cur = cur->next)
+               XRaiseWindow(((win_t*)cur->data)->sys->dpy,
+                            ((win_t*)cur->data)->sys->xid);
 }
 
 void sys_focus(win_t *win)
@@ -468,9 +473,11 @@ void sys_show(win_t *win, state_t state)
                return;
        case ST_FULL:
                printf("sys_show: full\n");
+               XMapWindow(win->sys->dpy, win->sys->xid);
                return;
        case ST_SHADE:
                printf("sys_show: shade\n");
+               XMapWindow(win->sys->dpy, win->sys->xid);
                return;
        case ST_ICON:
                printf("sys_show: icon\n");
@@ -495,7 +502,7 @@ void sys_watch(win_t *win, event_t ev, mod_t mod)
        if (EV_MOUSE0 <= ev && ev <= EV_MOUSE7)
                XGrabButton(win->sys->dpy, ev2xb(ev), mod2x(mod), win->sys->xid, False,
                                mod.up ? ButtonReleaseMask : ButtonPressMask,
-                               GrabModeAsync, GrabModeAsync, None, None);
+                               GrabModeSync, GrabModeAsync, None, None);
        else if (ev == EV_ENTER)
                XSelectInput(win->sys->dpy, win->sys->xid, EnterWindowMask|mask);
        else if (ev == EV_LEAVE)
@@ -563,7 +570,7 @@ win_t *sys_init(void)
        colors[CLR_FOCUS]   = get_color(dpy, "#a0a0ff");
        colors[CLR_UNFOCUS] = get_color(dpy, "#101066");
        colors[CLR_URGENT]  = get_color(dpy, "#ff0000");
-       printf("colors = #%06lx #%06lx #%06lx\n", colors[0], colors[1], colors[2]);
+       //printf("colors = #%06lx #%06lx #%06lx\n", colors[0], colors[1], colors[2]);
 
        /* Select window management events */
        XSelectInput(dpy, xid, SubstructureRedirectMask|SubstructureNotifyMask);