]> Pileus Git - wmpus/blobdiff - sys-x11.c
Fix closing windows
[wmpus] / sys-x11.c
index 51687cd653e0db61de0dbd91a99607c13ffc5ad2..c4a08ffc554254a3384658ad0c8eab1af2e9fbeb 100644 (file)
--- a/sys-x11.c
+++ b/sys-x11.c
@@ -246,16 +246,17 @@ static win_t *win_new(Display *dpy, Window xid)
                        win->parent = win_find(dpy, trans, 0);
 
                XSelectInput(dpy, xid, PropertyChangeMask);
-
-               wm_insert(win);
        }
 
-       printf("win_new: %p = %p, %d (%d,%d %dx%d) - %s\n",
-                       win, dpy, (int)xid,
+       printf("win_new: win=%p x11=(%p,%d) state=%x pos=(%d,%d %dx%d) type=%s\n",
+                       win, dpy, (int)xid, win->state,
                        win->x, win->y, win->w, win->h,
-                       win->type == TYPE_NORMAL  ? "normal" :
-                       win->type == TYPE_DIALOG  ? "dialog" :
-                       win->type == TYPE_TOOLBAR ? "normal" : "unknown");
+                       win->type == TYPE_NORMAL  ? "normal"  :
+                       win->type == TYPE_DIALOG  ? "dialog"  :
+                       win->type == TYPE_TOOLBAR ? "toolbar" : "unknown");
+
+       if (root)
+               wm_insert(win);
 
        return win;
 }
@@ -324,7 +325,7 @@ static int win_msg(win_t *win, atom_t msg)
                return 0;
 
        XSendEvent(win->sys->dpy, win->sys->xid, False, NoEventMask, &(XEvent){
-               .type                 = ClientMessage,
+               .xclient.type         = ClientMessage,
                .xclient.window       = win->sys->xid,
                .xclient.message_type = atoms[WM_PROTO],
                .xclient.format       = 32,
@@ -382,7 +383,7 @@ static void process_event(int type, XEvent *xe, win_t *root)
        if (type == KeyPress) {
                while (XCheckTypedEvent(dpy, KeyPress, xe));
                KeySym sym = XLookupKeysym(&xe->xkey, 0);
-               printf("got xe %c %hhx\n", xk2ev(sym), mod2int(mod));
+               //printf("got xe %c %hhx\n", xk2ev(sym), mod2int(mod));
                wm_handle_event(win, xk2ev(sym), mod, ptr);
        }
        else if (type == KeyRelease) {
@@ -428,6 +429,7 @@ static void process_event(int type, XEvent *xe, win_t *root)
        else if (type == UnmapNotify) {
                if ((win = win_find(dpy,xe->xunmap.window,0)) &&
                     win->state != ST_HIDE) {
+                       printf("unmap: %lx\n", xe->xunmap.window);
                        wm_handle_state(win, win->state, ST_HIDE);
                        win->state = ST_HIDE;
                }
@@ -461,8 +463,10 @@ static void process_event(int type, XEvent *xe, win_t *root)
                printf("map_req: %lx\n", xe->xmaprequest.window);
                win = win_find(dpy,xe->xmaprequest.window,1);
                // fixme, for hide -> max, etc
-               if (win->state == ST_HIDE)
+               if (win->state == ST_HIDE) {
+                       wm_handle_state(win, win->state, ST_SHOW);
                        win->state = ST_SHOW;
+               }
                sys_show(win, win->state);
        }
        else if (type == ClientMessage) {
@@ -478,6 +482,7 @@ static void process_event(int type, XEvent *xe, win_t *root)
                        state_t next = (cme->data.l[0] == 1 || /* _NET_WM_STATE_ADD    */
                                       (cme->data.l[0] == 2 && /* _NET_WM_STATE_TOGGLE */
                                        win->state != ST_FULL)) ? ST_FULL : ST_SHOW;
+                       printf("client_msg: fullscreen %x -> %x", win->state, next);
                        wm_handle_state(win, win->state, next);
                        sys_show(win, next);
                }
@@ -544,12 +549,12 @@ void sys_raise(win_t *win)
 
 void sys_focus(win_t *win)
 {
-       printf("sys_focus: %p\n", win);
+       //printf("sys_focus: %p\n", win);
 
        /* Set actual focus */
        XSetInputFocus(win->sys->dpy, win->sys->xid,
                        RevertToPointerRoot, CurrentTime);
-       win_msg(win, WM_FOCUS);
+       //win_msg(win, WM_FOCUS);
 
        /* Set border on focused window */
        static win_t *last = NULL;
@@ -590,6 +595,13 @@ void sys_show(win_t *win, state_t state)
                }
                XSetWindowBorderWidth(win->sys->dpy, win->sys->xid, 0);
                XMapWindow(win->sys->dpy, win->sys->xid);
+               XConfigureWindow(win->sys->dpy, win->sys->xid,
+                       CWX|CWY|CWWidth|CWHeight, &(XWindowChanges) {
+                               .x      = win->x,
+                               .y      = win->y,
+                               .width  = win->w,
+                               .height = win->h,
+               });
                XMoveResizeWindow(win->sys->dpy, win->sys->xid,
                        screen->x - screen->sys->strut.left,
                        screen->y - screen->sys->strut.top,
@@ -617,7 +629,6 @@ void sys_show(win_t *win, state_t state)
                        XSetErrorHandler(xerror);
                        XUngrabServer(win->sys->dpy);
                }
-               XDestroyWindow(win->sys->dpy, win->sys->xid);
                break;
        }
        win->state = state;