Skip to content

Commit

Permalink
fix: drag and move app icon in the grouped window list
Browse files Browse the repository at this point in the history
This current appList in the appLists array isn't allways corresponding
the current workspace's index
  • Loading branch information
anaximeno committed Jul 2, 2023
1 parent 112d51a commit b93cf85
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions files/usr/share/cinnamon/applets/[email protected]/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class GroupedWindowListApplet extends Applet.Applet {
}

refreshCurrentAppList() {
let appList = this.appLists[this.state.currentWs];
let appList = this.getCurrentAppList();
if (appList) appList.refreshList();
}

Expand Down Expand Up @@ -643,7 +643,16 @@ class GroupedWindowListApplet extends Applet.Applet {
}

getCurrentAppList() {
if (typeof this.appLists[this.state.currentWs] !== 'undefined') {
let metaWorkspace = global.workspace_manager.get_workspace_by_index(this.state.currentWs);

let refWorkspace = findIndex(
this.appLists,
(item) => item.metaWorkspace && item.metaWorkspace === metaWorkspace
);

if (refWorkspace !== -1) {
return this.appLists[refWorkspace];
} else if (typeof this.appLists[this.state.currentWs] !== 'undefined') {
return this.appLists[this.state.currentWs];
} else if (typeof this.appLists[0] !== 'undefined') {
return this.appLists[0];
Expand Down Expand Up @@ -694,6 +703,8 @@ class GroupedWindowListApplet extends Applet.Applet {

this.state.set({scrollActive: true});

let appList = this.getCurrentAppList();

let isAppScroll = this.state.settings.scrollBehavior === 2;
let direction, source;

Expand All @@ -708,15 +719,15 @@ class GroupedWindowListApplet extends Applet.Applet {
let lastFocusedApp, z, count

if (isAppScroll) {
lastFocusedApp = this.appLists[this.state.currentWs].listState.lastFocusedApp;
lastFocusedApp = appList.listState.lastFocusedApp;
if (!lastFocusedApp) {
lastFocusedApp = this.appLists[this.state.currentWs].appList[0].groupState.appId
lastFocusedApp = appList.appList[0].groupState.appId
}
let focusedIndex = findIndex(this.appLists[this.state.currentWs].appList, function(appGroup) {
let focusedIndex = findIndex(appList.appList, function(appGroup) {
return appGroup.groupState.metaWindows.length > 0 && appGroup.groupState.appId === lastFocusedApp;
});
z = direction === 0 ? focusedIndex - 1 : focusedIndex + 1;
count = this.appLists[this.state.currentWs].appList.length - 1;
count = appList.appList.length - 1;
} else {
if (!source.groupState || source.groupState.metaWindows.length < 1) {
return;
Expand All @@ -731,8 +742,8 @@ class GroupedWindowListApplet extends Applet.Applet {
let limit = count * 2;

while ((isAppScroll
&& (!this.appLists[this.state.currentWs].appList[z]
|| !this.appLists[this.state.currentWs].appList[z].groupState.lastFocused))
&& (!appList.appList[z]
|| !appList.appList[z].groupState.lastFocused))
|| (!isAppScroll &&
(!source.groupState.metaWindows[z]
|| source.groupState.metaWindows[z] === source.groupState.lastFocused))) {
Expand All @@ -755,7 +766,7 @@ class GroupedWindowListApplet extends Applet.Applet {
}

let _window = isAppScroll ?
this.appLists[this.state.currentWs].appList[z].groupState.lastFocused
appList.appList[z].groupState.lastFocused
: source.groupState.metaWindows[z];
Main.activateWindow(_window, global.get_current_time());
setTimeout(() => this.state.set({scrollActive: false}, 4000));
Expand All @@ -768,7 +779,7 @@ class GroupedWindowListApplet extends Applet.Applet {
if(actor.name === 'xdnd-proxy-actor')
return DND.DragMotionResult.CONTINUE;

let appList = this.appLists[this.state.currentWs];
let appList = this.getCurrentAppList();
let rtl_horizontal = this.state.isHorizontal
&& St.Widget.get_default_direction () === St.TextDirection.RTL;

Expand Down Expand Up @@ -897,6 +908,13 @@ class GroupedWindowListApplet extends Applet.Applet {

Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
appList.updateAppGroupIndexes();

// Refresh app lists in other workspaces
each(this.appLists, function(_appList) {
if (_appList !== appList)
setTimeout(() => _appList.refreshList(), 0);
});

// Refresh the group's thumbnails so hoverMenu is aware of the position change
// In the case of dragging a group that has a delay before Cinnamon can grab its
// thumbnail texture, e.g., LibreOffice, defer the refresh.
Expand Down

0 comments on commit b93cf85

Please sign in to comment.