Skip to content

Commit e31c330

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 e31c330

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,15 +1322,41 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
13221322

13231323
_updateKeybinding() {
13241324
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();
1328-
}
1329-
this.menu.toggle_with_options(this.enableAnimation);
1325+
const instancesWithSameBinding = this._getInstancesWithSameOverlayBinding();
1326+
if (!instancesWithSameBinding.length || this._mouseOnSameMonitor(this.actor)) {
1327+
this.toggleOverlay();
1328+
return;
13301329
}
1330+
const matchingInstance = instancesWithSameBinding.find(instance => this._mouseOnSameMonitor(instance.actor));
1331+
(matchingInstance ?? this).toggleOverlay();
13311332
}));
13321333
}
13331334

1335+
_getInstancesWithSameOverlayBinding() {
1336+
const instances = Main.AppletManager.getRunningInstancesForUuid("[email protected]");
1337+
const binds = this.overlayKey.split('::');
1338+
return instances.filter(instance => {
1339+
if (instance === this) return false;
1340+
const instance_binds = instance.overlayKey.split('::');
1341+
return instance_binds.some(bind => bind && binds.includes(bind));
1342+
});
1343+
}
1344+
1345+
_mouseOnSameMonitor(actor) {
1346+
const mouseMonitor = Main.layoutManager.currentMonitor.index;
1347+
const actorMonitor = Main.layoutManager.findMonitorIndexForActor(actor);
1348+
return mouseMonitor === actorMonitor;
1349+
}
1350+
1351+
toggleOverlay() {
1352+
if (!Main.overview.visible && !Main.expo.visible) {
1353+
if (this.forceShowPanel && !this.isOpen) {
1354+
this.panel.peekPanel();
1355+
}
1356+
this.menu.toggle_with_options(this.enableAnimation);
1357+
}
1358+
}
1359+
13341360
_updateCategoryHover() {
13351361
this.categoriesBox.get_children().forEach(child => {
13361362
if (child._delegate.actor_motion_id > 0) {

0 commit comments

Comments
 (0)