/** * meta_workspace_activate_with_focus: * @workspace: a #MetaWorkspace * @focus_this: the #MetaWindow to be focused, or %NULL * @timestamp: timestamp for @focus_this * * Switches to @workspace and possibly activates the window @focus_this. * * The window @focus_this is activated by calling meta_window_activate() * which will unminimize it and transient parents, raise it and give it * the focus. * * If a window is currently being moved by the user, it will be * moved to @workspace. * * The advantage of calling this function instead of meta_workspace_activate() * followed by meta_window_activate() is that it happens as a unit, so * no other window gets focused first before @focus_this. */ void meta_workspace_activate_with_focus (MetaWorkspace *workspace, MetaWindow *focus_this, guint32 timestamp) { MetaWorkspace *old; MetaWindow *move_window; MetaScreen *screen; MetaDisplay *display; MetaCompositor *comp; MetaWorkspaceLayout layout1, layout2; gint num_workspaces, current_space, new_space; MetaMotionDirection direction; meta_verbose ("Activating workspace %d\n", meta_workspace_index (workspace)); if (workspace->screen->active_workspace == workspace) return; /* Free any cached pointers to the workspaces's edges from * a current resize or move operation */ meta_display_cleanup_edges (workspace->screen->display); if (workspace->screen->active_workspace) workspace_switch_sound (workspace->screen->active_workspace, workspace); /* Note that old can be NULL; e.g. when starting up */ old = workspace->screen->active_workspace; workspace->screen->active_workspace = workspace; meta_screen_set_active_workspace_hint (workspace->screen); /* If the "show desktop" mode is active for either the old workspace * or the new one *but not both*, then update the * _net_showing_desktop hint */ if (old && (old->showing_desktop ^ workspace->showing_desktop)) meta_screen_update_showing_desktop_hint (workspace->screen); if (old == NULL) return; move_window = NULL; if (workspace->screen->display->grab_op == META_GRAB_OP_MOVING || workspace->screen->display->grab_op == META_GRAB_OP_KEYBOARD_MOVING) move_window = workspace->screen->display->grab_window; if (move_window != NULL) { if (move_window->on_all_workspaces) move_window = NULL; /* don't move it after all */ /* We put the window on the new workspace, flip spaces, * then remove from old workspace, so the window * never gets unmapped and we maintain the button grab * on it. * * \bug This comment appears to be the reverse of what happens */ if (move_window && (move_window->workspace != workspace)) { meta_workspace_remove_window (old, move_window); meta_workspace_add_window (workspace, move_window); } } meta_workspace_queue_calc_showing (old); meta_workspace_queue_calc_showing (workspace); /* FIXME: Why do we need this?!? Isn't it handled in the lines above? */ if (move_window) /* Removes window from other spaces */ meta_window_change_workspace (move_window, workspace); /* * Notify the compositor that the active workspace is changing. */ screen = workspace->screen; display = meta_screen_get_display (screen); comp = meta_display_get_compositor (display); direction = 0; current_space = meta_workspace_index (old); new_space = meta_workspace_index (workspace); num_workspaces = meta_screen_get_n_workspaces (workspace->screen); meta_screen_calc_workspace_layout (workspace->screen, num_workspaces, current_space, &layout1); meta_screen_calc_workspace_layout (workspace->screen, num_workspaces, new_space, &layout2); if (meta_ui_get_direction() == META_UI_DIRECTION_RTL) { if (layout1.current_col > layout2.current_col) direction = META_MOTION_RIGHT; else if (layout1.current_col < layout2.current_col) direction = META_MOTION_LEFT; } else { if (layout1.current_col < layout2.current_col) direction = META_MOTION_RIGHT; else if (layout1.current_col > layout2.current_col) direction = META_MOTION_LEFT; } if (layout1.current_row < layout2.current_row) { if (!direction) direction = META_MOTION_DOWN; else if (direction == META_MOTION_RIGHT) direction = META_MOTION_DOWN_RIGHT; else direction = META_MOTION_DOWN_LEFT; } if (layout1.current_row > layout2.current_row) { if (!direction) direction = META_MOTION_UP; else if (direction == META_MOTION_RIGHT) direction = META_MOTION_UP_RIGHT; else direction = META_MOTION_UP_LEFT; } meta_screen_free_workspace_layout (&layout1); meta_screen_free_workspace_layout (&layout2); meta_compositor_switch_workspace (comp, screen, old, workspace, direction); /* This needs to be done after telling the compositor we are switching * workspaces since focusing a window will cause it to be immediately * shown and that would confuse the compositor if it didn't know we * were in a workspace switch. */ if (focus_this) { meta_window_activate (focus_this, timestamp); } else if (move_window) { meta_window_raise (move_window); } else { meta_topic (META_DEBUG_FOCUS, "Focusing default window on new workspace\n"); meta_workspace_focus_default_window (workspace, NULL, timestamp); } /* Emit switched signal from screen.c */ meta_screen_workspace_switched (screen, current_space, new_space, direction); }
static void moses_overview_dispose(GObject *object) { MosesOverview *overview = MOSES_OVERVIEW(object); MosesOverviewPrivate* priv = overview->priv; if (priv->disposed) return; priv->disposed = TRUE; g_clear_pointer(&priv->ov_head, g_object_unref); MetaScreen* screen = meta_plugin_get_screen(priv->plugin); ClutterActor* stage = meta_get_stage_for_screen(screen); ClutterActor* to_focus = NULL; if (priv->selected_actor) { to_focus = clutter_clone_get_source(CLUTTER_CLONE(priv->selected_actor)); } for (int i = 0; priv->clones && i < priv->clones->len; i++) { ClutterActor* clone = g_ptr_array_index(priv->clones, i); ClutterActor* orig = clutter_clone_get_source(CLUTTER_CLONE(clone)); clutter_actor_show(orig); // FIXME: maybe some actors had not been shown. clutter_actor_destroy(clone); } for (int i = 0; priv->badges && i < priv->badges->len; i++) { clutter_actor_destroy(CLUTTER_ACTOR(g_ptr_array_index(priv->badges, i))); } if (priv->background_actor) { clutter_actor_show(clutter_clone_get_source(CLUTTER_CLONE(priv->background_actor))); g_clear_pointer(&priv->background_actor, clutter_actor_destroy); } if (priv->modaled) { meta_plugin_end_modal(priv->plugin, clutter_get_current_event_time()); meta_enable_unredirect_for_screen(screen); if (priv->selected_workspace) { meta_workspace_activate(priv->selected_workspace, CLUTTER_CURRENT_TIME); MetaDisplay* display = meta_screen_get_display(screen); meta_compositor_switch_workspace(meta_display_get_compositor(display), meta_screen_get_active_workspace(screen), priv->selected_workspace, META_MOTION_DOWN); } else if (to_focus) { clutter_stage_set_key_focus(CLUTTER_STAGE(stage), to_focus); MetaWindowActor* actor = META_WINDOW_ACTOR(to_focus); MetaWindow* win = meta_window_actor_get_meta_window(actor); meta_window_raise(win); meta_window_focus(win, CLUTTER_CURRENT_TIME); } else if (priv->previous_focused) { if (!CLUTTER_IS_STAGE(priv->previous_focused)) { clutter_stage_set_key_focus(CLUTTER_STAGE(stage), priv->previous_focused); } } } G_OBJECT_CLASS(moses_overview_parent_class)->dispose(object); }