2 Commits

Author SHA1 Message Date
9f6f4b65f8 added inputdevicerules patch and branch 2025-04-08 02:46:10 +02:00
96b753c3e5 added inputdevicerules patch and branch 2025-04-08 02:46:04 +02:00
5 changed files with 255 additions and 118 deletions

View File

@@ -94,12 +94,9 @@ client_activate_surface(struct wlr_surface *s, int activated)
{
struct wlr_xdg_toplevel *toplevel;
#ifdef XWAYLAND
struct wlr_xwayland_surface *surface;
if ((surface = wlr_xwayland_surface_try_from_wlr_surface(s))) {
if (activated && surface->minimized)
wlr_xwayland_surface_set_minimized(surface, false);
wlr_xwayland_surface_activate(surface, activated);
struct wlr_xwayland_surface *xsurface;
if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(s))) {
wlr_xwayland_surface_activate(xsurface, activated);
return;
}
#endif

View File

@@ -60,6 +60,18 @@ static const struct xkb_rule_names xkb_rules = {
.options = NULL,
};
/* input devices */
static const InputRule inputrules[] = {
/* name kbcreate ptrcreate */
/* ignore bad device - like a touchpad ;) */
{ "BAD DEVICE", NULL, NULL },
/* ungroup ydotool device - fixes a bug */
{ "ydotoold virtual device", createungroupedkeyboard, createpointer },
/* put your touchpad name here to enable toggle touchpad */
{ "Elan Touchpad", createkeyboard, createtogglepointer },
{ NULL, createkeyboard, createpointer },
};
static const int repeat_rate = 25;
static const int repeat_delay = 600;
@@ -142,6 +154,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_space, setlayout, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },
{ MODKEY, XKB_KEY_u, togglepointer, {0} },
{ MODKEY, XKB_KEY_0, view, {.ui = ~0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} },
{ MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} },

87
dwl.c
View File

