Skip to content

Commit

Permalink
Do not assume that workspace thumbnails are in a single row.
Browse files Browse the repository at this point in the history
The ThumbnailsBox base class only uses the x coordinate to test whether a point
is in a workspace. This is not sufficient when we may have multiple rows of
thumbnails.

The new _withinWorkspace function also uses the y coordinate. This requires
overriding handleDragOver as well so that it passes both the x and y coordinates
to _withinWorkspace.

Fixes mzur#177.
  • Loading branch information
mainland committed Oct 31, 2023
1 parent 7037a9e commit 62be78e
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions [email protected]/overview/thumbnailsBox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const Self = imports.misc.extensionUtils.getCurrentExtension();
const {Clutter, Meta, St} = imports.gi;

const DND = imports.ui.dnd;
const Main = imports.ui.main;
const GWorkspaceThumbnail = imports.ui.workspaceThumbnail;
const WorkspaceThumbnail = Self.imports.workspacePopup.workspaceThumbnail;
const Util = Self.imports.util;
Expand All @@ -11,6 +13,73 @@ var ThumbnailsBox = class {
constructor() {
this.originalThumbnailsBox = null;
this._overrideProperties = {
_withinWorkspace(x, y, index, rtl) {
const length = this._thumbnails.length;
const workspace = this._thumbnails[index];

let workspaceX1 = workspace.x + GWorkspaceThumbnail.WORKSPACE_CUT_SIZE;
let workspaceX2 = workspace.x + workspace.width - GWorkspaceThumbnail.WORKSPACE_CUT_SIZE;

if (index === length - 1) {
if (rtl)
workspaceX1 -= GWorkspaceThumbnail.WORKSPACE_CUT_SIZE;
else
workspaceX2 += GWorkspaceThumbnail.WORKSPACE_CUT_SIZE;
}

let workspaceY1 = workspace.y;
let workspaceY2 = workspace.y + workspace.height;

return x > workspaceX1 && x <= workspaceX2 && y > workspaceY1 && y <= workspaceY2;
},

// Draggable target interface
handleDragOver(source, actor, x, y, time) {
if (!source.metaWindow &&
(!source.app || !source.app.can_open_new_window()) &&
(source.app || !source.shellWorkspaceLaunch) &&
source != Main.xdndHandler)
return DND.DragMotionResult.CONTINUE;

const rtl = Clutter.get_default_text_direction() === Clutter.TextDirection.RTL;
let canCreateWorkspaces = Meta.prefs_get_dynamic_workspaces();
let spacing = this.get_theme_node().get_length('spacing');

this._dropWorkspace = -1;
let placeholderPos = -1;
let length = this._thumbnails.length;
for (let i = 0; i < length; i++) {
const index = rtl ? length - i - 1 : i;

if (canCreateWorkspaces && source !== Main.xdndHandler) {
const [targetStart, targetEnd] =
this._getPlaceholderTarget(index, spacing, rtl);

if (x > targetStart && x <= targetEnd) {
placeholderPos = index;
break;
}
}

if (this._withinWorkspace(x, y, index, rtl)) {
this._dropWorkspace = index;
break;
}
}

if (this._dropPlaceholderPos != placeholderPos) {
this._dropPlaceholderPos = placeholderPos;
this.queue_relayout();
}

if (this._dropWorkspace != -1)
return this._thumbnails[this._dropWorkspace].handleDragOverInternal(source, actor, time);
else if (this._dropPlaceholderPos != -1)
return source.metaWindow ? DND.DragMotionResult.MOVE_DROP : DND.DragMotionResult.COPY_DROP;
else
return DND.DragMotionResult.CONTINUE;
},

addThumbnails(start, count) {
const { ThumbnailState } = GWorkspaceThumbnail;
let workspaceManager = global.workspace_manager;
Expand Down

0 comments on commit 62be78e

Please sign in to comment.