diff options
-rw-r--r-- | include/rootston/seat.h | 10 | ||||
-rw-r--r-- | include/rootston/switch.h | 18 | ||||
-rw-r--r-- | include/wlr/types/wlr_switch.h | 3 | ||||
-rw-r--r-- | rootston/config.c | 7 | ||||
-rw-r--r-- | rootston/meson.build | 1 | ||||
-rw-r--r-- | rootston/seat.c | 4 | ||||
-rw-r--r-- | rootston/switch.c | 33 |
7 files changed, 60 insertions, 16 deletions
diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 7e6b63bf..105ba3aa 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -5,6 +5,7 @@ #include "rootston/input.h" #include "rootston/keyboard.h" #include "rootston/layers.h" +#include "rootston/switch.h" #include "rootston/text_input.h" struct roots_seat { @@ -75,15 +76,6 @@ struct roots_pointer { struct wl_list link; }; -struct roots_switch { - struct roots_seat *seat; - struct wlr_input_device *device; - struct wl_listener device_destroy; - - struct wl_listener toggle; - struct wl_list link; -}; - struct roots_touch { struct roots_seat *seat; struct wlr_input_device *device; diff --git a/include/rootston/switch.h b/include/rootston/switch.h new file mode 100644 index 00000000..28197774 --- /dev/null +++ b/include/rootston/switch.h @@ -0,0 +1,18 @@ +#ifndef ROOTSTON_SWITCH_H +#define ROOTSTON_SWITCH_H + +#include "rootston/input.h" + +struct roots_switch { + struct roots_seat *seat; + struct wlr_input_device *device; + struct wl_listener device_destroy; + + struct wl_listener toggle; + struct wl_list link; +}; + +void roots_switch_handle_toggle(struct roots_switch *lid_switch, + struct wlr_event_switch_toggle *event); + +#endif // ROOTSTON_SWITCH_H diff --git a/include/wlr/types/wlr_switch.h b/include/wlr/types/wlr_switch.h index 52b631b5..df1c8579 100644 --- a/include/wlr/types/wlr_switch.h +++ b/include/wlr/types/wlr_switch.h @@ -33,7 +33,8 @@ enum wlr_switch_type { enum wlr_switch_state { WLR_SWITCH_STATE_OFF = 0, - WLR_SWITCH_STATE_ON = 1, + WLR_SWITCH_STATE_ON, + WLR_SWITCH_STATE_TOGGLE }; struct wlr_event_switch_toggle { diff --git a/rootston/config.c b/rootston/config.c index addc9d24..198aaba6 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -201,7 +201,7 @@ void add_binding_config(struct wl_list *bindings, const char* combination, } } -void add_switch_config(struct wl_list *switches, const char *switch_name, const char *action, +void add_switch_config(struct wl_list *switches, const char *switch_name, const char *action, const char* command) { struct roots_switch_config *sc = calloc(1, sizeof(struct roots_switch_config)); @@ -218,10 +218,11 @@ void add_switch_config(struct wl_list *switches, const char *switch_name, const } else if (strcmp(action, "off") == 0) { sc->switch_state = WLR_SWITCH_STATE_OFF; } else if (strcmp(action, "toggle") == 0) { - sc->switch_state = -1; + sc->switch_state = WLR_SWITCH_STATE_TOGGLE; } else { wlr_log(WLR_ERROR, "Invalid switch action %s/n for switch %s:%s", action, switch_name, action); + return; } sc->command = strdup(command); wl_list_insert(switches, &sc->link); @@ -465,7 +466,7 @@ static int config_ini_handler(void *user, const char *section, const char *name, add_binding_config(&config->bindings, name, value); } else if (strncmp(switch_prefix, section, strlen(switch_prefix)) == 0) { const char *switch_name = section + strlen(switch_prefix); - add_switch_config(&config->bindings, switch_name, name, value); + add_switch_config(&config->switches, switch_name, name, value); } else { wlr_log(WLR_ERROR, "got unknown config section: %s", section); } diff --git a/rootston/meson.build b/rootston/meson.build index 8fefdcc4..db90a508 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -10,6 +10,7 @@ sources = [ 'main.c', 'output.c', 'seat.c', + 'switch.c', 'text_input.c', 'virtual_keyboard.c', 'wl_shell.c', diff --git a/rootston/seat.c b/rootston/seat.c index 33f27312..dda2f8df 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -82,8 +82,7 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = lid_switch->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, lid_switch->seat->seat); struct wlr_event_switch_toggle *event = data; - wlr_log(WLR_DEBUG, "Switch event %s: type %i state %i", event->device->name, event->switch_type, event->switch_state); - //roots_switch_handle_toggle(lid_switch, event); + roots_switch_handle_toggle(lid_switch, event); } static void handle_touch_down(struct wl_listener *listener, void *data) { @@ -742,7 +741,6 @@ static void seat_add_switch(struct roots_seat *seat, wlr_log(WLR_ERROR, "could not allocate switch for seat"); return; } - device->data = lid_switch; lid_switch->device = device; lid_switch->seat = seat; diff --git a/rootston/switch.c b/rootston/switch.c new file mode 100644 index 00000000..3ccaad6a --- /dev/null +++ b/rootston/switch.c @@ -0,0 +1,33 @@ +#include <stdlib.h> + +#include <wlr/util/log.h> + +#include "rootston/bindings.h" +#include "rootston/config.h" +#include "rootston/input.h" +#include "rootston/seat.h" +#include "rootston/switch.h" + +void roots_switch_handle_toggle(struct roots_switch *lid_switch, + struct wlr_event_switch_toggle *event) { + struct wl_list *bound_switches = &lid_switch->seat->input->server->config->switches; + struct roots_switch_config *sc; + wl_list_for_each(sc, bound_switches, link) { + bool device_match = false; + bool state_match = false; + if ((sc->name != NULL && strcmp(event->device->name, sc->name) == 0) || + (sc->name == NULL && event->switch_type == sc->switch_type)) { + device_match = true; + } + if (!device_match) { + break; + } + if (sc->switch_state == WLR_SWITCH_STATE_TOGGLE || + event->switch_state == sc->switch_state) { + state_match = true; + } + if (device_match && state_match) { + execute_binding_command(lid_switch->seat, lid_switch->seat->input, sc->command); + } + } +} |