From 5f7b7c9f3827d20a62335fd393e60a8dd758281a Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sun, 22 Jul 2018 01:24:22 +0900 Subject: [PATCH] Render windows as focused when they have menus, like we used to in python --- apps/file-browser.c | 16 ++++++++++++---- apps/help-browser.c | 16 ++++++++++++---- apps/terminal.c | 13 ++++++++++--- base/usr/include/toaru/hashmap.h | 25 +++++++++++++------------ lib/hashmap.c | 7 +++++++ 5 files changed, 54 insertions(+), 23 deletions(-) diff --git a/apps/file-browser.c b/apps/file-browser.c index 9658df5f..dbcef91c 100644 --- a/apps/file-browser.c +++ b/apps/file-browser.c @@ -124,7 +124,10 @@ int main(int argc, char * argv[]) { while (application_running) { yutani_msg_t * m = yutani_poll(yctx); while (m) { - menu_process_event(yctx, m); + if (menu_process_event(yctx, m)) { + main_window->focused = 0; + redraw_window(); + } switch (m->type) { case YUTANI_MSG_KEY_EVENT: { @@ -138,9 +141,14 @@ int main(int argc, char * argv[]) { { struct yutani_msg_window_focus_change * wf = (void*)m->data; yutani_window_t * win = hashmap_get(yctx->windows, (void*)wf->wid); - if (win) { - win->focused = wf->focused; - redraw_window(); + if (win == main_window) { + if (!hashmap_is_empty(menu_get_windows_hash())) { + win->focused = 1; + redraw_window(); + } else { + win->focused = wf->focused; + redraw_window(); + } } } break; diff --git a/apps/help-browser.c b/apps/help-browser.c index e8aa9e50..4e273756 100644 --- a/apps/help-browser.c +++ b/apps/help-browser.c @@ -115,7 +115,10 @@ int main(int argc, char * argv[]) { while (application_running) { yutani_msg_t * m = yutani_poll(yctx); while (m) { - menu_process_event(yctx, m); + if (menu_process_event(yctx, m)) { + main_window->focused = 0; + redraw_window(); + } switch (m->type) { case YUTANI_MSG_KEY_EVENT: { @@ -129,9 +132,14 @@ int main(int argc, char * argv[]) { { struct yutani_msg_window_focus_change * wf = (void*)m->data; yutani_window_t * win = hashmap_get(yctx->windows, (void*)wf->wid); - if (win) { - win->focused = wf->focused; - redraw_window(); + if (win == main_window) { + if (!hashmap_is_empty(menu_get_windows_hash())) { + win->focused = 1; + redraw_window(); + } else { + win->focused = wf->focused; + redraw_window(); + } } } break; diff --git a/apps/terminal.c b/apps/terminal.c index 154f4c51..ac261f53 100644 --- a/apps/terminal.c +++ b/apps/terminal.c @@ -1586,7 +1586,10 @@ void * handle_incoming(void) { yutani_msg_t * m = yutani_poll(yctx); while (m) { - menu_process_event(yctx, m); + if (menu_process_event(yctx, m)) { + window->focused = 0; + render_decors(); + } switch (m->type) { case YUTANI_MSG_KEY_EVENT: { @@ -1599,8 +1602,12 @@ void * handle_incoming(void) { { struct yutani_msg_window_focus_change * wf = (void*)m->data; yutani_window_t * win = hashmap_get(yctx->windows, (void*)wf->wid); - if (win) { - win->focused = wf->focused; + if (win == window) { + if (!hashmap_is_empty(menu_get_windows_hash())) { + win->focused = 1; + } else { + win->focused = wf->focused; + } render_decors(); } } diff --git a/base/usr/include/toaru/hashmap.h b/base/usr/include/toaru/hashmap.h index 686823e3..f896877e 100644 --- a/base/usr/include/toaru/hashmap.h +++ b/base/usr/include/toaru/hashmap.h @@ -32,17 +32,18 @@ typedef struct hashmap { hashmap_entry_t ** entries; } hashmap_t; -hashmap_t * hashmap_create(int size); -hashmap_t * hashmap_create_int(int size); -void * hashmap_set(hashmap_t * map, void * key, void * value); -void * hashmap_get(hashmap_t * map, void * key); -void * hashmap_remove(hashmap_t * map, void * key); -int hashmap_has(hashmap_t * map, void * key); -list_t * hashmap_keys(hashmap_t * map); -list_t * hashmap_values(hashmap_t * map); -void hashmap_free(hashmap_t * map); +extern hashmap_t * hashmap_create(int size); +extern hashmap_t * hashmap_create_int(int size); +extern void * hashmap_set(hashmap_t * map, void * key, void * value); +extern void * hashmap_get(hashmap_t * map, void * key); +extern void * hashmap_remove(hashmap_t * map, void * key); +extern int hashmap_has(hashmap_t * map, void * key); +extern list_t * hashmap_keys(hashmap_t * map); +extern list_t * hashmap_values(hashmap_t * map); +extern void hashmap_free(hashmap_t * map); -unsigned int hashmap_string_hash(void * key); -int hashmap_string_comp(void * a, void * b); -void * hashmap_string_dupe(void * key); +extern unsigned int hashmap_string_hash(void * key); +extern int hashmap_string_comp(void * a, void * b); +extern void * hashmap_string_dupe(void * key); +extern int hashmap_is_empty(hashmap_t * map); diff --git a/lib/hashmap.c b/lib/hashmap.c index 5d8d7309..5307efa3 100644 --- a/lib/hashmap.c +++ b/lib/hashmap.c @@ -217,3 +217,10 @@ void hashmap_free(hashmap_t * map) { } free(map->entries); } + +int hashmap_is_empty(hashmap_t * map) { + for (unsigned int i = 0; i < map->size; ++i) { + if (map->entries[i]) return 0; + } + return 1; +}