|
4 | 4 | #include "settings.h" |
5 | 5 | #include "queues.h" |
6 | 6 | #include <stddef.h> |
| 7 | +#include <xkbcommon/xkbcommon.h> |
7 | 8 | #if defined(__linux__) || defined(__FreeBSD__) |
8 | 9 | #include <linux/input-event-codes.h> |
9 | 10 | #else |
@@ -55,6 +56,35 @@ struct notification *get_notification_at(const int y) { |
55 | 56 | return NULL; |
56 | 57 | } |
57 | 58 |
|
| 59 | +bool handle_builtin_menu_click(int x, int y) { |
| 60 | + if (!settings.built_in_menu) { |
| 61 | + return false; |
| 62 | + } |
| 63 | + |
| 64 | + struct notification *n = get_notification_at(y); |
| 65 | + if (n) { |
| 66 | + if (menu_get_count(n) > 0) { |
| 67 | + struct menu *m = menu_get_at(n, x, y); |
| 68 | + if (m) { |
| 69 | + // find the index of the menu item |
| 70 | + for (guint i = 0; i < n->menus->len; i++) { |
| 71 | + struct menu *button = &g_array_index(n->menus, struct menu, i); |
| 72 | + if (button == m) { |
| 73 | + // update the selection |
| 74 | + update_menu_selection(n, i); |
| 75 | + break; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + m->n = n; |
| 80 | + menu_activate(m); // activate the selected menu item |
| 81 | + return true; |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + return false; |
| 86 | +} |
| 87 | + |
58 | 88 | void input_handle_click(unsigned int button, bool button_down, int mouse_x, int mouse_y){ |
59 | 89 | LOG_I("Pointer handle button %i: %i", button, button_down); |
60 | 90 |
|
@@ -116,4 +146,59 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int |
116 | 146 |
|
117 | 147 | wake_up(); |
118 | 148 | } |
| 149 | + |
| 150 | +static bool handle_builtin_menu_key(unsigned int keysym, bool pressed) { |
| 151 | + if (!settings.built_in_menu || !settings.built_in_menu_key_navigation) { |
| 152 | + return false; |
| 153 | + } |
| 154 | + |
| 155 | + if (keysym == XKB_KEY_Right || |
| 156 | + keysym == XKB_KEY_Left || |
| 157 | + keysym == XKB_KEY_Up || |
| 158 | + keysym == XKB_KEY_Down |
| 159 | + ) { |
| 160 | + struct notification *n = queues_get_displayed_head(); |
| 161 | + if (n) { |
| 162 | + if (menu_get_count(n) > 0) { |
| 163 | + struct menu *m = menu_get_selected(n); |
| 164 | + m->n = n; |
| 165 | + if (m) { |
| 166 | + if (pressed) { |
| 167 | + menu_move_selection(n, keysym); |
| 168 | + } |
| 169 | + return true; |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + if (keysym == XKB_KEY_Return || |
| 176 | + keysym == XKB_KEY_KP_Enter |
| 177 | + ) { |
| 178 | + struct notification *n = queues_get_displayed_head(); |
| 179 | + if (n) { |
| 180 | + if (menu_get_count(n) > 0) { |
| 181 | + struct menu *m = menu_get_selected(n); |
| 182 | + m->n = n; |
| 183 | + if (m) { |
| 184 | + if (pressed) { |
| 185 | + // activate the selected menu item |
| 186 | + menu_activate(m); |
| 187 | + } |
| 188 | + return true; |
| 189 | + } |
| 190 | + } |
| 191 | + } |
| 192 | + } |
| 193 | + return false; |
| 194 | +} |
| 195 | + |
| 196 | +void input_handle_key(unsigned int keysym, bool pressed) { |
| 197 | + LOG_I("Key %s: %u", pressed ? "pressed" : "released", keysym); |
| 198 | + |
| 199 | + if (settings.built_in_menu && settings.built_in_menu_key_navigation) { |
| 200 | + if (handle_builtin_menu_key(keysym, pressed)) |
| 201 | + return; |
| 202 | + } |
| 203 | +} |
119 | 204 | /* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */ |
0 commit comments