]> code.delx.au - spectrwm/commitdiff
Add new quirk NOFOCUSONMAP.
authorReginald Kennedy <rk@rejii.com>
Sun, 2 Dec 2012 09:00:30 +0000 (17:00 +0800)
committerReginald Kennedy <rk@rejii.com>
Tue, 4 Dec 2012 06:49:00 +0000 (14:49 +0800)
Don't change focus to the window when it gets mapped on the screen.

Add new quirk FOCUSONMAP_SINGLE.
When the window is mapped, change focus if it is the only mapped window
on the workspace using the quirk entry.

spectrwm.1
spectrwm.c

index 293f8bed9020a3ba4292179b5db4a8464c779123..dc427c513d1a07acd4851a9b610f391d61a770f6 100644 (file)
@@ -880,6 +880,17 @@ Remove border to allow window to use full region size.
 .It FOCUSPREV
 On exit force focus on previously focused application not previous
 application in the stack.
 .It FOCUSPREV
 On exit force focus on previously focused application not previous
 application in the stack.
+.It NOFOCUSONMAP
+Don't change focus to the window when it first appears on the screen.
+Has no effect when
+.Ic focus_mode
+is set to follow.
+.It FOCUSONMAP_SINGLE
+When the window first appears on the screen, change focus to the window
+if there are no other windows on the workspace with the same class/name.
+Has no effect when
+.Ic focus_mode
+is set to follow.
 .El
 .Pp
 Custom quirks in the configuration file are specified as follows:
 .El
 .Pp
 Custom quirks in the configuration file are specified as follows:
index cbf6fa3572ee07b9ab857779034383c3cc047071..059c2ac5182ab271ca5d3a6f71feca0b7fed9b5c 100644 (file)
@@ -610,6 +610,8 @@ struct quirk {
 #define SWM_Q_XTERM_FONTADJ    (1<<3)  /* adjust xterm fonts when resizing */
 #define SWM_Q_FULLSCREEN       (1<<4)  /* remove border */
 #define SWM_Q_FOCUSPREV                (1<<5)  /* focus on caller */
 #define SWM_Q_XTERM_FONTADJ    (1<<3)  /* adjust xterm fonts when resizing */
 #define SWM_Q_FULLSCREEN       (1<<4)  /* remove border */
 #define SWM_Q_FOCUSPREV                (1<<5)  /* focus on caller */
+#define SWM_Q_NOFOCUSONMAP     (1<<6)  /* Don't focus on window when mapped. */
+#define SWM_Q_FOCUSONMAP_SINGLE        (1<<7)  /* Only focus if single win of type. */
 };
 TAILQ_HEAD(quirk_list, quirk);
 struct quirk_list              quirks = TAILQ_HEAD_INITIALIZER(quirks);
 };
 TAILQ_HEAD(quirk_list, quirk);
 struct quirk_list              quirks = TAILQ_HEAD_INITIALIZER(quirks);
@@ -6579,6 +6581,8 @@ const char *quirkname[] = {
        "XTERM_FONTADJ",
        "FULLSCREEN",
        "FOCUSPREV",
        "XTERM_FONTADJ",
        "FULLSCREEN",
        "FOCUSPREV",
+       "NOFOCUSONMAP",
+       "FOCUSONMAP_SINGLE",
 };
 
 /* SWM_Q_WS: retain '|' for back compat for now (2009-08-11) */
 };
 
 /* SWM_Q_WS: retain '|' for back compat for now (2009-08-11) */
@@ -8325,7 +8329,7 @@ mappingnotify(xcb_mapping_notify_event_t *e)
 void
 maprequest(xcb_map_request_event_t *e)
 {
 void
 maprequest(xcb_map_request_event_t *e)
 {
-       struct ws_win           *win;
+       struct ws_win           *win, *w = NULL;
        xcb_get_window_attributes_reply_t *war;
 
        DNPRINTF(SWM_D_EVENT, "maprequest: win 0x%x\n",
        xcb_get_window_attributes_reply_t *war;
 
        DNPRINTF(SWM_D_EVENT, "maprequest: win 0x%x\n",
@@ -8349,8 +8353,25 @@ maprequest(xcb_map_request_event_t *e)
            (war->map_state == XCB_MAP_STATE_VIEWABLE));
 
        /* The new window should get focus; prepare. */
            (war->map_state == XCB_MAP_STATE_VIEWABLE));
 
        /* The new window should get focus; prepare. */
-       if (focus_mode != SWM_FOCUS_FOLLOW)
-               win->ws->focus_pending = get_focus_magic(win);
+       if (focus_mode != SWM_FOCUS_FOLLOW &&
+           !(win->quirks & SWM_Q_NOFOCUSONMAP)) {
+               if (win->quirks & SWM_Q_FOCUSONMAP_SINGLE) {
+                       /* See if other wins of same type are already mapped. */
+                       TAILQ_FOREACH(w, &win->ws->winlist, entry) {
+                               if (w == win || !w->mapped)
+                                       continue;
+
+                               if (!strcmp(w->ch.class_name,
+                                   win->ch.class_name) &&
+                                   !strcmp(w->ch.instance_name,
+                                   win->ch.instance_name))
+                                       break;
+                       }
+               }
+
+               if (w == NULL)
+                       win->ws->focus_pending = get_focus_magic(win);
+       }
 
        /* All windows need to be mapped if they are in the current workspace.*/
        if (win->ws->r)
 
        /* All windows need to be mapped if they are in the current workspace.*/
        if (win->ws->r)