summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2020-04-23 00:27:53 -0500
committerDevin J. Pohly <djpohly@gmail.com>2020-04-23 00:32:28 -0500
commit9b2eec24c2ba94886f1f196d99f2ffe9ac0b6d3b (patch)
tree6ae3d2c1ce738e46a7ef2c58f135c4195cadc686
parent3593da0e15cf3ffa7933a9f949736e2a356e15a6 (diff)
add selclient() helper
This may get inlined later, but it's nice for now. The focused client if any should always be both at the top of fstack and visible on selmon.
-rw-r--r--dwl.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/dwl.c b/dwl.c
index 6a11390..737b71c 100644
--- a/dwl.c
+++ b/dwl.c
@@ -141,6 +141,7 @@ static void rendermon(struct wl_listener *listener, void *data);
static void resize(Client *c, int x, int y, int w, int h);
static void resizemouse(const Arg *arg);
static void run(char *startup_cmd);
+static Client *selclient(void);
static void setcursor(struct wl_listener *listener, void *data);
static void setlayout(const Arg *arg);
static void setup(void);
@@ -410,18 +411,16 @@ focus(Client *c, struct wlr_surface *surface)
void
focusnext(const Arg *arg)
{
- /* XXX will need more logic with clients on different monitors */
- if (wl_list_length(&clients) < 2) {
+ Client *sel = selclient();
+ if (!sel)
return;
- }
/* Find the selected client (top of fstack) and focus the client
* following it in tiling order */
- Client *c = wl_container_of(fstack.next, c, flink);
- Client *n = wl_container_of(c->link.next, n, link);
+ Client *c = wl_container_of(sel->link.next, c, link);
/* Skip the sentinel node if we wrap around the end of the list */
- if (&n->link == &clients)
- n = wl_container_of(n->link.next, n, link);
- focus(n, n->xdg_surface->surface);
+ if (&c->link == &clients)
+ c = wl_container_of(c->link.next, c, link);
+ focus(c, c->xdg_surface->surface);
}
void
@@ -849,6 +848,15 @@ run(char *startup_cmd)
}
}
+Client *
+selclient(void)
+{
+ Client *c = wl_container_of(fstack.next, c, flink);
+ if (wl_list_empty(&fstack) || !VISIBLEON(c, selmon))
+ return NULL;
+ return c;
+}
+
void
setcursor(struct wl_listener *listener, void *data)
{