]> code.delx.au - spectrwm/blobdiff - spectrwm.c
Fix focus border issue on output only windows.
[spectrwm] / spectrwm.c
index ce0ea78f9aa8125f21cec201913260b63f6d2938..f3ac3c23e1bdf2b30384dab5faff7f28554d9c27 100644 (file)
@@ -452,7 +452,6 @@ struct ws_win {
        unsigned long           quirks;
        struct workspace        *ws;    /* always valid */
        struct swm_screen       *s;     /* always valid, never changes */
-       xcb_get_geometry_reply_t        *wa;
        xcb_size_hints_t        sh;
        xcb_icccm_get_wm_class_reply_t  ch;
        xcb_icccm_wm_hints_t    hints;
@@ -955,6 +954,7 @@ char        *get_stack_mode_name(uint8_t);
 #endif
 int32_t         get_swm_iconic(struct ws_win *);
 char   *get_win_name(xcb_window_t);
+void    get_wm_protocols(struct ws_win *);
 int     get_ws_idx(xcb_window_t);
 uint32_t getstate(xcb_window_t);
 void    grabbuttons(struct ws_win *);
@@ -1076,7 +1076,6 @@ void       update_window(struct ws_win *);
 void    validate_spawns(void);
 int     validate_win(struct ws_win *);
 int     validate_ws(struct workspace *);
-/*void  visibilitynotify(xcb_visibility_notify_event_t *);*/
 void    version(struct swm_region *, union arg *);
 void    win_to_ws(struct ws_win *, int, int);
 pid_t   window_get_pid(xcb_window_t);
@@ -1271,6 +1270,24 @@ get_atom_from_string(const char *str)
        return (XCB_ATOM_NONE);
 }
 
+void
+get_wm_protocols(struct ws_win *win) {
+       int                             i;
+       xcb_icccm_get_wm_protocols_reply_t      wpr;
+
+       if (xcb_icccm_get_wm_protocols_reply(conn,
+           xcb_icccm_get_wm_protocols(conn, win->id, a_prot),
+           &wpr, NULL)) {
+               for (i = 0; i < (int)wpr.atoms_len; i++) {
+                       if (wpr.atoms[i] == a_takefocus)
+                               win->take_focus = 1;
+                       if (wpr.atoms[i] == a_delete)
+                               win->can_delete = 1;
+               }
+               xcb_icccm_get_wm_protocols_reply_wipe(&wpr);
+       }
+}
+
 void
 set_swm_iconic(struct ws_win *win, int newv)
 {
@@ -3333,6 +3350,9 @@ focus_win(struct ws_win *win)
                     win->hints.input))
                        xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT,
                                        win->id, last_event_time);
