Skip to content

Commit 2347907

Browse files
committed
If multiple menu applets have the same toggle overlay key binding, prioritize the menu on the monitor with the mouse cursor.
1 parent 39fe76d commit 2347907

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,14 +1321,42 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
13211321
}
13221322

13231323
_updateKeybinding() {
1324-
Main.keybindingManager.addHotKey("overlay-key-" + this.instance_id, this.overlayKey, Lang.bind(this, function() {
1325-
if (!Main.overview.visible && !Main.expo.visible) {
1326-
if (this.forceShowPanel && !this.isOpen) {
1327-
this.panel.peekPanel();
1324+
const binds = this.overlayKey.split('::').map(e => e ? e : '::');
1325+
for (let i = 0; i < binds.length; i++) {
1326+
const bind = binds[i];
1327+
Main.keybindingManager.addHotKey(`overlay-key-${i}-${this.instance_id}`, bind, Lang.bind(this, function() {
1328+
const instancesWithSameBinding = this._getInstancesWithSameOverlayBinding(bind);
1329+
if (!instancesWithSameBinding.length || this._mouseOnSameMonitor(this.actor)) {
1330+
this.toggleOverlay();
1331+
return;
13281332
}
1329-
this.menu.toggle_with_options(this.enableAnimation);
1333+
const matchingInstance = instancesWithSameBinding.find(instance => this._mouseOnSameMonitor(instance.actor));
1334+
(matchingInstance ?? this).toggleOverlay();
1335+
}));
1336+
}
1337+
}
1338+
1339+
_getInstancesWithSameOverlayBinding(bind) {
1340+
const instances = Main.AppletManager.getRunningInstancesForUuid("[email protected]");
1341+
return instances.filter(instance => {
1342+
if (instance === this) return false;
1343+
return instance.overlayKey.split('::').includes(bind);
1344+
});
1345+
}
1346+
1347+
_mouseOnSameMonitor(actor) {
1348+
const mouseMonitor = Main.layoutManager.currentMonitor.index;
1349+
const actorMonitor = Main.layoutManager.findMonitorIndexForActor(actor);
1350+
return mouseMonitor === actorMonitor;
1351+
}
1352+
1353+
toggleOverlay() {
1354+
if (!Main.overview.visible && !Main.expo.visible) {
1355+
if (this.forceShowPanel && !this.isOpen) {
1356+
this.panel.peekPanel();
13301357
}
1331-
}));
1358+
this.menu.toggle_with_options(this.enableAnimation);
1359+
}
13321360
}
13331361

13341362
_updateCategoryHover() {

0 commit comments

Comments
 (0)