Touch input device control

* Added function toggle_touch_input_device to toggle enaled state of
  touch device.
* This function is called in key bindings.
* Touch device is identified by vendor/device id provided in config.h
This commit is contained in:
Mahesh Asolkar 2024-04-06 16:11:05 -07:00
parent 937623515a
commit cb828032c7
2 changed files with 74 additions and 30 deletions

View File

@ -18,6 +18,9 @@ static const float fullscreen_bg[] = COLOR(0x121212ff);
/* tagging - TAGCOUNT must be no greater than 31 */
#define TAGCOUNT (9)
/* control variables */
static int cfg_disable_touch_pad = 1;
/* logging */
static int log_level = WLR_ERROR;
@ -91,6 +94,11 @@ LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE
*/
static const uint32_t send_events_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
/* Touch device information to filter touch events
* Use udevadm info --tree to obtain info */
static const uint32_t touch_device_vendor_id = 0x6cb;
static const uint32_t touch_device_product_id = 0x0;
/* You can choose between:
LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT
LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE
@ -140,7 +148,8 @@ static const Key keys[] = {
/* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */
/* modifier key function argument */
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
{ MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = alttermcmd} },
{ MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,
XKB_KEY_Return, spawn, {.v = alttermcmd} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_P, spawn, {.v = launchcmd} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_N, spawn, {.v = dispcmd} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_W, spawn, {.v = webcmd} },
@ -160,13 +169,16 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XKB_KEY_space, setlayout, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen,
{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_space, toggle_touch_input_device,
{0} },
TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0),
TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),

34
dwl.c
View File

@ -247,6 +247,8 @@ typedef struct {
struct wl_listener destroy;
} SessionLock;
struct libinput_device *touch_input_device;
/* function declarations */
static void applybounds(Client *c, struct wlr_box *bbox);
static void applyrules(Client *c);
@ -349,6 +351,7 @@ static void startdrag(struct wl_listener *listener, void *data);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void toggle_touch_input_device(const Arg *arg);
static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
@ -1047,8 +1050,21 @@ createpointer(struct wlr_pointer *pointer)
if (libinput_device_config_click_get_methods(device) != LIBINPUT_CONFIG_CLICK_METHOD_NONE)
libinput_device_config_click_set_method (device, click_method);
if (libinput_device_config_send_events_get_modes(device))
if (libinput_device_config_send_events_get_modes(device)) {
if ((cfg_disable_touch_pad)
&& ((libinput_device_get_id_vendor(device) == touch_device_vendor_id)
&& (libinput_device_get_id_product(device) == touch_device_product_id))) {
libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
touch_input_device = device;
fprintf(stderr,"DWL::createpointer - Disable set to %d events for device %s (%d:%d) == %d:%d\n",
cfg_disable_touch_pad,
libinput_device_get_name(touch_input_device),
libinput_device_get_id_vendor(touch_input_device),
libinput_device_get_id_product(touch_input_device), touch_device_vendor_id, touch_device_product_id);
} else {
libinput_device_config_send_events_set_mode(device, send_events_mode);
}
}
if (libinput_device_config_accel_is_available(device)) {
libinput_device_config_accel_set_profile(device, accel_profile);
@ -2839,6 +2855,22 @@ tile(Monitor *m)
}
}
void
toggle_touch_input_device(const Arg *arg) {
if (cfg_disable_touch_pad) {
libinput_device_config_send_events_set_mode(touch_input_device, send_events_mode);
cfg_disable_touch_pad = 0;
} else {
libinput_device_config_send_events_set_mode(touch_input_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
cfg_disable_touch_pad = 1;
}
fprintf(stderr,"DWL::toggle_touch_input_device - Disable set to %d events for device %s (%d:%d) == %d:%d\n",
cfg_disable_touch_pad,
libinput_device_get_name(touch_input_device),
libinput_device_get_id_vendor(touch_input_device),
libinput_device_get_id_product(touch_input_device), touch_device_vendor_id, touch_device_product_id);
}
void
togglebar(const Arg *arg) {
DwlIpcOutput *ipc_output;