Add nmaster and mfact indicator in the panel

This commit is contained in:
2023-05-16 23:21:13 +09:00
parent 2cdc0138a4
commit 60587d5a8a
2 changed files with 20 additions and 5 deletions

View File

@@ -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}%`;
}
}
);

View File

@@ -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", () => {