+               else
+                       xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT,
+                           ws->r->id, XCB_CURRENT_TIME);
 
                /* Tell app it can adjust focus to a specific window. */
                if (win->take_focus) {
@@ -5321,7 +5341,8 @@ done:
 void
 wkill(struct swm_region *r, union arg *args)
 {
-       DNPRINTF(SWM_D_MISC, "wkill: id: %d\n", args->id);
+       DNPRINTF(SWM_D_MISC, "wkill: win %#x, id: %d\n", WINID(r->ws->focus),
+           args->id);
 
        if (r->ws->focus == NULL)
                return;
@@ -7698,7 +7719,7 @@ set_child_transient(struct ws_win *win, xcb_window_t *trans)
                DNPRINTF(SWM_D_MISC, "set_child_transient: parent doesn't exist"
                    " for 0x%x trans 0x%x\n", win->id, win->transient);
 
-               r = root_to_region(win->wa->root, SWM_CK_ALL);
+               r = root_to_region(win->s->root, SWM_CK_ALL);
                ws = r->ws;
                /* parent doen't exist in our window list */
                TAILQ_FOREACH(w, &ws->winlist, entry) {
@@ -7821,7 +7842,7 @@ manage_window(xcb_window_t id, uint16_t mapped)
        struct pid_e            *p;
        struct quirk            *qp;
        uint32_t                i, wa[2];
-       xcb_icccm_get_wm_protocols_reply_t      wpr;
+       xcb_get_geometry_reply_t        *gr;
 
        if ((win = find_window(id)) != NULL) {
                DNPRINTF(SWM_D_MISC, "manage_window: win 0x%x already "
@@ -7843,6 +7864,13 @@ manage_window(xcb_window_t id, uint16_t mapped)
                DNPRINTF(SWM_D_MISC, "manage_window: win 0x%x is new.\n", id);
        }
 
+       /* Try to get initial window geometry. */
+       gr = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, id), NULL);
+       if (gr == NULL) {
+               DNPRINTF(SWM_D_MISC, "manage_window: get geometry failed.\n");
+               return (NULL);
+       }
+
        /* Create and initialize ws_win object. */
        if ((win = calloc(1, sizeof(struct ws_win))) == NULL)
                err(1, "manage_window: calloc: failed to allocate memory for "
@@ -7850,25 +7878,33 @@ manage_window(xcb_window_t id, uint16_t mapped)
 
        win->id = id;
 
-       /* Get window geometry. */
-       win->wa = xcb_get_geometry_reply(conn,
-           xcb_get_geometry(conn, win->id),
-           NULL);
-
-       /* Figure out which region the window belongs to. */
-       r = root_to_region(win->wa->root, SWM_CK_ALL);
+       /* Figureout which region the window belongs to. */
+       r = root_to_region(gr->root, SWM_CK_ALL);
 
        /* Ignore window border if there is one. */
-       WIDTH(win) = win->wa->width;
-       HEIGHT(win) = win->wa->height;
-       X(win) = win->wa->x + win->wa->border_width - border_width;
-       Y(win) = win->wa->y + win->wa->border_width - border_width;
+       WIDTH(win) = gr->width;
+       HEIGHT(win) = gr->height;
+       X(win) = gr->x + gr->border_width - border_width;
+       Y(win) = gr->y + gr->border_width - border_width;
        win->bordered = 1;
        win->mapped = mapped;
        win->floatmaxed = 0;
        win->ewmh_flags = 0;
        win->s = r->s;  /* this never changes */
 
+       free(gr);
+
+       /* Select which X events to monitor and set border pixel color. */
+       wa[0] = win->s->c[SWM_S_COLOR_UNFOCUS].pixel;
+       wa[1] = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_PROPERTY_CHANGE |
+           XCB_EVENT_MASK_STRUCTURE_NOTIFY;
+#ifdef SWM_DEBUG
+       wa[1] |= XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_FOCUS_CHANGE;
+#endif
+
+       xcb_change_window_attributes(conn, win->id, XCB_CW_BORDER_PIXEL |
+           XCB_CW_EVENT_MASK, wa);
+
        /* Get WM_SIZE_HINTS. */
        xcb_icccm_get_wm_normal_hints_reply(conn,
            xcb_icccm_get_wm_normal_hints(conn, win->id),
@@ -7888,18 +7924,8 @@ manage_window(xcb_window_t id, uint16_t mapped)
                set_child_transient(win, &win->transient);
        }
 
-       /* Get supported protocols. */
-       if (xcb_icccm_get_wm_protocols_reply(conn,
-           xcb_icccm_get_wm_protocols(conn, win->id, a_prot),
-           &wpr, NULL)) {
-               for (i = 0; i < wpr.atoms_len; i++) {
-                       if (wpr.atoms[i] == a_takefocus)
-                               win->take_focus = 1;
-                       if (wpr.atoms[i] == a_delete)
-                               win->can_delete = 1;
-               }
-               xcb_icccm_get_wm_protocols_reply_wipe(&wpr);
-       }
+       /* Get WM_PROTOCOLS. */
+       get_wm_protocols(win);
 
        win->iconic = get_swm_iconic(win);
 
@@ -7981,17 +8007,6 @@ manage_window(xcb_window_t id, uint16_t mapped)
                update_window(win);
        }
 
-       /* Select which X events to monitor and set border pixel color. */
-       wa[0] = win->s->c[SWM_S_COLOR_UNFOCUS].pixel;
-       wa[1] = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_PROPERTY_CHANGE |
-           XCB_EVENT_MASK_STRUCTURE_NOTIFY;
-#ifdef SWM_DEBUG
-       wa[1] |= XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_FOCUS_CHANGE;
-#endif
-
-       xcb_change_window_attributes(conn, win->id, XCB_CW_BORDER_PIXEL |
-           XCB_CW_EVENT_MASK, wa);
-
 out:
        /* Figure out where to stack the window in the workspace. */
        if (trans && (ww = find_window(trans)))
@@ -8037,9 +8052,6 @@ free_window(struct ws_win *win)
 
        TAILQ_REMOVE(&win->ws->unmanagedlist, win, entry);
 
-       if (win->wa)
-               free(win->wa);
-
        xcb_icccm_get_wm_class_reply_wipe(&win->ch);
 
        kill_refs(win);
@@ -8588,8 +8600,8 @@ mapnotify(xcb_map_notify_event_t *e)
 
        DNPRINTF(SWM_D_EVENT, "mapnotify: window: 0x%x\n", e->window);
 
-       if ((win = find_window(e->window)) == NULL)
-               win = manage_window(e->window, 1);
+       if ((win = manage_window(e->window, 1)) == NULL)
+               return;
 
        win->mapped = 1;
        set_win_state(win, XCB_ICCCM_WM_STATE_NORMAL);
@@ -8639,10 +8651,15 @@ maprequest(xcb_map_request_event_t *e)
 
        win = manage_window(e->window,
            (war->map_state == XCB_MAP_STATE_VIEWABLE));
+       if (win == NULL)
+               goto out;
 
        /* The new window should get focus; prepare. */
        if (focus_mode != SWM_FOCUS_FOLLOW &&
-           !(win->quirks & SWM_Q_NOFOCUSONMAP)) {
+           !(win->quirks & SWM_Q_NOFOCUSONMAP) &&
+           (!(win->hints.flags & XCB_ICCCM_WM_HINT_INPUT) ||
+            (win->hints.flags & XCB_ICCCM_WM_HINT_INPUT &&
+             win->hints.input))) {
                if (win->quirks & SWM_Q_FOCUSONMAP_SINGLE) {
                        /* See if other wins of same type are already mapped. */
                        TAILQ_FOREACH(w, &win->ws->winlist, entry) {
@@ -8714,7 +8731,7 @@ char *
 get_atom_name(xcb_atom_t atom)
 {
        char                            *name = NULL;
-#if 0
+#ifdef SWM_DEBUG_ATOM_NAMES
        /*
         * This should be disabled during most debugging since
         * xcb_get_* causes an xcb_flush.
@@ -8815,6 +8832,8 @@ propertynotify(xcb_property_notify_event_t *e)
        } else if (e->atom == XCB_ATOM_WM_CLASS ||
            e->atom == XCB_ATOM_WM_NAME) {
                bar_draw();
+       } else if (e->atom == a_prot) {
+               get_wm_protocols(win);
        }
 
        xcb_flush(conn);
@@ -8879,15 +8898,6 @@ unmapnotify(xcb_unmap_notify_event_t *e)
        focus_flush();
 }
 
-#if 0
-void
-visibilitynotify(xcb_visibility_notify_event_t *e)
-{
-       DNPRINTF(SWM_D_EVENT, "visibilitynotify: window: 0x%x\n",
-           e->window);
-}
-#endif
-
 void
 clientmessage(xcb_client_message_event_t *e)
 {
@@ -9600,7 +9610,7 @@ event_handle(xcb_generic_event_t *evt)
        /*EVENT(XCB_SELECTION_NOTIFY, );*/
        /*EVENT(XCB_SELECTION_REQUEST, );*/
        EVENT(XCB_UNMAP_NOTIFY, unmapnotify);
-       /*EVENT(XCB_VISIBILITY_NOTIFY, visibilitynotify);*/
+       /*EVENT(XCB_VISIBILITY_NOTIFY, );*/
 #undef EVENT
        }
        if (type - xrandr_eventbase == XCB_RANDR_SCREEN_CHANGE_NOTIFY)