mirror of
https://github.com/tiyn/dwl.git
synced 2026-01-11 17:39:45 +01:00
Compare commits
3 Commits
warpcursor
...
en-keycode
| Author | SHA1 | Date | |
|---|---|---|---|
| ac3dbb1bba | |||
| 217ef375c9 | |||
| 5e17486ea9 |
50
dwl.c
50
dwl.c
@@ -347,7 +347,6 @@ static void urgent(struct wl_listener *listener, void *data);
|
|||||||
static void view(const Arg *arg);
|
static void view(const Arg *arg);
|
||||||
static void virtualkeyboard(struct wl_listener *listener, void *data);
|
static void virtualkeyboard(struct wl_listener *listener, void *data);
|
||||||
static void virtualpointer(struct wl_listener *listener, void *data);
|
static void virtualpointer(struct wl_listener *listener, void *data);
|
||||||
static void warpcursor(const Client *c);
|
|
||||||
static Monitor *xytomon(double x, double y);
|
static Monitor *xytomon(double x, double y);
|
||||||
static void xytonode(double x, double y, struct wlr_surface **psurface,
|
static void xytonode(double x, double y, struct wlr_surface **psurface,
|
||||||
Client **pc, LayerSurface **pl, double *nx, double *ny);
|
Client **pc, LayerSurface **pl, double *nx, double *ny);
|
||||||
@@ -437,6 +436,11 @@ static struct wl_listener request_start_drag = {.notify = requeststartdrag};
|
|||||||
static struct wl_listener start_drag = {.notify = startdrag};
|
static struct wl_listener start_drag = {.notify = startdrag};
|
||||||
static struct wl_listener new_session_lock = {.notify = locksession};
|
static struct wl_listener new_session_lock = {.notify = locksession};
|
||||||
|
|
||||||
|
static const struct xkb_rule_names en_rules = {.layout = "de"};
|
||||||
|
static struct xkb_context *en_context;
|
||||||
|
static struct xkb_keymap *en_keymap;
|
||||||
|
static struct xkb_state *en_state;
|
||||||
|
|
||||||
#ifdef XWAYLAND
|
#ifdef XWAYLAND
|
||||||
static void activatex11(struct wl_listener *listener, void *data);
|
static void activatex11(struct wl_listener *listener, void *data);
|
||||||
static void associatex11(struct wl_listener *listener, void *data);
|
static void associatex11(struct wl_listener *listener, void *data);
|
||||||
@@ -541,7 +545,6 @@ arrange(Monitor *m)
|
|||||||
m->lt[m->sellt]->arrange(m);
|
m->lt[m->sellt]->arrange(m);
|
||||||
motionnotify(0, NULL, 0, 0, 0, 0);
|
motionnotify(0, NULL, 0, 0, 0, 0);
|
||||||
checkidleinhibitor(NULL);
|
checkidleinhibitor(NULL);
|
||||||
warpcursor(focustop(selmon));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -719,6 +722,9 @@ cleanup(void)
|
|||||||
wlr_backend_destroy(backend);
|
wlr_backend_destroy(backend);
|
||||||
|
|
||||||
wl_display_destroy(dpy);
|
wl_display_destroy(dpy);
|
||||||
|
xkb_state_unref(en_state);
|
||||||
|
xkb_keymap_unref(en_keymap);
|
||||||
|
xkb_context_unref(en_context);
|
||||||
/* Destroy after the wayland display (when the monitors are already destroyed)
|
/* Destroy after the wayland display (when the monitors are already destroyed)
|
||||||
to avoid destroying them with an invalid scene output. */
|
to avoid destroying them with an invalid scene output. */
|
||||||
wlr_scene_node_destroy(&scene->tree.node);
|
wlr_scene_node_destroy(&scene->tree.node);
|
||||||
@@ -1409,10 +1415,6 @@ focusclient(Client *c, int lift)
|
|||||||
if (locked)
|
if (locked)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Warp cursor to center of client if it is outside */
|
|
||||||
if (lift)
|
|
||||||
warpcursor(c);
|
|
||||||
|
|
||||||
/* Raise client in stacking order if requested */
|
/* Raise client in stacking order if requested */
|
||||||
if (c && lift)
|
if (c && lift)
|
||||||
wlr_scene_node_raise_to_top(&c->scene->node);
|
wlr_scene_node_raise_to_top(&c->scene->node);
|
||||||
@@ -1634,16 +1636,19 @@ keypress(struct wl_listener *listener, void *data)
|
|||||||
/* This event is raised when a key is pressed or released. */
|
/* This event is raised when a key is pressed or released. */
|
||||||
KeyboardGroup *group = wl_container_of(listener, group, key);
|
KeyboardGroup *group = wl_container_of(listener, group, key);
|
||||||
struct wlr_keyboard_key_event *event = data;
|
struct wlr_keyboard_key_event *event = data;
|
||||||
|
int nsyms, handled;
|
||||||
|
|
||||||
/* Translate libinput keycode -> xkbcommon */
|
/* Translate libinput keycode -> xkbcommon */
|
||||||
uint32_t keycode = event->keycode + 8;
|
uint32_t keycode = event->keycode + 8;
|
||||||
/* Get a list of keysyms based on the keymap for this keyboard */
|
/* Get a list of keysyms based on the keymap for this keyboard */
|
||||||
const xkb_keysym_t *syms;
|
const xkb_keysym_t *syms;
|
||||||
int nsyms = xkb_state_key_get_syms(
|
|
||||||
group->wlr_group->keyboard.xkb_state, keycode, &syms);
|
|
||||||
|
|
||||||
int handled = 0;
|
|
||||||
uint32_t mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard);
|
uint32_t mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard);
|
||||||
|
xkb_state_update_key(en_state, keycode,
|
||||||
|
(event->state == WL_KEYBOARD_KEY_STATE_PRESSED)
|
||||||
|
? XKB_KEY_DOWN : XKB_KEY_UP);
|
||||||
|
nsyms = xkb_state_key_get_syms(en_state, keycode, &syms);
|
||||||
|
|
||||||
|
handled = 0;
|
||||||
|
|
||||||
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
|
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
|
||||||
|
|
||||||
@@ -2625,6 +2630,10 @@ setup(void)
|
|||||||
* pointer, touch, and drawing tablet device. We also rig up a listener to
|
* pointer, touch, and drawing tablet device. We also rig up a listener to
|
||||||
* let us know when new input devices are available on the backend.
|
* let us know when new input devices are available on the backend.
|
||||||
*/
|
*/
|
||||||
|
en_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||||
|
en_keymap = xkb_keymap_new_from_names(en_context, &en_rules,
|
||||||
|
XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||||
|
en_state = xkb_state_new(en_keymap);
|
||||||
wl_signal_add(&backend->events.new_input, &new_input_device);
|
wl_signal_add(&backend->events.new_input, &new_input_device);
|
||||||
virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy);
|
virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy);
|
||||||
wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard,
|
wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard,
|
||||||
@@ -3005,27 +3014,6 @@ virtualpointer(struct wl_listener *listener, void *data)
|
|||||||
wlr_cursor_map_input_to_output(cursor, device, event->suggested_output);
|
wlr_cursor_map_input_to_output(cursor, device, event->suggested_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
warpcursor(const Client *c) {
|
|
||||||
if (cursor_mode != CurNormal) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!c && selmon) {
|
|
||||||
wlr_cursor_warp_closest(cursor,
|
|
||||||
NULL,
|
|
||||||
selmon->w.x + selmon->w.width / 2.0 ,
|
|
||||||
selmon->w.y + selmon->w.height / 2.0);
|
|
||||||
}
|
|
||||||
else if ( c && (cursor->x < c->geom.x ||
|
|
||||||
cursor->x > c->geom.x + c->geom.width ||
|
|
||||||
cursor->y < c->geom.y ||
|
|
||||||
cursor->y > c->geom.y + c->geom.height))
|
|
||||||
wlr_cursor_warp_closest(cursor,
|
|
||||||
NULL,
|
|
||||||
c->geom.x + c->geom.width / 2.0,
|
|
||||||
c->geom.y + c->geom.height / 2.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Monitor *
|
Monitor *
|
||||||
xytomon(double x, double y)
|
xytomon(double x, double y)
|
||||||
{
|
{
|
||||||
|
|||||||
73
en-keycodes.patch
Normal file
73
en-keycodes.patch
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
From cd61fac9cb6e9d0172e2f7a01e6a514d676ba5f0 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Nikita Ivanov <nikita.vyach.ivanov@gmail.com>
|
||||||
|
Date: Tue, 4 Feb 2025 23:53:11 +0100
|
||||||
|
Subject: [PATCH] Always use the English keymap to get keycodes
|
||||||
|
|
||||||
|
---
|
||||||
|
dwl.c | 23 +++++++++++++++++++----
|
||||||
|
1 file changed, 19 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/dwl.c b/dwl.c
|
||||||
|
index def2562..c299365 100644
|
||||||
|
--- a/dwl.c
|
||||||
|
+++ b/dwl.c
|
||||||
|
@@ -413,6 +413,11 @@ static struct wlr_box sgeom;
|
||||||
|
static struct wl_list mons;
|
||||||
|
static Monitor *selmon;
|
||||||
|
|
||||||
|
+static const struct xkb_rule_names en_rules = {.layout = "us"};
|
||||||
|
+static struct xkb_context *en_context;
|
||||||
|
+static struct xkb_keymap *en_keymap;
|
||||||
|
+static struct xkb_state *en_state;
|
||||||
|
+
|
||||||
|
#ifdef XWAYLAND
|
||||||
|
static void activatex11(struct wl_listener *listener, void *data);
|
||||||
|
static void associatex11(struct wl_listener *listener, void *data);
|
||||||
|
@@ -694,6 +699,9 @@ cleanup(void)
|
||||||
|
wlr_backend_destroy(backend);
|
||||||
|
|
||||||
|
wl_display_destroy(dpy);
|
||||||
|
+ xkb_state_unref(en_state);
|
||||||
|
+ xkb_keymap_unref(en_keymap);
|
||||||
|
+ xkb_context_unref(en_context);
|
||||||
|
/* 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);
|
||||||
|
@@ -1582,16 +1590,19 @@ keypress(struct wl_listener *listener, void *data)
|
||||||
|
/* This event is raised when a key is pressed or released. */
|
||||||
|
KeyboardGroup *group = wl_container_of(listener, group, key);
|
||||||
|
struct wlr_keyboard_key_event *event = data;
|
||||||
|
+ int nsyms, handled;
|
||||||
|
|
||||||
|
/* 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(
|
||||||
|
- group->wlr_group->keyboard.xkb_state, keycode, &syms);
|
||||||
|
-
|
||||||
|
- int handled = 0;
|
||||||
|
uint32_t mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard);
|
||||||
|
+ xkb_state_update_key(en_state, keycode,
|
||||||
|
+ (event->state == WL_KEYBOARD_KEY_STATE_PRESSED)
|
||||||
|
+ ? XKB_KEY_DOWN : XKB_KEY_UP);
|
||||||
|
+ nsyms = xkb_state_key_get_syms(en_state, keycode, &syms);
|
||||||
|
+
|
||||||
|
+ handled = 0;
|
||||||
|
|
||||||
|
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
|
||||||
|
|
||||||
|
@@ -2607,6 +2618,10 @@ setup(void)
|
||||||
|
* pointer, touch, and drawing tablet device. We also rig up a listener to
|
||||||
|
* let us know when new input devices are available on the backend.
|
||||||
|
*/
|
||||||
|
+ en_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||||
|
+ en_keymap = xkb_keymap_new_from_names(en_context, &en_rules,
|
||||||
|
+ XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||||
|
+ en_state = xkb_state_new(en_keymap);
|
||||||
|
LISTEN_STATIC(&backend->events.new_input, inputdevice);
|
||||||
|
virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy);
|
||||||
|
LISTEN_STATIC(&virtual_keyboard_mgr->events.new_virtual_keyboard, virtualkeyboard);
|
||||||
|
--
|
||||||
|
2.48.1
|
||||||
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
From 4951ccc89dac2b557994b2f6c3aacb2398e2d1b1 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Ben Collerson <benc@benc.cc>
|
|
||||||
Date: Thu, 4 Jan 2024 20:30:01 +1000
|
|
||||||
Subject: [PATCH] warpcursor
|
|
||||||
|
|
||||||
---
|
|
||||||
dwl.c | 27 +++++++++++++++++++++++++++
|
|
||||||
1 file changed, 27 insertions(+)
|
|
||||||
|
|
||||||
diff --git a/dwl.c b/dwl.c
|
|
||||||
index 145fd018..f7ad6c13 100644
|
|
||||||
--- a/dwl.c
|
|
||||||
+++ b/dwl.c
|
|
||||||
@@ -347,6 +347,7 @@ static void urgent(struct wl_listener *listener, void *data);
|
|
||||||
static void view(const Arg *arg);
|
|
||||||
static void virtualkeyboard(struct wl_listener *listener, void *data);
|
|
||||||
static void virtualpointer(struct wl_listener *listener, void *data);
|
|
||||||
+static void warpcursor(const Client *c);
|
|
||||||
static Monitor *xytomon(double x, double y);
|
|
||||||
static void xytonode(double x, double y, struct wlr_surface **psurface,
|
|
||||||
Client **pc, LayerSurface **pl, double *nx, double *ny);
|
|
||||||
@@ -514,6 +515,7 @@ arrange(Monitor *m)
|
|
||||||
m->lt[m->sellt]->arrange(m);
|
|
||||||
motionnotify(0, NULL, 0, 0, 0, 0);
|
|
||||||
checkidleinhibitor(NULL);
|
|
||||||
+ warpcursor(focustop(selmon));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
@@ -1323,6 +1325,10 @@ focusclient(Client *c, int lift)
|
|
||||||
if (locked)
|
|
||||||
return;
|
|
||||||
|
|
||||||
+ /* Warp cursor to center of client if it is outside */
|
|
||||||
+ if (lift)
|
|
||||||
+ warpcursor(c);
|
|
||||||
+
|
|
||||||
/* Raise client in stacking order if requested */
|
|
||||||
if (c && lift)
|
|
||||||
wlr_scene_node_raise_to_top(&c->scene->node);
|
|
||||||
@@ -2927,6 +2933,27 @@ virtualpointer(struct wl_listener *listener, void *data)
|
|
||||||
wlr_cursor_map_input_to_output(cursor, &pointer.base, event->suggested_output);
|
|
||||||
}
|
|
||||||
|
|
||||||
+void
|
|
||||||
+warpcursor(const Client *c) {
|
|
||||||
+ if (cursor_mode != CurNormal) {
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
+ if (!c && selmon) {
|
|
||||||
+ wlr_cursor_warp_closest(cursor,
|
|
||||||
+ NULL,
|
|
||||||
+ selmon->w.x + selmon->w.width / 2.0 ,
|
|
||||||
+ selmon->w.y + selmon->w.height / 2.0);
|
|
||||||
+ }
|
|
||||||
+ else if ( c && (cursor->x < c->geom.x ||
|
|
||||||
+ cursor->x > c->geom.x + c->geom.width ||
|
|
||||||
+ cursor->y < c->geom.y ||
|
|
||||||
+ cursor->y > c->geom.y + c->geom.height))
|
|
||||||
+ wlr_cursor_warp_closest(cursor,
|
|
||||||
+ NULL,
|
|
||||||
+ c->geom.x + c->geom.width / 2.0,
|
|
||||||
+ c->geom.y + c->geom.height / 2.0);
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
Monitor *
|
|
||||||
xytomon(double x, double y)
|
|
||||||
{
|
|
||||||
--
|
|
||||||
2.45.2
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user