mirror of
https://github.com/tiyn/dwl.git
synced 2026-01-11 17:39:45 +01:00
Compare commits
2 Commits
inputdevic
...
togglekbla
| Author | SHA1 | Date | |
|---|---|---|---|
| b5fd524813 | |||
| 50c418df96 |
30
config.def.h
30
config.def.h
@@ -52,24 +52,15 @@ static const MonitorRule monrules[] = {
|
||||
};
|
||||
|
||||
/* keyboard */
|
||||
static const struct xkb_rule_names xkb_rules = {
|
||||
/* can specify fields: rules, model, layout, variant, options */
|
||||
/* example:
|
||||
.options = "ctrl:nocaps",
|
||||
*/
|
||||
.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 struct xkb_rule_names xkb_rules[] = {
|
||||
{
|
||||
.layout = "us",
|
||||
},
|
||||
/*{
|
||||
.layout = "us",
|
||||
.variant = "dvp",
|
||||
.options = "compose:102,numpad:shift3,kpdl:semi,keypad:atm,caps:super"
|
||||
}*/
|
||||
};
|
||||
|
||||
static const int repeat_rate = 25;
|
||||
@@ -154,13 +145,14 @@ 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} },
|
||||
{ MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_A, incxkbrules, {.i = +1} },
|
||||
/*{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_E, setxkbrules, {.i = +1} },*/
|
||||
TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0),
|
||||
TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
|
||||
TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
|
||||
|
||||
112
dwl.c
112
dwl.c
@@ -141,12 +141,6 @@ 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;
|
||||
@@ -252,6 +246,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 assignkeymap(struct wlr_keyboard *keyboard);
|
||||
static void axisnotify(struct wl_listener *listener, void *data);
|
||||
static void buttonpress(struct wl_listener *listener, void *data);
|
||||
static void chvt(const Arg *arg);
|
||||
@@ -274,8 +269,6 @@ 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);
|
||||
@@ -298,6 +291,7 @@ static void fullscreennotify(struct wl_listener *listener, void *data);
|
||||
static void gpureset(struct wl_listener *listener, void *data);
|
||||
static void handlesig(int signo);
|
||||
static void incnmaster(const Arg *arg);
|
||||
static void incxkbrules(const Arg *arg);
|
||||
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);
|
||||
@@ -337,6 +331,7 @@ static void setmon(Client *c, Monitor *m, uint32_t newtags);
|
||||
static void setpsel(struct wl_listener *listener, void *data);
|
||||
static void setsel(struct wl_listener *listener, void *data);
|
||||
static void setup(void);
|
||||
static void setxkbrules(const Arg *arg);
|
||||
static void spawn(const Arg *arg);
|
||||
static void startdrag(struct wl_listener *listener, void *data);
|
||||
static void tag(const Arg *arg);
|
||||
@@ -344,7 +339,6 @@ 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);
|
||||
@@ -406,6 +400,7 @@ static struct wlr_session_lock_v1 *cur_lock;
|
||||
|
||||
static struct wlr_seat *seat;
|
||||
static KeyboardGroup *kb_group;
|
||||
static unsigned int kblayout = 0;
|
||||
static unsigned int cursor_mode;
|
||||
static Client *grabc;
|
||||
static int grabcx, grabcy; /* client-relative */
|
||||
@@ -445,8 +440,6 @@ 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);
|
||||
@@ -613,6 +606,20 @@ arrangelayers(Monitor *m)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
assignkeymap(struct wlr_keyboard *keyboard) {
|
||||
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, &xkb_rules[kblayout],
|
||||
XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
|
||||
if (!keymap)
|
||||
die("failed to compile keymap");
|
||||
|
||||
wlr_keyboard_set_keymap(keyboard, keymap);
|
||||
xkb_keymap_unref(keymap);
|
||||
xkb_context_unref(context);
|
||||
}
|
||||
|
||||
void
|
||||
axisnotify(struct wl_listener *listener, void *data)
|
||||
{
|
||||
@@ -959,21 +966,11 @@ KeyboardGroup *
|
||||
createkeyboardgroup(void)
|
||||
{
|
||||
KeyboardGroup *group = ecalloc(1, sizeof(*group));
|
||||
struct xkb_context *context;
|
||||
struct xkb_keymap *keymap;
|
||||
|
||||
group->wlr_group = wlr_keyboard_group_create();
|
||||
group->wlr_group->data = group;
|
||||
|
||||
/* Prepare an XKB keymap and assign it to the keyboard group. */
|
||||
context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
if (!(keymap = xkb_keymap_new_from_names(context, &xkb_rules,
|
||||
XKB_KEYMAP_COMPILE_NO_FLAGS)))
|
||||
die("failed to compile keymap");
|
||||
|
||||
wlr_keyboard_set_keymap(&group->wlr_group->keyboard, keymap);
|
||||
xkb_keymap_unref(keymap);
|
||||
xkb_context_unref(context);
|
||||
assignkeymap(&group->wlr_group->keyboard);
|
||||
|
||||
wlr_keyboard_set_repeat_info(&group->wlr_group->keyboard, repeat_rate, repeat_delay);
|
||||
|
||||
@@ -1207,33 +1204,6 @@ 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)
|
||||
{
|
||||
@@ -1610,6 +1580,13 @@ incnmaster(const Arg *arg)
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
incxkbrules(const Arg *arg)
|
||||
{
|
||||
kblayout = (kblayout + arg->i) % LENGTH(xkb_rules);
|
||||
assignkeymap(&kb_group->wlr_group->keyboard);
|
||||
}
|
||||
|
||||
void
|
||||
inputdevice(struct wl_listener *listener, void *data)
|
||||
{
|
||||
@@ -1617,27 +1594,13 @@ 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:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
createkeyboard(wlr_keyboard_from_input_device(device));
|
||||
break;
|
||||
case WLR_INPUT_DEVICE_POINTER:
|
||||
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;
|
||||
}
|
||||
}
|
||||
createpointer(wlr_pointer_from_input_device(device));
|
||||
break;
|
||||
default:
|
||||
/* TODO handle other input device types */
|
||||
@@ -2713,6 +2676,13 @@ setup(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
setxkbrules(const Arg *arg)
|
||||
{
|
||||
kblayout = arg->i;
|
||||
assignkeymap(&kb_group->wlr_group->keyboard);
|
||||
}
|
||||
|
||||
void
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
@@ -2807,18 +2777,6 @@ 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)
|
||||
{
|
||||
|
||||
@@ -1,173 +0,0 @@
|
||||
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
|
||||
|
||||
160
togglekblayoutandoptions.patch
Normal file
160
togglekblayoutandoptions.patch
Normal file
@@ -0,0 +1,160 @@
|
||||
From 9ee76adc7c6567650e7b34273f953fed03191c05 Mon Sep 17 00:00:00 2001
|
||||
From: LaKato <lakato@noreply.codeberg.org>
|
||||
Date: Sat, 8 Mar 2025 12:14:41 -0500
|
||||
Subject: [PATCH] Update for v0.7
|
||||
|
||||
Additional changes:
|
||||
- incxkbrules now uses its argument
|
||||
- A new setxkbrules function has been added
|
||||
- Keyboard groups are no longer looped over because only one is created
|
||||
---
|
||||
config.def.h | 17 +++++++++++------
|
||||
dwl.c | 44 +++++++++++++++++++++++++++++++++-----------
|
||||
2 files changed, 44 insertions(+), 17 deletions(-)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 22d2171..b3b4699 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -52,12 +52,15 @@ static const MonitorRule monrules[] = {
|
||||
};
|
||||
|
||||
/* keyboard */
|
||||
-static const struct xkb_rule_names xkb_rules = {
|
||||
- /* can specify fields: rules, model, layout, variant, options */
|
||||
- /* example:
|
||||
- .options = "ctrl:nocaps",
|
||||
- */
|
||||
- .options = NULL,
|
||||
+static const struct xkb_rule_names xkb_rules[] = {
|
||||
+ {
|
||||
+ .layout = "us",
|
||||
+ },
|
||||
+ /*{
|
||||
+ .layout = "us",
|
||||
+ .variant = "dvp",
|
||||
+ .options = "compose:102,numpad:shift3,kpdl:semi,keypad:atm,caps:super"
|
||||
+ }*/
|
||||
};
|
||||
|
||||
static const int repeat_rate = 25;
|
||||
@@ -148,6 +151,8 @@ static const Key keys[] = {
|
||||
{ MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} },
|
||||
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_A, incxkbrules, {.i = +1} },
|
||||
+ /*{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_E, setxkbrules, {.i = +1} },*/
|
||||
TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0),
|
||||
TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
|
||||
TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
|
||||
diff --git a/dwl.c b/dwl.c
|
||||
index a2711f6..a2413e9 100644
|
||||
--- a/dwl.c
|
||||
+++ b/dwl.c
|
||||
@@ -249,6 +249,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 assignkeymap(struct wlr_keyboard *keyboard);
|
||||
static void axisnotify(struct wl_listener *listener, void *data);
|
||||
static void buttonpress(struct wl_listener *listener, void *data);
|
||||
static void chvt(const Arg *arg);
|
||||
@@ -293,6 +294,7 @@ static void fullscreennotify(struct wl_listener *listener, void *data);
|
||||
static void gpureset(struct wl_listener *listener, void *data);
|
||||
static void handlesig(int signo);
|
||||
static void incnmaster(const Arg *arg);
|
||||
+static void incxkbrules(const Arg *arg);
|
||||
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);
|
||||
@@ -333,6 +335,7 @@ static void setmon(Client *c, Monitor *m, uint32_t newtags);
|
||||
static void setpsel(struct wl_listener *listener, void *data);
|
||||
static void setsel(struct wl_listener *listener, void *data);
|
||||
static void setup(void);
|
||||
+static void setxkbrules(const Arg *arg);
|
||||
static void spawn(const Arg *arg);
|
||||
static void startdrag(struct wl_listener *listener, void *data);
|
||||
static void tag(const Arg *arg);
|
||||
@@ -404,6 +407,7 @@ static struct wl_listener lock_listener = {.notify = locksession};
|
||||
|
||||
static struct wlr_seat *seat;
|
||||
static KeyboardGroup *kb_group;
|
||||
+static unsigned int kblayout = 0;
|
||||
static unsigned int cursor_mode;
|
||||
static Client *grabc;
|
||||
static int grabcx, grabcy; /* client-relative */
|
||||
@@ -580,6 +584,20 @@ arrangelayers(Monitor *m)
|
||||
}
|
||||
}
|
||||
|
||||
+void
|
||||
+assignkeymap(struct wlr_keyboard *keyboard) {
|
||||
+ struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
+ struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, &xkb_rules[kblayout],
|
||||
+ XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
+
|
||||
+ if (!keymap)
|
||||
+ die("failed to compile keymap");
|
||||
+
|
||||
+ wlr_keyboard_set_keymap(keyboard, keymap);
|
||||
+ xkb_keymap_unref(keymap);
|
||||
+ xkb_context_unref(context);
|
||||
+}
|
||||
+
|
||||
void
|
||||
axisnotify(struct wl_listener *listener, void *data)
|
||||
{
|
||||
@@ -885,21 +903,11 @@ KeyboardGroup *
|
||||
createkeyboardgroup(void)
|
||||
{
|
||||
KeyboardGroup *group = ecalloc(1, sizeof(*group));
|
||||
- struct xkb_context *context;
|
||||
- struct xkb_keymap *keymap;
|
||||
|
||||
group->wlr_group = wlr_keyboard_group_create();
|
||||
group->wlr_group->data = group;
|
||||
|
||||
- /* Prepare an XKB keymap and assign it to the keyboard group. */
|
||||
- context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
- if (!(keymap = xkb_keymap_new_from_names(context, &xkb_rules,
|
||||
- XKB_KEYMAP_COMPILE_NO_FLAGS)))
|
||||
- die("failed to compile keymap");
|
||||
-
|
||||
- wlr_keyboard_set_keymap(&group->wlr_group->keyboard, keymap);
|
||||
- xkb_keymap_unref(keymap);
|
||||
- xkb_context_unref(context);
|
||||
+ assignkeymap(&group->wlr_group->keyboard);
|
||||
|
||||
wlr_keyboard_set_repeat_info(&group->wlr_group->keyboard, repeat_rate, repeat_delay);
|
||||
|
||||
@@ -1524,6 +1532,13 @@ incnmaster(const Arg *arg)
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
+void
|
||||
+incxkbrules(const Arg *arg)
|
||||
+{
|
||||
+ kblayout = (kblayout + arg->i) % LENGTH(xkb_rules);
|
||||
+ assignkeymap(&kb_group->wlr_group->keyboard);
|
||||
+}
|
||||
+
|
||||
void
|
||||
inputdevice(struct wl_listener *listener, void *data)
|
||||
{
|
||||
@@ -2645,6 +2660,13 @@ setup(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
+void
|
||||
+setxkbrules(const Arg *arg)
|
||||
+{
|
||||
+ kblayout = arg->i;
|
||||
+ assignkeymap(&kb_group->wlr_group->keyboard);
|
||||
+}
|
||||
+
|
||||
void
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
--
|
||||
2.48.1
|
||||
|
||||
Reference in New Issue
Block a user