@@ -131,7 +131,6 @@ typedef struct {
#ifdef XWAYLAND
struct wl_listener activate;
struct wl_listener associate;
struct wl_listener minimize;
struct wl_listener dissociate;
struct wl_listener configure;
struct wl_listener set_hints;
@@ -142,6 +141,12 @@ typedef struct {
uint32_t resize; /* configure serial of a pending resize */
} Client;
typedef struct {
const char *name;
void (*kbcreate)(struct wlr_keyboard *);
void (*ptrcreate)(struct wlr_pointer *);
} InputRule;
typedef struct {
uint32_t mod;
xkb_keysym_t keysym;
@@ -269,6 +274,8 @@ static void createnotify(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_pointer *pointer);
static void createpointerconstraint(struct wl_listener *listener, void *data);
static void createpopup(struct wl_listener *listener, void *data);
static void createtogglepointer(struct wlr_pointer *pointer);
static void createungroupedkeyboard(struct wlr_keyboard *keyboard);
static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void cursorframe(struct wl_listener *listener, void *data);
static void cursorwarptohint(void);
@@ -337,6 +344,7 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
static void togglepointer(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
@@ -437,13 +445,14 @@ static struct wl_listener request_start_drag = {.notify = requeststartdrag};
static struct wl_listener start_drag = {.notify = startdrag};
static struct wl_listener new_session_lock = {.notify = locksession};
static struct libinput_device *togglepointerdevice = NULL;
#ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data);
static void associatex11(struct wl_listener *listener, void *data);
static void configurex11(struct wl_listener *listener, void *data);
static void createnotifyx11(struct wl_listener *listener, void *data);
static void dissociatex11(struct wl_listener *listener, void *data);
static void minimizenotify(struct wl_listener *listener, void *data);
static void sethints(struct wl_listener *listener, void *data);
static void xwaylandready(struct wl_listener *listener, void *data);
static struct wl_listener new_xwayland_surface = {.notify = createnotifyx11};
@@ -1198,6 +1207,33 @@ createpopup(struct wl_listener *listener, void *data)
LISTEN_STATIC(&popup->base->surface->events.commit, commitpopup);
}
void
createtogglepointer(struct wlr_pointer *pointer)
{
struct libinput_device *device;
createpointer(pointer);
if (wlr_input_device_is_libinput(&pointer->base)
&& (device = wlr_libinput_get_device_handle(&pointer->base))) {
togglepointerdevice = device;
}
}
void
createungroupedkeyboard(struct wlr_keyboard *keyboard)
{
/* for keyboards that need their own keyboard group */
KeyboardGroup *group = createkeyboardgroup();
/* Set the keymap to match the group keymap */
wlr_keyboard_set_keymap(keyboard, group->wlr_group->keyboard.keymap);
LISTEN(&keyboard->base.events.destroy, &group->destroy, destroykeyboardgroup);
/* Add the new keyboard to the group */
wlr_keyboard_group_add_keyboard(group->wlr_group, keyboard);
}
void
cursorconstrain(struct wlr_pointer_constraint_v1 *constraint)
{
@@ -1336,7 +1372,6 @@ destroynotify(struct wl_listener *listener, void *data)
wl_list_remove(&c->activate.link);
wl_list_remove(&c->associate.link);
wl_list_remove(&c->configure.link);
wl_list_remove(&c->minimize.link);
wl_list_remove(&c->dissociate.link);
wl_list_remove(&c->set_hints.link);
} else
@@ -1582,13 +1617,27 @@ inputdevice(struct wl_listener *listener, void *data)
* available. */
struct wlr_input_device *device = data;
uint32_t caps;
const InputRule *r;
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
createkeyboard(wlr_keyboard_from_input_device(device));
for (r = inputrules; r < END(inputrules); r++) {
if (!r->name || strstr(device->name, r->name)) {
if (r->kbcreate)
r->kbcreate(wlr_keyboard_from_input_device(device));
break;
}
}
break;
case WLR_INPUT_DEVICE_POINTER:
createpointer(wlr_pointer_from_input_device(device));
for (r = inputrules; r < END(inputrules); r++) {
if (!r->name || strstr(device->name, r->name)) {
if (r->ptrcreate)
r->ptrcreate(wlr_pointer_from_input_device(device));
break;
}
}
break;
default:
/* TODO handle other input device types */
@@ -2758,6 +2807,18 @@ togglefullscreen(const Arg *arg)
setfullscreen(sel, !sel->isfullscreen);
}
void
togglepointer(const Arg *arg)
{
if (!togglepointerdevice)
return;
libinput_device_config_send_events_set_mode(
togglepointerdevice,
libinput_device_config_send_events_get_mode(togglepointerdevice) ^ LIBINPUT_CONFIG_SEND_EVENTS_DISABLED
);
}
void
toggletag(const Arg *arg)
{
@@ -3135,7 +3196,6 @@ createnotifyx11(struct wl_listener *listener, void *data)
LISTEN(&xsurface->events.destroy, &c->destroy, destroynotify);
LISTEN(&xsurface->events.dissociate, &c->dissociate, dissociatex11);
LISTEN(&xsurface->events.request_activate, &c->activate, activatex11);
LISTEN(&xsurface->events.request_minimize, &c->minimize, minimizenotify);
LISTEN(&xsurface->events.request_configure, &c->configure, configurex11);
LISTEN(&xsurface->events.request_fullscreen, &c->fullscreen, fullscreennotify);
LISTEN(&xsurface->events.set_hints, &c->set_hints, sethints);
@@ -3150,21 +3210,6 @@ dissociatex11(struct wl_listener *listener, void *data)
wl_list_remove(&c->unmap.link);
}
void
minimizenotify(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, minimize);
struct wlr_xwayland_surface *xsurface = c->surface.xwayland;
struct wlr_xwayland_minimize_event *e = data;
int focused;
if (xsurface->surface == NULL || !xsurface->surface->mapped)
return;
focused = seat->keyboard_state.focused_surface == xsurface->surface;
wlr_xwayland_surface_set_minimized(xsurface, !focused && e->minimize);
}
void
sethints(struct wl_listener *listener, void *data)
{

173
inputdevicerules-v0.7.patch Normal file
View File

@@ -0,0 +1,173 @@
From 89f870a04f903681b0a7a0ac4eb1ae70c4984b46 Mon Sep 17 00:00:00 2001
From: Ben Collerson <benc@benc.cc>
Date: Sat, 15 Jun 2024 12:34:01 +1000
Subject: [PATCH] input device rules
* customise input device handling
* ignore unwanted input devices
* configure a toggle for an input device
---
config.def.h | 13 ++++++++++
dwl.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 79 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
index 22d2171d..0b287ab5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -60,6 +60,18 @@ static const struct xkb_rule_names xkb_rules = {
.options = NULL,
};
+/* input devices */
+static const InputRule inputrules[] = {
+ /* name kbcreate ptrcreate */
+ /* ignore bad device - like a touchpad ;) */
+ { "BAD DEVICE", NULL, NULL },
+ /* ungroup ydotool device - fixes a bug */
+ { "ydotoold virtual device", createungroupedkeyboard, createpointer },
+ /* put your touchpad name here to enable toggle touchpad */
+ { "Elan Touchpad", createkeyboard, createtogglepointer },
+ { NULL, createkeyboard, createpointer },
+};
+
static const int repeat_rate = 25;
static const int repeat_delay = 600;
@@ -142,6 +154,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_space, setlayout, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },
+ { MODKEY, XKB_KEY_u, togglepointer, {0} },
{ MODKEY, XKB_KEY_0, view, {.ui = ~0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} },
{ MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} },
diff --git a/dwl.c b/dwl.c
index a2711f67..f6f91938 100644
--- a/dwl.c
+++ b/dwl.c
@@ -143,6 +143,12 @@ typedef struct {
uint32_t resize; /* configure serial of a pending resize */
} Client;
+typedef struct {
+ const char *name;
+ void (*kbcreate)(struct wlr_keyboard *);
+ void (*ptrcreate)(struct wlr_pointer *);
+} InputRule;
+
typedef struct {
uint32_t mod;
xkb_keysym_t keysym;
@@ -270,6 +276,8 @@ static void createnotify(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_pointer *pointer);
static void createpointerconstraint(struct wl_listener *listener, void *data);
static void createpopup(struct wl_listener *listener, void *data);
+static void createtogglepointer(struct wlr_pointer *pointer);
+static void createungroupedkeyboard(struct wlr_keyboard *keyboard);
static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void cursorframe(struct wl_listener *listener, void *data);
static void cursorwarptohint(void);
@@ -340,6 +348,7 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
+static void togglepointer(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
@@ -413,6 +422,8 @@ static struct wlr_box sgeom;
static struct wl_list mons;
static Monitor *selmon;
+static struct libinput_device *togglepointerdevice = NULL;
+
#ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data);
static void associatex11(struct wl_listener *listener, void *data);
@@ -1133,6 +1144,33 @@ createpopup(struct wl_listener *listener, void *data)
LISTEN_STATIC(&popup->base->surface->events.commit, commitpopup);
}
+void
+createtogglepointer(struct wlr_pointer *pointer)
+{
+ struct libinput_device *device;
+
+ createpointer(pointer);
+
+ if (wlr_input_device_is_libinput(&pointer->base)
+ && (device = wlr_libinput_get_device_handle(&pointer->base))) {
+ togglepointerdevice = device;
+ }
+}
+
+void
+createungroupedkeyboard(struct wlr_keyboard *keyboard)
+{
+ /* for keyboards that need their own keyboard group */
+ KeyboardGroup *group = createkeyboardgroup();
+
+ /* Set the keymap to match the group keymap */
+ wlr_keyboard_set_keymap(keyboard, group->wlr_group->keyboard.keymap);
+ LISTEN(&keyboard->base.events.destroy, &group->destroy, destroykeyboardgroup);
+
+ /* Add the new keyboard to the group */
+ wlr_keyboard_group_add_keyboard(group->wlr_group, keyboard);
+}
+
void
cursorconstrain(struct wlr_pointer_constraint_v1 *constraint)
{
@@ -1531,13 +1569,27 @@ inputdevice(struct wl_listener *listener, void *data)
* available. */
struct wlr_input_device *device = data;
uint32_t caps;
+ const InputRule *r;
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
- createkeyboard(wlr_keyboard_from_input_device(device));
+ for (r = inputrules; r < END(inputrules); r++) {
+ if (!r->name || strstr(device->name, r->name)) {
+ if (r->kbcreate)
+ r->kbcreate(wlr_keyboard_from_input_device(device));
+ break;
+ }
+ }
+
break;
case WLR_INPUT_DEVICE_POINTER:
- createpointer(wlr_pointer_from_input_device(device));
+ for (r = inputrules; r < END(inputrules); r++) {
+ if (!r->name || strstr(device->name, r->name)) {
+ if (r->ptrcreate)
+ r->ptrcreate(wlr_pointer_from_input_device(device));
+ break;
+ }
+ }
break;
default:
/* TODO handle other input device types */
@@ -2739,6 +2791,18 @@ togglefullscreen(const Arg *arg)
setfullscreen(sel, !sel->isfullscreen);
}
+void
+togglepointer(const Arg *arg)
+{
+ if (!togglepointerdevice)
+ return;
+
+ libinput_device_config_send_events_set_mode(
+ togglepointerdevice,
+ libinput_device_config_send_events_get_mode(togglepointerdevice) ^ LIBINPUT_CONFIG_SEND_EVENTS_DISABLED
+ );
+}
+
void
toggletag(const Arg *arg)
{
--
2.45.2

View File

@@ -1,91 +0,0 @@
From 7277f668f19f5a7fcfbbc96e80cb2829487848ca Mon Sep 17 00:00:00 2001
From: korei999 <ju7t1xe@gmail.com>
Date: Mon, 1 Apr 2024 15:13:11 +0300
Subject: [PATCH] handle minimize request for xwayland clients
---
client.h | 9 ++++++---
dwl.c | 19 +++++++++++++++++++
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/client.h b/client.h
index 800b867..c46cfb2 100644
--- a/client.h
+++ b/client.h
@@ -94,9 +94,12 @@ client_activate_surface(struct wlr_surface *s, int activated)
{
struct wlr_xdg_toplevel *toplevel;
#ifdef XWAYLAND
- struct wlr_xwayland_surface *xsurface;
- if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(s))) {
- wlr_xwayland_surface_activate(xsurface, activated);
+ struct wlr_xwayland_surface *surface;
+ if ((surface = wlr_xwayland_surface_try_from_wlr_surface(s))) {
+ if (activated && surface->minimized)
+ wlr_xwayland_surface_set_minimized(surface, false);
+
+ wlr_xwayland_surface_activate(surface, activated);
return;
}
#endif
diff --git a/dwl.c b/dwl.c
index 39ce68c..b49f57b 100644
--- a/dwl.c
+++ b/dwl.c
@@ -131,6 +131,7 @@ typedef struct {
#ifdef XWAYLAND
struct wl_listener activate;
struct wl_listener associate;
+ struct wl_listener minimize;
struct wl_listener dissociate;
struct wl_listener configure;
struct wl_listener set_hints;
@@ -412,6 +413,7 @@ static void configurex11(struct wl_listener *listener, void *data);
static void createnotifyx11(struct wl_listener *listener, void *data);
static void dissociatex11(struct wl_listener *listener, void *data);
static xcb_atom_t getatom(xcb_connection_t *xc, const char *name);
+static void minimizenotify(struct wl_listener *listener, void *data);
static void sethints(struct wl_listener *listener, void *data);
static void xwaylandready(struct wl_listener *listener, void *data);
static struct wlr_xwayland *xwayland;
@@ -1177,6 +1179,7 @@ destroynotify(struct wl_listener *listener, void *data)
wl_list_remove(&c->activate.link);
wl_list_remove(&c->associate.link);
wl_list_remove(&c->configure.link);
+ wl_list_remove(&c->minimize.link);
wl_list_remove(&c->dissociate.link);
wl_list_remove(&c->set_hints.link);
} else
@@ -2984,6 +2987,7 @@ createnotifyx11(struct wl_listener *listener, void *data)
LISTEN(&xsurface->events.destroy, &c->destroy, destroynotify);
LISTEN(&xsurface->events.dissociate, &c->dissociate, dissociatex11);
LISTEN(&xsurface->events.request_activate, &c->activate, activatex11);
+ LISTEN(&xsurface->events.request_minimize, &c->minimize, minimizenotify);
LISTEN(&xsurface->events.request_configure, &c->configure, configurex11);
LISTEN(&xsurface->events.request_fullscreen, &c->fullscreen, fullscreennotify);
LISTEN(&xsurface->events.set_hints, &c->set_hints, sethints);
@@ -3011,6 +3015,21 @@ getatom(xcb_connection_t *xc, const char *name)
return atom;
}
+void
+minimizenotify(struct wl_listener *listener, void *data)
+{
+ Client *c = wl_container_of(listener, c, minimize);
+ struct wlr_xwayland_surface *xsurface = c->surface.xwayland;
+ struct wlr_xwayland_minimize_event *e = data;
+ int focused;
+
+ if (xsurface->surface == NULL || !xsurface->surface->mapped)
+ return;
+
+ focused = seat->keyboard_state.focused_surface == xsurface->surface;
+ wlr_xwayland_surface_set_minimized(xsurface, !focused && e->minimize);
+}
+
void
sethints(struct wl_listener *listener, void *data)
{
--
2.44.0