]> Pileus Git - wmpus/blobdiff - sys-xcb.c
Fix configure and raise
[wmpus] / sys-xcb.c
index 624576ddc42e8604aaf1ca78db3161d82ebebf6e..e254608a6349385d8318ba794c0779a00e39c020 100644 (file)
--- a/sys-xcb.c
+++ b/sys-xcb.c
@@ -60,6 +60,7 @@ static xcb_colormap_t         colormap;
 static xcb_window_t           root;
 static xcb_event_mask_t       events;
 static list_t                *screens;
+static list_t                *struts;
 static void                  *cache;
 static unsigned int           grabbed;
 static int                    running;
@@ -242,43 +243,74 @@ static void win_free(win_t *win)
        free(win);
 }
 
+static void win_add_strut(win_t *win)
+{
+       win->type = TYPE_TOOLBAR;
+       for (list_t *cur = screens; cur; cur = cur->next) {
+               win_t   *screen = cur->data;
+               strut_t *strut  = &win->sys->strut;
+               screen->x += strut->left;
+               screen->y += strut->top;
+               screen->w -= strut->left + strut->right;
+               screen->h -= strut->top  + strut->bottom;
+       }
+       struts = list_insert(struts, win);
+
+}
+
+static void win_del_strut(win_t *win)
+{
+       list_t *link = list_find(struts, win);
+       if (!link)
+               return;
+       for (list_t *cur = screens; cur; cur = cur->next) {
+               win_t   *screen = cur->data;
+               strut_t *strut  = &win->sys->strut;
+               screen->x -= strut->left;
+               screen->y -= strut->top;
+               screen->w += strut->left + strut->right;
+               screen->h += strut->top  + strut->bottom;
+       }
+       struts = list_remove(struts, link, 0);
+}
+
 /****************
  * XCB Wrappers *
  ****************/
 
-static void *do_query_tree(xcb_window_t win, xcb_window_t **kids, int *nkids)
+static void *do_query_tree(xcb_window_t xcb, xcb_window_t **kids, int *nkids)
 {
        xcb_query_tree_cookie_t cookie =
-               xcb_query_tree(conn, win);
+               xcb_query_tree(conn, xcb);
        if (!cookie.sequence)
-               return warn("do_query_tree: %d - bad cookie", win), NULL;
+               return warn("do_query_tree: %d - bad cookie", xcb), NULL;
 
        xcb_query_tree_reply_t *reply =
                xcb_query_tree_reply(conn, cookie, NULL);
        if (!reply)
-               return warn("do_query_tree: %d - no reply", win), NULL;
+               return warn("do_query_tree: %d - no reply", xcb), NULL;
 
        *nkids = xcb_query_tree_children_length(reply);
        *kids  = xcb_query_tree_children(reply);
-       printf("do_query_tree: %d - n=%d\n", win, *nkids);
+       printf("do_query_tree: %d - n=%d\n", xcb, *nkids);
        return reply;
 }
 
