Browse Source

Render windows as focused when they have menus, like we used to in python

K. Lange 2 years ago
parent
commit
5f7b7c9f38
5 changed files with 55 additions and 24 deletions
  1. 12 4
      apps/file-browser.c
  2. 12 4
      apps/help-browser.c
  3. 10 3
      apps/terminal.c
  4. 14 13
      base/usr/include/toaru/hashmap.h
  5. 7 0
      lib/hashmap.c

+ 12 - 4
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;

+ 12 - 4
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;

+ 10 - 3
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();
 					}
 				}

+ 14 - 13
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);
-
-unsigned int hashmap_string_hash(void * key);
-int hashmap_string_comp(void * a, void * b);
-void * hashmap_string_dupe(void * key);
+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);
+
+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);
 

+ 7 - 0
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;
+}