Add layout indicator

This commit is contained in:
2023-05-16 16:20:39 +09:00
parent 8621a479ac
commit 7dac50c0e5
9 changed files with 64 additions and 16 deletions

View File

@@ -12,9 +12,10 @@ class Extension {
constructor() {
this._state = new State.StateManager();
this._settings = ExtensionUtils.getSettings("org.gnome.shell.extensions.fairy");
this._renderer = new Renderer.Renderer(this._state, this._settings);
this._keybinds = new Keybinds.KeyboardManager(this._state, this._renderer);
this._indicator = new Indicator.Indicator(this._state, this._renderer);
this._keybinds = new Keybinds.KeyboardManager(this._state, this._renderer, this._indicator);
}
enable() {

3
icons/deck.svg Normal file
View File

@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 96 960 960" width="48">
<path style="fill:#FFFFFF" d="M180 936q-24 0-42-18t-18-42V276q0-24 18-42t42-18h210q24 0 42 18t18 42v600q0 24-18 42t-42 18H180Zm390 0q-24 0-42-18t-18-42V276q0-24 18-42t42-18h210q24 0 42 18t18 42v600q0 24-18 42t-42 18H570Zm210-660H570v600h210V276ZM570 876h210-210Z"/>
</svg>

After

Width:  |  Height:  |  Size: 361 B

3
icons/floating.svg Normal file
View File

@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 96 960 960" width="48">
<path style="fill:#FFFFFF" d="M446 791h335V534H446v257ZM140 896q-24 0-42-18t-18-42V316q0-24 18-42t42-18h680q24.75 0 42.375 18T880 316v520q0 24-17.625 42T820 896H140Zm0-60V316v520Zm0 0h680V316H140v520Zm366-105V594h215v137H506Z"/>
</svg>

After

Width:  |  Height:  |  Size: 324 B

3
icons/monocle.svg Normal file
View File

@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 96 960 960" width="48">
<path style="fill:#FFFFFF" d="M450 778h60V610h168v-60H510V382h-60v168H282v60h168v168Zm30 198q-83 0-156-31.5T197 859q-54-54-85.5-127T80 576q0-83 31.5-156T197 293q54-54 127-85.5T480 176q83 0 156 31.5T763 293q54 54 85.5 127T880 576v318q0 33.825-24.088 57.912Q831.825 976 798 976H480Zm0-60q142.375 0 241.188-98.812Q820 718.375 820 576t-98.812-241.188Q622.375 236 480 236t-241.188 98.812Q140 433.625 140 576t98.812 241.188Q337.625 916 480 916Zm0-336Z"/>
</svg>

After

Width:  |  Height:  |  Size: 544 B

20
icons/tiling.svg Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="1280.000000pt" height="1280.000000pt" viewBox="0 0 1280.000000 1280.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,1280.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path style="fill:#ffffff" d="M1490 6400 l0 -3740 1995 0 1995 0 0 3740 0 3740 -1995 0 -1995 0 0
-3740z m3190 0 l0 -2930 -1190 0 -1190 0 0 2930 0 2930 1190 0 1190 0 0 -2930z"/>
<path style="fill:#ffffff" d="M6900 9735 l0 -405 2200 0 2200 0 0 405 0 405 -2200 0 -2200 0 0
-405z"/>
<path style="fill:#ffffff" d="M6900 7505 l0 -405 2200 0 2200 0 0 405 0 405 -2200 0 -2200 0 0
-405z"/>
<path style="fill:#ffffff" d="M6900 5295 l0 -405 2200 0 2200 0 0 405 0 405 -2200 0 -2200 0 0
-405z"/>
<path style="fill:#ffffff" d="M6900 3065 l0 -405 2200 0 2200 0 0 405 0 405 -2200 0 -2200 0 0
-405z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -18,6 +18,13 @@ var Indicator = GObject.registerClass(
super._init();
this._state = state;
this._renderer = renderer;
this._layoutIcons = {
tiling: Gio.icon_new_for_string(`${Me.path}/icons/tiling.svg`),
monocle: Gio.icon_new_for_string(`${Me.path}/icons/monocle.svg`),
floating: Gio.icon_new_for_string(`${Me.path}/icons/floating.svg`),
deck: Gio.icon_new_for_string(`${Me.path}/icons/deck.svg`),
};
}
enable() {
@@ -25,13 +32,13 @@ var Indicator = GObject.registerClass(
"org.gnome.shell.extensions.fairy"
);
const indicatorName = `${Me.metadata.name} Indicator`;
const indicatorName = `${Me.metadata.name} Indicator`;
this._layoutIndicator = new PanelMenu.Button(0.0, indicatorName);
const icon = new St.Icon({
gicon: new Gio.ThemedIcon({ name: "face-laugh-symbolic" }),
this._icon = new St.Icon({
gicon: this._layoutIcons.tiling,
style_class: "system-status-icon",
});
this._layoutIndicator.add_child(icon);
this._layoutIndicator.add_child(this._icon);
this.settings.bind(
"show-layout",
@@ -45,8 +52,14 @@ var Indicator = GObject.registerClass(
disable() {
this._layoutIndicator.destroy();
this._layoutIndicator = null;
this._icon = null;
this.settings = null;
}
update() {
const primaryMon = global.display.get_primary_monitor();
this._icon.gicon = this._layoutIcons[this._state.monitors[primaryMon].layout];
}
}
);

View File

@@ -8,10 +8,11 @@ const ExtensionUtils = imports.misc.extensionUtils;
var KeyboardManager = GObject.registerClass(
class KeyboardManager extends GObject.Object {
_init(state, renderer) {
_init(state, renderer, indicator) {
super._init();
this._state = state;
this._renderer = renderer;
this._indicator = indicator;
}
/**
@@ -197,6 +198,7 @@ var KeyboardManager = GObject.registerClass(
else state.layout = mode;
state.oldLayout = currentLayout;
this._renderer.render(mon);
this._indicator.update(mon);
}
_focusNext() {

View File

@@ -139,12 +139,12 @@ var Renderer = GObject.registerClass(
global.display.connect("window-created", (_display, window) =>
this._waitForWindow(window, () => {
this.trackWindow(window);
GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
// GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
this.focus(window);
// Do not retrigger this idle.
return false;
});
this.renderForWindow(window);
this.renderForHandle(window);
// // Do not retrigger this idle.
// return false;
// });
})
),
// global.display.connect("window-entered-monitor", (_display, monitor, window) => {
@@ -155,8 +155,8 @@ var Renderer = GObject.registerClass(
global.workspace_manager.connect("active-workspace-changed", () => {
// Convert gnome workspaces to fairy's tags
const workspace = global.display
.get_workspace_manager()
.get_active_workspace_index();
.get_workspace_manager()
.get_active_workspace_index();
const tags = 0b1 << workspace;
log("Switch to tags", tags);
if (Meta.prefs_get_workspaces_only_on_primary()) {
@@ -227,6 +227,7 @@ var Renderer = GObject.registerClass(
handle.connect("focus", (handle) => {
if (!this._isValidWindow(handle)) return;
this._state.monitors[handle.get_monitor()].focused = handle;
this.renderForHandle(handle);
}),
];
@@ -309,8 +310,8 @@ var Renderer = GObject.registerClass(
}
}
renderForWindow(window) {
const mon = window.get_monitor();
renderForHandle(handle) {
const mon = handle.get_monitor();
this.render(mon);
}

View File

@@ -150,10 +150,12 @@ var StateManager = GObject.registerClass(
}
_layout({ layout, nmaster, mfact, focused }, windows) {
const focusedW = this.windows.find((x) => x.handle === focused);
const focusedW = windows.find((x) => x.handle === focused)
?? windows[0];
switch (layout) {
case "monocle":
if (!focusedW) return [];
return [
{
...focusedW,