From 8eeffc12724890ee78571b31d0bac167386ceace Mon Sep 17 00:00:00 2001 From: "Mohammed Q. Hussain" Date: Sat, 29 Jun 2024 03:49:17 +0300 Subject: [PATCH 1/2] Minimize an activated window when its name is clicked from taskbar --- uspace/app/taskbar/types/wndlist.h | 2 ++ uspace/app/taskbar/wndlist.c | 14 ++++++++++-- uspace/lib/wndmgt/include/ipc/wndmgt.h | 1 + uspace/lib/wndmgt/include/wndmgt.h | 1 + uspace/lib/wndmgt/include/wndmgt_srv.h | 1 + uspace/lib/wndmgt/src/wndmgt.c | 22 +++++++++++++++++++ uspace/lib/wndmgt/src/wndmgt_srv.c | 21 ++++++++++++++++++ uspace/srv/hid/display/wmops.c | 30 ++++++++++++++++++++++++++ 8 files changed, 90 insertions(+), 2 deletions(-) diff --git a/uspace/app/taskbar/types/wndlist.h b/uspace/app/taskbar/types/wndlist.h index 704fbadddc..6fc5185088 100644 --- a/uspace/app/taskbar/types/wndlist.h +++ b/uspace/app/taskbar/types/wndlist.h @@ -58,6 +58,8 @@ typedef struct { ui_pbutton_t *button; /** Window button rectangle */ gfx_rect_t rect; + /** Window maximized **/ + bool maximized; } wndlist_entry_t; /** Taskbar window list */ diff --git a/uspace/app/taskbar/wndlist.c b/uspace/app/taskbar/wndlist.c index 178901c932..fba1899c6a 100644 --- a/uspace/app/taskbar/wndlist.c +++ b/uspace/app/taskbar/wndlist.c @@ -231,6 +231,7 @@ errno_t wndlist_append(wndlist_t *wndlist, sysarg_t wnd_id, list_append(&entry->lentries, &wndlist->entries); entry->visible = false; + entry->maximized = true; ui_pbutton_set_light(entry->button, active); @@ -721,8 +722,17 @@ static void wndlist_button_clicked(ui_pbutton_t *pbutton, void *arg) /* ID of device that clicked the button */ dev_id = entry->wndlist->ev_idev_id; - (void) wndmgt_activate_window(entry->wndlist->wndmgt, - dev_id, entry->wnd_id); + if (!entry->maximized) { + (void) wndmgt_activate_window(entry->wndlist->wndmgt, + dev_id, entry->wnd_id); + + entry->maximized = true; + } else { + (void) wndmgt_deactivate_window(entry->wndlist->wndmgt, + dev_id, entry->wnd_id); + + entry->maximized = false; + } } /** @} diff --git a/uspace/lib/wndmgt/include/ipc/wndmgt.h b/uspace/lib/wndmgt/include/ipc/wndmgt.h index bd0e815cdc..276641eef7 100644 --- a/uspace/lib/wndmgt/include/ipc/wndmgt.h +++ b/uspace/lib/wndmgt/include/ipc/wndmgt.h @@ -42,6 +42,7 @@ typedef enum { WNDMGT_GET_WINDOW_LIST, WNDMGT_GET_WINDOW_INFO, WNDMGT_ACTIVATE_WINDOW, + WNDMGT_DEACTIVATE_WINDOW, WNDMGT_CLOSE_WINDOW, WNDMGT_GET_EVENT, } wndmgt_request_t; diff --git a/uspace/lib/wndmgt/include/wndmgt.h b/uspace/lib/wndmgt/include/wndmgt.h index 511969d5df..ef22dfc854 100644 --- a/uspace/lib/wndmgt/include/wndmgt.h +++ b/uspace/lib/wndmgt/include/wndmgt.h @@ -47,6 +47,7 @@ extern errno_t wndmgt_get_window_info(wndmgt_t *, sysarg_t, wndmgt_window_info_t **); extern void wndmgt_free_window_info(wndmgt_window_info_t *); extern errno_t wndmgt_activate_window(wndmgt_t *, sysarg_t, sysarg_t); +extern errno_t wndmgt_deactivate_window(wndmgt_t *, sysarg_t, sysarg_t); extern errno_t wndmgt_close_window(wndmgt_t *, sysarg_t); #endif diff --git a/uspace/lib/wndmgt/include/wndmgt_srv.h b/uspace/lib/wndmgt/include/wndmgt_srv.h index 7603611edc..aa549a8a2c 100644 --- a/uspace/lib/wndmgt/include/wndmgt_srv.h +++ b/uspace/lib/wndmgt/include/wndmgt_srv.h @@ -52,6 +52,7 @@ struct wndmgt_ops { errno_t (*get_window_list)(void *, wndmgt_window_list_t **); errno_t (*get_window_info)(void *, sysarg_t, wndmgt_window_info_t **); errno_t (*activate_window)(void *, sysarg_t, sysarg_t); + errno_t (*deactivate_window)(void *, sysarg_t, sysarg_t); errno_t (*close_window)(void *, sysarg_t); errno_t (*get_event)(void *, wndmgt_ev_t *); }; diff --git a/uspace/lib/wndmgt/src/wndmgt.c b/uspace/lib/wndmgt/src/wndmgt.c index e3c2316e34..9e8e6a94d3 100644 --- a/uspace/lib/wndmgt/src/wndmgt.c +++ b/uspace/lib/wndmgt/src/wndmgt.c @@ -307,6 +307,28 @@ errno_t wndmgt_activate_window(wndmgt_t *wndmgt, sysarg_t dev_id, return rc; } +/** Deactivate (minimize) window. + * + * @param wndmgt Window management session + * @param dev_id ID of input device belonging to seat whose + * focus is to be switched + * @param wnd_id Window ID + * @return EOK on success or an error code + */ +errno_t wndmgt_deactivate_window(wndmgt_t *wndmgt, sysarg_t dev_id, + sysarg_t wnd_id) +{ + async_exch_t *exch; + errno_t rc; + + exch = async_exchange_begin(wndmgt->sess); + rc = async_req_2_0(exch, WNDMGT_DEACTIVATE_WINDOW, dev_id, + wnd_id); + + async_exchange_end(exch); + return rc; +} + /** Close window. * * @param wndmgt Window management diff --git a/uspace/lib/wndmgt/src/wndmgt_srv.c b/uspace/lib/wndmgt/src/wndmgt_srv.c index 492d33f3f0..32346acd8c 100644 --- a/uspace/lib/wndmgt/src/wndmgt_srv.c +++ b/uspace/lib/wndmgt/src/wndmgt_srv.c @@ -221,6 +221,24 @@ static void wndmgt_activate_window_srv(wndmgt_srv_t *srv, ipc_call_t *icall) async_answer_0(icall, rc); } +static void wndmgt_deactivate_window_srv(wndmgt_srv_t *srv, ipc_call_t *icall) +{ + sysarg_t dev_id; + sysarg_t wnd_id; + errno_t rc; + + dev_id = ipc_get_arg1(icall); + wnd_id = ipc_get_arg2(icall); + + if (srv->ops->deactivate_window == NULL) { + async_answer_0(icall, ENOTSUP); + return; + } + + rc = srv->ops->deactivate_window(srv->arg, dev_id, wnd_id); + async_answer_0(icall, rc); +} + static void wndmgt_close_window_srv(wndmgt_srv_t *srv, ipc_call_t *icall) { sysarg_t wnd_id; @@ -308,6 +326,9 @@ void wndmgt_conn(ipc_call_t *icall, wndmgt_srv_t *srv) case WNDMGT_ACTIVATE_WINDOW: wndmgt_activate_window_srv(srv, &call); break; + case WNDMGT_DEACTIVATE_WINDOW: + wndmgt_deactivate_window_srv(srv, &call); + break; case WNDMGT_CLOSE_WINDOW: wndmgt_close_window_srv(srv, &call); break; diff --git a/uspace/srv/hid/display/wmops.c b/uspace/srv/hid/display/wmops.c index 769ca77acd..bd390be637 100644 --- a/uspace/srv/hid/display/wmops.c +++ b/uspace/srv/hid/display/wmops.c @@ -46,6 +46,7 @@ static errno_t dispwm_get_window_list(void *, wndmgt_window_list_t **); static errno_t dispwm_get_window_info(void *, sysarg_t, wndmgt_window_info_t **); static errno_t dispwm_activate_window(void *, sysarg_t, sysarg_t); +static errno_t dispwm_deactivate_window(void *, sysarg_t, sysarg_t); static errno_t dispwm_close_window(void *, sysarg_t); static errno_t dispwm_get_event(void *, wndmgt_ev_t *); @@ -53,6 +54,7 @@ wndmgt_ops_t wndmgt_srv_ops = { .get_window_list = dispwm_get_window_list, .get_window_info = dispwm_get_window_info, .activate_window = dispwm_activate_window, + .deactivate_window = dispwm_deactivate_window, .close_window = dispwm_close_window, .get_event = dispwm_get_event, }; @@ -188,6 +190,34 @@ static errno_t dispwm_activate_window(void *arg, sysarg_t dev_id, return EOK; } +/** Deactivate (minimize) window. + * + * @param arg Argument (WM client) + * @param dev_id Input device ID + * @param wnd_id Window ID + * @return EOK on success or an error code + */ +static errno_t dispwm_deactivate_window(void *arg, sysarg_t dev_id, + sysarg_t wnd_id) +{ + ds_wmclient_t *wmclient = (ds_wmclient_t *)arg; + ds_window_t *wnd; + + log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_deactivate_window()"); + + ds_display_lock(wmclient->display); + wnd = ds_display_find_window(wmclient->display, wnd_id); + if (wnd == NULL) { + ds_display_unlock(wmclient->display); + return ENOENT; + } + + ds_window_minimize(wnd); + + ds_display_unlock(wmclient->display); + return EOK; +} + /** Close window. * * @param arg Argument (WM client) From 9a664b6dd10624fd8da3c9a74ecc75ab40ba4863 Mon Sep 17 00:00:00 2001 From: "Mohammed Q. Hussain" Date: Sat, 29 Jun 2024 21:44:23 +0300 Subject: [PATCH 2/2] Use windows flag to determine if the taskbar should minimize or maximize a window --- uspace/app/taskbar/types/wndlist.h | 2 -- uspace/app/taskbar/wndlist.c | 16 ++++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/uspace/app/taskbar/types/wndlist.h b/uspace/app/taskbar/types/wndlist.h index 6fc5185088..704fbadddc 100644 --- a/uspace/app/taskbar/types/wndlist.h +++ b/uspace/app/taskbar/types/wndlist.h @@ -58,8 +58,6 @@ typedef struct { ui_pbutton_t *button; /** Window button rectangle */ gfx_rect_t rect; - /** Window maximized **/ - bool maximized; } wndlist_entry_t; /** Taskbar window list */ diff --git a/uspace/app/taskbar/wndlist.c b/uspace/app/taskbar/wndlist.c index fba1899c6a..c23adb7e34 100644 --- a/uspace/app/taskbar/wndlist.c +++ b/uspace/app/taskbar/wndlist.c @@ -231,7 +231,6 @@ errno_t wndlist_append(wndlist_t *wndlist, sysarg_t wnd_id, list_append(&entry->lentries, &wndlist->entries); entry->visible = false; - entry->maximized = true; ui_pbutton_set_light(entry->button, active); @@ -717,21 +716,26 @@ errno_t wndlist_repaint(wndlist_t *wndlist) static void wndlist_button_clicked(ui_pbutton_t *pbutton, void *arg) { wndlist_entry_t *entry = (wndlist_entry_t *)arg; + wndmgt_window_info_t *winfo = NULL; sysarg_t dev_id; + errno_t rc; + bool minimized = false; /* ID of device that clicked the button */ dev_id = entry->wndlist->ev_idev_id; - if (!entry->maximized) { + rc = wndmgt_get_window_info(entry->wndlist->wndmgt, + entry->wnd_id, &winfo); + if (rc == EOK) { + minimized = (winfo->flags & wndf_minimized) == 0; + } + + if (!minimized) { (void) wndmgt_activate_window(entry->wndlist->wndmgt, dev_id, entry->wnd_id); - - entry->maximized = true; } else { (void) wndmgt_deactivate_window(entry->wndlist->wndmgt, dev_id, entry->wnd_id); - - entry->maximized = false; } }