From fedd800f2a1e4dddc024d4559e2cec299e8c541c Mon Sep 17 00:00:00 2001 From: Reginald Kennedy Date: Sun, 2 Dec 2012 17:00:30 +0800 Subject: [PATCH] Add new quirk NOFOCUSONMAP. 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 | 11 +++++++++++ spectrwm.c | 27 ++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/spectrwm.1 b/spectrwm.1 index 293f8be..dc427c5 100644 --- a/spectrwm.1 +++ b/spectrwm.1 @@ -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 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: diff --git a/spectrwm.c b/spectrwm.c index cbf6fa3..059c2ac 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -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_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); @@ -6579,6 +6581,8 @@ const char *quirkname[] = { "XTERM_FONTADJ", "FULLSCREEN", "FOCUSPREV", + "NOFOCUSONMAP", + "FOCUSONMAP_SINGLE", }; /* 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) { - 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", @@ -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. */ - 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) -- 1.7.10.4