Skip to content

Commit

Permalink
Add drag-and-drop assist.
Browse files Browse the repository at this point in the history
Switch windows by dragging and holding item on dock.
Cycle windows if more than one. Launch app if pinned but not running.
Fixes issue #278
  • Loading branch information
Valent-in committed Apr 18, 2021
1 parent a081e41 commit 1e4ba0b
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,73 @@ var MyDash = GObject.registerClass({
}
});

let switchTimerId = { id: 0 };
let isDndTarget = false;
let globalDnd = global.backend.get_dnd();
let scale = St.ThemeContext.get_for_stage(Meta.get_backend().get_stage()).scale_factor;

// Detect dragging over icon (Wayland)
appIcon.actor.connect('motion-event', (obj, event) => {
let [modifier] = event.get_state_full();
let mask = Clutter.ModifierType.BUTTON1_MASK;

if ((modifier & mask) && !isDndTarget) {
isDndTarget = true;
switchTimerId = this._setWindowSwitchTimeout(appIcon);
}
});

appIcon.actor.connect('leave-event', () => {
resetTimer(switchTimerId);
isDndTarget = false;
});

globalDnd.connect('dnd-enter', () => {
resetTimer(switchTimerId);
isDndTarget = false;
});

globalDnd.connect('dnd-leave', () => {
resetTimer(switchTimerId);
isDndTarget = false;
});

// Detect dragging over icon (X11)
globalDnd.connect('dnd-position-change', (obj, x, y) => {
if (isCoordsInActor(x * scale, y * scale, this._scrollView) &&
isCoordsInActor(x * scale, y * scale, item)) {

if (isDndTarget)
return
isDndTarget = true;

switchTimerId = this._setWindowSwitchTimeout(appIcon);

this._ensureAppIconVisibilityTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT, 100, () => {
ensureActorVisibleInScrollView(this._scrollView, appIcon);
this._ensureAppIconVisibilityTimeoutId = 0;
return GLib.SOURCE_REMOVE;
});

} else {
resetTimer(switchTimerId);
isDndTarget = false;
}
});

function resetTimer(timerIdObj) {
if (timerIdObj.id > 0) {
GLib.source_remove(timerIdObj.id);
timerIdObj.id = 0;
}
}

function isCoordsInActor(x, y, actor) {
let [gotPos, lx, ly] = actor.transform_stage_point(x, y);
return gotPos && lx > 0 && lx < actor.width && ly > 0 && ly < actor.height;
}

// Override default AppIcon label_actor, now the
// accessible_name is set at DashItemContainer.setLabelText
appIcon.label_actor = null;
Expand All @@ -538,6 +605,40 @@ var MyDash = GObject.registerClass({
return item;
}

_setWindowSwitchTimeout(appIconObj) {
const windowSwitchTimeout = 1000;
let windows = appIconObj.getInterestingWindows();
let index = windows.length > 0 && windows[0].has_focus() ? 1 : 0;
let timerIdObj = { id: 0 };

timerIdObj.id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, windowSwitchTimeout, function timeoutHandler() {
if (windows.length > 1) {
if (windows[index])
Main.activateWindow(windows[index]);

if (++index < windows.length) {
timerIdObj.id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, windowSwitchTimeout, timeoutHandler);
} else {
timerIdObj.id = 0;
}
} else {
timerIdObj.id = 0;
let appIsRunning = appIconObj && appIconObj.app && appIconObj.app.state == Shell.AppState.RUNNING
&& windows.length > 0;

if (appIsRunning) {
appIconObj.activate();
} else {
appIconObj.launchNewWindow();
}
}

return GLib.SOURCE_REMOVE;
});

return timerIdObj;
}

/**
* Return an array with the "proper" appIcons currently in the dash
*/
Expand Down

0 comments on commit 1e4ba0b

Please sign in to comment.