workspace: Use AppIcon.app to check action-support by the drag source
`AppIcon.shellWorkspaceLaunch()` can easily be replaced by checking for `AppIcon.app` and calling `AppIcon.app.open_new_window()` directly. For compatibility and to prevent breaking extensions implementing the function, keep supporting the `shellWorkspaceLaunch` API in AppIcon while logging a deprecation warning. Also keep supporting the API on drag sources (without deprecating it) to allow extensions to define custom actions on their drag sources. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/121
This commit is contained in:
parent
e0947b01bd
commit
942758bb30
@ -2222,6 +2222,9 @@ var AppIcon = class AppIcon {
|
||||
}
|
||||
|
||||
shellWorkspaceLaunch(params) {
|
||||
let { stack } = new Error();
|
||||
log(`shellWorkspaceLaunch is deprecated, use app.open_new_window() instead\n${stack}`);
|
||||
|
||||
params = Params.parse(params, { workspace: -1,
|
||||
timestamp: 0 });
|
||||
|
||||
|
@ -1994,13 +1994,20 @@ var Workspace = class {
|
||||
handleDragOver(source, _actor, _x, _y, _time) {
|
||||
if (source.realWindow && !this._isMyWindow(source.realWindow))
|
||||
return DND.DragMotionResult.MOVE_DROP;
|
||||
if (source.shellWorkspaceLaunch)
|
||||
if (source.app)
|
||||
return DND.DragMotionResult.COPY_DROP;
|
||||
if (!source.app && source.shellWorkspaceLaunch)
|
||||
return DND.DragMotionResult.COPY_DROP;
|
||||
|
||||
return DND.DragMotionResult.CONTINUE;
|
||||
}
|
||||
|
||||
acceptDrop(source, actor, x, y, time) {
|
||||
let workspaceManager = global.workspace_manager;
|
||||
let workspaceIndex = this.metaWorkspace
|
||||
? this.metaWorkspace.index()
|
||||
: workspaceManager.get_active_workspace_index();
|
||||
|
||||
if (source.realWindow) {
|
||||
let win = source.realWindow;
|
||||
if (this._isMyWindow(win))
|
||||
@ -2022,12 +2029,15 @@ var Workspace = class {
|
||||
if (metaWindow.get_monitor() != this.monitorIndex)
|
||||
metaWindow.move_to_monitor(this.monitorIndex);
|
||||
|
||||
let workspaceManager = global.workspace_manager;
|
||||
let index = this.metaWorkspace ? this.metaWorkspace.index() : workspaceManager.get_active_workspace_index();
|
||||
metaWindow.change_workspace_by_index(index, false);
|
||||
metaWindow.change_workspace_by_index(workspaceIndex, false);
|
||||
return true;
|
||||
} else if (source.shellWorkspaceLaunch) {
|
||||
source.shellWorkspaceLaunch({ workspace: this.metaWorkspace ? this.metaWorkspace.index() : -1,
|
||||
} else if (source.app) {
|
||||
source.app.open_new_window(workspaceIndex);
|
||||
return true;
|
||||
} else if (!source.app && source.shellWorkspaceLaunch) {
|
||||
// While unused in our own drag sources, shellWorkspaceLaunch allows
|
||||
// extensions to define custom actions for their drag sources.
|
||||
source.shellWorkspaceLaunch({ workspace: workspaceIndex,
|
||||
timestamp: time });
|
||||
return true;
|
||||
}
|
||||
|
@ -572,7 +572,9 @@ var WorkspaceThumbnail = GObject.registerClass({
|
||||
|
||||
if (source.realWindow && !this._isMyWindow(source.realWindow))
|
||||
return DND.DragMotionResult.MOVE_DROP;
|
||||
if (source.shellWorkspaceLaunch)
|
||||
if (source.app)
|
||||
return DND.DragMotionResult.COPY_DROP;
|
||||
if (!source.app && source.shellWorkspaceLaunch)
|
||||
return DND.DragMotionResult.COPY_DROP;
|
||||
|
||||
return DND.DragMotionResult.CONTINUE;
|
||||
@ -597,8 +599,13 @@ var WorkspaceThumbnail = GObject.registerClass({
|
||||
|
||||
metaWindow.change_workspace_by_index(this.metaWorkspace.index(), false);
|
||||
return true;
|
||||
} else if (source.shellWorkspaceLaunch) {
|
||||
source.shellWorkspaceLaunch({ workspace: this.metaWorkspace ? this.metaWorkspace.index() : -1,
|
||||
} else if (source.app) {
|
||||
source.app.open_new_window(this.metaWorkspace.index());
|
||||
return true;
|
||||
} else if (!source.app && source.shellWorkspaceLaunch) {
|
||||
// While unused in our own drag sources, shellWorkspaceLaunch allows
|
||||
// extensions to define custom actions for their drag sources.
|
||||
source.shellWorkspaceLaunch({ workspace: this.metaWorkspace.index(),
|
||||
timestamp: time });
|
||||
return true;
|
||||
}
|
||||
@ -779,7 +786,10 @@ var ThumbnailsBox = GObject.registerClass({
|
||||
|
||||
// Draggable target interface
|
||||
handleDragOver(source, actor, x, y, time) {
|
||||
if (!source.realWindow && !source.shellWorkspaceLaunch && source != Main.xdndHandler)
|
||||
if (!source.realWindow &&
|
||||
!source.app &&
|
||||
(source.app || !source.shellWorkspaceLaunch) &&
|
||||
source != Main.xdndHandler)
|
||||
return DND.DragMotionResult.CONTINUE;
|
||||
|
||||
let canCreateWorkspaces = Meta.prefs_get_dynamic_workspaces();
|
||||
@ -836,7 +846,9 @@ var ThumbnailsBox = GObject.registerClass({
|
||||
if (this._dropWorkspace != -1) {
|
||||
return this._thumbnails[this._dropWorkspace].acceptDropInternal(source, time);
|
||||
} else if (this._dropPlaceholderPos != -1) {
|
||||
if (!source.realWindow && !source.shellWorkspaceLaunch)
|
||||
if (!source.realWindow &&
|
||||
!source.app &&
|
||||
(source.app || !source.shellWorkspaceLaunch))
|
||||
return false;
|
||||
|
||||
let isWindow = !!source.realWindow;
|
||||
@ -853,9 +865,16 @@ var ThumbnailsBox = GObject.registerClass({
|
||||
if (source.metaWindow.get_monitor() != thumbMonitor)
|
||||
source.metaWindow.move_to_monitor(thumbMonitor);
|
||||
source.metaWindow.change_workspace_by_index(newWorkspaceIndex, true);
|
||||
} else if (source.shellWorkspaceLaunch) {
|
||||
} else if (source.app) {
|
||||
source.app.open_new_window(newWorkspaceIndex);
|
||||
} else if (!source.app && source.shellWorkspaceLaunch) {
|
||||
// While unused in our own drag sources, shellWorkspaceLaunch allows
|
||||
// extensions to define custom actions for their drag sources.
|
||||
source.shellWorkspaceLaunch({ workspace: newWorkspaceIndex,
|
||||
timestamp: time });
|
||||
}
|
||||
|
||||
if (source.app || (!source.app && source.shellWorkspaceLaunch)) {
|
||||
// This new workspace will be automatically removed if the application fails
|
||||
// to open its first window within some time, as tracked by Shell.WindowTracker.
|
||||
// Here, we only add a very brief timeout to avoid the _immediate_ removal of the
|
||||
|
Loading…
Reference in New Issue
Block a user