From 2a3c62b4d28ec7a69473e9c18c42f1ed26c74bbf Mon Sep 17 00:00:00 2001 From: Ryan Walklin Date: Wed, 14 Nov 2018 23:24:55 +0000 Subject: [WIP][DONTMERGE]Add support for libinput_switch input devices These are used primarily by laptops to signal the state of the lid (open/closed) and tablet mode if supported, based on ACPI events. --- rootston/config.c | 8 ++++++++ rootston/input.c | 2 ++ rootston/seat.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) (limited to 'rootston') diff --git a/rootston/config.c b/rootston/config.c index 119a9e2c..53b3718f 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -201,6 +201,11 @@ 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* command) { + wlr_log(WLR_DEBUG, "config switch %s: %s", switch_name, command); +} + static void config_handle_cursor(struct roots_config *config, const char *seat_name, const char *name, const char *value) { struct roots_cursor_config *cc; @@ -436,6 +441,8 @@ static int config_ini_handler(void *user, const char *section, const char *name, config_handle_keyboard(config, device_name, name, value); } else if (strcmp(section, "bindings") == 0) { add_binding_config(&config->bindings, name, value); + } else if (strcmp(section, "switches") == 0) { + add_switch_config(&config->bindings, name, value); } else { wlr_log(WLR_ERROR, "got unknown config section: %s", section); } @@ -456,6 +463,7 @@ struct roots_config *roots_config_create_from_args(int argc, char *argv[]) { wl_list_init(&config->keyboards); wl_list_init(&config->cursors); wl_list_init(&config->bindings); + wl_list_init(&config->switches); int c; unsigned int log_verbosity = WLR_DEBUG; diff --git a/rootston/input.c b/rootston/input.c index 7b4001b3..a863b919 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -23,6 +23,8 @@ static const char *device_type(enum wlr_input_device_type type) { return "keyboard"; case WLR_INPUT_DEVICE_POINTER: return "pointer"; + case WLR_INPUT_DEVICE_SWITCH: + return "switch"; case WLR_INPUT_DEVICE_TOUCH: return "touch"; case WLR_INPUT_DEVICE_TABLET_TOOL: diff --git a/rootston/seat.c b/rootston/seat.c index e91278c5..101c4ebe 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -9,6 +9,7 @@ #include #include #include +#include "wlr/types/wlr_switch.h" #include #include #include @@ -75,6 +76,16 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { roots_cursor_handle_axis(cursor, event); } +static void handle_switch_toggle(struct wl_listener *listener, void *data) { + struct roots_switch *lid_switch = + wl_container_of(listener, lid_switch, toggle); + 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); +} + static void handle_touch_down(struct wl_listener *listener, void *data) { struct roots_cursor *cursor = wl_container_of(listener, cursor, touch_down); @@ -587,6 +598,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { wl_list_init(&seat->touch); wl_list_init(&seat->tablets); wl_list_init(&seat->tablet_pads); + wl_list_init(&seat->switches); wl_list_init(&seat->views); wl_list_init(&seat->drag_icons); @@ -710,6 +722,39 @@ static void seat_add_pointer(struct roots_seat *seat, roots_seat_configure_cursor(seat); } +static void handle_switch_destroy(struct wl_listener *listener, void *data) { + struct roots_switch *lid_switch = + wl_container_of(listener, lid_switch, device_destroy); + struct roots_seat *seat = lid_switch->seat; + + wl_list_remove(&lid_switch->link); + wl_list_remove(&lid_switch->device_destroy.link); + free(lid_switch); + + seat_update_capabilities(seat); +} + +static void seat_add_switch(struct roots_seat *seat, + struct wlr_input_device *device) { + assert(device->type == WLR_INPUT_DEVICE_SWITCH); + struct roots_switch *lid_switch = calloc(1, sizeof(struct roots_switch)); + if (!lid_switch) { + wlr_log(WLR_ERROR, "could not allocate switch for seat"); + return; + } + + device->data = lid_switch; + lid_switch->device = device; + lid_switch->seat = seat; + wl_list_insert(&seat->switches, &lid_switch->link); + lid_switch->device_destroy.notify = handle_switch_destroy; + + lid_switch->toggle.notify = handle_switch_toggle; + wl_signal_add(&lid_switch->device->lid_switch->events.toggle, &lid_switch->toggle); + + wl_signal_add(&lid_switch->device->events.destroy, &lid_switch->device_destroy); +} + static void handle_touch_destroy(struct wl_listener *listener, void *data) { struct roots_pointer *touch = wl_container_of(listener, touch, device_destroy); @@ -953,6 +998,9 @@ void roots_seat_add_device(struct roots_seat *seat, case WLR_INPUT_DEVICE_POINTER: seat_add_pointer(seat, device); break; + case WLR_INPUT_DEVICE_SWITCH: + seat_add_switch(seat, device); + break; case WLR_INPUT_DEVICE_TOUCH: seat_add_touch(seat, device); break; -- cgit v1.2.3 From 2a7edfa24c973d3797aaa22e1a593cb1356eda94 Mon Sep 17 00:00:00 2001 From: Ryan Walklin Date: Sun, 25 Nov 2018 14:39:53 +0100 Subject: Factor out binding command execution to separate file --- include/rootston/bindings.h | 9 ++++ rootston/bindings.c | 109 ++++++++++++++++++++++++++++++++++++++++++++ rootston/keyboard.c | 103 +---------------------------------------- rootston/meson.build | 1 + 4 files changed, 121 insertions(+), 101 deletions(-) create mode 100644 include/rootston/bindings.h create mode 100644 rootston/bindings.c (limited to 'rootston') diff --git a/include/rootston/bindings.h b/include/rootston/bindings.h new file mode 100644 index 00000000..8ca23a9f --- /dev/null +++ b/include/rootston/bindings.h @@ -0,0 +1,9 @@ +#ifndef ROOTSTON_BINDINGS_H +#define ROOTSTON_BINDINGS_H + +#include "rootston/seat.h" +#include "rootston/input.h" + +void execute_binding_command (struct roots_seat *seat, struct roots_input *input, const char *command); + +#endif //ROOTSTON_BINDINGS_H diff --git a/rootston/bindings.c b/rootston/bindings.c new file mode 100644 index 00000000..d9813cbc --- /dev/null +++ b/rootston/bindings.c @@ -0,0 +1,109 @@ +#include +#include +#include +#include + +#include + +#include "rootston/bindings.h" + +static bool outputs_enabled = true; + +static const char *exec_prefix = "exec "; + +static void double_fork_shell_cmd(const char *shell_cmd) { + pid_t pid = fork(); + if (pid < 0) { + wlr_log(WLR_ERROR, "cannot execute binding command: fork() failed"); + return; + } + + if (pid == 0) { + pid = fork(); + if (pid == 0) { + execl("/bin/sh", "/bin/sh", "-c", shell_cmd, NULL); + _exit(EXIT_FAILURE); + } else { + _exit(pid == -1); + } + } + + int status; + while (waitpid(pid, &status, 0) < 0) { + if (errno == EINTR) { + continue; + } + wlr_log_errno(WLR_ERROR, "waitpid() on first child failed"); + return; + } + + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { + return; + } + + wlr_log(WLR_ERROR, "first child failed to fork command"); +} + +void execute_binding_command (struct roots_seat *seat, struct roots_input *input, const char *command) { + if (strcmp(command, "exit") == 0) { + wl_display_terminate(input->server->wl_display); + } else if (strcmp(command, "close") == 0) { + struct roots_view *focus = roots_seat_get_focus(seat); + if (focus != NULL) { + view_close(focus); + } + } else if (strcmp(command, "fullscreen") == 0) { + struct roots_view *focus = roots_seat_get_focus(seat); + if (focus != NULL) { + bool is_fullscreen = focus->fullscreen_output != NULL; + view_set_fullscreen(focus, !is_fullscreen, NULL); + } + } else if (strcmp(command, "next_window") == 0) { + roots_seat_cycle_focus(seat); + } else if (strcmp(command, "alpha") == 0) { + struct roots_view *focus = roots_seat_get_focus(seat); + if (focus != NULL) { + view_cycle_alpha(focus); + } + } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { + const char *shell_cmd = command + strlen(exec_prefix); + double_fork_shell_cmd(shell_cmd); + } else if (strcmp(command, "maximize") == 0) { + struct roots_view *focus = roots_seat_get_focus(seat); + if (focus != NULL) { + view_maximize(focus, !focus->maximized); + } + } else if (strcmp(command, "nop") == 0) { + wlr_log(WLR_DEBUG, "nop command"); + } else if (strcmp(command, "toggle_outputs") == 0) { + outputs_enabled = !outputs_enabled; + struct roots_output *output; + wl_list_for_each(output, &input->server->desktop->outputs, link) { + wlr_output_enable(output->wlr_output, outputs_enabled); + } + } else if (strcmp(command, "toggle_decoration_mode") == 0) { + struct roots_view *focus = roots_seat_get_focus(seat); + if (focus != NULL && focus->type == ROOTS_XDG_SHELL_VIEW) { + struct roots_xdg_toplevel_decoration *decoration = + focus->roots_xdg_surface->xdg_toplevel_decoration; + if (decoration != NULL) { + enum wlr_xdg_toplevel_decoration_v1_mode mode = + decoration->wlr_decoration->current_mode; + mode = mode == WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE + ? WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE + : WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; + wlr_xdg_toplevel_decoration_v1_set_mode( + decoration->wlr_decoration, mode); + } + } + } else if (strcmp(command, "break_pointer_constraint") == 0) { + struct wl_list *list = + &input->seats; + struct roots_seat *seat; + wl_list_for_each(seat, list, link) { + roots_cursor_constrain(seat->cursor, NULL, NAN, NAN); + } + } else { + wlr_log(WLR_ERROR, "unknown binding command: %s", command); + } +} diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 66c373cf..9d3fadf6 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -2,8 +2,6 @@ #include #include #include -#include -#include #include #include #include @@ -11,6 +9,7 @@ #include #include #include +#include "rootston/bindings.h" #include "rootston/input.h" #include "rootston/keyboard.h" #include "rootston/seat.h" @@ -85,107 +84,9 @@ static void pressed_keysyms_update(xkb_keysym_t *pressed_keysyms, } } -static void double_fork_shell_cmd(const char *shell_cmd) { - pid_t pid = fork(); - if (pid < 0) { - wlr_log(WLR_ERROR, "cannot execute binding command: fork() failed"); - return; - } - - if (pid == 0) { - pid = fork(); - if (pid == 0) { - execl("/bin/sh", "/bin/sh", "-c", shell_cmd, NULL); - _exit(EXIT_FAILURE); - } else { - _exit(pid == -1); - } - } - - int status; - while (waitpid(pid, &status, 0) < 0) { - if (errno == EINTR) { - continue; - } - wlr_log_errno(WLR_ERROR, "waitpid() on first child failed"); - return; - } - - if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { - return; - } - - wlr_log(WLR_ERROR, "first child failed to fork command"); -} - -static const char *exec_prefix = "exec "; - -static bool outputs_enabled = true; - static void keyboard_binding_execute(struct roots_keyboard *keyboard, const char *command) { - struct roots_seat *seat = keyboard->seat; - if (strcmp(command, "exit") == 0) { - wl_display_terminate(keyboard->input->server->wl_display); - } else if (strcmp(command, "close") == 0) { - struct roots_view *focus = roots_seat_get_focus(seat); - if (focus != NULL) { - view_close(focus); - } - } else if (strcmp(command, "fullscreen") == 0) { - struct roots_view *focus = roots_seat_get_focus(seat); - if (focus != NULL) { - bool is_fullscreen = focus->fullscreen_output != NULL; - view_set_fullscreen(focus, !is_fullscreen, NULL); - } - } else if (strcmp(command, "next_window") == 0) { - roots_seat_cycle_focus(seat); - } else if (strcmp(command, "alpha") == 0) { - struct roots_view *focus = roots_seat_get_focus(seat); - if (focus != NULL) { - view_cycle_alpha(focus); - } - } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { - const char *shell_cmd = command + strlen(exec_prefix); - double_fork_shell_cmd(shell_cmd); - } else if (strcmp(command, "maximize") == 0) { - struct roots_view *focus = roots_seat_get_focus(seat); - if (focus != NULL) { - view_maximize(focus, !focus->maximized); - } - } else if (strcmp(command, "nop") == 0) { - wlr_log(WLR_DEBUG, "nop command"); - } else if (strcmp(command, "toggle_outputs") == 0) { - outputs_enabled = !outputs_enabled; - struct roots_output *output; - wl_list_for_each(output, &keyboard->input->server->desktop->outputs, link) { - wlr_output_enable(output->wlr_output, outputs_enabled); - } - } else if (strcmp(command, "toggle_decoration_mode") == 0) { - struct roots_view *focus = roots_seat_get_focus(seat); - if (focus != NULL && focus->type == ROOTS_XDG_SHELL_VIEW) { - struct roots_xdg_toplevel_decoration *decoration = - focus->roots_xdg_surface->xdg_toplevel_decoration; - if (decoration != NULL) { - enum wlr_xdg_toplevel_decoration_v1_mode mode = - decoration->wlr_decoration->current_mode; - mode = mode == WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE - ? WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE - : WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; - wlr_xdg_toplevel_decoration_v1_set_mode( - decoration->wlr_decoration, mode); - } - } - } else if (strcmp(command, "break_pointer_constraint") == 0) { - struct wl_list *list = - &keyboard->input->seats; - struct roots_seat *seat; - wl_list_for_each(seat, list, link) { - roots_cursor_constrain(seat->cursor, NULL, NAN, NAN); - } - } else { - wlr_log(WLR_ERROR, "unknown binding command: %s", command); - } + execute_binding_command(keyboard->seat, keyboard->input, command); } /** diff --git a/rootston/meson.build b/rootston/meson.build index d41e00b0..8fefdcc4 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -1,4 +1,5 @@ sources = [ + 'bindings.c', 'config.c', 'cursor.c', 'desktop.c', -- cgit v1.2.3 From cc656670b29dbf53e7c56162daa3bf64fd2ddd14 Mon Sep 17 00:00:00 2001 From: Ryan Walklin Date: Sun, 25 Nov 2018 14:43:22 +0100 Subject: Remove redundant signal in seat.c --- rootston/seat.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'rootston') diff --git a/rootston/seat.c b/rootston/seat.c index 101c4ebe..33f27312 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -751,8 +751,6 @@ static void seat_add_switch(struct roots_seat *seat, lid_switch->toggle.notify = handle_switch_toggle; wl_signal_add(&lid_switch->device->lid_switch->events.toggle, &lid_switch->toggle); - - wl_signal_add(&lid_switch->device->events.destroy, &lid_switch->device_destroy); } static void handle_touch_destroy(struct wl_listener *listener, void *data) { -- cgit v1.2.3 From cd7a6daf48ec8f0203e6c7ec42d53806006653a5 Mon Sep 17 00:00:00 2001 From: Ryan Walklin Date: Mon, 26 Nov 2018 22:08:20 +0100 Subject: Update config struct, reduce complexity and correctly parse config.ini --- include/rootston/config.h | 2 +- rootston/config.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) (limited to 'rootston') diff --git a/include/rootston/config.h b/include/rootston/config.h index a95b8377..f8132269 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -67,9 +67,9 @@ struct roots_cursor_config { }; struct roots_switch_config { + char *name; enum wlr_switch_type switch_type; enum wlr_switch_state switch_state; - bool run_on_toggle; char *command; struct wl_list link; }; diff --git a/rootston/config.c b/rootston/config.c index 53b3718f..c3170c08 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -201,9 +201,32 @@ void add_binding_config(struct wl_list *bindings, const char* combination, } } -void add_switch_config(struct wl_list *switches, const char *switch_name, +void add_switch_config(struct wl_list *switches, const char *switch_name, const char *action, const char* command) { - wlr_log(WLR_DEBUG, "config switch %s: %s", switch_name, command); + wlr_log(WLR_DEBUG, "config switch %s: %s = %s", switch_name, action, command); + struct roots_switch_config *sc = calloc(1, sizeof(struct roots_switch_config)); + + if (strcmp(switch_name, "tablet") == 0) { + sc->switch_type = WLR_SWITCH_TYPE_TABLET_MODE; + } else if (strcmp(switch_name, "lid") == 0) { + sc->switch_type = WLR_SWITCH_TYPE_LID; + } else { + sc->switch_type = -1; + sc->name = strdup(switch_name); + } + if (strcmp(action, "on") == 0) { + sc->switch_state = WLR_SWITCH_STATE_ON; + } else if (strcmp(action, "off") == 0) { + sc->switch_state = WLR_SWITCH_STATE_OFF; + } else if (strcmp(action, "toggle") == 0) { + sc->switch_state = -1; + } else { + wlr_log(WLR_ERROR, "Invalid switch action %s/n for switch %s:%s", + action, switch_name, action); + } + sc->command = strdup(command); + wl_list_insert(switches, &sc->link); + wlr_log(WLR_DEBUG, "config %s: type %i state %i command %s", switch_name, sc->switch_type, sc->switch_state, sc->command); } static void config_handle_cursor(struct roots_config *config, @@ -285,6 +308,7 @@ static const char *output_prefix = "output:"; static const char *device_prefix = "device:"; static const char *keyboard_prefix = "keyboard:"; static const char *cursor_prefix = "cursor:"; +static const char *switch_prefix = "switch:"; static int config_ini_handler(void *user, const char *section, const char *name, const char *value) { @@ -441,8 +465,9 @@ static int config_ini_handler(void *user, const char *section, const char *name, config_handle_keyboard(config, device_name, name, value); } else if (strcmp(section, "bindings") == 0) { add_binding_config(&config->bindings, name, value); - } else if (strcmp(section, "switches") == 0) { - add_switch_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); } else { wlr_log(WLR_ERROR, "got unknown config section: %s", section); } -- cgit v1.2.3 From 62a9cf87fafdbc5f271ea1489f3d3f6bd7288b6e Mon Sep 17 00:00:00 2001 From: Ryan Walklin Date: Mon, 26 Nov 2018 21:11:56 +0000 Subject: Remove debug logs --- rootston/config.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'rootston') diff --git a/rootston/config.c b/rootston/config.c index c3170c08..addc9d24 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -203,7 +203,6 @@ 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, const char* command) { - wlr_log(WLR_DEBUG, "config switch %s: %s = %s", switch_name, action, command); struct roots_switch_config *sc = calloc(1, sizeof(struct roots_switch_config)); if (strcmp(switch_name, "tablet") == 0) { @@ -226,7 +225,6 @@ void add_switch_config(struct wl_list *switches, const char *switch_name, const } sc->command = strdup(command); wl_list_insert(switches, &sc->link); - wlr_log(WLR_DEBUG, "config %s: type %i state %i command %s", switch_name, sc->switch_type, sc->switch_state, sc->command); } static void config_handle_cursor(struct roots_config *config, -- cgit v1.2.3 From 810c7b700cfb381457ad1e5a07f184f4efdcc5d1 Mon Sep 17 00:00:00 2001 From: Ryan Walklin Date: Wed, 28 Nov 2018 20:03:42 +0000 Subject: Working switches in rootston: Factor out switch handling to separate file Add formal enum for toggle action Implement binding actions --- include/rootston/seat.h | 10 +--------- include/rootston/switch.h | 18 ++++++++++++++++++ include/wlr/types/wlr_switch.h | 3 ++- rootston/config.c | 7 ++++--- rootston/meson.build | 1 + rootston/seat.c | 4 +--- rootston/switch.c | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 include/rootston/switch.h create mode 100644 rootston/switch.c (limited to 'rootston') 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 + +#include + +#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); + } + } +} -- cgit v1.2.3 From 8f5ec5e2bb6ca0574dc9c6a292b9fac55d189d87 Mon Sep 17 00:00:00 2001 From: Ryan Walklin Date: Sat, 15 Dec 2018 14:57:12 +1100 Subject: Fix style nits --- include/rootston/bindings.h | 2 +- rootston/bindings.c | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'rootston') diff --git a/include/rootston/bindings.h b/include/rootston/bindings.h index 8ca23a9f..db38130b 100644 --- a/include/rootston/bindings.h +++ b/include/rootston/bindings.h @@ -4,6 +4,6 @@ #include "rootston/seat.h" #include "rootston/input.h" -void execute_binding_command (struct roots_seat *seat, struct roots_input *input, const char *command); +void execute_binding_command(struct roots_seat *seat, struct roots_input *input, const char *command); #endif //ROOTSTON_BINDINGS_H diff --git a/rootston/bindings.c b/rootston/bindings.c index d9813cbc..9fdbb33b 100644 --- a/rootston/bindings.c +++ b/rootston/bindings.c @@ -2,9 +2,7 @@ #include #include #include - #include - #include "rootston/bindings.h" static bool outputs_enabled = true; @@ -44,7 +42,8 @@ static void double_fork_shell_cmd(const char *shell_cmd) { wlr_log(WLR_ERROR, "first child failed to fork command"); } -void execute_binding_command (struct roots_seat *seat, struct roots_input *input, const char *command) { +void execute_binding_command(struct roots_seat *seat, + struct roots_input *input, const char *command) { if (strcmp(command, "exit") == 0) { wl_display_terminate(input->server->wl_display); } else if (strcmp(command, "close") == 0) { @@ -97,8 +96,7 @@ void execute_binding_command (struct roots_seat *seat, struct roots_input *input } } } else if (strcmp(command, "break_pointer_constraint") == 0) { - struct wl_list *list = - &input->seats; + struct wl_list *list = &input->seats; struct roots_seat *seat; wl_list_for_each(seat, list, link) { roots_cursor_constrain(seat->cursor, NULL, NAN, NAN); -- cgit v1.2.3 From 282fcd458cc8e6ecd757174fe7f10271c323f0e7 Mon Sep 17 00:00:00 2001 From: Ryan Walklin Date: Sat, 15 Dec 2018 14:57:25 +1100 Subject: Improve event matching logic --- rootston/switch.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'rootston') diff --git a/rootston/switch.c b/rootston/switch.c index 3ccaad6a..b480e054 100644 --- a/rootston/switch.c +++ b/rootston/switch.c @@ -15,19 +15,14 @@ void roots_switch_handle_toggle(struct roots_switch *lid_switch, 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 ((sc->name != NULL && strcmp(event->device->name, sc->name) != 0) && + (sc->name == NULL && event->switch_type != sc->switch_type)) { + continue; } - 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); + if (sc->switch_state != WLR_SWITCH_STATE_TOGGLE && + event->switch_state != sc->switch_state) { + continue; } + execute_binding_command(lid_switch->seat, lid_switch->seat->input, sc->command); } } -- cgit v1.2.3 From f8129ecbc5147a62d93d6bac5e61e5ce79d89667 Mon Sep 17 00:00:00 2001 From: Ryan Walklin Date: Sat, 15 Dec 2018 14:59:51 +1100 Subject: Remove unused variables --- rootston/switch.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'rootston') diff --git a/rootston/switch.c b/rootston/switch.c index b480e054..65c5e627 100644 --- a/rootston/switch.c +++ b/rootston/switch.c @@ -13,8 +13,6 @@ void roots_switch_handle_toggle(struct roots_switch *lid_switch, 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)) { continue; -- cgit v1.2.3