mirror of
https://github.com/swaywm/sway.git
synced 2025-10-29 05:40:18 -04:00
bar_cmd_tray_bind: Use mouse button helpers
This modifies `bar_cmd_tray_bindsym` to use `get_mouse_bindsym` for parsing mouse buttons. This also introduces `bar_cmd_tray_bindcode`, which will use `get_mouse_bindcode` for parsing mouse buttons. Like with sway bindings, the two commands are encapsulated in a single file to maximize shared code. This also modifies tray bindings to work off of events codes rather than x11 buttons, which allows for any mouse buttons to be used. For `get_bar_config`, `event_code` has been added to the `tray_bindings` section and will include to event code for the button. If the event code can be mapped to a x11 button, `input_code` will still be the x11 button number. Otherwise, `input_code` will be `0`.
This commit is contained in:
parent
247817f68c
commit
02bbefda20
19 changed files with 229 additions and 143 deletions
|
|
@ -78,6 +78,7 @@ struct swaybar_config *init_config(void) {
|
|||
|
||||
#if HAVE_TRAY
|
||||
config->tray_padding = 2;
|
||||
wl_list_init(&config->tray_bindings);
|
||||
#endif
|
||||
|
||||
return config;
|
||||
|
|
@ -91,6 +92,16 @@ static void free_binding(struct swaybar_binding *binding) {
|
|||
free(binding);
|
||||
}
|
||||
|
||||
#if HAVE_TRAY
|
||||
static void free_tray_binding(struct tray_binding *binding) {
|
||||
if (!binding) {
|
||||
return;
|
||||
}
|
||||
free(binding->command);
|
||||
free(binding);
|
||||
}
|
||||
#endif
|
||||
|
||||
void free_config(struct swaybar_config *config) {
|
||||
free(config->status_command);
|
||||
free(config->font);
|
||||
|
|
@ -111,9 +122,14 @@ void free_config(struct swaybar_config *config) {
|
|||
}
|
||||
#if HAVE_TRAY
|
||||
list_free_items_and_destroy(config->tray_outputs);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
free(config->tray_bindings[i]);
|
||||
|
||||
struct tray_binding *tray_bind = NULL, *tmp_tray_bind = NULL;
|
||||
wl_list_for_each_safe(tray_bind, tmp_tray_bind, &config->tray_bindings,
|
||||
link) {
|
||||
wl_list_remove(&tray_bind->link);
|
||||
free_tray_binding(tray_bind);
|
||||
}
|
||||
|
||||
free(config->icon_theme);
|
||||
#endif
|
||||
free(config);
|
||||
|
|
|
|||
|
|
@ -259,31 +259,6 @@ bool i3bar_handle_readable(struct status_line *status) {
|
|||
}
|
||||
}
|
||||
|
||||
static uint32_t event_to_x11_button(uint32_t event) {
|
||||
switch (event) {
|
||||
case BTN_LEFT:
|
||||
return 1;
|
||||
case BTN_MIDDLE:
|
||||
return 2;
|
||||
case BTN_RIGHT:
|
||||
return 3;
|
||||
case SWAY_SCROLL_UP:
|
||||
return 4;
|
||||
case SWAY_SCROLL_DOWN:
|
||||
return 5;
|
||||
case SWAY_SCROLL_LEFT:
|
||||
return 6;
|
||||
case SWAY_SCROLL_RIGHT:
|
||||
return 7;
|
||||
case BTN_SIDE:
|
||||
return 8;
|
||||
case BTN_EXTRA:
|
||||
return 9;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
|
||||
struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h,
|
||||
uint32_t button) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,31 @@ void free_hotspots(struct wl_list *list) {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t event_to_x11_button(uint32_t event) {
|
||||
switch (event) {
|
||||
case BTN_LEFT:
|
||||
return 1;
|
||||
case BTN_MIDDLE:
|
||||
return 2;
|
||||
case BTN_RIGHT:
|
||||
return 3;
|
||||
case SWAY_SCROLL_UP:
|
||||
return 4;
|
||||
case SWAY_SCROLL_DOWN:
|
||||
return 5;
|
||||
case SWAY_SCROLL_LEFT:
|
||||
return 6;
|
||||
case SWAY_SCROLL_RIGHT:
|
||||
return 7;
|
||||
case BTN_SIDE:
|
||||
return 8;
|
||||
case BTN_EXTRA:
|
||||
return 9;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t wl_axis_to_button(uint32_t axis, wl_fixed_t value) {
|
||||
bool negative = wl_fixed_to_double(value) < 0;
|
||||
switch (axis) {
|
||||
|
|
|
|||
|
|
@ -313,11 +313,13 @@ static bool ipc_parse_config(
|
|||
int length = json_object_array_length(tray_bindings);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
json_object *bind = json_object_array_get_idx(tray_bindings, i);
|
||||
json_object *button, *command;
|
||||
json_object_object_get_ex(bind, "input_code", &button);
|
||||
json_object_object_get_ex(bind, "command", &command);
|
||||
config->tray_bindings[json_object_get_int(button)] =
|
||||
strdup(json_object_get_string(command));
|
||||
struct tray_binding *binding =
|
||||
calloc(1, sizeof(struct tray_binding));
|
||||
binding->button = json_object_get_int(
|
||||
json_object_object_get(bind, "event_code"));
|
||||
binding->command = strdup(json_object_get_string(
|
||||
json_object_object_get(bind, "command")));
|
||||
wl_list_insert(&config->tray_bindings, &binding->link);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -301,8 +301,15 @@ void destroy_sni(struct swaybar_sni *sni) {
|
|||
}
|
||||
|
||||
static void handle_click(struct swaybar_sni *sni, int x, int y,
|
||||
enum x11_button button, int delta) {
|
||||
const char *method = sni->tray->bar->config->tray_bindings[button];
|
||||
uint32_t button, int delta) {
|
||||
const char *method = NULL;
|
||||
struct tray_binding *binding = NULL;
|
||||
wl_list_for_each(binding, &sni->tray->bar->config->tray_bindings, link) {
|
||||
if (binding->button == button) {
|
||||
method = binding->command;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!method) {
|
||||
static const char *default_bindings[10] = {
|
||||
"nop",
|
||||
|
|
@ -316,7 +323,7 @@ static void handle_click(struct swaybar_sni *sni, int x, int y,
|
|||
"nop",
|
||||
"nop"
|
||||
};
|
||||
method = default_bindings[button];
|
||||
method = default_bindings[event_to_x11_button(button)];
|
||||
}
|
||||
if (strcmp(method, "nop") == 0) {
|
||||
return;
|
||||
|
|
@ -345,7 +352,7 @@ static int cmp_sni_id(const void *item, const void *cmp_to) {
|
|||
|
||||
static enum hotspot_event_handling icon_hotspot_callback(
|
||||
struct swaybar_output *output, struct swaybar_hotspot *hotspot,
|
||||
int x, int y, enum x11_button button, void *data) {
|
||||
int x, int y, uint32_t button, void *data) {
|
||||
wlr_log(WLR_DEBUG, "Clicked on %s", (char *)data);
|
||||
|
||||
struct swaybar_tray *tray = output->bar->tray;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue