2018-11-25 22:12:48 +11:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-12-24 02:54:54 +11:00
|
|
|
#include <libevdev/libevdev.h>
|
2017-12-28 02:08:18 +11:00
|
|
|
#include <linux/input-event-codes.h>
|
|
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
#include <xkbcommon/xkbcommon-names.h>
|
2018-07-18 20:37:50 +10:00
|
|
|
#include <string.h>
|
2017-12-28 02:08:18 +11:00
|
|
|
#include <strings.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
2018-12-24 02:54:54 +11:00
|
|
|
#include "sway/input/cursor.h"
|
2018-07-18 20:37:50 +10:00
|
|
|
#include "sway/ipc-server.h"
|
2017-12-28 02:08:18 +11:00
|
|
|
#include "list.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "stringop.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
int binding_order = 0;
|
|
|
|
|
|
|
|
void free_sway_binding(struct sway_binding *binding) {
|
2017-12-30 01:10:07 +11:00
|
|
|
if (!binding) {
|
|
|
|
return;
|
2017-12-28 02:08:18 +11:00
|
|
|
}
|
2017-12-30 01:10:07 +11:00
|
|
|
|
2018-12-09 12:15:23 +11:00
|
|
|
list_free_items_and_destroy(binding->keys);
|
2018-10-19 04:13:40 +11:00
|
|
|
free(binding->input);
|
2017-12-30 01:10:07 +11:00
|
|
|
free(binding->command);
|
2017-12-28 02:08:18 +11:00
|
|
|
free(binding);
|
|
|
|
}
|
|
|
|
|
2017-12-29 10:50:22 +11:00
|
|
|
/**
|
|
|
|
* Returns true if the bindings have the same key and modifier combinations.
|
|
|
|
* Note that keyboard layout is not considered, so the bindings might actually
|
|
|
|
* not be equivalent on some layouts.
|
|
|
|
*/
|
2018-06-13 00:37:47 +10:00
|
|
|
static bool binding_key_compare(struct sway_binding *binding_a,
|
2017-12-29 10:50:22 +11:00
|
|
|
struct sway_binding *binding_b) {
|
2018-10-19 04:13:40 +11:00
|
|
|
if (strcmp(binding_a->input, binding_b->input) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
if (binding_a->type != binding_b->type) {
|
2018-01-04 23:25:52 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
uint32_t conflict_generating_flags = BINDING_RELEASE | BINDING_BORDER
|
|
|
|
| BINDING_CONTENTS | BINDING_TITLEBAR;
|
|
|
|
if ((binding_a->flags & conflict_generating_flags) !=
|
|
|
|
(binding_b->flags & conflict_generating_flags)) {
|
2017-12-29 10:50:22 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (binding_a->modifiers ^ binding_b->modifiers) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (binding_a->keys->length != binding_b->keys->length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-13 00:37:47 +10:00
|
|
|
// Keys are sorted
|
2017-12-29 10:50:22 +11:00
|
|
|
int keys_len = binding_a->keys->length;
|
|
|
|
for (int i = 0; i < keys_len; ++i) {
|
2018-06-13 00:37:47 +10:00
|
|
|
uint32_t key_a = *(uint32_t *)binding_a->keys->items[i];
|
|
|
|
uint32_t key_b = *(uint32_t *)binding_b->keys->items[i];
|
|
|
|
if (key_a != key_b) {
|
2017-12-29 10:50:22 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-13 00:37:47 +10:00
|
|
|
static int key_qsort_cmp(const void *keyp_a, const void *keyp_b) {
|
|
|
|
uint32_t key_a = **(uint32_t **)keyp_a;
|
|
|
|
uint32_t key_b = **(uint32_t **)keyp_b;
|
|
|
|
return (key_a < key_b) ? -1 : ((key_a > key_b) ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
/**
|
|
|
|
* From a keycode, bindcode, or bindsym name and the most likely binding type,
|
|
|
|
* identify the appropriate numeric value corresponding to the key. Return NULL
|
|
|
|
* and set *key_val if successful, otherwise return a specific error. Change
|
|
|
|
* the value of *type if the initial type guess was incorrect and if this
|
|
|
|
* was the first identified key.
|
|
|
|
*/
|
|
|
|
static struct cmd_results *identify_key(const char* name, bool first_key,
|
|
|
|
uint32_t* key_val, enum binding_input_type* type) {
|
|
|
|
if (*type == BINDING_KEYCODE) {
|
|
|
|
// check for keycode
|
|
|
|
xkb_keycode_t keycode = strtol(name, NULL, 10);
|
|
|
|
if (!xkb_keycode_is_legal_ext(keycode)) {
|
|
|
|
return cmd_results_new(CMD_INVALID, "bindcode",
|
|
|
|
"Invalid keycode '%s'", name);
|
|
|
|
}
|
|
|
|
*key_val = keycode;
|
|
|
|
} else {
|
|
|
|
// check for keysym
|
|
|
|
xkb_keysym_t keysym = xkb_keysym_from_name(name,
|
|
|
|
XKB_KEYSYM_CASE_INSENSITIVE);
|
|
|
|
|
|
|
|
// Check for mouse binding
|
|
|
|
uint32_t button = 0;
|
2018-12-24 02:54:54 +11:00
|
|
|
if (strncasecmp(name, "button", strlen("button")) == 0) {
|
|
|
|
// Map to x11 mouse buttons
|
|
|
|
button = name[strlen("button")] - '0';
|
|
|
|
if (button < 1 || button > 9 || strlen(name) > strlen("button0")) {
|
|
|
|
return cmd_results_new(CMD_INVALID, "bindsym",
|
|
|
|
"Only buttons 1-9 are supported. For other mouse "
|
|
|
|
"buttons, use the name of the event code.");
|
|
|
|
}
|
|
|
|
uint32_t buttons[] = {BTN_LEFT, BTN_MIDDLE, BTN_RIGHT,
|
|
|
|
SWAY_SCROLL_UP, SWAY_SCROLL_DOWN, SWAY_SCROLL_LEFT,
|
|
|
|
SWAY_SCROLL_RIGHT, BTN_SIDE, BTN_EXTRA};
|
|
|
|
button = buttons[button - 1];
|
|
|
|
} else if (strncmp(name, "BTN_", strlen("BTN_")) == 0) {
|
|
|
|
// Get event code
|
|
|
|
int code = libevdev_event_code_from_name(EV_KEY, name);
|
|
|
|
if (code == -1) {
|
|
|
|
return cmd_results_new(CMD_INVALID, "bindsym",
|
|
|
|
"Invalid event code name %s", name);
|
|
|
|
}
|
|
|
|
button = code;
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*type == BINDING_KEYSYM) {
|
|
|
|
if (button) {
|
|
|
|
if (first_key) {
|
|
|
|
*type = BINDING_MOUSE;
|
|
|
|
*key_val = button;
|
|
|
|
} else {
|
|
|
|
return cmd_results_new(CMD_INVALID, "bindsym",
|
|
|
|
"Mixed button '%s' into key sequence", name);
|
|
|
|
}
|
|
|
|
} else if (keysym) {
|
|
|
|
*key_val = keysym;
|
|
|
|
} else {
|
|
|
|
return cmd_results_new(CMD_INVALID, "bindsym",
|
|
|
|
"Unknown key '%s'", name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (button) {
|
|
|
|
*key_val = button;
|
|
|
|
} else if (keysym) {
|
|
|
|
return cmd_results_new(CMD_INVALID, "bindsym",
|
|
|
|
"Mixed keysym '%s' into button sequence", name);
|
|
|
|
} else {
|
|
|
|
return cmd_results_new(CMD_INVALID, "bindsym",
|
|
|
|
"Unknown button '%s'", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-01 20:50:53 +10:00
|
|
|
static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
|
|
|
|
bool bindcode) {
|
|
|
|
const char *bindtype = bindcode ? "bindcode" : "bindsym";
|
2018-06-01 05:16:01 +10:00
|
|
|
|
2017-12-28 02:08:18 +11:00
|
|
|
struct cmd_results *error = NULL;
|
2018-10-23 20:17:58 +11:00
|
|
|
if ((error = checkarg(argc, bindtype, EXPECTED_AT_LEAST, 2))) {
|
2017-12-28 02:08:18 +11:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-12-30 01:10:07 +11:00
|
|
|
struct sway_binding *binding = calloc(1, sizeof(struct sway_binding));
|
2017-12-28 02:08:18 +11:00
|
|
|
if (!binding) {
|
2018-06-01 05:16:01 +10:00
|
|
|
return cmd_results_new(CMD_FAILURE, bindtype,
|
2017-12-28 02:08:18 +11:00
|
|
|
"Unable to allocate binding");
|
|
|
|
}
|
2018-10-19 04:13:40 +11:00
|
|
|
binding->input = strdup("*");
|
2017-12-28 02:08:18 +11:00
|
|
|
binding->keys = create_list();
|
|
|
|
binding->modifiers = 0;
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
binding->flags = 0;
|
|
|
|
binding->type = bindcode ? BINDING_KEYCODE : BINDING_KEYSYM;
|
|
|
|
|
|
|
|
bool exclude_titlebar = false;
|
2018-12-03 08:05:51 +11:00
|
|
|
bool warn = true;
|
2017-12-28 02:08:18 +11:00
|
|
|
|
2018-05-28 02:37:18 +10:00
|
|
|
// Handle --release and --locked
|
|
|
|
while (argc > 0) {
|
|
|
|
if (strcmp("--release", argv[0]) == 0) {
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
binding->flags |= BINDING_RELEASE;
|
2018-05-28 02:37:18 +10:00
|
|
|
} else if (strcmp("--locked", argv[0]) == 0) {
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
binding->flags |= BINDING_LOCKED;
|
|
|
|
} else if (strcmp("--whole-window", argv[0]) == 0) {
|
|
|
|
binding->flags |= BINDING_BORDER | BINDING_CONTENTS | BINDING_TITLEBAR;
|
|
|
|
} else if (strcmp("--border", argv[0]) == 0) {
|
|
|
|
binding->flags |= BINDING_BORDER;
|
|
|
|
} else if (strcmp("--exclude-titlebar", argv[0]) == 0) {
|
|
|
|
exclude_titlebar = true;
|
2018-10-19 04:13:40 +11:00
|
|
|
} else if (strncmp("--input-device=", argv[0],
|
|
|
|
strlen("--input-device=")) == 0) {
|
|
|
|
free(binding->input);
|
|
|
|
binding->input = strdup(argv[0] + strlen("--input-device="));
|
2018-12-03 08:05:51 +11:00
|
|
|
} else if (strcmp("--no-warn", argv[0]) == 0) {
|
|
|
|
warn = false;
|
2017-12-28 02:08:18 +11:00
|
|
|
} else {
|
2018-05-28 02:37:18 +10:00
|
|
|
break;
|
2017-12-28 02:08:18 +11:00
|
|
|
}
|
2018-05-28 02:37:18 +10:00
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
if (binding->flags & (BINDING_BORDER | BINDING_CONTENTS | BINDING_TITLEBAR)
|
|
|
|
|| exclude_titlebar) {
|
|
|
|
binding->type = BINDING_MOUSE;
|
|
|
|
}
|
|
|
|
|
2018-05-28 02:37:18 +10:00
|
|
|
if (argc < 2) {
|
|
|
|
free_sway_binding(binding);
|
2018-06-01 05:16:01 +10:00
|
|
|
return cmd_results_new(CMD_FAILURE, bindtype,
|
|
|
|
"Invalid %s command "
|
|
|
|
"(expected at least 2 non-option arguments, got %d)", bindtype, argc);
|
2017-12-28 02:08:18 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
binding->command = join_args(argv + 1, argc - 1);
|
|
|
|
|
|
|
|
list_t *split = split_string(argv[0], "+");
|
|
|
|
for (int i = 0; i < split->length; ++i) {
|
|
|
|
// Check for a modifier key
|
|
|
|
uint32_t mod;
|
|
|
|
if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) {
|
|
|
|
binding->modifiers |= mod;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
// Identify the key and possibly change binding->type
|
|
|
|
uint32_t key_val = 0;
|
|
|
|
error = identify_key(split->items[i], binding->keys->length == 0,
|
|
|
|
&key_val, &binding->type);
|
|
|
|
if (error) {
|
|
|
|
free_sway_binding(binding);
|
|
|
|
list_free(split);
|
|
|
|
return error;
|
2017-12-28 02:08:18 +11:00
|
|
|
}
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
|
2018-06-01 20:50:53 +10:00
|
|
|
uint32_t *key = calloc(1, sizeof(uint32_t));
|
2017-12-28 02:08:18 +11:00
|
|
|
if (!key) {
|
|
|
|
free_sway_binding(binding);
|
2018-12-09 12:15:23 +11:00
|
|
|
list_free_items_and_destroy(split);
|
2018-06-01 05:16:01 +10:00
|
|
|
return cmd_results_new(CMD_FAILURE, bindtype,
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
"Unable to allocate binding key");
|
2017-12-28 02:08:18 +11:00
|
|
|
}
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
*key = key_val;
|
2017-12-28 02:08:18 +11:00
|
|
|
list_add(binding->keys, key);
|
|
|
|
}
|
2018-12-09 12:15:23 +11:00
|
|
|
list_free_items_and_destroy(split);
|
2017-12-28 02:08:18 +11:00
|
|
|
binding->order = binding_order++;
|
2017-12-29 10:50:22 +11:00
|
|
|
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
// refine region of interest for mouse binding once we are certain
|
|
|
|
// that this is one
|
|
|
|
if (exclude_titlebar) {
|
|
|
|
binding->flags &= ~BINDING_TITLEBAR;
|
|
|
|
} else if (binding->type == BINDING_MOUSE) {
|
|
|
|
binding->flags |= BINDING_TITLEBAR;
|
|
|
|
}
|
|
|
|
|
2018-06-13 00:37:47 +10:00
|
|
|
// sort ascending
|
|
|
|
list_qsort(binding->keys, key_qsort_cmp);
|
|
|
|
|
2018-06-01 05:16:01 +10:00
|
|
|
list_t *mode_bindings;
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
if (binding->type == BINDING_KEYCODE) {
|
2018-06-01 05:16:01 +10:00
|
|
|
mode_bindings = config->current_mode->keycode_bindings;
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
} else if (binding->type == BINDING_KEYSYM) {
|
2018-06-01 05:16:01 +10:00
|
|
|
mode_bindings = config->current_mode->keysym_bindings;
|
Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.
The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.
Next, list of mouse bindings is introduced and cleaned up.
Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag. As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-18 12:01:06 +10:00
|
|
|
} else {
|
|
|
|
mode_bindings = config->current_mode->mouse_bindings;
|
2018-06-01 05:16:01 +10:00
|
|
|
}
|
2017-12-29 10:50:22 +11:00
|
|
|
|
|
|
|
// overwrite the binding if it already exists
|
|
|
|
bool overwritten = false;
|
|
|
|
for (int i = 0; i < mode_bindings->length; ++i) {
|
|
|
|
struct sway_binding *config_binding = mode_bindings->items[i];
|
|
|
|
if (binding_key_compare(binding, config_binding)) {
|
2018-11-29 03:08:54 +11:00
|
|
|
wlr_log(WLR_INFO, "Overwriting binding '%s' for device '%s' "
|
|
|
|
"from `%s` to `%s`", argv[0], binding->input,
|
|
|
|
binding->command, config_binding->command);
|
2018-12-03 08:05:51 +11:00
|
|
|
if (warn) {
|
|
|
|
config_add_swaynag_warning("Overwriting binding"
|
|
|
|
"'%s' for device '%s' to `%s` from `%s`",
|
|
|
|
argv[0], binding->input, binding->command,
|
|
|
|
config_binding->command);
|
|
|
|
}
|
2017-12-29 10:50:22 +11:00
|
|
|
free_sway_binding(config_binding);
|
|
|
|
mode_bindings->items[i] = binding;
|
|
|
|
overwritten = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!overwritten) {
|
|
|
|
list_add(mode_bindings, binding);
|
|
|
|
}
|
2017-12-28 02:08:18 +11:00
|
|
|
|
2018-10-19 04:13:40 +11:00
|
|
|
wlr_log(WLR_DEBUG, "%s - Bound %s to command `%s` for device '%s'",
|
|
|
|
bindtype, argv[0], binding->command, binding->input);
|
2017-12-28 02:08:18 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
2018-06-01 05:16:01 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_results *cmd_bindsym(int argc, char **argv) {
|
|
|
|
return cmd_bindsym_or_bindcode(argc, argv, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_results *cmd_bindcode(int argc, char **argv) {
|
|
|
|
return cmd_bindsym_or_bindcode(argc, argv, true);
|
2017-12-28 02:08:18 +11:00
|
|
|
}
|
2018-07-24 11:38:29 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the command associated to a binding
|
|
|
|
*/
|
|
|
|
void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding) {
|
2018-10-08 20:28:53 +11:00
|
|
|
wlr_log(WLR_DEBUG, "running command for binding: %s", binding->command);
|
2018-07-18 20:37:50 +10:00
|
|
|
|
2019-01-09 17:50:40 +11:00
|
|
|
list_t *res_list = execute_command(binding->command, seat, NULL);
|
2018-11-28 13:42:09 +11:00
|
|
|
bool success = true;
|
2018-12-09 10:55:14 +11:00
|
|
|
for (int i = 0; i < res_list->length; ++i) {
|
|
|
|
struct cmd_results *results = res_list->items[i];
|
2018-11-28 13:42:09 +11:00
|
|
|
if (results->status != CMD_SUCCESS) {
|
|
|
|
wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)",
|
|
|
|
binding->command, results->error);
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
free_cmd_results(results);
|
|
|
|
}
|
|
|
|
list_free(res_list);
|
|
|
|
if (success) {
|
2018-10-08 20:28:53 +11:00
|
|
|
ipc_event_binding(binding);
|
2018-07-24 11:38:29 +10:00
|
|
|
}
|
|
|
|
}
|