hide behind monocle

This commit is contained in:
Leonardo Hernández Hernández 2023-07-08 17:25:16 -06:00
parent 4b8c1bf31e
commit ad9a1cfcb9
No known key found for this signature in database
GPG Key ID: E538897EE11B9624

85
dwl.c
View File

@ -258,9 +258,10 @@ static Monitor *dirtomon(enum wlr_direction dir);
static void focusclient(Client *c, int lift); static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg); static void focusmon(const Arg *arg);
static void focusstack(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 fullscreennotify(struct wl_listener *listener, void *data);
static void handlesig(int signo); static void handlesig(int signo);
static void hidebehindmonocle(Monitor *m);
static void incnmaster(const Arg *arg); static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data); static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym); static int keybinding(uint32_t mods, xkb_keysym_t sym);
@ -480,7 +481,7 @@ arrange(Monitor *m)
wlr_scene_node_set_enabled(&c->scene->node, VISIBLEON(c, m)); wlr_scene_node_set_enabled(&c->scene->node, VISIBLEON(c, m));
wlr_scene_node_set_enabled(&m->fullscreen_bg->node, 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)); strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
@ -729,7 +730,7 @@ closemon(Monitor *m)
if (c->mon == m) if (c->mon == m)
setmon(c, selmon, c->tags); setmon(c, selmon, c->tags);
} }
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
printstatus(); printstatus();
} }
@ -1075,7 +1076,7 @@ destroydragicon(struct wl_listener *listener, void *data)
struct wlr_drag_icon *icon = data; struct wlr_drag_icon *icon = data;
wlr_scene_node_destroy(icon->data); wlr_scene_node_destroy(icon->data);
/* Focus enter isn't sent during drag, so refocus the focused node. */ /* Focus enter isn't sent during drag, so refocus the focused node. */
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
motionnotify(0); motionnotify(0);
} }
@ -1110,7 +1111,7 @@ destroylock(SessionLock *lock, int unlock)
wlr_scene_node_set_enabled(&locked_bg->node, 0); wlr_scene_node_set_enabled(&locked_bg->node, 0);
focusclient(focustop(selmon), 0); focusclient(focustop(selmon, 0), 0);
motionnotify(0); motionnotify(0);
destroy: destroy:
@ -1139,7 +1140,7 @@ destroylocksurface(struct wl_listener *listener, void *data)
surface = wl_container_of(cur_lock->surfaces.next, surface, link); surface = wl_container_of(cur_lock->surfaces.next, surface, link);
client_notify_enter(surface->surface, wlr_seat_get_keyboard(seat)); client_notify_enter(surface->surface, wlr_seat_get_keyboard(seat));
} else if (!locked) { } else if (!locked) {
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
} else { } else {
wlr_seat_keyboard_clear_focus(seat); wlr_seat_keyboard_clear_focus(seat);
} }
@ -1225,6 +1226,7 @@ focusclient(Client *c, int lift)
wl_list_insert(&fstack, &c->flink); wl_list_insert(&fstack, &c->flink);
selmon = c->mon; selmon = c->mon;
c->isurgent = 0; c->isurgent = 0;
hidebehindmonocle(c->mon);
client_restack_surface(c); client_restack_surface(c);
/* Don't change border color if there is an exclusive focus or we are /* Don't change border color if there is an exclusive focus or we are
@ -1280,14 +1282,14 @@ focusmon(const Arg *arg)
do /* don't switch to disabled mons */ do /* don't switch to disabled mons */
selmon = dirtomon(arg->i); selmon = dirtomon(arg->i);
while (!selmon->wlr_output->enabled && i++ < nmons); while (!selmon->wlr_output->enabled && i++ < nmons);
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
} }
void void
focusstack(const Arg *arg) focusstack(const Arg *arg)
{ {
/* Focus the next or previous client (in tiling order) on selmon */ /* 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) if (!sel || sel->isfullscreen)
return; return;
if (arg->i > 0) { if (arg->i > 0) {
@ -1313,12 +1315,16 @@ focusstack(const Arg *arg)
* will focus the topmost client of this mon, when actually will * will focus the topmost client of this mon, when actually will
* only return that client */ * only return that client */
Client * Client *
focustop(Monitor *m) focustop(Monitor *m, int onlytiled)
{ {
Client *c; Client *c;
wl_list_for_each(c, &fstack, flink) wl_list_for_each(c, &fstack, flink) {
if (VISIBLEON(c, m)) if (VISIBLEON(c, m)) {
if (onlytiled && c->isfloating)
continue;
return c; return c;
}
}
return NULL; return NULL;
} }
@ -1350,6 +1356,22 @@ handlesig(int signo)
} }
} }
void
hidebehindmonocle(Monitor *m)
{
Client *c;
if (m && m->lt[m->sellt]->arrange == monocle) {
wl_list_for_each(c, &clients, link)
wlr_scene_node_set_enabled(&c->scene->node, VISIBLEON(c, m) && c->isfloating);
c = NULL;
/* Enable top tiled client, fullscreen is considered tiled */
if ((c = focustop(m, 1)))
wlr_scene_node_set_enabled(&c->scene->node, 1);
}
}
void void
incnmaster(const Arg *arg) incnmaster(const Arg *arg)
{ {
@ -1494,7 +1516,7 @@ keyrepeat(void *data)
void void
killclient(const Arg *arg) killclient(const Arg *arg)
{ {
Client *sel = focustop(selmon); Client *sel = focustop(selmon, 0);
if (sel) if (sel)
client_send_close(sel); client_send_close(sel);
} }
@ -1629,8 +1651,7 @@ monocle(Monitor *m)
} }
if (n) if (n)
snprintf(m->ltsymbol, LENGTH(m->ltsymbol), "[%d]", n); snprintf(m->ltsymbol, LENGTH(m->ltsymbol), "[%d]", n);
if ((c = focustop(m))) hidebehindmonocle(m);
wlr_scene_node_raise_to_top(&c->scene->node);
} }
void void
@ -1861,7 +1882,7 @@ printstatus(void)
if (c->isurgent) if (c->isurgent)
urg |= c->tags; urg |= c->tags;
} }
if ((c = focustop(m))) { if ((c = focustop(m, 0))) {
title = client_get_title(c); title = client_get_title(c);
appid = client_get_appid(c); appid = client_get_appid(c);
printf("%s title %s\n", m->wlr_output->name, title ? title : broken); printf("%s title %s\n", m->wlr_output->name, title ? title : broken);
@ -2102,7 +2123,7 @@ setmon(Client *c, Monitor *m, uint32_t newtags)
c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */ c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */
setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */ setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */
} }
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
} }
void void
@ -2334,12 +2355,12 @@ startdrag(struct wl_listener *listener, void *data)
void void
tag(const Arg *arg) tag(const Arg *arg)
{ {
Client *sel = focustop(selmon); Client *sel = focustop(selmon, 0);
if (!sel || (arg->ui & TAGMASK) == 0) if (!sel || (arg->ui & TAGMASK) == 0)
return; return;
sel->tags = arg->ui & TAGMASK; sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
arrange(selmon); arrange(selmon);
printstatus(); printstatus();
} }
@ -2347,7 +2368,7 @@ tag(const Arg *arg)
void void
tagmon(const Arg *arg) tagmon(const Arg *arg)
{ {
Client *sel = focustop(selmon); Client *sel = focustop(selmon, 0);
if (sel) if (sel)
setmon(sel, dirtomon(arg->i), 0); setmon(sel, dirtomon(arg->i), 0);
} }
@ -2388,7 +2409,7 @@ tile(Monitor *m)
void void
togglefloating(const Arg *arg) togglefloating(const Arg *arg)
{ {
Client *sel = focustop(selmon); Client *sel = focustop(selmon, 0);
/* return if fullscreen */ /* return if fullscreen */
if (sel && !sel->isfullscreen) if (sel && !sel->isfullscreen)
setfloating(sel, !sel->isfloating); setfloating(sel, !sel->isfloating);
@ -2397,7 +2418,7 @@ togglefloating(const Arg *arg)
void void
togglefullscreen(const Arg *arg) togglefullscreen(const Arg *arg)
{ {
Client *sel = focustop(selmon); Client *sel = focustop(selmon, 0);
if (sel) if (sel)
setfullscreen(sel, !sel->isfullscreen); setfullscreen(sel, !sel->isfullscreen);
} }
@ -2406,7 +2427,7 @@ void
toggletag(const Arg *arg) toggletag(const Arg *arg)
{ {
uint32_t newtags; uint32_t newtags;
Client *sel = focustop(selmon); Client *sel = focustop(selmon, 0);
if (!sel) if (!sel)
return; return;
newtags = sel->tags ^ (arg->ui & TAGMASK); newtags = sel->tags ^ (arg->ui & TAGMASK);
@ -2414,7 +2435,7 @@ toggletag(const Arg *arg)
return; return;
sel->tags = newtags; sel->tags = newtags;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
arrange(selmon); arrange(selmon);
printstatus(); printstatus();
} }
@ -2428,7 +2449,7 @@ toggleview(const Arg *arg)
return; return;
selmon->tagset[selmon->seltags] = newtagset; selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
arrange(selmon); arrange(selmon);
printstatus(); printstatus();
} }
@ -2454,7 +2475,7 @@ unmaplayersurfacenotify(struct wl_listener *listener, void *data)
arrangelayers(layersurface->mon); arrangelayers(layersurface->mon);
if (layersurface->layer_surface->surface == if (layersurface->layer_surface->surface ==
seat->keyboard_state.focused_surface) seat->keyboard_state.focused_surface)
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
motionnotify(0); motionnotify(0);
} }
@ -2472,7 +2493,7 @@ unmapnotify(struct wl_listener *listener, void *data)
if (c == exclusive_focus) if (c == exclusive_focus)
exclusive_focus = NULL; exclusive_focus = NULL;
if (client_surface(c) == seat->keyboard_state.focused_surface) if (client_surface(c) == seat->keyboard_state.focused_surface)
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
} else { } else {
wl_list_remove(&c->link); wl_list_remove(&c->link);
setmon(c, NULL, 0); setmon(c, NULL, 0);
@ -2561,7 +2582,7 @@ updatemons(struct wl_listener *listener, void *data)
wl_list_for_each(c, &clients, link) wl_list_for_each(c, &clients, link)
if (!c->mon && client_is_mapped(c)) if (!c->mon && client_is_mapped(c))
setmon(c, selmon, c->tags); setmon(c, selmon, c->tags);
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
if (selmon->lock_surface) { if (selmon->lock_surface) {
client_notify_enter(selmon->lock_surface->surface, client_notify_enter(selmon->lock_surface->surface,
wlr_seat_get_keyboard(seat)); wlr_seat_get_keyboard(seat));
@ -2576,7 +2597,7 @@ void
updatetitle(struct wl_listener *listener, void *data) updatetitle(struct wl_listener *listener, void *data)
{ {
Client *c = wl_container_of(listener, c, set_title); Client *c = wl_container_of(listener, c, set_title);
if (c == focustop(c->mon)) if (c == focustop(c->mon, 0))
printstatus(); printstatus();
} }
@ -2586,7 +2607,7 @@ urgent(struct wl_listener *listener, void *data)
struct wlr_xdg_activation_v1_request_activate_event *event = data; struct wlr_xdg_activation_v1_request_activate_event *event = data;
Client *c = NULL; Client *c = NULL;
toplevel_from_wlr_surface(event->surface, &c, NULL); toplevel_from_wlr_surface(event->surface, &c, NULL);
if (!c || c == focustop(selmon)) if (!c || c == focustop(selmon, 0))
return; return;
c->isurgent = 1; c->isurgent = 1;
@ -2601,7 +2622,7 @@ view(const Arg *arg)
selmon->seltags ^= 1; /* toggle sel tagset */ selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK) if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon, 0), 1);
arrange(selmon); arrange(selmon);
printstatus(); printstatus();
} }
@ -2654,7 +2675,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
void void
zoom(const Arg *arg) 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) if (!sel || !selmon || !selmon->lt[selmon->sellt]->arrange || sel->isfloating)
return; return;
@ -2748,7 +2769,7 @@ void
sethints(struct wl_listener *listener, void *data) sethints(struct wl_listener *listener, void *data)
{ {
Client *c = wl_container_of(listener, c, set_hints); Client *c = wl_container_of(listener, c, set_hints);
if (c == focustop(selmon)) if (c == focustop(selmon, 0))
return; return;
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints); c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);