From d5aec183fdb5c75185f302f31c45e8021cd19813 Mon Sep 17 00:00:00 2001 From: Jimmy Huang Date: Mon, 11 Mar 2013 15:20:51 -0700 Subject: [PATCH] Added key binding to toggle task manager Added key binding to the Windows key (left meta key) to toggle the taskmanager, launching it or kill it if it's running, since there's no mechanism to bring up the task manager now. Signed-off-by: Jimmy Huang --- src/shell.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/src/shell.c b/src/shell.c index 2af7205..fe845bb 100644 --- a/src/shell.c +++ b/src/shell.c @@ -44,6 +44,8 @@ #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 #ifdef ENABLE_TIZEN #define DEFAULT_HOMESCREEN_NAME "org.tizen.menu-screen" +#define DEFAULT_TASKMANAGER_NAME "taskmgr" +#define DEFAULT_TASKMANAGER_PATH "/opt/apps/org.tizen.taskmgr/bin/taskmgr" #endif enum animation_type { @@ -133,6 +135,13 @@ struct desktop_shell { struct weston_process process; } screensaver; +#ifdef ENABLE_TIZEN + struct { + char *path; + struct weston_process process; + } taskmanager; +#endif + struct { struct wl_resource *binding; struct wl_list surfaces; @@ -379,6 +388,9 @@ shell_configuration(struct desktop_shell *shell) shell->screensaver.path = path; shell->screensaver.duration = duration; +#ifdef ENABLE_TIZEN + shell->taskmanager.path = DEFAULT_TASKMANAGER_PATH; +#endif shell->binding_modifier = get_modifier(modifier); shell->win_animation_type = get_animation_type(win_animation); shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1; @@ -2174,6 +2186,41 @@ terminate_screensaver(struct desktop_shell *shell) kill(shell->screensaver.process.pid, SIGTERM); } +#ifdef ENABLE_TIZEN +static void +handle_taskmanager_sigchld(struct weston_process *proc, int status) +{ + weston_log("taskmanager terminated\n"); + proc->pid = 0; +} + +static void +terminate_taskmanager(struct desktop_shell *shell) +{ + if (shell->taskmanager.process.pid == 0) + return; + + kill(shell->taskmanager.process.pid, SIGTERM); +} + +static void +launch_taskmanager(struct desktop_shell *shell) +{ + if (!shell->taskmanager.path) + return; + + if (shell->taskmanager.process.pid != 0) { + weston_log("old taskmanager still running\n"); + return; + } + + weston_client_launch(shell->compositor, + &shell->taskmanager.process, + shell->taskmanager.path, + handle_taskmanager_sigchld); +} +#endif + static void configure_static_surface(struct weston_surface *es, struct weston_layer *layer) { @@ -3746,6 +3793,53 @@ workspace_move_surface_down_binding(struct wl_seat *seat, uint32_t time, take_surface_to_workspace_by_seat(shell, seat, new_index); } +#ifdef ENABLE_TIZEN +/* + * Toggle the task manager if key is pressed + * This is a work around to launch the taskmanager since + * there's isn't a home button in the menu screen + */ +static void +taskmanager_key_binding(struct wl_seat *seat, uint32_t time, + uint32_t key, void *data) +{ + struct desktop_shell *shell = data; + struct weston_surface *surface = NULL; + struct weston_surface *taskmgr = NULL; + struct shell_surface *shsurf; + struct weston_seat *s; + + struct workspace *ws = get_current_workspace(shell); + struct weston_compositor *ec = shell->compositor; + + if (shell->taskmanager.process.pid != 0) { + wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { + shsurf = get_shell_surface(surface); + if (shsurf->title && !strcmp(DEFAULT_TASKMANAGER_NAME, shsurf->title)) { + taskmgr = surface; + break; + } + } + + /* + * if taskmanger is not in focus, just raise the surface + * otherwise kill it + */ + if (taskmgr && taskmgr != (struct weston_surface *) seat->keyboard->focus) { + wl_list_for_each(s, &ec->seat_list, link) { + activate(shell, surface, s); + } + } + else { + terminate_taskmanager(shell); + } + } + else { + launch_taskmanager(shell); + } +} +#endif + static void shell_destroy(struct wl_listener *listener, void *data) { @@ -3828,6 +3922,12 @@ shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) workspace_move_surface_down_binding, shell); +#ifdef ENABLE_TIZEN + /* Register key bindings to toggle task manager */ + weston_compositor_add_key_binding(ec, KEY_LEFTMETA, 0, + taskmanager_key_binding, shell); +#endif + /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ if (shell->workspaces.num > 1) { num_workspace_bindings = shell->workspaces.num; -- 2.7.4