patch(bar): dwl bar.patch

This commit is contained in:
Zhongheng Liu 2026-01-10 21:48:59 +01:00
commit b1ea5090ee
Signed by: steven
GPG key ID: 805A28B071DAD84B
5 changed files with 780 additions and 79 deletions

408
dwl.c
View file

@ -1,10 +1,12 @@
/*
* See LICENSE file for copyright and license details.
*/
#include <fcntl.h>
#include <getopt.h>
#include <libinput.h>
#include <linux/input-event-codes.h>
#include <math.h>
#include <libdrm/drm_fourcc.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -60,6 +62,7 @@
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/interfaces/wlr_buffer.h>
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#include <xkbcommon/xkbcommon.h>
@ -71,6 +74,7 @@
#include "dwl-ipc-unstable-v2-protocol.h"
#include "util.h"
#include "drwl.h"
/* macros */
#define MAX(A, B) ((A) > (B) ? (A) : (B))
@ -79,14 +83,17 @@
#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define END(A) ((A) + LENGTH(A))
#define TAGMASK ((1u << TAGCOUNT) - 1)
#define TAGMASK ((1u << LENGTH(tags)) - 1)
#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
#define LISTEN_STATIC(E, H) do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0)
#define TEXTW(mon, text) (drwl_font_getwidth(mon->drw, text) + mon->lrpad)
/* enums */
enum { SchemeNorm, SchemeSel, SchemeUrg }; /* color schemes */
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11 }; /* client types */
enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
enum { ClkTagBar, ClkLtSymbol, ClkStatus, ClkTitle, ClkClient, ClkRoot }; /* clicks */
typedef union {
int i;
@ -96,6 +103,7 @@ typedef union {
} Arg;
typedef struct {
unsigned int click;
unsigned int mod;
unsigned int button;
void (*func)(const Arg *);
@ -192,11 +200,20 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
typedef struct {
struct wlr_buffer base;
struct wl_listener release;
bool busy;
Img *image;
uint32_t data[];
} Buffer;
struct Monitor {
struct wl_list link;
struct wl_list dwl_ipc_outputs;
struct wlr_output *wlr_output;
struct wlr_scene_output *scene_output;
struct wlr_scene_buffer *scene_buffer; /* bar buffer */
struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
struct wl_listener frame;
struct wl_listener destroy;
@ -204,6 +221,11 @@ struct Monitor {
struct wl_listener destroy_lock_surface;
struct wlr_session_lock_surface_v1 *lock_surface;
struct wlr_box m; /* monitor area, layout-relative */
struct {
int width, height;
int real_width, real_height; /* non-scaled */
float scale;
} b; /* bar area */
struct wlr_box w; /* window area, layout-relative */
struct wl_list layers[4]; /* LayerSurface.link */
const Layout *lt[2];
@ -215,6 +237,9 @@ struct Monitor {
int nmaster;
char ltsymbol[16];
int asleep;
Drwl *drw;
Buffer *pool[2];
int lrpad;
};
typedef struct {
@ -258,6 +283,13 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
struct wlr_box *usable_area, int exclusive);
static void arrangelayers(Monitor *m);
static void axisnotify(struct wl_listener *listener, void *data);
static bool baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy);
static void bufdestroy(struct wlr_buffer *buffer);
static bool bufdatabegin(struct wlr_buffer *buffer, uint32_t flags,
void **data, uint32_t *format, size_t *stride);
static void bufdataend(struct wlr_buffer *buffer);
static Buffer *bufmon(Monitor *m);
static void bufrelease(struct wl_listener *listener, void *data);
static void buttonpress(struct wl_listener *listener, void *data);
static void chvt(const Arg *arg);
static void checkidleinhibitor(struct wlr_surface *exclude);
@ -305,6 +337,8 @@ static void dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_r
static void dwl_ipc_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index);
static void dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset);
static void dwl_ipc_output_release(struct wl_client *client, struct wl_resource *resource);
static void drawbar(Monitor *m);
static void drawbars(void);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
static void focusnthmon(const Arg *arg);
@ -355,6 +389,7 @@ static void setsel(struct wl_listener *listener, void *data);
static void setup(void);
static void spawn(const Arg *arg);
static void startdrag(struct wl_listener *listener, void *data);
static int statusin(int fd, unsigned int mask, void *data);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tagnthmon(const Arg *arg);
@ -370,6 +405,7 @@ static void unlocksession(struct wl_listener *listener, void *data);
static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
static void unmapnotify(struct wl_listener *listener, void *data);
static void updatemons(struct wl_listener *listener, void *data);
static void updatebar(Monitor *m);
static void updatetitle(struct wl_listener *listener, void *data);
static void urgent(struct wl_listener *listener, void *data);
static void view(const Arg *arg);
@ -436,6 +472,15 @@ static struct wl_list mons;
static Monitor *selmon;
static int DIMOPT = 1;
static char stext[256];
static struct wl_event_source *status_event_source;
static const struct wlr_buffer_impl buffer_impl = {
.destroy = bufdestroy,
.begin_data_ptr_access = bufdatabegin,
.end_data_ptr_access = bufdataend,
};
/* global event handlers */
static struct wl_listener cursor_axis = {.notify = axisnotify};
static struct wl_listener cursor_button = {.notify = buttonpress};
@ -553,7 +598,7 @@ arrange(Monitor *m)
wlr_scene_node_set_enabled(&m->fullscreen_bg->node,
(c = focustop(m)) && c->isfullscreen);
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof(m->ltsymbol));
/* We move all clients (except fullscreen and unmanaged) to LyrTile while
* in floating layout to avoid "real" floating clients be always on top */
@ -609,6 +654,11 @@ arrangelayers(Monitor *m)
if (!m->wlr_output->enabled)
return;
if (m->scene_buffer->node.enabled) {
usable_area.height -= m->b.real_height;
usable_area.y += topbar ? m->b.real_height : 0;
}
/* Arrange exclusive surfaces from top->bottom */
for (i = 3; i >= 0; i--)
arrangelayer(m, &m->layers[i], &usable_area, 1);
@ -651,17 +701,102 @@ axisnotify(struct wl_listener *listener, void *data)
event->delta_discrete, event->source, event->relative_direction);
}
bool
baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy)
{
return true;
}
void
bufdestroy(struct wlr_buffer *wlr_buffer)
{
Buffer *buf = wl_container_of(wlr_buffer, buf, base);
if (buf->busy)
wl_list_remove(&buf->release.link);
drwl_image_destroy(buf->image);
free(buf);
}
bool
bufdatabegin(struct wlr_buffer *wlr_buffer, uint32_t flags,
void **data, uint32_t *format, size_t *stride)
{
Buffer *buf = wl_container_of(wlr_buffer, buf, base);
if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) return false;
*data = buf->data;
*stride = wlr_buffer->width * 4;
*format = DRM_FORMAT_ARGB8888;
return true;
}
void
bufdataend(struct wlr_buffer *wlr_buffer)
{
}
Buffer *
bufmon(Monitor *m)
{
size_t i;
Buffer *buf = NULL;
for (i = 0; i < LENGTH(m->pool); i++) {
if (m->pool[i]) {
if (m->pool[i]->busy)
continue;
buf = m->pool[i];
break;
}
buf = ecalloc(1, sizeof(Buffer) + (m->b.width * 4 * m->b.height));
buf->image = drwl_image_create(NULL, m->b.width, m->b.height, buf->data);
wlr_buffer_init(&buf->base, &buffer_impl, m->b.width, m->b.height);
m->pool[i] = buf;
break;
}
if (!buf)
return NULL;
buf->busy = true;
LISTEN(&buf->base.events.release, &buf->release, bufrelease);
wlr_buffer_lock(&buf->base);
drwl_setimage(m->drw, buf->image);
return buf;
}
void
bufrelease(struct wl_listener *listener, void *data)
{
Buffer *buf = wl_container_of(listener, buf, release);
buf->busy = false;
wl_list_remove(&buf->release.link);
}
void
buttonpress(struct wl_listener *listener, void *data)
{
unsigned int i = 0, x = 0;
double cx;
unsigned int click;
struct wlr_pointer_button_event *event = data;
struct wlr_keyboard *keyboard;
struct wlr_scene_node *node;
struct wlr_scene_buffer *buffer;
uint32_t mods;
Arg arg = {0};
Client *c;
const Button *b;
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
click = ClkRoot;
xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
if (c)
click = ClkClient;
switch (event->state) {
case WL_POINTER_BUTTON_STATE_PRESSED:
cursor_mode = CurPressed;
@ -669,17 +804,34 @@ buttonpress(struct wl_listener *listener, void *data)
if (locked)
break;
if (!c && !exclusive_focus &&
(node = wlr_scene_node_at(&layers[LyrBottom]->node, cursor->x, cursor->y, NULL, NULL)) &&
(buffer = wlr_scene_buffer_from_node(node)) && buffer == selmon->scene_buffer) {
cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale;
do
x += TEXTW(selmon, tags[i]);
while (cx >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
click = ClkTagBar;
arg.ui = 1 << i;
} else if (cx < x + TEXTW(selmon, selmon->ltsymbol))
click = ClkLtSymbol;
else if (cx > selmon->b.width - (TEXTW(selmon, stext) - selmon->lrpad + 2)) {
click = ClkStatus;
} else
click = ClkTitle;
}
/* Change focus if the button was _pressed_ over a client */
xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
if (click == ClkClient && (!client_is_unmanaged(c) || client_wants_focus(c)))
focusclient(c, 1);
keyboard = wlr_seat_get_keyboard(seat);
mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
for (b = buttons; b < END(buttons); b++) {
if (CLEANMASK(mods) == CLEANMASK(b->mod) &&
event->button == b->button && b->func) {
b->func(&b->arg);
if (CLEANMASK(mods) == CLEANMASK(b->mod) && event->button == b->button && click == b->click && b->func) {
b->func(click == ClkTagBar && b->arg.i == 0 ? &arg : &b->arg);
return;
}
}
@ -754,6 +906,8 @@ cleanup(void)
/* Destroy after the wayland display (when the monitors are already destroyed)
to avoid destroying them with an invalid scene output. */
wlr_scene_node_destroy(&scene->tree.node);
drwl_fini();
}
void
@ -773,6 +927,12 @@ cleanupmon(struct wl_listener *listener, void *data)
wlr_layer_surface_v1_destroy(l->layer_surface);
}
for (i = 0; i < LENGTH(m->pool); i++)
wlr_buffer_drop(&m->pool[i]->base);
drwl_setimage(m->drw, NULL);
drwl_destroy(m->drw);
wl_list_remove(&m->destroy.link);
wl_list_remove(&m->frame.link);
wl_list_remove(&m->link);
@ -785,6 +945,7 @@ cleanupmon(struct wl_listener *listener, void *data)
closemon(m);
wlr_scene_node_destroy(&m->fullscreen_bg->node);
wlr_scene_node_destroy(&m->scene_buffer->node);
free(m);
}
@ -851,7 +1012,7 @@ closemon(Monitor *m)
setmon(c, selmon, c->tags);
}
focusclient(focustop(selmon), 1);
printstatus();
drawbars();
}
void
@ -1105,7 +1266,7 @@ createmon(struct wl_listener *listener, void *data)
m->nmaster = r->nmaster;
m->lt[0] = r->lt;
m->lt[1] = &layouts[LENGTH(layouts) > 1 && r->lt != &layouts[1]];
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof(m->ltsymbol));
wlr_output_state_set_scale(&state, r->scale);
wlr_output_state_set_transform(&state, r->rr);
break;
@ -1127,8 +1288,15 @@ createmon(struct wl_listener *listener, void *data)
wlr_output_commit_state(wlr_output, &state);
wlr_output_state_finish(&state);
if (!(m->drw = drwl_create()))
die("failed to create drwl context");
m->scene_buffer = wlr_scene_buffer_create(layers[LyrBottom], NULL);
m->scene_buffer->point_accepts_input = baracceptsinput;
updatebar(m);
wl_list_insert(&mons, &m->link);
printstatus();
drawbars();
/* The xdg-protocol specifies:
*
@ -1467,7 +1635,7 @@ dwl_ipc_manager_bind(struct wl_client *client, void *data, uint32_t version, uin
}
wl_resource_set_implementation(manager_resource, &dwl_manager_implementation, NULL, dwl_ipc_manager_destroy);
zdwl_ipc_manager_v2_send_tags(manager_resource, TAGCOUNT);
zdwl_ipc_manager_v2_send_tags(manager_resource, LENGTH(tags));
for (unsigned int i = 0; i < LENGTH(layouts); i++)
zdwl_ipc_manager_v2_send_layout(manager_resource, layouts[i].symbol);
@ -1528,7 +1696,7 @@ dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output)
focused = focustop(monitor);
zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon);
for (tag = 0 ; tag < TAGCOUNT; tag++) {
for (tag = 0 ; tag < LENGTH(tags); tag++) {
numclients = state = focused_client = 0;
tagmask = 1 << tag;
if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
@ -1643,6 +1811,80 @@ dwl_ipc_output_release(struct wl_client *client, struct wl_resource *resource)
wl_resource_destroy(resource);
}
void
drawbar(Monitor *m)
{
int x, w, tw = 0;
int boxs = m->drw->font->height / 9;
int boxw = m->drw->font->height / 6 + 2;
uint32_t i, occ = 0, urg = 0;
Client *c;
Buffer *buf;
if (!m->scene_buffer->node.enabled)
return;
if (!(buf = bufmon(m)))
return;
/* draw status first so it can be overdrawn by tags later */
if (m == selmon) { /* status is only drawn on selected monitor */
drwl_setscheme(m->drw, colors[SchemeNorm]);
tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */
drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0);
}
wl_list_for_each(c, &clients, link) {
if (c->mon != m)
continue;
occ |= c->tags;
if (c->isurgent)
urg |= c->tags;
}
x = 0;
c = focustop(m);
for (i = 0; i < LENGTH(tags); i++) {
w = TEXTW(m, tags[i]);
drwl_setscheme(m->drw, colors[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, tags[i], urg & 1 << i);
if (occ & 1 << i)
drwl_rect(m->drw, x + boxs, boxs, boxw, boxw,
m == selmon && c && c->tags & 1 << i,
urg & 1 << i);
x += w;
}
w = TEXTW(m, m->ltsymbol);
drwl_setscheme(m->drw, colors[SchemeNorm]);
x = drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0);
if ((w = m->b.width - tw - x) > m->b.height) {
if (c) {
drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]);
drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, client_get_title(c), 0);
if (c && c->isfloating)
drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0);
} else {
drwl_setscheme(m->drw, colors[SchemeNorm]);
drwl_rect(m->drw, x, 0, w, m->b.height, 1, 1);
}
}
wlr_scene_buffer_set_dest_size(m->scene_buffer,
m->b.real_width, m->b.real_height);
wlr_scene_node_set_position(&m->scene_buffer->node, m->m.x,
m->m.y + (topbar ? 0 : m->m.height - m->b.real_height));
wlr_scene_buffer_set_buffer(m->scene_buffer, &buf->base);
wlr_buffer_unlock(&buf->base);
}
void
drawbars(void)
{
Monitor *m = NULL;
wl_list_for_each(m, &mons, link)
drawbar(m);
}
void
focusclient(Client *c, int lift)
{
@ -1681,7 +1923,7 @@ focusclient(Client *c, int lift)
/* Don't change border color if there is an exclusive focus or we are
* handling a drag operation */
if (!exclusive_focus && !seat->drag) {
client_set_border_color(c, focuscolor);
client_set_border_color(c, (float[])COLOR(colors[SchemeSel][ColBorder]));
client_set_dimmer_state(c, 0);
}
}
@ -1689,7 +1931,7 @@ focusclient(Client *c, int lift)
/* Deactivate old client if focus is changing */
if (old && (!c || client_surface(c) != old)) {
/* If an overlay is focused, don't focus or activate the client,
* but only update its position in fstack to render its border with focuscolor
* but only update its position in fstack to render its border with its color
* and focus it after the overlay is closed. */
if (old_client_type == LayerShell && wlr_scene_node_coords(
&old_l->scene->node, &unused_lx, &unused_ly)
@ -1700,12 +1942,12 @@ focusclient(Client *c, int lift)
/* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
* and probably other clients */
} else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
client_set_border_color(old_c, bordercolor);
client_set_border_color(old_c, (float[])COLOR(colors[SchemeNorm][ColBorder]));
client_set_dimmer_state(old_c, 1);
client_activate_surface(old, 0);
}
}
printstatus();
drawbars();
if (!c) {
/* With no client, all we have left is to clear focus */
@ -2028,7 +2270,7 @@ mapnotify(struct wl_listener *listener, void *data)
for (i = 0; i < 4; i++) {
c->border[i] = wlr_scene_rect_create(c->scene, 0, 0,
c->isurgent ? urgentcolor : bordercolor);
(float[])COLOR(colors[c->isurgent ? SchemeUrg : SchemeNorm][ColBorder]));
c->border[i]->node.data = c;
}
@ -2059,7 +2301,7 @@ mapnotify(struct wl_listener *listener, void *data)
client_set_dimmer_state(d, 0);
}
}
printstatus();
drawbars();
unset_fullscreen:
m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
@ -2352,7 +2594,7 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
}
void
static void
printstatus(void)
{
Monitor *m = NULL;
@ -2491,22 +2733,14 @@ run(char *startup_cmd)
/* Now that the socket exists and the backend is started, run the startup command */
if (startup_cmd) {
int piperw[2];
if (pipe(piperw) < 0)
die("startup: pipe:");
if ((child_pid = fork()) < 0)
die("startup: fork:");
if (child_pid == 0) {
close(STDIN_FILENO);
setsid();
dup2(piperw[0], STDIN_FILENO);
close(piperw[0]);
close(piperw[1]);
execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
die("startup: execl:");
}
dup2(piperw[1], STDOUT_FILENO);
close(piperw[1]);
close(piperw[0]);
}
/* Mark stdout as non-blocking to avoid the startup script
@ -2516,7 +2750,7 @@ run(char *startup_cmd)
if (fd_set_nonblock(STDOUT_FILENO) < 0)
close(STDOUT_FILENO);
printstatus();
drawbars();
/* At this point the outputs are initialized, choose initial selmon based on
* cursor position, and set default cursor image */
@ -2582,7 +2816,7 @@ setfloating(Client *c, int floating)
(p && p->isfullscreen) ? LyrFS
: c->isfloating ? LyrFloat : LyrTile]);
arrange(c->mon);
printstatus();
drawbars();
}
void
@ -2605,7 +2839,7 @@ setfullscreen(Client *c, int fullscreen)
resize(c, c->prev, 0);
}
arrange(c->mon);
printstatus();
drawbars();
}
void
@ -2617,9 +2851,9 @@ setlayout(const Arg *arg)
selmon->sellt ^= 1;
if (arg && arg->v)
selmon->lt[selmon->sellt] = (Layout *)arg->v;
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof(selmon->ltsymbol));
arrange(selmon);
printstatus();
drawbar(selmon);
}
/* arg > 1.0 will set mfact absolutely */
@ -2692,6 +2926,7 @@ setup(void)
for (i = 0; i < (int)LENGTH(sig); i++)
sigaction(sig[i], &sa, NULL);
wlr_log_init(log_level, NULL);
/* The Wayland display is managed by libwayland. It handles accepting
@ -2887,6 +3122,10 @@ setup(void)
wl_signal_add(&output_mgr->events.test, &output_mgr_test);
wl_global_create(dpy, &zdwl_ipc_manager_v2_interface, 2, NULL, dwl_ipc_manager_bind);
drwl_init();
status_event_source = wl_event_loop_add_fd(wl_display_get_event_loop(dpy),
STDIN_FILENO, WL_EVENT_READABLE, statusin, NULL);
/* Make sure XWayland clients don't connect to the parent X server,
* e.g when running in the x11 backend or the wayland backend and the
@ -2912,6 +3151,8 @@ void
spawn(const Arg *arg)
{
if (fork() == 0) {
close(STDIN_FILENO);
open("/dev/null", O_RDWR);
dup2(STDERR_FILENO, STDOUT_FILENO);
setsid();
execvp(((char **)arg->v)[0], (char **)arg->v);
@ -2930,6 +3171,30 @@ startdrag(struct wl_listener *listener, void *data)
LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon);
}
int
statusin(int fd, unsigned int mask, void *data)
{
char status[256];
ssize_t n;
if (mask & WL_EVENT_ERROR)
die("status in event error");
if (mask & WL_EVENT_HANGUP)
wl_event_source_remove(status_event_source);
n = read(fd, status, sizeof(status) - 1);
if (n < 0 && errno != EWOULDBLOCK)
die("read:");
status[n] = '\0';
status[strcspn(status, "\n")] = '\0';
strncpy(stext, status, sizeof(stext));
drawbars();
return 0;
}
void
tag(const Arg *arg)
{
@ -2940,7 +3205,7 @@ tag(const Arg *arg)
sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
arrange(selmon);
printstatus();
drawbars();
}
void
@ -3018,12 +3283,17 @@ toggledimmingclient(const Arg *arg)
if (sel)
sel -> neverdim ^= 1;
}
void
togglebar(const Arg *arg) {
togglebar(const Arg *arg)
{
DwlIpcOutput *ipc_output;
wl_list_for_each(ipc_output, &selmon->dwl_ipc_outputs, link)
zdwl_ipc_output_v2_send_toggle_visibility(ipc_output->resource);
wlr_scene_node_set_enabled(&selmon->scene_buffer->node,
!selmon->scene_buffer->node.enabled);
arrangelayers(selmon);
drawbars();
}
void
@ -3054,7 +3324,7 @@ toggletag(const Arg *arg)
sel->tags = newtags;
focusclient(focustop(selmon), 1);
arrange(selmon);
printstatus();
drawbars();
}
void
@ -3067,7 +3337,7 @@ toggleview(const Arg *arg)
selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1);
arrange(selmon);
printstatus();
drawbars();
}
void
@ -3115,7 +3385,7 @@ unmapnotify(struct wl_listener *listener, void *data)
}
wlr_scene_node_destroy(&c->scene->node);
printstatus();
drawbars();
motionnotify(0, NULL, 0, 0, 0, 0);
}
@ -3215,6 +3485,13 @@ updatemons(struct wl_listener *listener, void *data)
}
}
if (stext[0] == '\0')
strncpy(stext, "dwl-"VERSION, sizeof(stext));
wl_list_for_each(m, &mons, link) {
updatebar(m);
drawbar(m);
}
/* FIXME: figure out why the cursor image is at 0,0 after turning all
* the monitors on.
* Move the cursor image where it used to be. It does not generate a
@ -3225,12 +3502,45 @@ updatemons(struct wl_listener *listener, void *data)
wlr_output_manager_v1_set_configuration(output_mgr, config);
}
void
updatebar(Monitor *m)
{
size_t i;
int rw, rh;
char fontattrs[12];
wlr_output_transformed_resolution(m->wlr_output, &rw, &rh);
m->b.width = rw;
m->b.real_width = (int)((float)m->b.width / m->wlr_output->scale);
wlr_scene_node_set_enabled(&m->scene_buffer->node, m->wlr_output->enabled ? showbar : 0);
for (i = 0; i < LENGTH(m->pool); i++)
if (m->pool[i]) {
wlr_buffer_drop(&m->pool[i]->base);
m->pool[i] = NULL;
}
if (m->b.scale == m->wlr_output->scale && m->drw)
return;
drwl_font_destroy(m->drw->font);
snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * m->wlr_output->scale);
if (!(drwl_font_create(m->drw, LENGTH(fonts), fonts, fontattrs)))
die("Could not load font");
m->b.scale = m->wlr_output->scale;
m->lrpad = m->drw->font->height;
m->b.height = m->drw->font->height + 2;
m->b.real_height = (int)((float)m->b.height / m->wlr_output->scale);
}
void
updatetitle(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, set_title);
if (c == focustop(c->mon))
printstatus();
drawbars();
}
void
@ -3243,10 +3553,10 @@ urgent(struct wl_listener *listener, void *data)
return;
c->isurgent = 1;
printstatus();
drawbars();
if (client_surface(c)->mapped)
client_set_border_color(c, urgentcolor);
client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
}
void
@ -3259,7 +3569,7 @@ view(const Arg *arg)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
arrange(selmon);
printstatus();
drawbars();
}
void
@ -3321,6 +3631,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
{
struct wlr_scene_node *node, *pnode;
struct wlr_surface *surface = NULL;
struct wlr_scene_surface *scene_surface = NULL;
Client *c = NULL;
LayerSurface *l = NULL;
int layer;
@ -3329,9 +3640,12 @@ xytonode(double x, double y, struct wlr_surface **psurface,
if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
continue;
if (node->type == WLR_SCENE_NODE_BUFFER)
surface = wlr_scene_surface_try_from_buffer(
wlr_scene_buffer_from_node(node))->surface;
if (node->type == WLR_SCENE_NODE_BUFFER) {
scene_surface = wlr_scene_surface_try_from_buffer(
wlr_scene_buffer_from_node(node));
if (!scene_surface) continue;
surface = scene_surface->surface;
}
/* Walk the tree to find a node that knows the client */
for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
c = pnode->data;
@ -3464,10 +3778,10 @@ sethints(struct wl_listener *listener, void *data)
return;
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
printstatus();
drawbars();
if (c->isurgent && surface && surface->mapped)
client_set_border_color(c, urgentcolor);
client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
}
void