Skip to content

Commit 3c17a2a

Browse files
committed
Added feature to keep track of last focused window per workspace
This allow to loop only through a set of two windows
1 parent 9816784 commit 3c17a2a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: 2bwm.c

+18
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ xcb_screen_t *screen = NULL; // Our current screen.
4444
int randrbase = 0; // Beginning of RANDR extension events.
4545
static uint8_t curws = 0; // Current workspace.
4646
struct client *focuswin = NULL; // Current focus window.
47+
struct client *lastwin[WORKSPACES]; // Last focused window.
4748
static xcb_drawable_t top_win=0; // Window always on top.
4849
static xcb_drawable_t dock_win=0; // A single dock always on top.
4950
static struct item *winlist = NULL; // Global list of all client windows.
@@ -66,6 +67,7 @@ static void cursor_move(const Arg *);
6667
static void changeworkspace(const Arg *);
6768
static void changeworkspace_helper(const uint32_t);
6869
static void focusnext(const Arg *);
70+
static void focuslastwin(const Arg *);
6971
static void focusnext_helper(bool);
7072
static void sendtoworkspace(const Arg *);
7173
static void sendtonextworkspace(const Arg *);
@@ -190,6 +192,15 @@ focusnext(const Arg *arg)
190192
focusnext_helper(arg->i > 0);
191193
}
192194

195+
void
196+
focuslastwin(const Arg *arg)
197+
{
198+
if (lastwin[curws] == NULL)
199+
return;
200+
raisewindow(lastwin[curws]->id);
201+
setfocus(lastwin[curws]);
202+
}
203+
193204
void
194205
delfromworkspace(struct client *client)
195206
{
@@ -1634,6 +1645,7 @@ setfocus(struct client *client)// Set focus on window client.
16341645
ewmh->_NET_ACTIVE_WINDOW, XCB_ATOM_WINDOW, 32, 1,&client->id);
16351646

16361647
/* Remember the new window as the current focused window. */
1648+
lastwin[curws] = focuswin;
16371649
focuswin = client;
16381650

16391651
grabbuttons(client);
@@ -2957,6 +2969,9 @@ destroynotify(xcb_generic_event_t *ev)
29572969
if (NULL != focuswin && focuswin->id == e->window)
29582970
focuswin = NULL;
29592971

2972+
if (NULL != lastwin[curws] && lastwin[curws]->id == e->window)
2973+
lastwin[curws] = NULL;
2974+
29602975
cl = findclient( & e->window);
29612976

29622977
/* Find this window in list of clients and forget about it. */
@@ -3061,6 +3076,9 @@ unmapnotify(xcb_generic_event_t *ev)
30613076
return;
30623077
if (focuswin!=NULL && client->id == focuswin->id)
30633078
focuswin = NULL;
3079+
if (lastwin[curws]!=NULL && client->id == lastwin[curws]->id)
3080+
lastwin[curws] = NULL;
3081+
30643082
if (client->iconic == false)
30653083
forgetclient(client);
30663084

0 commit comments

Comments
 (0)