Add Main.activateWindow() to remove some duplication

This commit is contained in:
Dan Winship 2009-09-21 16:29:37 -04:00
parent 110ef17e2d
commit 24d42adc04
2 changed files with 27 additions and 16 deletions

View File

@ -329,3 +329,25 @@ function currentTime() {
return Clutter.get_current_event_time(); return Clutter.get_current_event_time();
} }
/**
* activateWindow:
* @window: the Meta.Window to activate
* @time: (optional) current event time
*
* Activates @window, switching to its workspace first if necessary
*/
function activateWindow(window, time) {
let activeWorkspaceNum = global.screen.get_active_workspace_index();
let windowWorkspaceNum = window.get_workspace().index();
if (!time)
time = currentTime();
if (windowWorkspaceNum != activeWorkspaceNum) {
let workspace = global.screen.get_workspace_by_index(windowWorkspaceNum);
workspace.activate_with_focus(window, time);
} else {
window.activate(time);
}
}

View File

@ -1409,21 +1409,6 @@ Workspaces.prototype = {
} }
}, },
_activateWindowInternal: function (metaWindow, time) {
let activeWorkspaceNum = global.screen.get_active_workspace_index();
let windowWorkspaceNum = metaWindow.get_workspace().index();
let clone = this._lookupCloneForMetaWindow (metaWindow);
clone.actor.raise_top();
if (windowWorkspaceNum != activeWorkspaceNum) {
let workspace = global.screen.get_workspace_by_index(windowWorkspaceNum);
workspace.activate_with_focus(metaWindow, time);
} else {
metaWindow.activate(time);
}
},
/** /**
* activateWindowFromOverview: * activateWindowFromOverview:
* @metaWindow: A #MetaWindow * @metaWindow: A #MetaWindow
@ -1436,7 +1421,11 @@ Workspaces.prototype = {
if (this._windowSelectionAppId != null) { if (this._windowSelectionAppId != null) {
this._clearApplicationWindowSelection(false); this._clearApplicationWindowSelection(false);
} }
this._activateWindowInternal(metaWindow, time);
let clone = this._lookupCloneForMetaWindow (metaWindow);
clone.actor.raise_top();
Main.activateWindow(metaWindow, time);
Main.overview.hide(); Main.overview.hide();
}, },