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
|
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>
|
|
|
|
|
#include <unistd.h>
|
2021-08-31 17:43:49 -04:00
|
|
|
#include <wlr/util/log.h>
|
2021-09-06 21:54:00 +01:00
|
|
|
#include "config/mousebind.h"
|
|
|
|
|
#include "config/rcxml.h"
|
2021-08-29 14:22:49 -04:00
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
uint32_t
|
2021-12-01 02:32:24 +00:00
|
|
|
mousebind_button_from_str(const char *str, uint32_t *modifiers)
|
2021-08-29 14:22:49 -04:00
|
|
|
{
|
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);
|
|
|
|
|
if (!parsed_modifier)
|
|
|
|
|
goto invalid;
|
|
|
|
|
*modifiers |= parsed_modifier;
|
|
|
|
|
str += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
if (!strcasecmp(str, "Left")) {
|
2021-08-30 18:42:38 -04:00
|
|
|
return BTN_LEFT;
|
2021-09-06 21:54:00 +01:00
|
|
|
} else if (!strcasecmp(str, "Right")) {
|
2021-08-30 18:42:38 -04:00
|
|
|
return BTN_RIGHT;
|
2021-09-06 21:54:00 +01:00
|
|
|
} else if (!strcasecmp(str, "Middle")) {
|
2021-08-30 18:42:38 -04:00
|
|
|
return BTN_MIDDLE;
|
2021-08-29 14:22:49 -04: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-08-29 14:22:49 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
enum mouse_event
|
|
|
|
|
mousebind_event_from_str(const char *str)
|
2021-08-29 14:22:49 -04:00
|
|
|
{
|
2021-09-06 21:54:00 +01:00
|
|
|
assert(str);
|
2021-11-01 20:32:14 -04:00
|
|
|
if (!strcasecmp(str, "doubleclick")) {
|
2021-08-29 14:22:49 -04: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;
|
2021-08-29 14:22:49 -04:00
|
|
|
}
|
2021-09-24 22:04:03 +01:00
|
|
|
wlr_log(WLR_ERROR, "unknown mouse action (%s)", str);
|
|
|
|
|
return MOUSE_ACTION_NONE;
|
2021-08-29 14:22:49 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
static enum ssd_part_type
|
|
|
|
|
context_from_str(const char *str)
|
2021-08-29 14:22:49 -04:00
|
|
|
{
|
2021-09-06 21:54:00 +01:00
|
|
|
if (!strcasecmp(str, "Titlebar")) {
|
|
|
|
|
return LAB_SSD_PART_TITLEBAR;
|
2021-11-01 20:32:14 -04:00
|
|
|
} else if (!strcasecmp(str, "Close")) {
|
|
|
|
|
return LAB_SSD_BUTTON_CLOSE;
|
|
|
|
|
} else if (!strcasecmp(str, "Maximize")) {
|
|
|
|
|
return LAB_SSD_BUTTON_MAXIMIZE;
|
|
|
|
|
} else if (!strcasecmp(str, "Iconify")) {
|
|
|
|
|
return LAB_SSD_BUTTON_ICONIFY;
|
2021-12-01 22:17:04 +00:00
|
|
|
} else if (!strcasecmp(str, "Frame")) {
|
|
|
|
|
return LAB_SSD_FRAME;
|
|
|
|
|
} else if (!strcasecmp(str, "Client")) {
|
|
|
|
|
return LAB_SSD_CLIENT;
|
|
|
|
|
} else if (!strcasecmp(str, "Desktop")) {
|
|
|
|
|
return LAB_SSD_ROOT;
|
|
|
|
|
} else if (!strcasecmp(str, "Root")) {
|
|
|
|
|
return LAB_SSD_ROOT;
|
2021-08-29 14:22:49 -04:00
|
|
|
}
|
2021-09-24 22:04:03 +01:00
|
|
|
wlr_log(WLR_ERROR, "unknown mouse context (%s)", str);
|
|
|
|
|
return LAB_SSD_NONE;
|
2021-09-06 21:54:00 +01:00
|
|
|
}
|
2021-08-29 14:22:49 -04:00
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
struct mousebind *
|
|
|
|
|
mousebind_create(const char *context)
|
|
|
|
|
{
|
|
|
|
|
if (!context) {
|
|
|
|
|
wlr_log(WLR_ERROR, "mousebind context not specified");
|
|
|
|
|
return NULL;
|
2021-08-30 22:03:41 -04:00
|
|
|
}
|
2021-09-06 21:54:00 +01:00
|
|
|
struct mousebind *m = calloc(1, sizeof(struct mousebind));
|
|
|
|
|
m->context = context_from_str(context);
|
2021-12-01 22:34:51 +00:00
|
|
|
if (m->context != LAB_SSD_NONE) {
|
|
|
|
|
wl_list_insert(&rc.mousebinds, &m->link);
|
|
|
|
|
}
|
2021-08-29 14:22:49 -04:00
|
|
|
return m;
|
|
|
|
|
}
|