aboutsummaryrefslogtreecommitdiff
path: root/rootston/config.c
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-12-15 19:54:25 +0100
committerGitHub <noreply@github.com>2018-12-15 19:54:25 +0100
commit6d4bfa3226123e958ff2bdc4f226489cba49f84d (patch)
tree256c7c3ded68d4b95ed09f7a2fbfd5bc67dbcee9 /rootston/config.c
parent8a56b96c5516ee089b7561949aac4f83e5b94808 (diff)
parentf8129ecbc5147a62d93d6bac5e61e5ce79d89667 (diff)
Merge pull request #1377 from tokyovigilante/switch-events
Add support for libinput_switch input devices
Diffstat (limited to 'rootston/config.c')
-rw-r--r--rootston/config.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/rootston/config.c b/rootston/config.c
index 119a9e2c..198aaba6 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -201,6 +201,33 @@ 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) {
+ 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 = 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);
+}
+
static void config_handle_cursor(struct roots_config *config,
const char *seat_name, const char *name, const char *value) {
struct roots_cursor_config *cc;
@@ -280,6 +307,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) {
@@ -436,6 +464,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 (strncmp(switch_prefix, section, strlen(switch_prefix)) == 0) {
+ const char *switch_name = section + strlen(switch_prefix);
+ add_switch_config(&config->switches, switch_name, name, value);
} else {
wlr_log(WLR_ERROR, "got unknown config section: %s", section);
}
@@ -456,6 +487,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;