From f7d6a34cd98e3c090956c8a263a44972c3ffa05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Wed, 28 Sep 2022 00:54:48 -0500 Subject: [PATCH 1/5] use sigaction(2) for signal handling References: http://git.suckless.org/dwm/commit/712d6639ff8e863560328131bbb92b248dc9cde7.html --- dwl.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/dwl.c b/dwl.c index 19bb6ce..c2273ba 100644 --- a/dwl.c +++ b/dwl.c @@ -1885,6 +1885,8 @@ run(char *startup_cmd) { /* Add a Unix socket to the Wayland display. */ const char *socket = wl_display_add_socket_auto(dpy); + struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = SIG_IGN}; + sigemptyset(&sa.sa_mask); if (!socket) die("startup: display_add_socket_auto"); setenv("WAYLAND_DISPLAY", socket, 1); @@ -1913,7 +1915,7 @@ run(char *startup_cmd) close(piperw[0]); } /* If nobody is reading the status output, don't terminate */ - signal(SIGPIPE, SIG_IGN); + sigaction(SIGPIPE, &sa, NULL); printstatus(); /* At this point the outputs are initialized, choose initial selmon based on @@ -2066,18 +2068,26 @@ setsel(struct wl_listener *listener, void *data) void setup(void) { + struct sigaction sa_term = {.sa_flags = SA_RESTART, .sa_handler = quitsignal}; + struct sigaction sa_sigchld = { +#ifdef XWAYLAND + .sa_flags = SA_RESTART, + .sa_handler = sigchld, +#else + .sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART, + .sa_handler = SIG_IGN, +#endif + }; + sigemptyset(&sa_term.sa_mask); + sigemptyset(&sa_sigchld.sa_mask); /* The Wayland display is managed by libwayland. It handles accepting * clients from the Unix socket, manging Wayland globals, and so on. */ dpy = wl_display_create(); /* Set up signal handlers */ -#ifdef XWAYLAND - sigchld(0); -#else - signal(SIGCHLD, SIG_IGN); -#endif - signal(SIGINT, quitsignal); - signal(SIGTERM, quitsignal); + sigaction(SIGCHLD, &sa_sigchld, NULL); + sigaction(SIGINT, &sa_term, NULL); + sigaction(SIGTERM, &sa_term, NULL); /* The backend is a wlroots feature which abstracts the underlying input and * output hardware. The autocreate option will choose the most suitable @@ -2699,12 +2709,11 @@ sigchld(int unused) { siginfo_t in; /* We should be able to remove this function in favor of a simple - * signal(SIGCHLD, SIG_IGN); + * struct sigaction sa = {.sa_handler = SIG_IGN}; + * sigaction(SIGCHLD, &sa, NULL); * but the Xwayland implementation in wlroots currently prevents us from * setting our own disposition for SIGCHLD. */ - if (signal(SIGCHLD, sigchld) == SIG_ERR) - die("can't install SIGCHLD handler:"); /* WNOWAIT leaves the child in a waitable state, in case this is the * XWayland process */ From 23ede80f741d8452dbf223226974476ef8860541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Thu, 8 Sep 2022 12:24:13 -0500 Subject: [PATCH 2/5] allow configure x and y of outputs --- config.def.h | 6 +++--- dwl.c | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config.def.h b/config.def.h index a4f7c13..419e6ef 100644 --- a/config.def.h +++ b/config.def.h @@ -29,12 +29,12 @@ static const Layout layouts[] = { /* monitors */ static const MonitorRule monrules[] = { - /* name mfact nmaster scale layout rotate/reflect */ + /* name mfact nmaster scale layout rotate/reflect x y */ /* example of a HiDPI laptop monitor: - { "eDP-1", 0.5, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL }, + { "eDP-1", 0.5, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL -1, -1 }, */ /* defaults */ - { NULL, 0.55, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL }, + { NULL, 0.55, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, }; /* keyboard */ diff --git a/dwl.c b/dwl.c index c2273ba..57870fe 100644 --- a/dwl.c +++ b/dwl.c @@ -194,6 +194,7 @@ typedef struct { float scale; const Layout *lt; enum wl_output_transform rr; + int x, y; } MonitorRule; typedef struct { @@ -908,6 +909,8 @@ createmon(struct wl_listener *listener, void *data) wlr_xcursor_manager_load(cursor_mgr, r->scale); m->lt[0] = m->lt[1] = r->lt; wlr_output_set_transform(wlr_output, r->rr); + m->m.x = r->x; + m->m.y = r->y; break; } } @@ -953,7 +956,10 @@ createmon(struct wl_listener *listener, void *data) * output (such as DPI, scale factor, manufacturer, etc). */ m->scene_output = wlr_scene_output_create(scene, wlr_output); - wlr_output_layout_add_auto(output_layout, wlr_output); + if (m->m.x < 0 || m->m.y < 0) + wlr_output_layout_add_auto(output_layout, wlr_output); + else + wlr_output_layout_add(output_layout, wlr_output, m->m.x, m->m.y); } void From ab8334bd8a85c5c63a2d06bc68bf0b5f5e1c2923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Mon, 26 Dec 2022 16:45:38 -0600 Subject: [PATCH 3/5] implement repeatable keybindings --- dwl.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/dwl.c b/dwl.c index 57870fe..ac741d2 100644 --- a/dwl.c +++ b/dwl.c @@ -139,6 +139,11 @@ typedef struct { struct wl_list link; struct wlr_keyboard *wlr_keyboard; + int nsyms; + const xkb_keysym_t *keysyms; /* invalid if nsyms == 0 */ + uint32_t mods; /* invalid if nsyms == 0 */ + struct wl_event_source *key_repeat_source; + struct wl_listener modifiers; struct wl_listener key; struct wl_listener destroy; @@ -259,6 +264,7 @@ static void inputdevice(struct wl_listener *listener, void *data); static int keybinding(uint32_t mods, xkb_keysym_t sym); static void keypress(struct wl_listener *listener, void *data); static void keypressmod(struct wl_listener *listener, void *data); +static int keyrepeat(void *data); static void killclient(const Arg *arg); static void locksession(struct wl_listener *listener, void *data); static void maplayersurfacenotify(struct wl_listener *listener, void *data); @@ -667,6 +673,7 @@ cleanupkeyboard(struct wl_listener *listener, void *data) { Keyboard *kb = wl_container_of(listener, kb, destroy); + wl_event_source_remove(kb->key_repeat_source); wl_list_remove(&kb->link); wl_list_remove(&kb->modifiers.link); wl_list_remove(&kb->key.link); @@ -812,6 +819,9 @@ createkeyboard(struct wlr_keyboard *keyboard) wlr_seat_set_keyboard(seat, keyboard); + kb->key_repeat_source = wl_event_loop_add_timer( + wl_display_get_event_loop(dpy), keyrepeat, kb); + /* And add the keyboard to our list of keyboards */ wl_list_insert(&keyboards, &kb->link); } @@ -1400,6 +1410,17 @@ keypress(struct wl_listener *listener, void *data) for (i = 0; i < nsyms; i++) handled = keybinding(mods, syms[i]) || handled; + if (handled && kb->wlr_keyboard->repeat_info.delay > 0) { + kb->mods = mods; + kb->keysyms = syms; + kb->nsyms = nsyms; + wl_event_source_timer_update(kb->key_repeat_source, + kb->wlr_keyboard->repeat_info.delay); + } else { + kb->nsyms = 0; + wl_event_source_timer_update(kb->key_repeat_source, 0); + } + if (!handled) { /* Pass unhandled keycodes along to the client. */ wlr_seat_set_keyboard(seat, kb->wlr_keyboard); @@ -1426,6 +1447,22 @@ keypressmod(struct wl_listener *listener, void *data) &kb->wlr_keyboard->modifiers); } +int +keyrepeat(void *data) +{ + Keyboard *kb = data; + int i; + if (kb->nsyms && kb->wlr_keyboard->repeat_info.rate > 0) { + wl_event_source_timer_update(kb->key_repeat_source, + 1000 / kb->wlr_keyboard->repeat_info.rate); + + for (i = 0; i < kb->nsyms; i++) + keybinding(kb->mods, kb->keysyms[i]); + } + + return 0; +} + void killclient(const Arg *arg) { From 7f9a21247613a0d8ba6575869220e29071a40c64 Mon Sep 17 00:00:00 2001 From: Ben Collerson Date: Wed, 23 Nov 2022 21:55:04 +1000 Subject: [PATCH 4/5] Add appid field to printstatus() output Adds an appid field to printstatus which can be used to monitor the currently active application. --- dwl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index ac741d2..efd6977 100644 --- a/dwl.c +++ b/dwl.c @@ -1823,6 +1823,7 @@ printstatus(void) Monitor *m = NULL; Client *c; unsigned int occ, urg, sel; + const char *appid, *title; wl_list_for_each(m, &mons, link) { occ = urg = 0; @@ -1834,12 +1835,16 @@ printstatus(void) urg |= c->tags; } if ((c = focustop(m))) { - printf("%s title %s\n", m->wlr_output->name, client_get_title(c)); + title = client_get_title(c); + appid = client_get_appid(c); + printf("%s title %s\n", m->wlr_output->name, title ? title : broken); + printf("%s appid %s\n", m->wlr_output->name, appid ? appid : broken); printf("%s fullscreen %u\n", m->wlr_output->name, c->isfullscreen); printf("%s floating %u\n", m->wlr_output->name, c->isfloating); sel = c->tags; } else { printf("%s title \n", m->wlr_output->name); + printf("%s appid \n", m->wlr_output->name); printf("%s fullscreen \n", m->wlr_output->name); printf("%s floating \n", m->wlr_output->name); sel = 0; From f8373ccf2581fa481602bbb7528ba8871f6d5c85 Mon Sep 17 00:00:00 2001 From: pino-desktop Date: Sun, 8 Jan 2023 17:37:24 +0100 Subject: [PATCH 5/5] Fixed 'unused variable' compiler warning. --- dwl.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/dwl.c b/dwl.c index efd6977..27d051f 100644 --- a/dwl.c +++ b/dwl.c @@ -1526,7 +1526,6 @@ mapnotify(struct wl_listener *listener, void *data) } c->scene->node.data = c->scene_surface->node.data = c; -#ifdef XWAYLAND /* Handle unmanaged clients first so we can return prior create borders */ if (client_is_unmanaged(c)) { client_get_geometry(c, &c->geom); @@ -1540,7 +1539,6 @@ mapnotify(struct wl_listener *listener, void *data) } goto unset_fullscreen; } -#endif for (i = 0; i < 4; i++) { c->border[i] = wlr_scene_rect_create(c->scene, 0, 0, bordercolor);