From ee1361fb6e874b90a62e6c8c0c47913bf91c3baf Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 3 Jan 2002 23:28:19 +0000 Subject: focus top window when switching to a new workspace 2002-01-03 Havoc Pennington * src/workspace.c (meta_workspace_activate): focus top window when switching to a new workspace * src/util.c (meta_topic): start putting verbose output in categories * src/window.c (meta_window_shade): focus frame after we queue the calc_showing so the maps/unmaps have already happened. * src/display.c (meta_display_get_current_time): add the "get time of current event" function and call it occasionally. * src/window.c (meta_window_free): if we have focus, call meta_screen_focus_top_window(). (meta_window_minimize): ditto (meta_window_delete): ditto * src/screen.c (meta_screen_ensure_tab_popup): fix memory leak - didn't free tab list (meta_screen_focus_top_window): new function to use when we unmap or unmanage a focused window * src/stack.c (meta_stack_get_default_focus_window): function used in meta_screen_focus_top_window --- src/stack.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/stack.c') diff --git a/src/stack.c b/src/stack.c index f586577..8f03971 100644 --- a/src/stack.c +++ b/src/stack.c @@ -869,8 +869,62 @@ meta_stack_get_below (MetaStack *stack, return link->next->data; else return find_prev_below_layer (stack, window->layer); +} + +MetaWindow* +meta_stack_get_default_focus_window (MetaStack *stack, + MetaWorkspace *workspace, + MetaWindow *not_this_one) +{ + /* FIXME if stack is frozen this is kind of broken. */ + + /* Find the topmost, focusable, mapped, window. */ + + MetaWindow *topmost_dock; + int layer = META_LAYER_LAST; + + topmost_dock = NULL; + + --layer; + while (layer >= 0) + { + GList *link; + + g_assert (layer >= 0 && layer < META_LAYER_LAST); + + /* top of this layer is at the front of the list */ + link = stack->layers[layer]; + + while (link) + { + MetaWindow *window = link->data; + + if (window && + window != not_this_one && + (workspace == NULL || + meta_window_visible_on_workspace (window, workspace))) + { + if (topmost_dock == NULL && + window->type == META_WINDOW_DOCK) + topmost_dock = window; + else + return window; + } + + link = link->next; + } + + --layer; + } + + /* If we didn't find a window to focus, we use the topmost dock. + * Note that we already tried the desktop - so we prefer focusing + * desktop to focusing the dock. + */ + return topmost_dock; } + #define IN_TAB_CHAIN(w) ((w)->type != META_WINDOW_DOCK && (w)->type != META_WINDOW_DESKTOP) #define GET_XWINDOW(stack, i) (g_array_index ((stack)->windows, \ Window, (i))) -- cgit v1.1