apply keycodes patch

This commit is contained in:
korei999 2023-11-29 21:55:52 +02:00
parent 6adb5d7ae5
commit 1d60a3aece
2 changed files with 257 additions and 114 deletions

91
dwl.c
View file

@ -143,7 +143,7 @@ typedef struct {
typedef struct {
uint32_t mod;
xkb_keysym_t keysym;
xkb_keycode_t keycode;
void (*func)(const Arg *);
const Arg arg;
} Key;
@ -152,9 +152,8 @@ 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 */
xkb_keycode_t keycode;
uint32_t mods; /* invalid if keycode == 0 */
struct wl_event_source *key_repeat_source;
struct wl_listener modifiers;
@ -243,6 +242,7 @@ static void arrange(Monitor *m);
static void arrangelayer(Monitor *m, struct wl_list *list,
struct wlr_box *usable_area, int exclusive);
static void arrangelayers(Monitor *m);
static void autostartexec(void);
static void axisnotify(struct wl_listener *listener, void *data);
static void buttonpress(struct wl_listener *listener, void *data);
static void chvt(const Arg *arg);
@ -290,7 +290,7 @@ static void fullscreennotify(struct wl_listener *listener, void *data);
static void handlesig(int signo);
static void incnmaster(const Arg *arg);
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_keycode_t keycode);
static void keypress(struct wl_listener *listener, void *data);
static void keypressmod(struct wl_listener *listener, void *data);
static int keyrepeat(void *data);
@ -427,6 +427,9 @@ static xcb_atom_t netatom[NetLast];
/* attempt to encapsulate suck into one file */
#include "client.h"
static pid_t *autostart_pids;
static size_t autostart_len;
/* function implementations */
void
applybounds(Client *c, struct wlr_box *bbox)
@ -557,6 +560,27 @@ arrangelayers(Monitor *m)
}
}
void
autostartexec(void) {
const char *const *p;
size_t i = 0;
/* count entries */
for (p = autostart; *p; autostart_len++, p++)
while (*++p);
autostart_pids = calloc(autostart_len, sizeof(pid_t));
for (p = autostart; *p; i++, p++) {
if ((autostart_pids[i] = fork()) == 0) {
setsid();
execvp(*p, (char *const *)p);
die("dwl: execvp %s:", *p);
}
/* skip arguments */
while (*++p);
}
}
void
axisnotify(struct wl_listener *listener, void *data)
{
@ -652,10 +676,18 @@ checkidleinhibitor(struct wlr_surface *exclude)
void
cleanup(void)
{
size_t i;
#ifdef XWAYLAND
wlr_xwayland_destroy(xwayland);
xwayland = NULL;
#endif
/* kill child processes */
for (i = 0; i < autostart_len; i++) {
if (0 < autostart_pids[i]) {
kill(autostart_pids[i], SIGTERM);
waitpid(autostart_pids[i], NULL, 0);
}
wl_display_destroy_clients(dpy);
if (child_pid > 0) {
kill(child_pid, SIGTERM);
@ -664,6 +696,8 @@ cleanup(void)
wlr_xcursor_manager_destroy(cursor_mgr);
wlr_output_layout_destroy(output_layout);
wl_display_destroy(dpy);
}
/* 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);
@ -1526,18 +1560,31 @@ void
handlesig(int signo)
{
if (signo == SIGCHLD) {
#ifdef XWAYLAND
siginfo_t in;
/* wlroots expects to reap the XWayland process itself, so we
* use WNOWAIT to keep the child waitable until we know it's not
* XWayland.
*/
while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid
&& (!xwayland || in.si_pid != xwayland->server->pid))
waitpid(in.si_pid, NULL, 0);
#else
while (waitpid(-1, NULL, WNOHANG) > 0);
#ifdef XWAYLAND
&& (!xwayland || in.si_pid != xwayland->server->pid)
#endif
) {
pid_t *p, *lim;
waitpid(in.si_pid, NULL, 0);
if (in.si_pid == child_pid)
child_pid = -1;
if (!(p = autostart_pids))
continue;
lim = &p[autostart_len];
for (; p < lim; p++) {
if (*p == in.si_pid) {
*p = -1;
break;
}
}
}
} else if (signo == SIGINT || signo == SIGTERM) {
quit(NULL);
}
@ -1583,7 +1630,7 @@ inputdevice(struct wl_listener *listener, void *data)
}
int
keybinding(uint32_t mods, xkb_keysym_t sym)
keybinding(uint32_t mods, xkb_keycode_t keycode)
{
/*
* Here we handle compositor keybindings. This is when the compositor is
@ -1594,7 +1641,7 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
const Key *k;
for (k = keys; k < END(keys); k++) {
if (CLEANMASK(mods) == CLEANMASK(k->mod) &&
sym == k->keysym && k->func) {
keycode == k->keycode && k->func) {
k->func(&k->arg);
handled = 1;
}
@ -1605,17 +1652,12 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
void
keypress(struct wl_listener *listener, void *data)
{
int i;
/* This event is raised when a key is pressed or released. */
Keyboard *kb = wl_container_of(listener, kb, key);
struct wlr_keyboard_key_event *event = data;
/* Translate libinput keycode -> xkbcommon */
uint32_t keycode = event->keycode + 8;
/* Get a list of keysyms based on the keymap for this keyboard */
const xkb_keysym_t *syms;
int nsyms = xkb_state_key_get_syms(
kb->wlr_keyboard->xkb_state, keycode, &syms);
int handled = 0;
uint32_t mods = wlr_keyboard_get_modifiers(kb->wlr_keyboard);
@ -1625,17 +1667,15 @@ keypress(struct wl_listener *listener, void *data)
/* On _press_ if there is no active screen locker,
* attempt to process a compositor keybinding. */
if (!locked && event->state == WL_KEYBOARD_KEY_STATE_PRESSED)
for (i = 0; i < nsyms; i++)
handled = keybinding(mods, syms[i]) || handled;
handled = keybinding(mods, keycode);
if (handled && kb->wlr_keyboard->repeat_info.delay > 0) {
kb->mods = mods;
kb->keysyms = syms;
kb->nsyms = nsyms;
kb->keycode = keycode;
wl_event_source_timer_update(kb->key_repeat_source,
kb->wlr_keyboard->repeat_info.delay);
} else {
kb->nsyms = 0;
kb->keycode = 0;
wl_event_source_timer_update(kb->key_repeat_source, 0);
}
@ -1670,15 +1710,13 @@ int
keyrepeat(void *data)
{
Keyboard *kb = data;
int i;
if (!kb->nsyms || kb->wlr_keyboard->repeat_info.rate <= 0)
if (!kb->keycode || kb->wlr_keyboard->repeat_info.rate <= 0)
return 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]);
keybinding(kb->mods, kb->keycode);
return 0;
}
@ -2191,6 +2229,7 @@ run(char *startup_cmd)
die("startup: backend_start");
/* Now that the socket exists and the backend is started, run the startup command */
autostartexec();
if (startup_cmd) {
int piperw[2];
if (pipe(piperw) < 0)