2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2021-08-29 14:22:49 -04:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2025-07-28 01:02:01 -04:00
|
|
|
#include "config/mousebind.h"
|
2021-09-06 21:54:00 +01:00
|
|
|
#include <assert.h>
|
2021-08-31 17:43:49 -04:00
|
|
|
#include <linux/input-event-codes.h>
|
2021-08-29 14:22:49 -04:00
|
|
|
#include <strings.h>
|
2021-08-31 17:43:49 -04:00
|
|
|
#include <wlr/util/log.h>
|
2022-10-05 08:43:56 +02:00
|
|
|
#include "common/list.h"
|
2022-09-16 18:41:02 -04:00
|
|
|
#include "common/mem.h"
|
2025-09-03 05:08:52 -04:00
|
|
|
#include "config/keybind.h"
|
2021-09-06 21:54:00 +01:00
|
|
|
#include "config/rcxml.h"
|
|
|
|
|
|
|
|
|
|
uint32_t
|
2021-12-01 02:32:24 +00:00
|
|
|
mousebind_button_from_str(const char *str, uint32_t *modifiers)
|
2021-09-06 21:54:00 +01:00
|
|
|
{
|
|
|
|
|
assert(str);
|
2021-12-01 02:32:24 +00:00
|
|
|
|
|
|
|
|
if (modifiers) {
|
|
|
|
|
*modifiers = 0;
|
|
|
|
|
while (strlen(str) >= 2 && str[1] == '-') {
|
|
|
|
|
char modname[2] = {str[0], 0};
|
|
|
|
|
uint32_t parsed_modifier = parse_modifier(modname);
|
2022-01-09 05:48:27 +01:00
|
|
|
if (!parsed_modifier) {
|
2021-12-01 02:32:24 +00:00
|
|
|
goto invalid;
|
2022-01-09 05:48:27 +01:00
|
|
|
}
|
2021-12-01 02:32:24 +00:00
|
|
|
*modifiers |= parsed_modifier;
|
|
|
|
|
str += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
if (!strcasecmp(str, "Left")) {
|
|
|
|
|
return BTN_LEFT;
|
|
|
|
|
} else if (!strcasecmp(str, "Right")) {
|
|
|
|
|
return BTN_RIGHT;
|
|
|
|
|
} else if (!strcasecmp(str, "Middle")) {
|
|
|
|
|
return BTN_MIDDLE;
|
2024-01-06 17:55:04 +01:00
|
|
|
} else if (!strcasecmp(str, "Side")) {
|
|
|
|
|
return BTN_SIDE;
|
|
|
|
|
} else if (!strcasecmp(str, "Extra")) {
|
|
|
|
|
return BTN_EXTRA;
|
|
|
|
|
} else if (!strcasecmp(str, "Forward")) {
|
|
|
|
|
return BTN_FORWARD;
|
|
|
|
|
} else if (!strcasecmp(str, "Back")) {
|
|
|
|
|
return BTN_BACK;
|
|
|
|
|
} else if (!strcasecmp(str, "Task")) {
|
|
|
|
|
return BTN_TASK;
|
2021-09-06 21:54:00 +01:00
|
|
|
}
|
2021-12-01 02:32:24 +00:00
|
|
|
invalid:
|
2021-09-24 22:04:03 +01:00
|
|
|
wlr_log(WLR_ERROR, "unknown button (%s)", str);
|
|
|
|
|
return UINT32_MAX;
|
2021-09-06 21:54:00 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-09 05:18:14 +00:00
|
|
|
enum direction
|
|
|
|
|
mousebind_direction_from_str(const char *str, uint32_t *modifiers)
|
|
|
|
|
{
|
|
|
|
|
assert(str);
|
|
|
|
|
|
|
|
|
|
if (modifiers) {
|
|
|
|
|
*modifiers = 0;
|
|
|
|
|
while (strlen(str) >= 2 && str[1] == '-') {
|
|
|
|
|
char modname[2] = {str[0], 0};
|
|
|
|
|
uint32_t parsed_modifier = parse_modifier(modname);
|
|
|
|
|
if (!parsed_modifier) {
|
|
|
|
|
goto invalid;
|
|
|
|
|
}
|
|
|
|
|
*modifiers |= parsed_modifier;
|
|
|
|
|
str += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcasecmp(str, "Left")) {
|
|
|
|
|
return LAB_DIRECTION_LEFT;
|
|
|
|
|
} else if (!strcasecmp(str, "Right")) {
|
|
|
|
|
return LAB_DIRECTION_RIGHT;
|
|
|
|
|
} else if (!strcasecmp(str, "Up")) {
|
|
|
|
|
return LAB_DIRECTION_UP;
|
|
|
|
|
} else if (!strcasecmp(str, "Down")) {
|
|
|
|
|
return LAB_DIRECTION_DOWN;
|
|
|
|
|
}
|
|
|
|
|
invalid:
|
|
|
|
|
wlr_log(WLR_ERROR, "unknown direction (%s)", str);
|
|
|
|
|
return LAB_DIRECTION_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
enum mouse_event
|
|
|
|
|
mousebind_event_from_str(const char *str)
|
|
|
|
|
{
|
|
|
|
|
assert(str);
|
2021-11-01 20:32:14 -04:00
|
|
|
if (!strcasecmp(str, "doubleclick")) {
|
2021-09-06 21:54:00 +01:00
|
|
|
return MOUSE_ACTION_DOUBLECLICK;
|
2021-11-01 20:32:14 -04:00
|
|
|
} else if (!strcasecmp(str, "click")) {
|
|
|
|
|
return MOUSE_ACTION_CLICK;
|
|
|
|
|
} else if (!strcasecmp(str, "press")) {
|
|
|
|
|
return MOUSE_ACTION_PRESS;
|
|
|
|
|
} else if (!strcasecmp(str, "release")) {
|
|
|
|
|
return MOUSE_ACTION_RELEASE;
|
2022-01-06 18:30:17 -05:00
|
|
|
} else if (!strcasecmp(str, "drag")) {
|
|
|
|
|
return MOUSE_ACTION_DRAG;
|
2022-10-25 21:46:46 +02:00
|
|
|
} else if (!strcasecmp(str, "scroll")) {
|
|
|
|
|
return MOUSE_ACTION_SCROLL;
|
2021-09-06 21:54:00 +01:00
|
|
|
}
|
2021-09-24 22:04:03 +01:00
|
|
|
wlr_log(WLR_ERROR, "unknown mouse action (%s)", str);
|
|
|
|
|
return MOUSE_ACTION_NONE;
|
2021-09-06 21:54:00 +01:00
|
|
|
}
|
2021-08-29 14:22:49 -04:00
|
|
|
|
2023-01-29 04:06:46 +01:00
|
|
|
bool
|
|
|
|
|
mousebind_the_same(struct mousebind *a, struct mousebind *b)
|
|
|
|
|
{
|
|
|
|
|
assert(a && b);
|
|
|
|
|
return a->context == b->context
|
|
|
|
|
&& a->button == b->button
|
|
|
|
|
&& a->direction == b->direction
|
|
|
|
|
&& a->mouse_event == b->mouse_event
|
|
|
|
|
&& a->modifiers == b->modifiers;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 17:43:49 -04:00
|
|
|
struct mousebind *
|
2021-09-06 21:54:00 +01:00
|
|
|
mousebind_create(const char *context)
|
2021-08-29 14:22:49 -04:00
|
|
|
{
|
2021-09-06 21:54:00 +01:00
|
|
|
if (!context) {
|
|
|
|
|
wlr_log(WLR_ERROR, "mousebind context not specified");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2022-09-18 15:22:26 -04:00
|
|
|
struct mousebind *m = znew(*m);
|
2025-09-03 05:08:52 -04:00
|
|
|
m->context = node_type_parse(context);
|
|
|
|
|
if (m->context != LAB_NODE_NONE) {
|
2022-10-05 08:43:56 +02:00
|
|
|
wl_list_append(&rc.mousebinds, &m->link);
|
2021-12-01 22:34:51 +00:00
|
|
|
}
|
2022-01-05 09:11:24 +01:00
|
|
|
wl_list_init(&m->actions);
|
2021-12-23 05:37:57 +01:00
|
|
|
return m;
|
|
|
|
|
}
|