diff --git a/client.h b/client.h index eb1bb47..c41e287 100644 --- a/client.h +++ b/client.h @@ -347,6 +347,12 @@ client_set_border_color(Client *c, const float color[static 4]) wlr_scene_rect_set_color(c->border[i], color); } +static inline void +client_set_dimmer_state(Client *c, const int dim) +{ + wlr_scene_node_set_enabled(&c->dimmer->node, DIMOPT && !c->neverdim && dim); +} + static inline void client_set_fullscreen(Client *c, int fullscreen) { diff --git a/config.def.h b/config.def.h index a4019d3..bf829c6 100644 --- a/config.def.h +++ b/config.def.h @@ -11,6 +11,7 @@ static const unsigned int snap = 32; /* snap pixel */ static const float rootcolor[] = COLOR(0x222222ff); static const float bordercolor[] = COLOR(0x444444ff); static const float focuscolor[] = COLOR(0x005577ff); +static const float unfocuseddim[] = COLOR(0x00000088); static const float urgentcolor[] = COLOR(0xff0000ff); /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You can also use glsl colors */ @@ -168,6 +169,7 @@ static const Key keys[] = { static const Button buttons[] = { { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} }, { MODKEY, BTN_MIDDLE, togglefloating, {0} }, + { MODKEY|ShiftMask, BTN_MIDDLE, toggledimmingclient, {0} }, { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} }, }; diff --git a/dwl.c b/dwl.c index cca1ea4..af6371b 100644 --- a/dwl.c +++ b/dwl.c @@ -121,6 +121,7 @@ typedef struct { Monitor *mon; struct wlr_scene_tree *scene; struct wlr_scene_rect *border[4]; /* top, bottom, left, right */ + struct wlr_scene_rect *dimmer; struct wlr_scene_tree *scene_surface; struct wl_list link; struct wl_list flink; @@ -158,7 +159,7 @@ typedef struct { #endif unsigned int bw; uint32_t tags; - int isfloating, isurgent, isfullscreen; + int isfloating, isurgent, isfullscreen, neverdim; } Client; typedef struct { @@ -248,6 +249,7 @@ typedef struct { const char *title; uint32_t tags; int isfloating; + int neverdim; int monitor; } Rule; @@ -357,6 +359,8 @@ static void startdrag(struct wl_listener *listener, void *data); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *m); +static void toggledimming(const Arg *arg); +static void toggledimmingclient(const Arg *arg); static void togglefloating(const Arg *arg); static void togglefullscreen(const Arg *arg); static void toggletag(const Arg *arg); @@ -431,6 +435,7 @@ static struct wlr_box sgeom; static struct wl_list mons; static Monitor *selmon; static int consumed[KEY_MAX + 1]; +static int DIMOPT = 1; /* global event handlers */ static struct wl_listener cursor_axis = {.notify = axisnotify}; @@ -533,6 +538,7 @@ applyrules(Client *c) if ((!r->title || strstr(title, r->title)) && (!r->id || strstr(appid, r->id))) { c->isfloating = r->isfloating; + c->neverdim = r-> neverdim; newtags |= r->tags; i = 0; wl_list_for_each(m, &mons, link) { @@ -1550,8 +1556,10 @@ focusclient(Client *c, LayerSurface *l, int lift) * handling a drag operation */ if (!(old_l && old_l->layer_surface->current.keyboard_interactive == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) && !(old_c && client_wants_focus(old_c)) - && !seat->drag) + && !seat->drag) { client_set_border_color(c, focuscolor); + client_set_dimmer_state(c, 0); + } } /* If an overlay is focused, don't focus or activate the client, @@ -1566,8 +1574,10 @@ focusclient(Client *c, LayerSurface *l, int lift) if (focused_client && focused_client != c && !(c && client_is_unmanaged(c))) { struct wlr_surface *s = client_surface(focused_client); - if (c) + if (c) { client_set_border_color(focused_client, bordercolor); + client_set_dimmer_state(focused_client, 1); + } if (s && s->mapped) client_activate_surface(s, 0); focused_client = NULL; @@ -1887,7 +1897,7 @@ mapnotify(struct wl_listener *listener, void *data) { /* Called when the surface is mapped, or ready to display on-screen. */ Client *p = NULL; - Client *w, *c = wl_container_of(listener, c, map); + Client *w, *d, *c = wl_container_of(listener, c, map); Monitor *m; int i; @@ -1923,6 +1933,10 @@ mapnotify(struct wl_listener *listener, void *data) c->border[i]->node.data = c; } + c->dimmer = wlr_scene_rect_create(c->scene, 0, 0, unfocuseddim); + c->dimmer->node.data = c; + client_set_dimmer_state(c, 1); + /* Initialize client geometry with room for border */ client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT); @@ -1954,6 +1968,10 @@ mapnotify(struct wl_listener *listener, void *data) setmon(c, p->mon, p->tags); } else { applyrules(c); + d = focustop(selmon); + if (d) { + client_set_dimmer_state(d, 0); + } } printstatus(); @@ -2398,7 +2416,7 @@ resize(Client *c, struct wlr_box geo, int interact) c->geom = geo; applybounds(c, bbox); - /* Update scene-graph, including borders */ + /* Update scene-graph, including borders and dimmer*/ wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y); wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw); wlr_scene_rect_set_size(c->border[0], c->geom.width, c->bw); @@ -2408,6 +2426,8 @@ resize(Client *c, struct wlr_box geo, int interact) wlr_scene_node_set_position(&c->border[1]->node, 0, c->geom.height - c->bw); wlr_scene_node_set_position(&c->border[2]->node, 0, c->bw); wlr_scene_node_set_position(&c->border[3]->node, c->geom.width - c->bw, c->bw); + wlr_scene_rect_set_size(c->dimmer, c->geom.width - 2*c->bw, c-> geom.height - 2*c->bw); + wlr_scene_node_set_position(&c->dimmer->node, c->bw, c->bw); client_set_size(c, c->geom.width - 2 * c->bw, c->geom.height - 2 * c->bw); client_get_clip(c, &clip); @@ -2935,6 +2955,27 @@ tile(Monitor *m) } } +void toggledimming(const Arg *arg) +{ + Client *c; + DIMOPT ^= 1; + wl_list_for_each(c, &clients, link) + { + client_set_dimmer_state(c, 1); + } + c = focustop(selmon); + if (c) + client_set_dimmer_state(c, 0); +} + +void +toggledimmingclient(const Arg *arg) +{ + Client *sel = focustop(selmon); + if (sel) + sel -> neverdim ^= 1; +} + void togglefloating(const Arg *arg) { @@ -3237,10 +3278,32 @@ xytonode(double x, double y, struct wlr_surface **psurface, struct wlr_scene_node *node; struct wlr_surface *surface = NULL; int layer; + struct wlr_scene_node *hidden_dimmers[32]; + int hidden_count = 0; for (layer = NUM_LAYERS - 1; !surface && layer >= (locked ? LyrBlock : 0); layer--) { - if (layer == LyrIMPopup || - !(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny))) + if (layer == LyrIMPopup) + continue; + node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny); + + while (node && node->type == WLR_SCENE_NODE_RECT && node->data) { + Client *hit_c = node->data; + /* Verify the node is actually a client's dimmer */ + if (hit_c->type != LayerShell && hit_c->dimmer && &hit_c->dimmer->node == node) { + if (hidden_count < 32) { + wlr_scene_node_set_enabled(node, 0); + hidden_dimmers[hidden_count++] = node; + node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny); + continue; + } + } + break; + } + + for(int i=0; itype == WLR_SCENE_NODE_BUFFER)