-static int do_get_geometry(xcb_window_t win,
+static int do_get_geometry(xcb_window_t xcb,
                int *x, int *y, int *w, int *h)
 {
        xcb_get_geometry_cookie_t cookie =
-               xcb_get_geometry(conn, win);
+               xcb_get_geometry(conn, xcb);
        if (!cookie.sequence)
-               return warn("do_get_geometry: %d - bad cookie", win);
+               return warn("do_get_geometry: %d - bad cookie", xcb);
 
        xcb_get_geometry_reply_t *reply =
                xcb_get_geometry_reply(conn, cookie, NULL);
        if (!reply)
-               return warn("do_get_geometry: %d - no reply", win);
+               return warn("do_get_geometry: %d - no reply", xcb);
 
        printf("do_get_geometry: %d - %dx%d @ %d,%d\n",
-                       win, reply->width, reply->height, reply->x, reply->y);
+                       xcb, reply->width, reply->height, reply->x, reply->y);
        *x = reply->x;
        *y = reply->y;
        *w = reply->width;
@@ -287,21 +319,21 @@ static int do_get_geometry(xcb_window_t win,
        return 1;
 }
 
-static int do_get_window_attributes(xcb_window_t win,
+static int do_get_window_attributes(xcb_window_t xcb,
                int *override, int *mapped)
 {
        xcb_get_window_attributes_cookie_t cookie =
-               xcb_get_window_attributes(conn, win);
+               xcb_get_window_attributes(conn, xcb);
        if (!cookie.sequence)
-               return warn("do_get_window_attributes: %d - bad cookie", win);
+               return warn("do_get_window_attributes: %d - bad cookie", xcb);
 
        xcb_get_window_attributes_reply_t *reply =
                xcb_get_window_attributes_reply(conn, cookie, NULL);
        if (!reply)
-               return warn("do_get_window_attributes: %d - no reply ", win);
+               return warn("do_get_window_attributes: %d - no reply ", xcb);
 
        printf("do_get_window_attributes: %d - %d\n",
-                       win, reply->override_redirect);
+                       xcb, reply->override_redirect);
        *override = reply->override_redirect;
        *mapped   = reply->map_state != XCB_MAP_STATE_UNMAPPED;
        free(reply);
@@ -397,10 +429,10 @@ static int do_ewmh_init_atoms(void)
        return status;
 }
 
-static int do_get_strut(xcb_window_t win, strut_t *strut)
+static int do_get_strut(xcb_window_t xcb, strut_t *strut)
 {
        xcb_get_property_cookie_t cookie =
-               xcb_ewmh_get_wm_strut(&ewmh, win);
+               xcb_ewmh_get_wm_strut(&ewmh, xcb);
        if (!cookie.sequence)
                return warn("do_get_strut: bad cookie");
 
@@ -456,7 +488,7 @@ static void do_ungrab_pointer(void)
                xcb_ungrab_pointer(conn, XCB_CURRENT_TIME);
 }
 
-static void do_configure_window(xcb_window_t win,
+static void do_configure_window(xcb_window_t xcb,
                int x, int y, int w, int h,
                int b, int s, int r)
 {
@@ -472,27 +504,27 @@ static void do_configure_window(xcb_window_t win,
 
        uint16_t mask    = 0;
        uint32_t list[7] = {};
-       for (int i = 0; i < 7; i++) {
+       for (int i=0,j=0; i < 7; i++) {
                if (table[i][0] >= 0) {
-                       list[i] = table[i][0];
-                       mask   |= table[i][1];
+                       list[j++] = table[i][0];
+                       mask     |= table[i][1];
                }
        }
 
-       xcb_configure_window(conn, win, mask, list);
+       xcb_configure_window(conn, xcb, mask, list);
 }
 
-static int do_client_message(xcb_window_t win, xcb_atom_t atom)
+static int do_client_message(xcb_window_t xcb, xcb_atom_t atom)
 {
        /* Get protocols */
        xcb_get_property_cookie_t cookie =
-               xcb_icccm_get_wm_protocols(conn, win, wm_protos);
+               xcb_icccm_get_wm_protocols(conn, xcb, wm_protos);
        if (!cookie.sequence)
-               return warn("do_client_message: %d - bad cookie", win);
+               return warn("do_client_message: %d - bad cookie", xcb);
 
        xcb_icccm_get_wm_protocols_reply_t protos = {};
        if (!xcb_icccm_get_wm_protocols_reply(conn, cookie, &protos, NULL))
-               return warn("do_client_message: %d - no reply", win);
+               return warn("do_client_message: %d - no reply", xcb);
 
        /* Search for the atom */
        int found = 0;
@@ -501,18 +533,18 @@ static int do_client_message(xcb_window_t win, xcb_atom_t atom)
                        found = 1;
        xcb_icccm_get_wm_protocols_reply_wipe(&protos);
        if (!found)
-               return warn("do_client_message: %d - no atom", win);
+               return warn("do_client_message: %d - no atom", xcb);
 
        /* Send the message */
        xcb_client_message_event_t msg = {
                .response_type  = XCB_CLIENT_MESSAGE,
                .format         = 32,
-               .window         = win,
+               .window         = xcb,
                .type           = wm_protos,
                .data.data32[0] = atom,
                .data.data32[1] = XCB_CURRENT_TIME,
        };
-       xcb_send_event(conn, 0, win, XCB_EVENT_MASK_NO_EVENT,
+       xcb_send_event(conn, 0, xcb, XCB_EVENT_MASK_NO_EVENT,
                        (const char *)&msg);
        return 1;
 }
@@ -695,6 +727,7 @@ static void on_unmap_notify(xcb_unmap_notify_event_t *event)
                        event->window, win);
        if (!win) return;
 
+       win_del_strut(win);
        send_state(win, ST_HIDE);
 }
 
@@ -716,10 +749,7 @@ static void on_map_request(xcb_map_request_event_t *event)
        if (!win) return;
 
        if (do_get_strut(win->sys->xcb, &win->sys->strut))
-               printf("Map: Got a strut!\n");
-       else
-               printf("Map: No struts here!\n");
-
+               win_add_strut(win);
        send_state(win, ST_SHOW);
        xcb_map_window(conn, win->sys->xcb);
        sys_move(win, win->x, win->y, win->w, win->h);
@@ -863,6 +893,9 @@ void sys_raise(win_t *win)
        uint32_t list = XCB_STACK_MODE_ABOVE;
 
        xcb_configure_window(conn, win->sys->xcb, mask, &list);
+       for (list_t *cur = struts; cur; cur = cur->next)
+               xcb_configure_window(conn,
+                       ((win_t*)cur->data)->sys->xcb, mask, &list);
 }
 
 void sys_focus(win_t *win)
@@ -881,12 +914,12 @@ void sys_show(win_t *win, state_t state)
        xcb_window_t xcb = win ? win->sys->xcb : root;
 
        /* Find screen */
-       win_t *screen = NULL;
+       win_t full, max;
        if (state == ST_FULL || state == ST_MAX) {
                for (list_t *cur = screens; cur; cur = cur->next) {
-                       screen = cur->data;
-                       if (win->x >= screen->x && win->x <= screen->x+screen->w &&
-                           win->y >= screen->y && win->y <= screen->y+screen->h)
+                       full = max = *(win_t*)cur->data;
+                       if (win->x >= max.x && win->x <= max.x+max.w &&
+                           win->y >= max.y && win->y <= max.y+max.h)
                                break;
                }
        }
@@ -907,16 +940,15 @@ void sys_show(win_t *win, state_t state)
 
                case ST_FULL:
                        xcb_map_window(conn, xcb);
-                       do_configure_window(xcb, screen->x, screen->y, screen->w, screen->h,
+                       do_configure_window(xcb, full.x, full.y, full.w, full.h,
                                        0, -1, XCB_STACK_MODE_ABOVE);
-                       xcb_circulate_window(conn, XCB_CIRCULATE_RAISE_LOWEST, xcb);
                        break;
 
                case ST_MAX:
                        xcb_map_window(conn, xcb);
-                       do_configure_window(xcb, screen->x, screen->y,
-                                       MAX(screen->w - 2*border, 1),
-                                       MAX(screen->h - 2*border, 1),
+                       do_configure_window(xcb, max.x, max.y,
+                                       MAX(max.w - 2*border, 1),
+                                       MAX(max.h - 2*border, 1),
                                        border, -1, XCB_STACK_MODE_ABOVE);
                        break;
 
@@ -1126,6 +1158,8 @@ void sys_run(void)
                        if (kids[i] == control)
                                continue;
                        win_t *win = win_new(kids[i]);
+                       if (do_get_strut(win->sys->xcb, &win->sys->strut))
+                               win_add_strut(win);
                        do_get_geometry(kids[i], &win->x, &win->y, &win->w, &win->h);
                        do_get_window_attributes(kids[i], &override, &mapped);
                        printf("  found %-8u %dx%d @ %d,%d --%s%s\n", kids[i],