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

This commit is contained in:
K. Lange 2018-07-22 01:24:22 +09:00
parent c46861ef08
commit 5f7b7c9f38
5 changed files with 54 additions and 23 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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;
}