diff options
author | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-01-05 00:49:11 +0100 |
---|---|---|
committer | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-01-05 00:49:44 +0100 |
commit | 7727c9efbc105269befe06a5bb12d2019c52515e (patch) | |
tree | 14ae600a7fe97012c4a2a8bbd4e2d9abecc2e105 | |
parent | Merge pull request #432 from mikkeloscar/fix-sway-multikey (diff) | |
download | sway-7727c9efbc105269befe06a5bb12d2019c52515e.tar.gz sway-7727c9efbc105269befe06a5bb12d2019c52515e.tar.zst sway-7727c9efbc105269befe06a5bb12d2019c52515e.zip |
Detect bar modifier pressed/released
-rw-r--r-- | include/input_state.h | 20 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/handlers.c | 16 | ||||
-rw-r--r-- | sway/input_state.c | 24 |
4 files changed, 61 insertions, 1 deletions
diff --git a/include/input_state.h b/include/input_state.h index a1f238e1..79e27d91 100644 --- a/include/input_state.h +++ b/include/input_state.h | |||
@@ -60,6 +60,12 @@ extern struct pointer_state { | |||
60 | int mode; | 60 | int mode; |
61 | } pointer_state; | 61 | } pointer_state; |
62 | 62 | ||
63 | enum modifier_state { | ||
64 | MOD_STATE_UNCHANGED = 0, | ||
65 | MOD_STATE_PRESSED = 1, | ||
66 | MOD_STATE_RELEASED = 2 | ||
67 | }; | ||
68 | |||
63 | void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); | 69 | void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); |
64 | void center_pointer_on(swayc_t *view); | 70 | void center_pointer_on(swayc_t *view); |
65 | 71 | ||
@@ -75,5 +81,19 @@ void pointer_mode_reset(void); | |||
75 | 81 | ||
76 | void input_init(void); | 82 | void input_init(void); |
77 | 83 | ||
84 | /** | ||
85 | * Check if state of mod changed from current state to new_state. | ||
86 | * | ||
87 | * Returns MOD_STATE_UNCHANGED if the state didn't change, MOD_STATE_PRESSED if | ||
88 | * the state changed to pressed and MOD_STATE_RELEASED if the state changed to | ||
89 | * released. | ||
90 | */ | ||
91 | uint32_t modifier_state_changed(uint32_t new_state, uint32_t mod); | ||
92 | |||
93 | /** | ||
94 | * Update the current modifiers state to new_state. | ||
95 | */ | ||
96 | void modifiers_state_update(uint32_t new_state); | ||
97 | |||
78 | #endif | 98 | #endif |
79 | 99 | ||
diff --git a/sway/config.c b/sway/config.c index 1973de02..87b1342d 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -695,7 +695,7 @@ struct bar_config *default_bar_config(void) { | |||
695 | bar = malloc(sizeof(struct bar_config)); | 695 | bar = malloc(sizeof(struct bar_config)); |
696 | bar->mode = strdup("dock"); | 696 | bar->mode = strdup("dock"); |
697 | bar->hidden_state = strdup("hide"); | 697 | bar->hidden_state = strdup("hide"); |
698 | bar->modifier = 0; | 698 | bar->modifier = WLC_BIT_MOD_LOGO; |
699 | bar->outputs = NULL; | 699 | bar->outputs = NULL; |
700 | bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | 700 | bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; |
701 | bar->bindings = create_list(); | 701 | bar->bindings = create_list(); |
diff --git a/sway/handlers.c b/sway/handlers.c index 6c6d0e60..5e523468 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -387,6 +387,22 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
387 | } | 387 | } |
388 | } | 388 | } |
389 | } | 389 | } |
390 | |||
391 | // handle bar modifiers pressed/released | ||
392 | struct bar_config *bar; | ||
393 | for (i = 0; i < config->bars->length; ++i) { | ||
394 | bar = config->bars->items[i]; | ||
395 | switch (modifier_state_changed(modifiers->mods, bar->modifier)) { | ||
396 | case MOD_STATE_PRESSED: | ||
397 | sway_log(L_INFO, "pressed!!!"); | ||
398 | break; | ||
399 | case MOD_STATE_RELEASED: | ||
400 | sway_log(L_INFO, "released!!!"); | ||
401 | break; | ||
402 | } | ||
403 | } | ||
404 | // update modifiers state | ||
405 | modifiers_state_update(modifiers->mods); | ||
390 | return EVENT_PASSTHROUGH; | 406 | return EVENT_PASSTHROUGH; |
391 | } | 407 | } |
392 | 408 | ||
diff --git a/sway/input_state.c b/sway/input_state.c index 58619d1f..2f40b6c2 100644 --- a/sway/input_state.c +++ b/sway/input_state.c | |||
@@ -22,12 +22,36 @@ struct key_state { | |||
22 | 22 | ||
23 | static struct key_state key_state_array[KEY_STATE_MAX_LENGTH]; | 23 | static struct key_state key_state_array[KEY_STATE_MAX_LENGTH]; |
24 | 24 | ||
25 | static uint32_t modifiers_state; | ||
26 | |||
25 | void input_init(void) { | 27 | void input_init(void) { |
26 | int i; | 28 | int i; |
27 | for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { | 29 | for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { |
28 | struct key_state none = { 0, 0, 0 }; | 30 | struct key_state none = { 0, 0, 0 }; |
29 | key_state_array[i] = none; | 31 | key_state_array[i] = none; |
30 | } | 32 | } |
33 | |||
34 | modifiers_state = 0; | ||
35 | } | ||
36 | |||
37 | uint32_t modifier_state_changed(uint32_t new_state, uint32_t mod) { | ||
38 | if ((new_state & mod) != 0) { // pressed | ||
39 | if ((modifiers_state & mod) != 0) { // already pressed | ||
40 | return MOD_STATE_UNCHANGED; | ||
41 | } else { // pressed | ||
42 | return MOD_STATE_PRESSED; | ||
43 | } | ||
44 | } else { // not pressed | ||
45 | if ((modifiers_state & mod) != 0) { // released | ||
46 | return MOD_STATE_RELEASED; | ||
47 | } else { // already released | ||
48 | return MOD_STATE_UNCHANGED; | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
53 | void modifiers_state_update(uint32_t new_state) { | ||
54 | modifiers_state = new_state; | ||
31 | } | 55 | } |
32 | 56 | ||
33 | static uint8_t find_key(uint32_t key_sym, uint32_t key_code, bool update) { | 57 | static uint8_t find_key(uint32_t key_sym, uint32_t key_code, bool update) { |