hide behind monocle

This commit is contained in:
Leonardo Hernández Hernández 2022-09-27 13:06:09 -05:00 committed by Leonardo Hernández Hernández
parent c766bb02f0
commit 0eb873340b
No known key found for this signature in database
GPG key ID: E538897EE11B9624

92
dwl.c
View file

@ -299,9 +299,10 @@ static Monitor *dirtomon(enum wlr_direction dir);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m);
static Client *focustop(Monitor *m, int onlytiled);
static void fullscreennotify(struct wl_listener *listener, void *data);
static void handlesig(int signo);
static void hidebehindmonocle(Monitor *m);
static void incnmaster(const Arg *arg);
static void incgaps(const Arg *arg);
static void incigaps(const Arg *arg);
@ -537,7 +538,7 @@ void
arrange(Monitor *m)
{
LayerSurface *l;
Client *c, *sel = focustop(selmon);
Client *c, *sel = focustop(selmon, 0);
int i;
wl_list_for_each(c, &clients, link) {
if (c->mon == m) {
@ -547,7 +548,7 @@ arrange(Monitor *m)
}
wlr_scene_node_set_enabled(&m->fullscreen_bg->node,
(c = focustop(m)) && c->isfullscreen);
(c = focustop(m, 0)) && c->isfullscreen);
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
@ -851,7 +852,7 @@ closemon(Monitor *m)
if (c->mon == m)
setmon(c, selmon, c->tags);
}
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
printstatus();
}
@ -1262,7 +1263,7 @@ createpointerconstraint(struct wl_listener *listener, void *data)
{
struct wlr_pointer_constraint_v1 *wlr_constraint = data;
PointerConstraint *constraint = ecalloc(1, sizeof(*constraint));
Client *c = NULL, *sel = focustop(selmon);
Client *c = NULL, *sel = focustop(selmon, 0);
toplevel_from_wlr_surface(wlr_constraint->surface, &c, NULL);
constraint->constraint = wlr_constraint;
wlr_constraint->data = constraint;
@ -1390,7 +1391,7 @@ void
destroydragicon(struct wl_listener *listener, void *data)
{
/* Focus enter isn't sent during drag, so refocus the focused node. */
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
motionnotify(0, NULL, 0, 0, 0, 0);
}
@ -1425,7 +1426,7 @@ destroylock(SessionLock *lock, int unlock)
wlr_scene_node_set_enabled(&locked_bg->node, 0);
focusclient(focustop(selmon), 0);
focusclient(focustop(selmon, 0), 0);
motionnotify(0, NULL, 0, 0, 0, 0);
destroy:
@ -1454,7 +1455,7 @@ destroylocksurface(struct wl_listener *listener, void *data)
surface = wl_container_of(cur_lock->surfaces.next, surface, link);
client_notify_enter(surface->surface, wlr_seat_get_keyboard(seat));
} else if (!locked) {
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
} else {
wlr_seat_keyboard_clear_focus(seat);
}
@ -1564,6 +1565,7 @@ focusclient(Client *c, int lift)
wl_list_insert(&fstack, &c->flink);
selmon = c->mon;
c->isurgent = 0;
hidebehindmonocle(c->mon);
client_restack_surface(c);
/* Don't change border color if there is an exclusive focus or we are
@ -1617,14 +1619,14 @@ focusmon(const Arg *arg)
do /* don't switch to disabled mons */
selmon = dirtomon(arg->i);
while (!selmon->wlr_output->enabled && i++ < nmons);
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
}
void
focusstack(const Arg *arg)
{
/* Focus the next or previous client (in tiling order) on selmon */
Client *c, *sel = focustop(selmon);
Client *c, *sel = focustop(selmon, 0);
if (!sel || sel->isfullscreen)
return;
if (arg->i > 0) {
@ -1650,12 +1652,16 @@ focusstack(const Arg *arg)
* will focus the topmost client of this mon, when actually will
* only return that client */
Client *
focustop(Monitor *m)
focustop(Monitor *m, int onlytiled)
{
Client *c;
wl_list_for_each(c, &fstack, flink)
if (VISIBLEON(c, m))
wl_list_for_each(c, &fstack, flink) {
if (VISIBLEON(c, m)) {
if (onlytiled && c->isfloating)
continue;
return c;
}
}
return NULL;
}
@ -1700,6 +1706,21 @@ handlesig(int signo)
}
}
void
hidebehindmonocle(Monitor *m)
{
Client *c;
if (m && m->lt[m->sellt]->arrange == monocle) {
wl_list_for_each(c, &clients, link)
if (VISIBLEON(c, m))
wlr_scene_node_set_enabled(&c->scene->node, c->isfloating);
/* Enable top tiled client, fullscreen is considered tiled */
if ((c = focustop(m, 1)))
wlr_scene_node_set_enabled(&c->scene->node, 1);
}
}
void
incnmaster(const Arg *arg)
{
@ -1920,7 +1941,7 @@ keyrepeat(void *data)
void
killclient(const Arg *arg)
{
Client *sel = focustop(selmon);
Client *sel = focustop(selmon, 0);
if (sel)
client_send_close(sel);
}
@ -2061,8 +2082,7 @@ monocle(Monitor *m)
}
if (n)
snprintf(m->ltsymbol, LENGTH(m->ltsymbol), "[%d]", n);
if ((c = focustop(m)))
wlr_scene_node_raise_to_top(&c->scene->node);
hidebehindmonocle(m);
}
void
@ -2328,7 +2348,7 @@ printstatus(void)
if (c->isurgent)
urg |= c->tags;
}
if ((c = focustop(m))) {
if ((c = focustop(m, 0))) {
title = client_get_title(c);
appid = client_get_appid(c);
printf("%s title %s\n", m->wlr_output->name, title ? title : broken);
@ -2664,13 +2684,13 @@ setmon(Client *c, Monitor *m, uint32_t newtags)
setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */
setfloating(c, c->isfloating);
}
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
}
void
setopacity(const Arg *arg)
{
Client *sel = focustop(selmon);
Client *sel = focustop(selmon, 0);
if (!sel)
return;
@ -2936,12 +2956,12 @@ startdrag(struct wl_listener *listener, void *data)
void
tag(const Arg *arg)
{
Client *sel = focustop(selmon);
Client *sel = focustop(selmon, 0);
if (!sel || (arg->ui & TAGMASK) == 0)
return;
sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
arrange(selmon);
printstatus();
}
@ -2949,7 +2969,7 @@ tag(const Arg *arg)
void
tagmon(const Arg *arg)
{
Client *sel = focustop(selmon);
Client *sel = focustop(selmon, 0);
if (sel)
setmon(sel, dirtomon(arg->i), 0);
}
@ -2999,7 +3019,7 @@ tile(Monitor *m)
void
togglefloating(const Arg *arg)
{
Client *sel = focustop(selmon);
Client *sel = focustop(selmon, 0);
/* return if fullscreen */
if (sel && !sel->isfullscreen)
setfloating(sel, !sel->isfloating);
@ -3008,7 +3028,7 @@ togglefloating(const Arg *arg)
void
togglefullscreen(const Arg *arg)
{
Client *sel = focustop(selmon);
Client *sel = focustop(selmon, 0);
if (sel)
setfullscreen(sel, !sel->isfullscreen);
}
@ -3024,7 +3044,7 @@ void
toggletag(const Arg *arg)
{
uint32_t newtags;
Client *sel = focustop(selmon);
Client *sel = focustop(selmon, 0);
if (!sel)
return;
newtags = sel->tags ^ (arg->ui & TAGMASK);
@ -3032,7 +3052,7 @@ toggletag(const Arg *arg)
return;
sel->tags = newtags;
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
arrange(selmon);
printstatus();
}
@ -3046,7 +3066,7 @@ toggleview(const Arg *arg)
return;
selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
arrange(selmon);
printstatus();
}
@ -3072,7 +3092,7 @@ unmaplayersurfacenotify(struct wl_listener *listener, void *data)
arrangelayers(layersurface->mon);
if (layersurface->layer_surface->surface ==
seat->keyboard_state.focused_surface)
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
motionnotify(0, NULL, 0, 0, 0, 0);
}
@ -3090,7 +3110,7 @@ unmapnotify(struct wl_listener *listener, void *data)
if (c == exclusive_focus)
exclusive_focus = NULL;
if (client_surface(c) == seat->keyboard_state.focused_surface)
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
} else {
wl_list_remove(&c->link);
setmon(c, NULL, 0);
@ -3167,7 +3187,7 @@ updatemons(struct wl_listener *listener, void *data)
/* Don't move clients to the left output when plugging monitors */
arrange(m);
/* make sure fullscreen clients have the right size */
if ((c = focustop(m)) && c->isfullscreen)
if ((c = focustop(m, 0)) && c->isfullscreen)
resize(c, m->m, 0, 0);
m->gamma_lut_changed = 1;
@ -3181,7 +3201,7 @@ updatemons(struct wl_listener *listener, void *data)
wl_list_for_each(c, &clients, link)
if (!c->mon && client_surface(c)->mapped)
setmon(c, selmon, c->tags);
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
if (selmon->lock_surface) {
client_notify_enter(selmon->lock_surface->surface,
wlr_seat_get_keyboard(seat));
@ -3203,7 +3223,7 @@ void
updatetitle(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, set_title);
if (c == focustop(c->mon))
if (c == focustop(c->mon, 0))
printstatus();
}
@ -3213,7 +3233,7 @@ urgent(struct wl_listener *listener, void *data)
struct wlr_xdg_activation_v1_request_activate_event *event = data;
Client *c = NULL;
toplevel_from_wlr_surface(event->surface, &c, NULL);
if (!c || c == focustop(selmon))
if (!c || c == focustop(selmon, 0))
return;
if (client_surface(c)->mapped)
@ -3230,7 +3250,7 @@ view(const Arg *arg)
selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
focusclient(focustop(selmon, 0), 1);
arrange(selmon);
printstatus();
}
@ -3283,7 +3303,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
void
zoom(const Arg *arg)
{
Client *c, *sel = focustop(selmon);
Client *c, *sel = focustop(selmon, 0);
if (!sel || !selmon || !selmon->lt[selmon->sellt]->arrange || sel->isfloating)
return;
@ -3396,7 +3416,7 @@ sethints(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, set_hints);
struct wlr_surface *surface = client_surface(c);
if (c == focustop(selmon))
if (c == focustop(selmon, 0))
return;
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);