diff options
author | Bad Diode <bd@badd10de.dev> | 2022-10-12 15:05:06 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-10-12 15:05:06 +0200 |
commit | 241ee5cfb2d8d81ea9f31648f4c1f05c6a5006ff (patch) | |
tree | 9c61eb52898e3bcbf943b042b5f6821623716028 | |
parent | 457efc07cd5989e947bc2f05feef9173fbde541a (diff) | |
download | uxnfb-241ee5cfb2d8d81ea9f31648f4c1f05c6a5006ff.tar.gz uxnfb-241ee5cfb2d8d81ea9f31648f4c1f05c6a5006ff.zip |
[WIP] Add exit handler to home button
-rw-r--r-- | src/main.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -60,6 +60,7 @@ typedef struct Mouse { | |||
60 | typedef struct Input { | 60 | typedef struct Input { |
61 | int kbd_fd; | 61 | int kbd_fd; |
62 | int mouse_fd; | 62 | int mouse_fd; |
63 | int home_fd; | ||
63 | char map[KEY_MAX / 8 + 1]; | 64 | char map[KEY_MAX / 8 + 1]; |
64 | u8 controller; | 65 | u8 controller; |
65 | Mouse mouse; | 66 | Mouse mouse; |
@@ -84,6 +85,12 @@ init_input(void) { | |||
84 | fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno)); | 85 | fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno)); |
85 | } | 86 | } |
86 | 87 | ||
88 | // NOTE: nook home and power buttons event handler. | ||
89 | in.home_fd = open("/dev/input/event1", O_RDONLY | O_NONBLOCK); | ||
90 | if (in.home_fd == -1) { | ||
91 | fprintf(stderr, "error: couldn't open home buttons %s: %s.\n", "/dev/input/event1", strerror(errno)); | ||
92 | } | ||
93 | |||
87 | // in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK); | 94 | // in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK); |
88 | in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK); | 95 | in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK); |
89 | if (in.mouse_fd == -1) { | 96 | if (in.mouse_fd == -1) { |
@@ -162,9 +169,24 @@ poll_mouse(void) { | |||
162 | } | 169 | } |
163 | 170 | ||
164 | void | 171 | void |
172 | poll_home(void) { | ||
173 | if (in.home_fd == -1) { | ||
174 | return; | ||
175 | } | ||
176 | |||
177 | struct input_event event; | ||
178 | if (read(in.home_fd, &event, sizeof(event)) != -1) { | ||
179 | if (event.code == 102 && event.value == 1) { | ||
180 | exit(EXIT_SUCCESS); | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | void | ||
165 | poll_input(void) { | 186 | poll_input(void) { |
166 | poll_keyboard(); | 187 | poll_keyboard(); |
167 | poll_mouse(); | 188 | poll_mouse(); |
189 | poll_home(); | ||
168 | } | 190 | } |
169 | 191 | ||
170 | void | 192 | void |