Skip to content

Commit fd57bcc

Browse files
committed
src/keybindings: Avoid re-registering window-management mode bindings.
Entering window-management mode removed the normal bindings and re-added the management bindings, then did the inverse on exit. This leads to journalctl spam since we overwrite a keybinding, and mutter logs overwrite warnings. Register the window-management mode bindings once with it being inactive initially (Shell.ActionMode.NONE), and later enable it (Shell.ActionMode.NORMAL) when entering the management mode, and then disabling on exit. Closes: #1820 Signed-off-by: Siddh Raman Pant <25429745+siddhpant@users.noreply.github.com>
1 parent 335d3f1 commit fd57bcc

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,7 @@ export default class PopShellExtension extends Extension {
27152715
}
27162716

27172717
ext.keybindings.enable(ext.keybindings.global).enable(ext.keybindings.window_focus);
2718+
ext.tiler.enable_keybindings(ext);
27182719

27192720
if (ext.settings.tile_by_default()) {
27202721
ext.auto_tile_on();
@@ -2740,6 +2741,7 @@ export default class PopShellExtension extends Extension {
27402741
layoutManager.removeChrome(ext.overlay);
27412742

27422743
ext.keybindings.disable(ext.keybindings.global).disable(ext.keybindings.window_focus);
2744+
ext.tiler.disable_keybindings(ext);
27432745

27442746
if (ext.auto_tiler) {
27452747
ext.auto_tiler.destroy(ext);

src/keybindings.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export class Keybindings {
88
global: Object;
99
window_focus: Object;
1010

11+
private active: Set<string> = new Set();
12+
1113
private ext: Ext;
1214

1315
constructor(ext: Ext) {
@@ -62,23 +64,43 @@ export class Keybindings {
6264
};
6365
}
6466

65-
enable(keybindings: any) {
67+
enable(keybindings: any, modes: number = Shell.ActionMode.NORMAL) {
6668
for (const name in keybindings) {
69+
if (this.active.has(name)) {
70+
wm.allowKeybinding(name, modes);
71+
continue;
72+
}
73+
6774
wm.addKeybinding(
6875
name,
6976
this.ext.settings.ext,
7077
Meta.KeyBindingFlags.NONE,
71-
Shell.ActionMode.NORMAL,
78+
modes,
7279
keybindings[name],
7380
);
81+
82+
this.active.add(name);
7483
}
7584

7685
return this;
7786
}
7887

7988
disable(keybindings: Object) {
8089
for (const name in keybindings) {
90+
if (!this.active.has(name))
91+
continue;
92+
8193
wm.removeKeybinding(name);
94+
this.active.delete(name);
95+
}
96+
97+
return this;
98+
}
99+
100+
allow(keybindings: Object, modes: number) {
101+
for (const name in keybindings) {
102+
if (this.active.has(name))
103+
wm.allowKeybinding(name, modes);
82104
}
83105

84106
return this;

src/tiling.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { AutoTiler } from './auto_tiler.js';
1717
import { Fork } from './fork.js';
1818

1919
import Meta from 'gi://Meta';
20+
import Shell from 'gi://Shell';
2021
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
2122
const { ShellWindow } = window;
2223

@@ -60,6 +61,14 @@ export class Tiler {
6061
};
6162
}
6263

64+
enable_keybindings(ext: Ext) {
65+
ext.keybindings.enable(this.keybindings, Shell.ActionMode.NONE);
66+
}
67+
68+
disable_keybindings(ext: Ext) {
69+
ext.keybindings.disable(this.keybindings);
70+
}
71+
6372
toggle_orientation(ext: Ext) {
6473
const window = ext.focus_window();
6574
if (window && ext.auto_tiler) {
@@ -763,7 +772,9 @@ export class Tiler {
763772
});
764773
}
765774

766-
ext.keybindings.disable(ext.keybindings.window_focus).enable(this.keybindings);
775+
ext.keybindings
776+
.allow(ext.keybindings.window_focus, Shell.ActionMode.NONE)
777+
.allow(this.keybindings, Shell.ActionMode.NORMAL);
767778
}
768779
}
769780

@@ -817,7 +828,9 @@ export class Tiler {
817828
ext.overlay.visible = false;
818829

819830
// Disable tiling keybindings
820-
ext.keybindings.disable(this.keybindings).enable(ext.keybindings.window_focus);
831+
ext.keybindings
832+
.allow(this.keybindings, Shell.ActionMode.NONE)
833+
.allow(ext.keybindings.window_focus, Shell.ActionMode.NORMAL);
821834
}
822835
}
823836

0 commit comments

Comments
 (0)