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),

88
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))
libinput_device_config_send_events_set_mode(device, send_events_mode);
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);
@ -1270,13 +1286,13 @@ dwl_ipc_manager_bind(struct wl_client *client, void *data, uint32_t version, uin
}
wl_resource_set_implementation(manager_resource, &dwl_manager_implementation, NULL, dwl_ipc_manager_destroy);
// printf("DWL::dwl_ipc_manager - EVENT Sent tagcount = %d\n", TAGCOUNT);
// printf("DWL::dwl_ipc_manager - EVENT Sent tagcount = %d\n", TAGCOUNT);
zdwl_ipc_manager_v2_send_tags(manager_resource, TAGCOUNT);
for (long unsigned int i = 0; i < LENGTH(layouts); i++) {
// printf("DWL::dwl_ipc_manager - EVENT Sent layout = %s\n", layouts[i].symbol);
// printf("DWL::dwl_ipc_manager - EVENT Sent layout = %s\n", layouts[i].symbol);
zdwl_ipc_manager_v2_send_layout(manager_resource, layouts[i].symbol);
}
}
}
void
@ -1305,7 +1321,7 @@ dwl_ipc_manager_get_output(struct wl_client *client, struct wl_resource *resourc
void
dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource)
{
// printf("DWL::dwl_ipc_manager_release - REQUEST Received\n");
// printf("DWL::dwl_ipc_manager_release - REQUEST Received\n");
wl_resource_destroy(resource);
}
@ -1321,11 +1337,11 @@ void
dwl_ipc_output_printstatus(Monitor *monitor)
{
DwlIpcOutput *ipc_output;
// printf("DWL::dwl_ipc_output_printstatus - Starting\n");
// printf("DWL::dwl_ipc_output_printstatus - Starting\n");
wl_list_for_each(ipc_output, &monitor->dwl_ipc_outputs, link) {
// printf("DWL::dwl_ipc_output_printstatus - In input\n");
// printf("DWL::dwl_ipc_output_printstatus - In input\n");
dwl_ipc_output_printstatus_to(ipc_output);
}
}
}
void
@ -1336,11 +1352,11 @@ dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output)
int tagmask, state, numclients, focused_client, tag;
const char *title, *appid;
focused = focustop(monitor);
// printf("DWL::dwl_ipc_output - EVENT Sent active = %d\n", (monitor == selmon));
// printf("DWL::dwl_ipc_output - EVENT Sent active = %d\n", (monitor == selmon));
zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon);
for (tag = 0 ; tag < TAGCOUNT; tag++) {
// printf("DWL::dwl_ipc_output_printstatus_to - tag = %d\n", tag);
// printf("DWL::dwl_ipc_output_printstatus_to - tag = %d\n", tag);
numclients = state = focused_client = 0;
tagmask = 1 << tag;
if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
@ -1359,22 +1375,22 @@ dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output)
numclients++;
}
// numclients = state = focused_client = 0;
// printf("DWL::dwl_ipc_output - EVENT Sent tag = %d, num_clients = %d\n",
// tag, numclients);
// printf("DWL::dwl_ipc_output - EVENT Sent tag = %d, num_clients = %d\n",
// tag, numclients);
zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients, focused_client);
// printf("DWL::dwl_ipc_output_printstatus_to - after send_tag tag = %d, num_clients = %d\n",
// tag, numclients);
// printf("DWL::dwl_ipc_output_printstatus_to - after send_tag tag = %d, num_clients = %d\n",
// tag, numclients);
}
title = focused ? client_get_title(focused) : "NF";
appid = focused ? client_get_appid(focused) : "NF";
// printf("DWL::dwl_ipc_output - EVENT Sent layout = %lu\n", monitor->lt[monitor->sellt] - layouts);
// printf("DWL::dwl_ipc_output - EVENT Sent layout = %lu\n", monitor->lt[monitor->sellt] - layouts);
zdwl_ipc_output_v2_send_layout(ipc_output->resource, monitor->lt[monitor->sellt] - layouts);
// printf("DWL::dwl_ipc_output - EVENT Sent title = %s\n", title ? title : broken);
// printf("DWL::dwl_ipc_output - EVENT Sent title = %s\n", title ? title : broken);
zdwl_ipc_output_v2_send_title(ipc_output->resource, title ? title : broken);
// printf("DWL::dwl_ipc_output - EVENT Sent appid = %s\n", appid ? appid : broken);
// printf("DWL::dwl_ipc_output - EVENT Sent appid = %s\n", appid ? appid : broken);
zdwl_ipc_output_v2_send_appid(ipc_output->resource, appid ? appid : broken);
// printf("DWL::dwl_ipc_output - EVENT Sent layout_symbol = %s\n", monitor->ltsymbol);
// printf("DWL::dwl_ipc_output - EVENT Sent layout_symbol = %s\n", monitor->ltsymbol);
zdwl_ipc_output_v2_send_layout_symbol(ipc_output->resource, monitor->ltsymbol);
if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FULLSCREEN_SINCE_VERSION) {
zdwl_ipc_output_v2_send_fullscreen(ipc_output->resource, focused ? focused->isfullscreen : 0);
@ -1382,7 +1398,7 @@ dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output)
if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) {
zdwl_ipc_output_v2_send_floating(ipc_output->resource, focused ? focused->isfloating : 0);
}
// printf("DWL::dwl_ipc_output - EVENT Sent frame = done (dwl_ipc_output_printstatus_to)\n");
// printf("DWL::dwl_ipc_output - EVENT Sent frame = done (dwl_ipc_output_printstatus_to)\n");
zdwl_ipc_output_v2_send_frame(ipc_output->resource);
}
@ -1394,7 +1410,7 @@ dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *res
Client *selected_client;
unsigned int newtags = 0;
// printf("DWL::dwl_ipc_output - REQUEST Received set_client_tags and_tags = %d, xor_tags = %d\n", and_tags, xor_tags);
// printf("DWL::dwl_ipc_output - REQUEST Received set_client_tags and_tags = %d, xor_tags = %d\n", and_tags, xor_tags);
ipc_output = wl_resource_get_user_data(resource);
if (!ipc_output)
return;
@ -1420,7 +1436,7 @@ dwl_ipc_output_set_layout(struct wl_client *client, struct wl_resource *resource
DwlIpcOutput *ipc_output;
Monitor *monitor;
// printf("DWL::dwl_ipc_output - REQUEST Received set_layout index = %d\n", index);
// printf("DWL::dwl_ipc_output - REQUEST Received set_layout index = %d\n", index);
ipc_output = wl_resource_get_user_data(resource);
if (!ipc_output)
return;
@ -1443,7 +1459,7 @@ dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource,
Monitor *monitor;
unsigned int newtags = tagmask & TAGMASK;
// printf("DWL::dwl_ipc_output - REQUEST Received set_tags tagmask = %d, toggle_tagset = %d\n", tagmask, toggle_tagset);
// printf("DWL::dwl_ipc_output - REQUEST Received set_tags tagmask = %d, toggle_tagset = %d\n", tagmask, toggle_tagset);
ipc_output = wl_resource_get_user_data(resource);
if (!ipc_output)
return;
@ -1463,7 +1479,7 @@ dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource,
void
dwl_ipc_output_release(struct wl_client *client, struct wl_resource *resource)
{
// printf("DWL::dwl_ipc_output_release - REQUEST Received\n");
// printf("DWL::dwl_ipc_output_release - REQUEST Received\n");
wl_resource_destroy(resource);
}
@ -2143,7 +2159,7 @@ void
printstatus(void)
{
Monitor *m = NULL;
// printf("DWL::printstatus - Starting\n");
// printf("DWL::printstatus - Starting\n");
wl_list_for_each(m, &mons, link) {
// occ = urg = 0;
// wl_list_for_each(c, &clients, link) {
@ -2175,9 +2191,9 @@ printstatus(void)
// printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
// }
// fflush(stdout);
// printf("DWL::printstatus - In monitor\n");
// printf("DWL::printstatus - In monitor\n");
dwl_ipc_output_printstatus(m);
}
}
}
void
@ -2839,11 +2855,27 @@ 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;
wl_list_for_each(ipc_output, &selmon->dwl_ipc_outputs, link)
// printf("DWL::dwl_ipc_output - EVENT Sent toggle_visibility\n");
// printf("DWL::dwl_ipc_output - EVENT Sent toggle_visibility\n");
zdwl_ipc_output_v2_send_toggle_visibility(ipc_output->resource);
}