From 60587d5a8ae95ba57dc0c46abaab5b504d032b16 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 16 May 2023 23:21:13 +0900 Subject: [PATCH] Add nmaster and mfact indicator in the panel --- sources/indicator.js | 21 ++++++++++++++++----- sources/keybinds.js | 4 ++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/sources/indicator.js b/sources/indicator.js index 1e1f7cd..75f0baf 100644 --- a/sources/indicator.js +++ b/sources/indicator.js @@ -49,7 +49,6 @@ var Indicator = GObject.registerClass( }); this._layoutIndicator.add_child(this._icon); - const mon = global.display.get_primary_monitor(); this._layoutPanelItems = { tiling: this._createSelectableItem("Tiling", () => this._keybinds.switchLayout("tiling") @@ -64,10 +63,15 @@ var Indicator = GObject.registerClass( this._keybinds.switchLayout("deck") ), }; + this._nmasterPanelItem = new PopupMenu.PopupMenuItem("nmaster", {}); + this._mfactPanelItem = new PopupMenu.PopupMenuItem("mfact", {}); this._layoutIndicator.menu.addMenuItem(this._layoutPanelItems.tiling); this._layoutIndicator.menu.addMenuItem(this._layoutPanelItems.monocle); this._layoutIndicator.menu.addMenuItem(this._layoutPanelItems.floating); this._layoutIndicator.menu.addMenuItem(this._layoutPanelItems.deck); + this._layoutIndicator.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); + this._layoutIndicator.menu.addMenuItem(this._nmasterPanelItem); + this._layoutIndicator.menu.addMenuItem(this._mfactPanelItem); this.settings.bind( "show-layout", @@ -81,6 +85,11 @@ var Indicator = GObject.registerClass( } disable() { + this._layoutPanelItems = {}; + this._nmasterPanelItem = null; + this._mfactPanelItem = nulll + for (const item of this._layoutIndicator.menu) + item.destroy(); this._layoutIndicator.destroy(); this._layoutIndicator = null; this._icon.destroy(); @@ -91,15 +100,17 @@ var Indicator = GObject.registerClass( update() { const primaryMon = global.display.get_primary_monitor(); - const layout = this._state.monitors[primaryMon].layout; - log(layout); - this._icon.gicon = this._layoutIcons[layout]; + const state = this._state.monitors[primaryMon]; + this._icon.gicon = this._layoutIcons[state.layout]; for (const [key, value] of Object.entries(this._layoutPanelItems)) { value.setOrnament( - key === layout ? PopupMenu.Ornament.DOT : PopupMenu.Ornament.NONE + key === state.layout ? PopupMenu.Ornament.DOT : PopupMenu.Ornament.NONE ); } + + this._nmasterPanelItem.label.text = `nmaster: ${state.nmaster}`; + this._mfactPanelItem.label.text = `mfact: ${state.mfact}%`; } } ); diff --git a/sources/keybinds.js b/sources/keybinds.js index d7f1bc7..9c8d4c0 100644 --- a/sources/keybinds.js +++ b/sources/keybinds.js @@ -70,24 +70,28 @@ var KeyboardManager = GObject.registerClass( const state = this._state.monitors[mon]; state.mfact = Math.min(95, state.mfact + 5); this._renderer.render(mon); + this._indicator.update(mon); }); this._addBinding("decmfact", () => { const mon = global.display.get_current_monitor(); const state = this._state.monitors[mon]; state.mfact = Math.max(5, state.mfact - 5); this._renderer.render(mon); + this._indicator.update(mon); }); this._addBinding("incrnmaster", () => { const mon = global.display.get_current_monitor(); this._state.monitors[mon].nmaster += 1; this._renderer.render(mon); + this._indicator.update(mon); }); this._addBinding("decnmaster", () => { const mon = global.display.get_current_monitor(); if (this._state.monitors[mon].nmaster > 0) this._state.monitors[mon].nmaster -= 1; this._renderer.render(mon); + this._indicator.update(mon); }); this._addBinding("swap-prev", () => {