Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a8f7ca7e7e | |||
| d249abe804 | |||
| 59b2fe1646 | |||
| 6e9fb687fe | |||
| f9c1aee610 | |||
| 70a0fd9eab | |||
| 2fee754776 | |||
| 114b7cc265 | |||
| 8e6d9ab2d9 | |||
| bcd14cb87d | |||
| 307908cd39 | |||
| fcfdf39059 | |||
| e7618cf3e5 | |||
| 811db01995 | |||
| ae59b60a7a | |||
| d9bacba373 | |||
| 4e26db91ea | |||
| 6f56a5c7c8 | |||
| 6549e5bca3 | |||
| 553a1599c6 | |||
| 921928bd2a | |||
| 07f1d40726 | |||
| 40f7ca64ef | |||
| 7d864878b4 | |||
| 0c79ce6da1 | |||
| 843ea1d819 | |||
| c7cf481e33 | |||
| 54172118e1 |
@@ -11,7 +11,7 @@ A lightweight, opinionated, and automatic tiling window manager for GNOME Shell
|
||||
[](https://opensource.org/licenses/MIT)
|
||||

|
||||
|
||||
<img width="2560" height="1440" alt="Simple Tiling v4" src="https://github.com/user-attachments/assets/b080483e-40fe-4ea2-b0dd-56fcb587f9b8" />
|
||||
<img width="2560" height="1440" alt="Simple-Tiling-v6" src="https://github.com/user-attachments/assets/eb0f7cc3-6a5a-4036-8a1e-8f945c52e55c" />
|
||||
|
||||
## Introduction
|
||||
|
||||
@@ -50,17 +50,28 @@ Use the [GNOME Shell Extensions website](https://extensions.gnome.org/extension/
|
||||
|
||||
#### Manual Installation
|
||||
|
||||
1. **Clone the repository** into your local extensions directory:
|
||||
1. **Navigate to your extensions folder:**
|
||||
|
||||
```bash
|
||||
cd ~/.local/share/gnome-shell/extensions/
|
||||
```
|
||||
3. **Clone the repository directly into a folder named after the extension's UUID:**
|
||||
|
||||
```bash
|
||||
git clone https://github.com/Domoel/Simple-Tiling.git simple-tiling@domoel
|
||||
```
|
||||
5. **Compile the GSettings schema.** This is a mandatory step for the keyboard shortcuts to work.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/Domoel/Simple-Tiling.git
|
||||
```
|
||||
2. **Compile the GSettings schema.** This is a mandatory step for the keyboard shortcuts to work.
|
||||
```bash
|
||||
cd ~/.local/share/gnome-shell/extensions/simple-tiling@domoel/
|
||||
cd ~/.local/share/gnome-shell/extensions/simple-tiling@domoel
|
||||
glib-compile-schemas schemas/
|
||||
```
|
||||
|
||||
3. **Restart GNOME Shell.** Press `Alt` + `F2`, type `r`, and press `Enter`.
|
||||
4. **Enable the extension** using the GNOME Extensions app or GNOME Tweaks.
|
||||
|
||||
5. **Enable the extension** using the GNOME Extensions app or GNOME Tweaks.
|
||||
|
||||
**Note:** You have to use "simple-tiling@domoel" as your extension folder / directory. Put all necessary files into this directory. Otherwise the extension will not show up in extension manager.
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
+23
-8
@@ -1,11 +1,26 @@
|
||||
# --- Ausnahmeliste für den Tiler ---
|
||||
# Jede Zeile enthält die WM_CLASS einer Anwendung, die ignoriert werden soll.
|
||||
# Die Groß- und Kleinschreibung wird ignoriert.
|
||||
# --- Exception List for Tiling Windows ---
|
||||
# Each line contains an application identifier (WM_CLASS for X11, or App ID for Wayland)
|
||||
# that should be ignored by the tiling manager.
|
||||
# For best results, add both identifiers for an application if they differ.
|
||||
# Uppercase and lowercase letters are ignored.
|
||||
|
||||
# Befehl zum Finden der WM_CLASS:
|
||||
# 1. Terminal öffnen
|
||||
# 2. 'xprop WM_CLASS' eingeben und Enter drücken
|
||||
# 3. Mit dem Kreuz auf das gewünschte Fenster klicken
|
||||
# -----------------------------------------------------------
|
||||
# Finding the App ID (for Wayland & modern apps)
|
||||
# -----------------------------------------------------------
|
||||
# 1. Press Alt + F2, type 'lg', and press Enter.
|
||||
# 2. In the Looking Glass window, click the "Windows" tab.
|
||||
# 3. Click on the desired window to see its details.
|
||||
# 4. Find the value for "app id" and add it to a new line below.
|
||||
|
||||
gnome-screenshot
|
||||
# -----------------------------------------------------------
|
||||
# Finding the WM_CLASS (for X11)
|
||||
# -----------------------------------------------------------
|
||||
# 1. Open a terminal.
|
||||
# 2. Type 'xprop WM_CLASS' and press Enter.
|
||||
# 3. Your cursor will turn into a crosshair. Click on the desired window.
|
||||
# 4. The terminal will output a line like: WM_CLASS(STRING) = "navigator", "Firefox".
|
||||
# 5. Add one of these values (e.g., "firefox") to a new line below.
|
||||
|
||||
# --- Start of the Exception List ---
|
||||
|
||||
ulauncher
|
||||
|
||||
+34
-687
@@ -1,694 +1,41 @@
|
||||
// ---------------------------------------------------- //
|
||||
// Simple-Tiling – GNOME Shell 3.38 (X11) - Version 5 //
|
||||
// © 2025 domoel – MIT //
|
||||
// ---------------------------------------------------- //
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Simple-Tiling – GLOBAL CONFIG //
|
||||
// © 2025 domoel – MIT //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// --- GLOBAL IMPORTS ---
|
||||
'use strict';
|
||||
|
||||
// ---------------------------------------------------- //
|
||||
// Global Imports //
|
||||
// ---------------------------------------------------- //
|
||||
const Main = imports.ui.main;
|
||||
const Meta = imports.gi.Meta;
|
||||
const Shell = imports.gi.Shell;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GLib = imports.gi.GLib;
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
const ByteArray = imports.byteArray;
|
||||
const TILING_DELAY_MS = 20; // Change Tiling Window Delay
|
||||
const CENTERING_DELAY_MS = 5; // Change Centered Window Delay
|
||||
|
||||
const Config = imports.misc.config;
|
||||
const Me = ExtensionUtils.getCurrentExtension();
|
||||
const SCHEMA_NAME = "org.gnome.shell.extensions.simple-tiling.domoel";
|
||||
const WM_SCHEMA = "org.gnome.desktop.wm.keybindings";
|
||||
const [SHELL_MAJOR] = Config.PACKAGE_VERSION.split('.').map(n => parseInt(n));
|
||||
|
||||
const KEYBINDINGS = {
|
||||
"swap-master-window": (self) => self._swapWithMaster(),
|
||||
"swap-left-window": (self) => self._swapInDirection("left"),
|
||||
"swap-right-window": (self) => self._swapInDirection("right"),
|
||||
"swap-up-window": (self) => self._swapInDirection("up"),
|
||||
"swap-down-window": (self) => self._swapInDirection("down"),
|
||||
|
||||
"focus-left": (self) => self._focusInDirection("left"),
|
||||
"focus-right": (self) => self._focusInDirection("right"),
|
||||
"focus-up": (self) => self._focusInDirection("up"),
|
||||
"focus-down": (self) => self._focusInDirection("down"),
|
||||
};
|
||||
|
||||
// ---------------------------------------------------- //
|
||||
// InteractionHandler //
|
||||
// ---------------------------------------------------- //
|
||||
class InteractionHandler {
|
||||
constructor(tiler) {
|
||||
this.tiler = tiler;
|
||||
this._settings = ExtensionUtils.getSettings(SCHEMA_NAME);
|
||||
this._wmSettings = new Gio.Settings({ schema: WM_SCHEMA });
|
||||
this._wmKeysToDisable = [];
|
||||
this._savedWmShortcuts = {};
|
||||
this._grabOpIds = [];
|
||||
this._settingsChangedId = null;
|
||||
this._onSettingsChanged = this._onSettingsChanged.bind(this);
|
||||
this._prepareWmShortcuts();
|
||||
}
|
||||
|
||||
enable() {
|
||||
if (this._wmKeysToDisable.length) {
|
||||
this._wmKeysToDisable.forEach((key) =>
|
||||
this._wmSettings.set_value(key, new GLib.Variant("as", []))
|
||||
);
|
||||
}
|
||||
this._bindAllShortcuts();
|
||||
this._settingsChangedId = this._settings.connect(
|
||||
"changed",
|
||||
this._onSettingsChanged
|
||||
);
|
||||
this._grabOpIds.push(
|
||||
global.display.connect(
|
||||
"grab-op-begin",
|
||||
(display, screen, window) => {
|
||||
if (this.tiler.windows.includes(window)) {
|
||||
this.tiler.grabbedWindow = window;
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
this._grabOpIds.push(
|
||||
global.display.connect("grab-op-end", this._onGrabEnd.bind(this))
|
||||
);
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this._wmKeysToDisable.length) {
|
||||
this._wmKeysToDisable.forEach((key) =>
|
||||
this._wmSettings.set_value(key, this._savedWmShortcuts[key])
|
||||
);
|
||||
}
|
||||
this._unbindAllShortcuts();
|
||||
if (this._settingsChangedId) {
|
||||
this._settings.disconnect(this._settingsChangedId);
|
||||
this._settingsChangedId = null;
|
||||
}
|
||||
this._grabOpIds.forEach((id) => global.display.disconnect(id));
|
||||
this._grabOpIds = [];
|
||||
}
|
||||
|
||||
_bind(key, callback) {
|
||||
Main.wm.addKeybinding(key, this._settings, Meta.KeyBindingFlags.NONE, Shell.ActionMode.NORMAL,
|
||||
() => callback(this));
|
||||
}
|
||||
|
||||
_bindAllShortcuts() {
|
||||
for (const [key, handler] of Object.entries(KEYBINDINGS)) {
|
||||
this._bind(key, handler);
|
||||
}
|
||||
}
|
||||
_unbindAllShortcuts() {
|
||||
for (const key in KEYBINDINGS) {
|
||||
Main.wm.removeKeybinding(key);
|
||||
}
|
||||
}
|
||||
|
||||
_onSettingsChanged() {
|
||||
this._unbindAllShortcuts();
|
||||
this._bindAllShortcuts();
|
||||
}
|
||||
_prepareWmShortcuts() {
|
||||
const schema = this._wmSettings.settings_schema;
|
||||
const keys = [];
|
||||
if (schema.has_key("toggle-tiled-left"))
|
||||
keys.push("toggle-tiled-left", "toggle-tiled-right");
|
||||
else if (schema.has_key("tile-left"))
|
||||
keys.push("tile-left", "tile-right");
|
||||
if (schema.has_key("toggle-maximized")) keys.push("toggle-maximized");
|
||||
else {
|
||||
if (schema.has_key("maximize")) keys.push("maximize");
|
||||
if (schema.has_key("unmaximize")) keys.push("unmaximize");
|
||||
}
|
||||
if (keys.length) {
|
||||
this._wmKeysToDisable = keys;
|
||||
keys.forEach(
|
||||
(key) =>
|
||||
(this._savedWmShortcuts[
|
||||
key
|
||||
] = this._wmSettings.get_value(key))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_focusInDirection(direction) {
|
||||
const sourceWindow = global.display.get_focus_window();
|
||||
if (!sourceWindow || !this.tiler.windows.includes(sourceWindow)) return;
|
||||
|
||||
const targetWindow = this._findTargetInDirection(
|
||||
sourceWindow,
|
||||
direction
|
||||
);
|
||||
if (targetWindow) {
|
||||
targetWindow.activate(global.get_current_time());
|
||||
}
|
||||
}
|
||||
|
||||
_swapWithMaster() {
|
||||
const windows = this.tiler.windows;
|
||||
if (windows.length < 2) return;
|
||||
const focusedWindow = global.display.get_focus_window();
|
||||
if (!focusedWindow || !windows.includes(focusedWindow)) return;
|
||||
const focusedIndex = windows.indexOf(focusedWindow);
|
||||
if (focusedIndex > 0) {
|
||||
[windows[0], windows[focusedIndex]] = [
|
||||
windows[focusedIndex],
|
||||
windows[0],
|
||||
];
|
||||
} else if (focusedIndex === 0) {
|
||||
[windows[0], windows[1]] = [windows[1], windows[0]];
|
||||
}
|
||||
this.tiler.tileNow();
|
||||
if (windows.length > 0) windows[0].activate(global.get_current_time());
|
||||
}
|
||||
|
||||
_swapInDirection(direction) {
|
||||
const sourceWindow = global.display.get_focus_window();
|
||||
if (!sourceWindow || !this.tiler.windows.includes(sourceWindow)) return;
|
||||
let targetWindow = null;
|
||||
const sourceIndex = this.tiler.windows.indexOf(sourceWindow);
|
||||
if (
|
||||
sourceIndex === 0 &&
|
||||
direction === "right" &&
|
||||
this.tiler.windows.length > 1
|
||||
) {
|
||||
targetWindow = this.tiler.windows[1];
|
||||
} else {
|
||||
targetWindow = this._findTargetInDirection(sourceWindow, direction);
|
||||
}
|
||||
if (!targetWindow) return;
|
||||
const targetIndex = this.tiler.windows.indexOf(targetWindow);
|
||||
[this.tiler.windows[sourceIndex], this.tiler.windows[targetIndex]] = [
|
||||
this.tiler.windows[targetIndex],
|
||||
this.tiler.windows[sourceIndex],
|
||||
];
|
||||
this.tiler.tileNow();
|
||||
sourceWindow.activate(global.get_current_time());
|
||||
}
|
||||
|
||||
_findTargetInDirection(source, direction) {
|
||||
const sourceRect = source.get_frame_rect();
|
||||
let candidates = [];
|
||||
for (const win of this.tiler.windows) {
|
||||
if (win === source) continue;
|
||||
const targetRect = win.get_frame_rect();
|
||||
switch (direction) {
|
||||
case "left":
|
||||
if (targetRect.x < sourceRect.x) candidates.push(win);
|
||||
break;
|
||||
case "right":
|
||||
if (targetRect.x > sourceRect.x) candidates.push(win);
|
||||
break;
|
||||
case "up":
|
||||
if (targetRect.y < sourceRect.y) candidates.push(win);
|
||||
break;
|
||||
case "down":
|
||||
if (targetRect.y > sourceRect.y) candidates.push(win);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (candidates.length === 0) return null;
|
||||
let bestTarget = null;
|
||||
let minDeviation = Infinity;
|
||||
for (const win of candidates) {
|
||||
const targetRect = win.get_frame_rect();
|
||||
let deviation;
|
||||
if (direction === "left" || direction === "right") {
|
||||
deviation = Math.abs(sourceRect.y - targetRect.y);
|
||||
} else {
|
||||
deviation = Math.abs(sourceRect.x - targetRect.x);
|
||||
}
|
||||
if (deviation < minDeviation) {
|
||||
minDeviation = deviation;
|
||||
bestTarget = win;
|
||||
}
|
||||
}
|
||||
return bestTarget;
|
||||
}
|
||||
|
||||
_onGrabEnd() {
|
||||
const grabbedWindow = this.tiler.grabbedWindow;
|
||||
if (!grabbedWindow) return;
|
||||
const targetWindow = this._findTargetUnderPointer(grabbedWindow);
|
||||
if (targetWindow) {
|
||||
const sourceIndex = this.tiler.windows.indexOf(grabbedWindow);
|
||||
const targetIndex = this.tiler.windows.indexOf(targetWindow);
|
||||
[
|
||||
this.tiler.windows[sourceIndex],
|
||||
this.tiler.windows[targetIndex],
|
||||
] = [
|
||||
this.tiler.windows[targetIndex],
|
||||
this.tiler.windows[sourceIndex],
|
||||
];
|
||||
}
|
||||
this.tiler.queueTile();
|
||||
this.tiler.grabbedWindow = null;
|
||||
}
|
||||
|
||||
_findTargetUnderPointer(excludeWindow) {
|
||||
let [pointerX, pointerY] = global.get_pointer();
|
||||
let windows = global
|
||||
.get_window_actors()
|
||||
.map((actor) => actor.meta_window)
|
||||
.filter((win) => {
|
||||
if (
|
||||
!win ||
|
||||
win === excludeWindow ||
|
||||
!this.tiler.windows.includes(win)
|
||||
)
|
||||
return false;
|
||||
let frame = win.get_frame_rect();
|
||||
return (
|
||||
pointerX >= frame.x &&
|
||||
pointerX < frame.x + frame.width &&
|
||||
pointerY >= frame.y &&
|
||||
pointerY < frame.y + frame.height
|
||||
);
|
||||
});
|
||||
if (windows.length > 0) {
|
||||
return windows[windows.length - 1];
|
||||
}
|
||||
|
||||
let bestTarget = null;
|
||||
let maxOverlap = 0;
|
||||
const sourceFrame = excludeWindow.get_frame_rect();
|
||||
for (const win of this.tiler.windows) {
|
||||
if (win === excludeWindow) continue;
|
||||
const targetFrame = win.get_frame_rect();
|
||||
const overlapX = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
sourceFrame.x + sourceFrame.width,
|
||||
targetFrame.x + targetFrame.width
|
||||
) - Math.max(sourceFrame.x, targetFrame.x)
|
||||
);
|
||||
const overlapY = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
sourceFrame.y + sourceFrame.height,
|
||||
targetFrame.y + targetFrame.height
|
||||
) - Math.max(sourceFrame.y, targetFrame.y)
|
||||
);
|
||||
const overlapArea = overlapX * overlapY;
|
||||
if (overlapArea > maxOverlap) {
|
||||
maxOverlap = overlapArea;
|
||||
bestTarget = win;
|
||||
}
|
||||
}
|
||||
return bestTarget;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------- //
|
||||
// Tiler //
|
||||
// Main Classes for Tiling Logic //
|
||||
// ---------------------------------------------------- //
|
||||
class Tiler {
|
||||
constructor() {
|
||||
this.windows = [];
|
||||
this.grabbedWindow = null;
|
||||
this._settings = ExtensionUtils.getSettings(SCHEMA_NAME);
|
||||
this._signalIds = new Map();
|
||||
this._tileInProgress = false;
|
||||
|
||||
this._innerGap = this._settings.get_int("inner-gap");
|
||||
this._outerGapVertical = this._settings.get_int("outer-gap-vertical");
|
||||
this._outerGapHorizontal = this._settings.get_int(
|
||||
"outer-gap-horizontal"
|
||||
);
|
||||
|
||||
this._tilingDelay = TILING_DELAY_MS;
|
||||
this._centeringDelay = CENTERING_DELAY_MS;
|
||||
|
||||
this._exceptions = [];
|
||||
this._interactionHandler = new InteractionHandler(this);
|
||||
|
||||
this._tileTimeoutId = null;
|
||||
this._centerTimeoutIds = [];
|
||||
|
||||
this._onWindowAdded = this._onWindowAdded.bind(this);
|
||||
this._onWindowRemoved = this._onWindowRemoved.bind(this);
|
||||
this._onActiveWorkspaceChanged = this._onActiveWorkspaceChanged.bind(
|
||||
this
|
||||
);
|
||||
this._onWindowMinimizedStateChanged = this._onWindowMinimizedStateChanged.bind(
|
||||
this
|
||||
);
|
||||
this._onSettingsChanged = this._onSettingsChanged.bind(this);
|
||||
}
|
||||
|
||||
enable() {
|
||||
this._loadExceptions();
|
||||
const workspaceManager = global.workspace_manager;
|
||||
this._signalIds.set("workspace-changed", {
|
||||
object: workspaceManager,
|
||||
id: workspaceManager.connect(
|
||||
"active-workspace-changed",
|
||||
this._onActiveWorkspaceChanged
|
||||
),
|
||||
});
|
||||
this._connectToWorkspace();
|
||||
this._interactionHandler.enable();
|
||||
this._signalIds.set("settings-changed", {
|
||||
object: this._settings,
|
||||
id: this._settings.connect("changed", this._onSettingsChanged),
|
||||
});
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this._tileTimeoutId) {
|
||||
GLib.source_remove(this._tileTimeoutId);
|
||||
this._tileTimeoutId = null;
|
||||
}
|
||||
this._centerTimeoutIds.forEach(id => GLib.source_remove(id));
|
||||
this._centerTimeoutIds = [];
|
||||
|
||||
this._interactionHandler.disable();
|
||||
this._disconnectFromWorkspace();
|
||||
for (const [, signal] of this._signalIds) {
|
||||
try {
|
||||
signal.object.disconnect(signal.id);
|
||||
} catch (e) {}
|
||||
}
|
||||
this._signalIds.clear();
|
||||
this.windows = [];
|
||||
}
|
||||
|
||||
_onSettingsChanged() {
|
||||
this._innerGap = this._settings.get_int("inner-gap");
|
||||
this._outerGapVertical = this._settings.get_int("outer-gap-vertical");
|
||||
this._outerGapHorizontal = this._settings.get_int(
|
||||
"outer-gap-horizontal"
|
||||
);
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_loadExceptions() {
|
||||
const file = Gio.file_new_for_path(Me.path + "/exceptions.txt");
|
||||
if (!file.query_exists(null)) {
|
||||
this._exceptions = [];
|
||||
return;
|
||||
}
|
||||
const [ok, data] = file.load_contents(null);
|
||||
this._exceptions = ok
|
||||
? ByteArray.toString(data)
|
||||
.split("\n")
|
||||
.map((l) => l.trim())
|
||||
.filter((l) => l && !l.startsWith("#"))
|
||||
.map((l) => l.toLowerCase())
|
||||
: [];
|
||||
}
|
||||
|
||||
_isException(win) {
|
||||
return (
|
||||
!!win &&
|
||||
this._exceptions.includes((win.get_wm_class() || "").toLowerCase())
|
||||
);
|
||||
}
|
||||
|
||||
_isTileable(win) {
|
||||
return (
|
||||
win &&
|
||||
!win.minimized &&
|
||||
!this._isException(win) &&
|
||||
win.get_window_type() === Meta.WindowType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
_centerWindow(win) {
|
||||
const timeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, this._centeringDelay, () => {
|
||||
const index = this._centerTimeoutIds.indexOf(timeoutId);
|
||||
if (index > -1) {
|
||||
this._centerTimeoutIds.splice(index, 1);
|
||||
}
|
||||
|
||||
if (!win || !win.get_display()) return GLib.SOURCE_REMOVE;
|
||||
if (win.get_maximized()) {
|
||||
win.unmaximize(Meta.MaximizeFlags.BOTH);
|
||||
}
|
||||
const monitorIndex = win.get_monitor();
|
||||
const workArea = Main.layoutManager.getWorkAreaForMonitor(
|
||||
monitorIndex
|
||||
);
|
||||
const frame = win.get_frame_rect();
|
||||
win.move_frame(
|
||||
true,
|
||||
workArea.x + Math.floor((workArea.width - frame.width) / 2),
|
||||
workArea.y + Math.floor((workArea.height - frame.height) / 2)
|
||||
);
|
||||
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
||||
if (win.get_display()) {
|
||||
if (typeof win.set_keep_above === "function")
|
||||
win.set_keep_above(true);
|
||||
else if (typeof win.make_above === "function")
|
||||
win.make_above();
|
||||
}
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
|
||||
this._centerTimeoutIds.push(timeoutId);
|
||||
}
|
||||
|
||||
_onWindowMinimizedStateChanged() {
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_onWindowAdded(workspace, win) {
|
||||
if (this.windows.includes(win)) return;
|
||||
|
||||
if (this._isException(win)) {
|
||||
this._centerWindow(win);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._isTileable(win)) {
|
||||
if (this._settings.get_string("new-window-behavior") === "master") {
|
||||
this.windows.unshift(win);
|
||||
} else {
|
||||
this.windows.push(win);
|
||||
}
|
||||
|
||||
const id = win.get_id();
|
||||
this._signalIds.set(`unmanaged-${id}`, {
|
||||
object: win,
|
||||
id: win.connect("unmanaged", () =>
|
||||
this._onWindowRemoved(null, win)
|
||||
),
|
||||
});
|
||||
this._signalIds.set(`size-changed-${id}`, {
|
||||
object: win,
|
||||
id: win.connect("size-changed", () => {
|
||||
if (!this.grabbedWindow) this.queueTile();
|
||||
}),
|
||||
});
|
||||
this._signalIds.set(`minimized-${id}`, {
|
||||
object: win,
|
||||
id: win.connect(
|
||||
"notify::minimized",
|
||||
this._onWindowMinimizedStateChanged
|
||||
),
|
||||
});
|
||||
|
||||
this.queueTile();
|
||||
}
|
||||
}
|
||||
|
||||
_onWindowRemoved(workspace, win) {
|
||||
const index = this.windows.indexOf(win);
|
||||
if (index > -1) {
|
||||
this.windows.splice(index, 1);
|
||||
}
|
||||
|
||||
["unmanaged", "size-changed", "minimized"].forEach((prefix) => {
|
||||
const key = `${prefix}-${win.get_id()}`;
|
||||
if (this._signalIds.has(key)) {
|
||||
const { object, id } = this._signalIds.get(key);
|
||||
try {
|
||||
object.disconnect(id);
|
||||
} catch (e) {}
|
||||
this._signalIds.delete(key);
|
||||
}
|
||||
});
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_onActiveWorkspaceChanged() {
|
||||
this._disconnectFromWorkspace();
|
||||
this._connectToWorkspace();
|
||||
}
|
||||
|
||||
_connectToWorkspace() {
|
||||
const workspace = global.workspace_manager.get_active_workspace();
|
||||
workspace
|
||||
.list_windows()
|
||||
.forEach((win) => this._onWindowAdded(workspace, win));
|
||||
this._signalIds.set("window-added", {
|
||||
object: workspace,
|
||||
id: workspace.connect("window-added", this._onWindowAdded),
|
||||
});
|
||||
this._signalIds.set("window-removed", {
|
||||
object: workspace,
|
||||
id: workspace.connect("window-removed", this._onWindowRemoved),
|
||||
});
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_disconnectFromWorkspace() {
|
||||
this.windows.slice().forEach((win) => this._onWindowRemoved(null, win));
|
||||
|
||||
["window-added", "window-removed"].forEach((key) => {
|
||||
if (this._signalIds.has(key)) {
|
||||
const { object, id } = this._signalIds.get(key);
|
||||
try {
|
||||
object.disconnect(id);
|
||||
} catch (e) {}
|
||||
this._signalIds.delete(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
queueTile() {
|
||||
if (this._tileInProgress || this._tileTimeoutId) return;
|
||||
this._tileInProgress = true;
|
||||
|
||||
this._tileTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, this._tilingDelay, () => {
|
||||
this._tileWindows();
|
||||
this._tileInProgress = false;
|
||||
this._tileTimeoutId = null;
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
}
|
||||
|
||||
tileNow() {
|
||||
if (!this._tileInProgress) {
|
||||
this._tileWindows();
|
||||
}
|
||||
}
|
||||
|
||||
_splitLayout(windows, area) {
|
||||
if (windows.length === 0) return;
|
||||
if (windows.length === 1) {
|
||||
windows[0].move_resize_frame(
|
||||
true,
|
||||
area.x,
|
||||
area.y,
|
||||
area.width,
|
||||
area.height
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const gap = Math.floor(this._innerGap / 2);
|
||||
const primaryWindows = [windows[0]];
|
||||
const secondaryWindows = windows.slice(1);
|
||||
let primaryArea, secondaryArea;
|
||||
|
||||
if (area.width > area.height) {
|
||||
const primaryWidth = Math.floor(area.width / 2) - gap;
|
||||
primaryArea = {
|
||||
x: area.x,
|
||||
y: area.y,
|
||||
width: primaryWidth,
|
||||
height: area.height,
|
||||
};
|
||||
secondaryArea = {
|
||||
x: area.x + primaryWidth + this._innerGap,
|
||||
y: area.y,
|
||||
width: area.width - primaryWidth - this._innerGap,
|
||||
height: area.height,
|
||||
};
|
||||
} else {
|
||||
const primaryHeight = Math.floor(area.height / 2) - gap;
|
||||
primaryArea = {
|
||||
x: area.x,
|
||||
y: area.y,
|
||||
width: area.width,
|
||||
height: primaryHeight,
|
||||
};
|
||||
secondaryArea = {
|
||||
x: area.x,
|
||||
y: area.y + primaryHeight + this._innerGap,
|
||||
width: area.width,
|
||||
height: area.height - primaryHeight - this._innerGap,
|
||||
};
|
||||
}
|
||||
|
||||
this._splitLayout(primaryWindows, primaryArea);
|
||||
this._splitLayout(secondaryWindows, secondaryArea);
|
||||
}
|
||||
|
||||
_tileWindows() {
|
||||
const windowsToTile = this.windows.filter((win) => !win.minimized);
|
||||
if (windowsToTile.length === 0) return;
|
||||
const monitor = Main.layoutManager.primaryMonitor;
|
||||
const workArea = Main.layoutManager.getWorkAreaForMonitor(
|
||||
monitor.index
|
||||
);
|
||||
const innerArea = {
|
||||
x: workArea.x + this._outerGapHorizontal,
|
||||
y: workArea.y + this._outerGapVertical,
|
||||
width: workArea.width - 2 * this._outerGapHorizontal,
|
||||
height: workArea.height - 2 * this._outerGapVertical,
|
||||
};
|
||||
|
||||
windowsToTile.forEach((win) => {
|
||||
if (win.get_maximized()) win.unmaximize(Meta.MaximizeFlags.BOTH);
|
||||
});
|
||||
|
||||
if (windowsToTile.length === 1) {
|
||||
windowsToTile[0].move_resize_frame(
|
||||
true,
|
||||
innerArea.x,
|
||||
innerArea.y,
|
||||
innerArea.width,
|
||||
innerArea.height
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const gap = Math.floor(this._innerGap / 2);
|
||||
const masterWidth = Math.floor(innerArea.width / 2) - gap;
|
||||
const master = windowsToTile[0];
|
||||
master.move_resize_frame(
|
||||
true,
|
||||
innerArea.x,
|
||||
innerArea.y,
|
||||
masterWidth,
|
||||
innerArea.height
|
||||
);
|
||||
const stackArea = {
|
||||
x: innerArea.x + masterWidth + this._innerGap,
|
||||
y: innerArea.y,
|
||||
width: innerArea.width - masterWidth - this._innerGap,
|
||||
height: innerArea.height,
|
||||
};
|
||||
this._splitLayout(windowsToTile.slice(1), stackArea);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------- //
|
||||
// Extension Wrapper //
|
||||
// ---------------------------------------------------- //
|
||||
class SimpleTilingExtension {
|
||||
constructor() {
|
||||
this.tiler = null;
|
||||
}
|
||||
enable() {
|
||||
this.tiler = new Tiler();
|
||||
this.tiler.enable();
|
||||
}
|
||||
disable() {
|
||||
if (this.tiler) {
|
||||
this.tiler.disable();
|
||||
this.tiler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
let extension = null;
|
||||
|
||||
function init() {
|
||||
return new SimpleTilingExtension();
|
||||
}
|
||||
|
||||
// --- SHELL SWITCH ---
|
||||
async function enable() {
|
||||
try {
|
||||
if (SHELL_MAJOR >= 40) {
|
||||
const module = await import('./modern.js');
|
||||
extension = new module.default(Me.metadata);
|
||||
} else {
|
||||
const { LegacyExtension } = Me.imports.legacy;
|
||||
extension = new LegacyExtension(Me.metadata);
|
||||
}
|
||||
extension.enable();
|
||||
} catch (e) {
|
||||
logError(e, `[Simple Tiling] Failed to enable extension`);
|
||||
}
|
||||
}
|
||||
|
||||
function disable() {
|
||||
if (extension) {
|
||||
extension.disable();
|
||||
extension = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,682 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Simple-Tiling – LEGACY (for GNOME Shell 3.38) //
|
||||
// © 2025 domoel – MIT //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// --- GLOBAL IMPORTS ---
|
||||
'use strict';
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const Meta = imports.gi.Meta;
|
||||
const Shell = imports.gi.Shell;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GLib = imports.gi.GLib;
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
const ByteArray = imports.byteArray;
|
||||
|
||||
const Me = ExtensionUtils.getCurrentExtension();
|
||||
const SCHEMA_NAME = "org.gnome.shell.extensions.simple-tiling.domoel";
|
||||
const WM_SCHEMA = "org.gnome.desktop.wm.keybindings";
|
||||
|
||||
const TILING_DELAY_MS = 20; // Change Tiling Window Delay
|
||||
const CENTERING_DELAY_MS = 5; // Change Centered Window Delay
|
||||
|
||||
const KEYBINDINGS = {
|
||||
"swap-master-window": (self) => self._swapWithMaster(),
|
||||
"swap-left-window": (self) => self._swapInDirection("left"),
|
||||
"swap-right-window": (self) => self._swapInDirection("right"),
|
||||
"swap-up-window": (self) => self._swapInDirection("up"),
|
||||
"swap-down-window": (self) => self._swapInDirection("down"),
|
||||
"focus-left": (self) => self._focusInDirection("left"),
|
||||
"focus-right": (self) => self._focusInDirection("right"),
|
||||
"focus-up": (self) => self._focusInDirection("up"),
|
||||
"focus-down": (self) => self._focusInDirection("down"),
|
||||
};
|
||||
|
||||
// --- INTERACTIONHANDLER ---
|
||||
class InteractionHandler {
|
||||
constructor(tiler) {
|
||||
this.tiler = tiler;
|
||||
this._settings = ExtensionUtils.getSettings(SCHEMA_NAME);
|
||||
this._wmSettings = new Gio.Settings({ schema: WM_SCHEMA });
|
||||
this._wmKeysToDisable = [];
|
||||
this._savedWmShortcuts = {};
|
||||
this._grabOpIds = [];
|
||||
this._settingsChangedId = null;
|
||||
this._onSettingsChanged = this._onSettingsChanged.bind(this);
|
||||
this._prepareWmShortcuts();
|
||||
}
|
||||
|
||||
enable() {
|
||||
if (this._wmKeysToDisable.length) {
|
||||
this._wmKeysToDisable.forEach((key) =>
|
||||
this._wmSettings.set_value(key, new GLib.Variant("as", []))
|
||||
);
|
||||
}
|
||||
this._bindAllShortcuts();
|
||||
this._settingsChangedId = this._settings.connect(
|
||||
"changed",
|
||||
this._onSettingsChanged
|
||||
);
|
||||
this._grabOpIds.push(
|
||||
global.display.connect(
|
||||
"grab-op-begin",
|
||||
(display, screen, window) => {
|
||||
if (this.tiler.windows.includes(window)) {
|
||||
this.tiler.grabbedWindow = window;
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
this._grabOpIds.push(
|
||||
global.display.connect("grab-op-end", this._onGrabEnd.bind(this))
|
||||
);
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this._wmKeysToDisable.length) {
|
||||
this._wmKeysToDisable.forEach((key) =>
|
||||
this._wmSettings.set_value(key, this._savedWmShortcuts[key])
|
||||
);
|
||||
}
|
||||
this._unbindAllShortcuts();
|
||||
if (this._settingsChangedId) {
|
||||
this._settings.disconnect(this._settingsChangedId);
|
||||
this._settingsChangedId = null;
|
||||
}
|
||||
this._grabOpIds.forEach((id) => global.display.disconnect(id));
|
||||
this._grabOpIds = [];
|
||||
}
|
||||
|
||||
_bind(key, callback) {
|
||||
Main.wm.addKeybinding(key, this._settings, Meta.KeyBindingFlags.NONE, Shell.ActionMode.NORMAL,
|
||||
() => callback(this));
|
||||
}
|
||||
|
||||
_bindAllShortcuts() {
|
||||
for (const [key, handler] of Object.entries(KEYBINDINGS)) {
|
||||
this._bind(key, handler);
|
||||
}
|
||||
}
|
||||
|
||||
_unbindAllShortcuts() {
|
||||
for (const key in KEYBINDINGS) {
|
||||
Main.wm.removeKeybinding(key);
|
||||
}
|
||||
}
|
||||
|
||||
_onSettingsChanged() {
|
||||
this._unbindAllShortcuts();
|
||||
this._bindAllShortcuts();
|
||||
}
|
||||
|
||||
_prepareWmShortcuts() {
|
||||
const schema = this._wmSettings.settings_schema;
|
||||
const keys = [];
|
||||
if (schema.has_key("toggle-tiled-left"))
|
||||
keys.push("toggle-tiled-left", "toggle-tiled-right");
|
||||
else if (schema.has_key("tile-left"))
|
||||
keys.push("tile-left", "tile-right");
|
||||
if (schema.has_key("toggle-maximized")) keys.push("toggle-maximized");
|
||||
else {
|
||||
if (schema.has_key("maximize")) keys.push("maximize");
|
||||
if (schema.has_key("unmaximize")) keys.push("unmaximize");
|
||||
}
|
||||
if (keys.length) {
|
||||
this._wmKeysToDisable = keys;
|
||||
keys.forEach(
|
||||
(key) =>
|
||||
(this._savedWmShortcuts[
|
||||
key
|
||||
] = this._wmSettings.get_value(key))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_focusInDirection(direction) {
|
||||
const sourceWindow = global.display.get_focus_window();
|
||||
if (!sourceWindow || !this.tiler.windows.includes(sourceWindow)) return;
|
||||
|
||||
const targetWindow = this._findTargetInDirection(
|
||||
sourceWindow,
|
||||
direction
|
||||
);
|
||||
if (targetWindow) {
|
||||
targetWindow.activate(global.get_current_time());
|
||||
}
|
||||
}
|
||||
|
||||
_swapWithMaster() {
|
||||
const windows = this.tiler.windows;
|
||||
if (windows.length < 2) return;
|
||||
const focusedWindow = global.display.get_focus_window();
|
||||
if (!focusedWindow || !windows.includes(focusedWindow)) return;
|
||||
const focusedIndex = windows.indexOf(focusedWindow);
|
||||
if (focusedIndex > 0) {
|
||||
[windows[0], windows[focusedIndex]] = [
|
||||
windows[focusedIndex],
|
||||
windows[0],
|
||||
];
|
||||
} else if (focusedIndex === 0) {
|
||||
[windows[0], windows[1]] = [windows[1], windows[0]];
|
||||
}
|
||||
this.tiler.tileNow();
|
||||
if (windows.length > 0) windows[0].activate(global.get_current_time());
|
||||
}
|
||||
|
||||
_swapInDirection(direction) {
|
||||
const sourceWindow = global.display.get_focus_window();
|
||||
if (!sourceWindow || !this.tiler.windows.includes(sourceWindow)) return;
|
||||
let targetWindow = null;
|
||||
const sourceIndex = this.tiler.windows.indexOf(sourceWindow);
|
||||
if (
|
||||
sourceIndex === 0 &&
|
||||
direction === "right" &&
|
||||
this.tiler.windows.length > 1
|
||||
) {
|
||||
targetWindow = this.tiler.windows[1];
|
||||
} else {
|
||||
targetWindow = this._findTargetInDirection(sourceWindow, direction);
|
||||
}
|
||||
if (!targetWindow) return;
|
||||
const targetIndex = this.tiler.windows.indexOf(targetWindow);
|
||||
[this.tiler.windows[sourceIndex], this.tiler.windows[targetIndex]] = [
|
||||
this.tiler.windows[targetIndex],
|
||||
this.tiler.windows[sourceIndex],
|
||||
];
|
||||
this.tiler.tileNow();
|
||||
sourceWindow.activate(global.get_current_time());
|
||||
}
|
||||
|
||||
_findTargetInDirection(source, direction) {
|
||||
const sourceRect = source.get_frame_rect();
|
||||
let candidates = [];
|
||||
for (const win of this.tiler.windows) {
|
||||
if (win === source) continue;
|
||||
const targetRect = win.get_frame_rect();
|
||||
switch (direction) {
|
||||
case "left":
|
||||
if (targetRect.x < sourceRect.x) candidates.push(win);
|
||||
break;
|
||||
case "right":
|
||||
if (targetRect.x > sourceRect.x) candidates.push(win);
|
||||
break;
|
||||
case "up":
|
||||
if (targetRect.y < sourceRect.y) candidates.push(win);
|
||||
break;
|
||||
case "down":
|
||||
if (targetRect.y > sourceRect.y) candidates.push(win);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (candidates.length === 0) return null;
|
||||
let bestTarget = null;
|
||||
let minDeviation = Infinity;
|
||||
for (const win of candidates) {
|
||||
const targetRect = win.get_frame_rect();
|
||||
let deviation;
|
||||
if (direction === "left" || direction === "right") {
|
||||
deviation = Math.abs(sourceRect.y - targetRect.y);
|
||||
} else {
|
||||
deviation = Math.abs(sourceRect.x - targetRect.x);
|
||||
}
|
||||
if (deviation < minDeviation) {
|
||||
minDeviation = deviation;
|
||||
bestTarget = win;
|
||||
}
|
||||
}
|
||||
return bestTarget;
|
||||
}
|
||||
|
||||
_onGrabEnd() {
|
||||
const grabbedWindow = this.tiler.grabbedWindow;
|
||||
if (!grabbedWindow) return;
|
||||
const targetWindow = this._findTargetUnderPointer(grabbedWindow);
|
||||
if (targetWindow) {
|
||||
const sourceIndex = this.tiler.windows.indexOf(grabbedWindow);
|
||||
const targetIndex = this.tiler.windows.indexOf(targetWindow);
|
||||
[
|
||||
this.tiler.windows[sourceIndex],
|
||||
this.tiler.windows[targetIndex],
|
||||
] = [
|
||||
this.tiler.windows[targetIndex],
|
||||
this.tiler.windows[sourceIndex],
|
||||
];
|
||||
}
|
||||
this.tiler.queueTile();
|
||||
this.tiler.grabbedWindow = null;
|
||||
}
|
||||
|
||||
_findTargetUnderPointer(excludeWindow) {
|
||||
let [pointerX, pointerY] = global.get_pointer();
|
||||
let windows = global
|
||||
.get_window_actors()
|
||||
.map((actor) => actor.meta_window)
|
||||
.filter((win) => {
|
||||
if (
|
||||
!win ||
|
||||
win === excludeWindow ||
|
||||
!this.tiler.windows.includes(win)
|
||||
)
|
||||
return false;
|
||||
let frame = win.get_frame_rect();
|
||||
return (
|
||||
pointerX >= frame.x &&
|
||||
pointerX < frame.x + frame.width &&
|
||||
pointerY >= frame.y &&
|
||||
pointerY < frame.y + frame.height
|
||||
);
|
||||
});
|
||||
if (windows.length > 0) {
|
||||
return windows[windows.length - 1];
|
||||
}
|
||||
|
||||
let bestTarget = null;
|
||||
let maxOverlap = 0;
|
||||
const sourceFrame = excludeWindow.get_frame_rect();
|
||||
for (const win of this.tiler.windows) {
|
||||
if (win === excludeWindow) continue;
|
||||
const targetFrame = win.get_frame_rect();
|
||||
const overlapX = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
sourceFrame.x + sourceFrame.width,
|
||||
targetFrame.x + targetFrame.width
|
||||
) - Math.max(sourceFrame.x, targetFrame.x)
|
||||
);
|
||||
const overlapY = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
sourceFrame.y + sourceFrame.height,
|
||||
targetFrame.y + targetFrame.height
|
||||
) - Math.max(sourceFrame.y, targetFrame.y)
|
||||
);
|
||||
const overlapArea = overlapX * overlapY;
|
||||
if (overlapArea > maxOverlap) {
|
||||
maxOverlap = overlapArea;
|
||||
bestTarget = win;
|
||||
}
|
||||
}
|
||||
return bestTarget;
|
||||
}
|
||||
}
|
||||
|
||||
// --- TILER ---
|
||||
class Tiler {
|
||||
constructor() {
|
||||
this.windows = [];
|
||||
this.grabbedWindow = null;
|
||||
this._settings = ExtensionUtils.getSettings(SCHEMA_NAME);
|
||||
this._signalIds = new Map();
|
||||
this._tileInProgress = false;
|
||||
|
||||
this._innerGap = this._settings.get_int("inner-gap");
|
||||
this._outerGapVertical = this._settings.get_int("outer-gap-vertical");
|
||||
this._outerGapHorizontal = this._settings.get_int("outer-gap-horizontal");
|
||||
|
||||
this._tilingDelay = TILING_DELAY_MS;
|
||||
this._centeringDelay = CENTERING_DELAY_MS;
|
||||
|
||||
this._exceptions = [];
|
||||
this._interactionHandler = new InteractionHandler(this);
|
||||
|
||||
this._tileTimeoutId = null;
|
||||
this._centerTimeoutIds = [];
|
||||
|
||||
this._onWindowAdded = this._onWindowAdded.bind(this);
|
||||
this._onWindowRemoved = this._onWindowRemoved.bind(this);
|
||||
this._onActiveWorkspaceChanged = this._onActiveWorkspaceChanged.bind(
|
||||
this
|
||||
);
|
||||
this._onWindowMinimizedStateChanged = this._onWindowMinimizedStateChanged.bind(
|
||||
this
|
||||
);
|
||||
this._onSettingsChanged = this._onSettingsChanged.bind(this);
|
||||
}
|
||||
|
||||
enable() {
|
||||
this._loadExceptions();
|
||||
const workspaceManager = global.workspace_manager;
|
||||
this._signalIds.set("workspace-changed", {
|
||||
object: workspaceManager,
|
||||
id: workspaceManager.connect(
|
||||
"active-workspace-changed",
|
||||
this._onActiveWorkspaceChanged
|
||||
),
|
||||
});
|
||||
this._connectToWorkspace();
|
||||
this._interactionHandler.enable();
|
||||
this._signalIds.set("settings-changed", {
|
||||
object: this._settings,
|
||||
id: this._settings.connect("changed", this._onSettingsChanged),
|
||||
});
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this._tileTimeoutId) {
|
||||
GLib.source_remove(this._tileTimeoutId);
|
||||
this._tileTimeoutId = null;
|
||||
}
|
||||
this._centerTimeoutIds.forEach(id => GLib.source_remove(id));
|
||||
this._centerTimeoutIds = [];
|
||||
|
||||
this._interactionHandler.disable();
|
||||
this._disconnectFromWorkspace();
|
||||
for (const [, signal] of this._signalIds) {
|
||||
try {
|
||||
signal.object.disconnect(signal.id);
|
||||
} catch (e) {}
|
||||
}
|
||||
this._signalIds.clear();
|
||||
this.windows = [];
|
||||
}
|
||||
|
||||
_onSettingsChanged() {
|
||||
this._innerGap = this._settings.get_int("inner-gap");
|
||||
this._outerGapVertical = this._settings.get_int("outer-gap-vertical");
|
||||
this._outerGapHorizontal = this._settings.get_int("outer-gap-horizontal");
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_loadExceptions() {
|
||||
const file = Gio.file_new_for_path(Me.path + "/exceptions.txt");
|
||||
if (!file.query_exists(null)) {
|
||||
this._exceptions = [];
|
||||
return;
|
||||
}
|
||||
const [ok, data] = file.load_contents(null);
|
||||
this._exceptions = ok
|
||||
? ByteArray.toString(data)
|
||||
.split("\n")
|
||||
.map((l) => l.trim())
|
||||
.filter((l) => l && !l.startsWith("#"))
|
||||
.map((l) => l.toLowerCase())
|
||||
: [];
|
||||
}
|
||||
|
||||
_isException(win) {
|
||||
if (!win) return false;
|
||||
const wmClass = (win.get_wm_class() || "").toLowerCase();
|
||||
const appId = (win.get_gtk_application_id() || "").toLowerCase();
|
||||
return this._exceptions.includes(wmClass) || this._exceptions.includes(appId);
|
||||
}
|
||||
|
||||
_isTileable(win) {
|
||||
return (
|
||||
win &&
|
||||
!win.minimized &&
|
||||
!this._isException(win) &&
|
||||
win.get_window_type() === Meta.WindowType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
_centerWindow(win) {
|
||||
const timeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, this._centeringDelay, () => {
|
||||
const index = this._centerTimeoutIds.indexOf(timeoutId);
|
||||
if (index > -1) {
|
||||
this._centerTimeoutIds.splice(index, 1);
|
||||
}
|
||||
|
||||
if (!win || !win.get_display()) return GLib.SOURCE_REMOVE;
|
||||
if (win.get_maximized()) {
|
||||
win.unmaximize(Meta.MaximizeFlags.BOTH);
|
||||
}
|
||||
const monitorIndex = win.get_monitor();
|
||||
const workArea = Main.layoutManager.getWorkAreaForMonitor(
|
||||
monitorIndex
|
||||
);
|
||||
const frame = win.get_frame_rect();
|
||||
win.move_frame(
|
||||
true,
|
||||
workArea.x + Math.floor((workArea.width - frame.width) / 2),
|
||||
workArea.y + Math.floor((workArea.height - frame.height) / 2)
|
||||
);
|
||||
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
||||
if (win.get_display()) {
|
||||
if (typeof win.set_keep_above === "function")
|
||||
win.set_keep_above(true);
|
||||
else if (typeof win.make_above === "function")
|
||||
win.make_above();
|
||||
}
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
|
||||
this._centerTimeoutIds.push(timeoutId);
|
||||
}
|
||||
|
||||
_onWindowMinimizedStateChanged() {
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_onWindowAdded(workspace, win) {
|
||||
if (this.windows.includes(win)) return;
|
||||
|
||||
if (this._isException(win)) {
|
||||
this._centerWindow(win);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._isTileable(win)) {
|
||||
if (this._settings.get_string("new-window-behavior") === "master") {
|
||||
this.windows.unshift(win);
|
||||
} else {
|
||||
this.windows.push(win);
|
||||
}
|
||||
|
||||
const id = win.get_id();
|
||||
this._signalIds.set(`unmanaged-${id}`, {
|
||||
object: win,
|
||||
id: win.connect("unmanaged", () =>
|
||||
this._onWindowRemoved(null, win)
|
||||
),
|
||||
});
|
||||
this._signalIds.set(`size-changed-${id}`, {
|
||||
object: win,
|
||||
id: win.connect("size-changed", () => {
|
||||
if (!this.grabbedWindow) this.queueTile();
|
||||
}),
|
||||
});
|
||||
this._signalIds.set(`minimized-${id}`, {
|
||||
object: win,
|
||||
id: win.connect(
|
||||
"notify::minimized",
|
||||
this._onWindowMinimizedStateChanged
|
||||
),
|
||||
});
|
||||
|
||||
this.queueTile();
|
||||
}
|
||||
}
|
||||
|
||||
_onWindowRemoved(workspace, win) {
|
||||
const index = this.windows.indexOf(win);
|
||||
if (index > -1) {
|
||||
this.windows.splice(index, 1);
|
||||
}
|
||||
|
||||
["unmanaged", "size-changed", "minimized"].forEach((prefix) => {
|
||||
const key = `${prefix}-${win.get_id()}`;
|
||||
if (this._signalIds.has(key)) {
|
||||
const { object, id } = this._signalIds.get(key);
|
||||
try {
|
||||
object.disconnect(id);
|
||||
} catch (e) {}
|
||||
this._signalIds.delete(key);
|
||||
}
|
||||
});
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_onActiveWorkspaceChanged() {
|
||||
this._disconnectFromWorkspace();
|
||||
this._connectToWorkspace();
|
||||
}
|
||||
|
||||
_connectToWorkspace() {
|
||||
const workspace = global.workspace_manager.get_active_workspace();
|
||||
workspace
|
||||
.list_windows()
|
||||
.forEach((win) => this._onWindowAdded(workspace, win));
|
||||
this._signalIds.set("window-added", {
|
||||
object: workspace,
|
||||
id: workspace.connect("window-added", this._onWindowAdded),
|
||||
});
|
||||
this._signalIds.set("window-removed", {
|
||||
object: workspace,
|
||||
id: workspace.connect("window-removed", this._onWindowRemoved),
|
||||
});
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_disconnectFromWorkspace() {
|
||||
this.windows.slice().forEach((win) => this._onWindowRemoved(null, win));
|
||||
|
||||
["window-added", "window-removed"].forEach((key) => {
|
||||
if (this._signalIds.has(key)) {
|
||||
const { object, id } = this._signalIds.get(key);
|
||||
try {
|
||||
object.disconnect(id);
|
||||
} catch (e) {}
|
||||
this._signalIds.delete(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
queueTile() {
|
||||
if (this._tileInProgress || this._tileTimeoutId) return;
|
||||
this._tileInProgress = true;
|
||||
|
||||
this._tileTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, this._tilingDelay, () => {
|
||||
this._tileWindows();
|
||||
this._tileInProgress = false;
|
||||
this._tileTimeoutId = null;
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
}
|
||||
|
||||
tileNow() {
|
||||
if (!this._tileInProgress) {
|
||||
this._tileWindows();
|
||||
}
|
||||
}
|
||||
|
||||
_splitLayout(windows, area) {
|
||||
if (windows.length === 0) return;
|
||||
if (windows.length === 1) {
|
||||
windows[0].move_resize_frame(
|
||||
true,
|
||||
area.x,
|
||||
area.y,
|
||||
area.width,
|
||||
area.height
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const gap = Math.floor(this._innerGap / 2);
|
||||
const primaryWindows = [windows[0]];
|
||||
const secondaryWindows = windows.slice(1);
|
||||
let primaryArea, secondaryArea;
|
||||
|
||||
if (area.width > area.height) {
|
||||
const primaryWidth = Math.floor(area.width / 2) - gap;
|
||||
primaryArea = {
|
||||
x: area.x,
|
||||
y: area.y,
|
||||
width: primaryWidth,
|
||||
height: area.height,
|
||||
};
|
||||
secondaryArea = {
|
||||
x: area.x + primaryWidth + this._innerGap,
|
||||
y: area.y,
|
||||
width: area.width - primaryWidth - this._innerGap,
|
||||
height: area.height,
|
||||
};
|
||||
} else {
|
||||
const primaryHeight = Math.floor(area.height / 2) - gap;
|
||||
primaryArea = {
|
||||
x: area.x,
|
||||
y: area.y,
|
||||
width: area.width,
|
||||
height: primaryHeight,
|
||||
};
|
||||
secondaryArea = {
|
||||
x: area.x,
|
||||
y: area.y + primaryHeight + this._innerGap,
|
||||
width: area.width,
|
||||
height: area.height - primaryHeight - this._innerGap,
|
||||
};
|
||||
}
|
||||
|
||||
this._splitLayout(primaryWindows, primaryArea);
|
||||
this._splitLayout(secondaryWindows, secondaryArea);
|
||||
}
|
||||
|
||||
_tileWindows() {
|
||||
const windowsToTile = this.windows.filter((win) => !win.minimized);
|
||||
if (windowsToTile.length === 0) return;
|
||||
const monitor = Main.layoutManager.primaryMonitor;
|
||||
const workArea = Main.layoutManager.getWorkAreaForMonitor(
|
||||
monitor.index
|
||||
);
|
||||
const innerArea = {
|
||||
x: workArea.x + this._outerGapHorizontal,
|
||||
y: workArea.y + this._outerGapVertical,
|
||||
width: workArea.width - 2 * this._outerGapHorizontal,
|
||||
height: workArea.height - 2 * this._outerGapVertical,
|
||||
};
|
||||
|
||||
windowsToTile.forEach((win) => {
|
||||
if (win.get_maximized()) win.unmaximize(Meta.MaximizeFlags.BOTH);
|
||||
});
|
||||
|
||||
if (windowsToTile.length === 1) {
|
||||
windowsToTile[0].move_resize_frame(
|
||||
true,
|
||||
innerArea.x,
|
||||
innerArea.y,
|
||||
innerArea.width,
|
||||
innerArea.height
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const gap = Math.floor(this._innerGap / 2);
|
||||
const masterWidth = Math.floor(innerArea.width / 2) - gap;
|
||||
const master = windowsToTile[0];
|
||||
master.move_resize_frame(
|
||||
true,
|
||||
innerArea.x,
|
||||
innerArea.y,
|
||||
masterWidth,
|
||||
innerArea.height
|
||||
);
|
||||
const stackArea = {
|
||||
x: innerArea.x + masterWidth + this._innerGap,
|
||||
y: innerArea.y,
|
||||
width: innerArea.width - masterWidth - this._innerGap,
|
||||
height: innerArea.height,
|
||||
};
|
||||
this._splitLayout(windowsToTile.slice(1), stackArea);
|
||||
}
|
||||
}
|
||||
|
||||
// --- EXTENSION WRAPPER ---
|
||||
var LegacyExtension = class {
|
||||
constructor() {
|
||||
this.tiler = null;
|
||||
}
|
||||
enable() {
|
||||
this.tiler = new Tiler();
|
||||
this.tiler.enable();
|
||||
}
|
||||
disable() {
|
||||
if (this.tiler) {
|
||||
this.tiler.disable();
|
||||
this.tiler = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
+9
-3
@@ -1,9 +1,15 @@
|
||||
{
|
||||
"uuid": "simple-tiling@domoel",
|
||||
"name": "Simple Tiling",
|
||||
"description": "A Simple Tiling Extension for Gnome Shell 3.38.",
|
||||
"version": 5,
|
||||
"shell-version": [ "3.38" ],
|
||||
"description": "A Simple Tiling Extension for Gnome Shell.",
|
||||
"version": 6,
|
||||
"shell-version": [
|
||||
"3.38",
|
||||
"45",
|
||||
"46",
|
||||
"47",
|
||||
"48"
|
||||
],
|
||||
"settings-schema": "org.gnome.shell.extensions.simple-tiling.domoel",
|
||||
"preferences_ui": "prefs.js",
|
||||
"url": "https://github.com/Domoel/Simple-Tiling",
|
||||
|
||||
@@ -0,0 +1,693 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Simple-Tiling – MODERN (for GNOME Shell 40+) //
|
||||
// © 2025 domoel – MIT //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// --- GLOBAL IMPORTS ---
|
||||
import { Extension } from "resource:///org/gnome/shell/extensions/extension.js";
|
||||
import * as Main from "resource:///org/gnome/shell/ui/main.js";
|
||||
import Meta from "gi://Meta";
|
||||
import Shell from "gi://Shell";
|
||||
import Gio from "gi://Gio";
|
||||
import GLib from "gi://GLib";
|
||||
|
||||
const SCHEMA_NAME = "org.gnome.shell.extensions.simple-tiling.domoel";
|
||||
const WM_SCHEMA = "org.gnome.desktop.wm.keybindings";
|
||||
|
||||
const TILING_DELAY_MS = 20; // Change Tiling Window Delay
|
||||
const CENTERING_DELAY_MS = 5; // Change Centered Window Delay
|
||||
|
||||
const KEYBINDINGS = {
|
||||
"swap-master-window": (self) => self._swapWithMaster(),
|
||||
"swap-left-window": (self) => self._swapInDirection("left"),
|
||||
"swap-right-window": (self) => self._swapInDirection("right"),
|
||||
"swap-up-window": (self) => self._swapInDirection("up"),
|
||||
"swap-down-window": (self) => self._swapInDirection("down"),
|
||||
"focus-left": (self) => self._focusInDirection("left"),
|
||||
"focus-right": (self) => self._focusInDirection("right"),
|
||||
"focus-up": (self) => self._focusInDirection("up"),
|
||||
"focus-down": (self) => self._focusInDirection("down"),
|
||||
};
|
||||
|
||||
// --- INTERACTIONHANDLER ---
|
||||
class InteractionHandler {
|
||||
constructor(tiler) {
|
||||
this.tiler = tiler;
|
||||
this._settings = this.tiler.settings;
|
||||
this._wmSettings = new Gio.Settings({ schema: WM_SCHEMA });
|
||||
this._wmKeysToDisable = [];
|
||||
this._savedWmShortcuts = {};
|
||||
this._grabOpIds = [];
|
||||
this._settingsChangedId = null;
|
||||
}
|
||||
|
||||
enable() {
|
||||
this._prepareWmShortcuts();
|
||||
if (this._wmKeysToDisable.length) {
|
||||
this._wmKeysToDisable.forEach((key) =>
|
||||
this._wmSettings.set_value(key, new GLib.Variant("as", []))
|
||||
);
|
||||
}
|
||||
this._bindAllShortcuts();
|
||||
this._settingsChangedId = this._settings.connect("changed", () =>
|
||||
this._onSettingsChanged()
|
||||
);
|
||||
this._grabOpIds.push(
|
||||
global.display.connect(
|
||||
"grab-op-begin",
|
||||
(display, screen, window) => {
|
||||
if (this.tiler.windows.includes(window)) {
|
||||
this.tiler.grabbedWindow = window;
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
this._grabOpIds.push(
|
||||
global.display.connect("grab-op-end", () => this._onGrabEnd())
|
||||
);
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this._wmKeysToDisable.length) {
|
||||
this._wmKeysToDisable.forEach((key) =>
|
||||
this._wmSettings.set_value(key, this._savedWmShortcuts[key])
|
||||
);
|
||||
}
|
||||
this._unbindAllShortcuts();
|
||||
if (this._settingsChangedId) {
|
||||
this._settings.disconnect(this._settingsChangedId);
|
||||
this._settingsChangedId = null;
|
||||
}
|
||||
this._grabOpIds.forEach((id) => global.display.disconnect(id));
|
||||
this._grabOpIds = [];
|
||||
}
|
||||
|
||||
_bind(key, callback) {
|
||||
global.display.add_keybinding(
|
||||
key,
|
||||
this._settings,
|
||||
Meta.KeyBindingFlags.NONE,
|
||||
Shell.ActionMode.NORMAL,
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
_bindAllShortcuts() {
|
||||
for (const [key, handler] of Object.entries(KEYBINDINGS)) {
|
||||
this._bind(key, () => handler(this));
|
||||
}
|
||||
}
|
||||
|
||||
_unbindAllShortcuts() {
|
||||
for (const key in KEYBINDINGS) {
|
||||
global.display.remove_keybinding(key);
|
||||
}
|
||||
}
|
||||
|
||||
_onSettingsChanged() {
|
||||
this._unbindAllShortcuts();
|
||||
this._bindAllShortcuts();
|
||||
}
|
||||
|
||||
_prepareWmShortcuts() {
|
||||
const schema = this._wmSettings
|
||||
.get_schema_source()
|
||||
.lookup(WM_SCHEMA, true);
|
||||
if (!schema) return;
|
||||
|
||||
const addKeyIfExists = (keys, key) => {
|
||||
if (schema.has_key(key)) keys.push(key);
|
||||
};
|
||||
|
||||
const keys = [];
|
||||
if (schema.has_key("toggle-tiled-left")) {
|
||||
keys.push("toggle-tiled-left", "toggle-tiled-right");
|
||||
} else {
|
||||
addKeyIfExists(keys, "tile-left");
|
||||
addKeyIfExists(keys, "tile-right");
|
||||
}
|
||||
|
||||
if (schema.has_key("toggle-maximized")) {
|
||||
keys.push("toggle-maximized");
|
||||
} else {
|
||||
addKeyIfExists(keys, "maximize");
|
||||
addKeyIfExists(keys, "unmaximize");
|
||||
}
|
||||
|
||||
if (keys.length) {
|
||||
this._wmKeysToDisable = keys;
|
||||
keys.forEach(
|
||||
(key) =>
|
||||
(this._savedWmShortcuts[key] = this._wmSettings.get_value(
|
||||
key
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_focusInDirection(direction) {
|
||||
const sourceWindow = global.display.get_focus_window();
|
||||
if (!sourceWindow || !this.tiler.windows.includes(sourceWindow)) return;
|
||||
|
||||
const targetWindow = this._findTargetInDirection(
|
||||
sourceWindow,
|
||||
direction
|
||||
);
|
||||
if (targetWindow) {
|
||||
targetWindow.activate(global.get_current_time());
|
||||
}
|
||||
}
|
||||
|
||||
_swapWithMaster() {
|
||||
const windows = this.tiler.windows;
|
||||
if (windows.length < 2) return;
|
||||
const focusedWindow = global.display.get_focus_window();
|
||||
if (!focusedWindow || !windows.includes(focusedWindow)) return;
|
||||
const focusedIndex = windows.indexOf(focusedWindow);
|
||||
if (focusedIndex > 0) {
|
||||
[windows[0], windows[focusedIndex]] = [
|
||||
windows[focusedIndex],
|
||||
windows[0],
|
||||
];
|
||||
} else if (focusedIndex === 0) {
|
||||
[windows[0], windows[1]] = [windows[1], windows[0]];
|
||||
}
|
||||
this.tiler.tileNow();
|
||||
if (windows.length > 0) windows[0].activate(global.get_current_time());
|
||||
}
|
||||
|
||||
_swapInDirection(direction) {
|
||||
const sourceWindow = global.display.get_focus_window();
|
||||
if (!sourceWindow || !this.tiler.windows.includes(sourceWindow)) return;
|
||||
let targetWindow = null;
|
||||
const sourceIndex = this.tiler.windows.indexOf(sourceWindow);
|
||||
if (
|
||||
sourceIndex === 0 &&
|
||||
direction === "right" &&
|
||||
this.tiler.windows.length > 1
|
||||
) {
|
||||
targetWindow = this.tiler.windows[1];
|
||||
} else {
|
||||
targetWindow = this._findTargetInDirection(sourceWindow, direction);
|
||||
}
|
||||
if (!targetWindow) return;
|
||||
const targetIndex = this.tiler.windows.indexOf(targetWindow);
|
||||
[this.tiler.windows[sourceIndex], this.tiler.windows[targetIndex]] = [
|
||||
this.tiler.windows[targetIndex],
|
||||
this.tiler.windows[sourceIndex],
|
||||
];
|
||||
this.tiler.tileNow();
|
||||
sourceWindow.activate(global.get_current_time());
|
||||
}
|
||||
|
||||
_findTargetInDirection(source, direction) {
|
||||
const sourceRect = source.get_frame_rect();
|
||||
let candidates = [];
|
||||
for (const win of this.tiler.windows) {
|
||||
if (win === source) continue;
|
||||
const targetRect = win.get_frame_rect();
|
||||
switch (direction) {
|
||||
case "left":
|
||||
if (targetRect.x < sourceRect.x) candidates.push(win);
|
||||
break;
|
||||
case "right":
|
||||
if (targetRect.x > sourceRect.x) candidates.push(win);
|
||||
break;
|
||||
case "up":
|
||||
if (targetRect.y < sourceRect.y) candidates.push(win);
|
||||
break;
|
||||
case "down":
|
||||
if (targetRect.y > sourceRect.y) candidates.push(win);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (candidates.length === 0) return null;
|
||||
let bestTarget = null;
|
||||
let minDeviation = Infinity;
|
||||
for (const win of candidates) {
|
||||
const targetRect = win.get_frame_rect();
|
||||
let deviation;
|
||||
if (direction === "left" || direction === "right") {
|
||||
deviation = Math.abs(sourceRect.y - targetRect.y);
|
||||
} else {
|
||||
deviation = Math.abs(sourceRect.x - targetRect.x);
|
||||
}
|
||||
if (deviation < minDeviation) {
|
||||
minDeviation = deviation;
|
||||
bestTarget = win;
|
||||
}
|
||||
}
|
||||
return bestTarget;
|
||||
}
|
||||
|
||||
_onGrabEnd() {
|
||||
const grabbedWindow = this.tiler.grabbedWindow;
|
||||
if (!grabbedWindow) return;
|
||||
const targetWindow = this._findTargetUnderPointer(grabbedWindow);
|
||||
if (targetWindow) {
|
||||
const sourceIndex = this.tiler.windows.indexOf(grabbedWindow);
|
||||
const targetIndex = this.tiler.windows.indexOf(targetWindow);
|
||||
[
|
||||
this.tiler.windows[sourceIndex],
|
||||
this.tiler.windows[targetIndex],
|
||||
] = [
|
||||
this.tiler.windows[targetIndex],
|
||||
this.tiler.windows[sourceIndex],
|
||||
];
|
||||
}
|
||||
this.tiler.queueTile();
|
||||
this.tiler.grabbedWindow = null;
|
||||
}
|
||||
|
||||
_findTargetUnderPointer(excludeWindow) {
|
||||
let [pointerX, pointerY] = global.get_pointer();
|
||||
let windows = global
|
||||
.get_window_actors()
|
||||
.map((actor) => actor.meta_window)
|
||||
.filter((win) => {
|
||||
if (
|
||||
!win ||
|
||||
win === excludeWindow ||
|
||||
!this.tiler.windows.includes(win)
|
||||
)
|
||||
return false;
|
||||
let frame = win.get_frame_rect();
|
||||
return (
|
||||
pointerX >= frame.x &&
|
||||
pointerX < frame.x + frame.width &&
|
||||
pointerY >= frame.y &&
|
||||
pointerY < frame.y + frame.height
|
||||
);
|
||||
});
|
||||
if (windows.length > 0) {
|
||||
return windows[windows.length - 1];
|
||||
}
|
||||
|
||||
let bestTarget = null;
|
||||
let maxOverlap = 0;
|
||||
const sourceFrame = excludeWindow.get_frame_rect();
|
||||
for (const win of this.tiler.windows) {
|
||||
if (win === excludeWindow) continue;
|
||||
const targetFrame = win.get_frame_rect();
|
||||
const overlapX = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
sourceFrame.x + sourceFrame.width,
|
||||
targetFrame.x + targetFrame.width
|
||||
) - Math.max(sourceFrame.x, targetFrame.x)
|
||||
);
|
||||
const overlapY = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
sourceFrame.y + sourceFrame.height,
|
||||
targetFrame.y + targetFrame.height
|
||||
) - Math.max(sourceFrame.y, targetFrame.y)
|
||||
);
|
||||
const overlapArea = overlapX * overlapY;
|
||||
if (overlapArea > maxOverlap) {
|
||||
maxOverlap = overlapArea;
|
||||
bestTarget = win;
|
||||
}
|
||||
}
|
||||
return bestTarget;
|
||||
}
|
||||
}
|
||||
|
||||
// --- TILER ---
|
||||
class Tiler {
|
||||
constructor(extension) {
|
||||
this._extension = extension;
|
||||
this.settings = this._extension.getSettings();
|
||||
|
||||
this.windows = [];
|
||||
this.grabbedWindow = null;
|
||||
this._signalIds = new Map();
|
||||
this._tileInProgress = false;
|
||||
|
||||
this._innerGap = this.settings.get_int("inner-gap");
|
||||
this._outerGapVertical = this.settings.get_int("outer-gap-vertical");
|
||||
this._outerGapHorizontal = this.settings.get_int(
|
||||
"outer-gap-horizontal"
|
||||
);
|
||||
|
||||
this._tilingDelay = TILING_DELAY_MS;
|
||||
this._centeringDelay = CENTERING_DELAY_MS;
|
||||
|
||||
this._exceptions = [];
|
||||
this._interactionHandler = new InteractionHandler(this);
|
||||
|
||||
this._tileTimeoutId = null;
|
||||
this._centerTimeoutIds = [];
|
||||
}
|
||||
|
||||
enable() {
|
||||
this._loadExceptions();
|
||||
this._workspaceManager = global.workspace_manager;
|
||||
|
||||
this._signalIds.set("workspace-changed", {
|
||||
object: this._workspaceManager,
|
||||
id: this._workspaceManager.connect("active-workspace-changed", () =>
|
||||
this._onActiveWorkspaceChanged()
|
||||
),
|
||||
});
|
||||
this._connectToWorkspace();
|
||||
this._interactionHandler.enable();
|
||||
this._signalIds.set("settings-changed", {
|
||||
object: this.settings,
|
||||
id: this.settings.connect("changed", () =>
|
||||
this._onSettingsChanged()
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this._tileTimeoutId) {
|
||||
GLib.source_remove(this._tileTimeoutId);
|
||||
this._tileTimeoutId = null;
|
||||
}
|
||||
this._centerTimeoutIds.forEach((id) => GLib.source_remove(id));
|
||||
this._centerTimeoutIds = [];
|
||||
|
||||
this._interactionHandler.disable();
|
||||
this._disconnectFromWorkspace();
|
||||
for (const [, signal] of this._signalIds) {
|
||||
try {
|
||||
signal.object.disconnect(signal.id);
|
||||
} catch (e) {}
|
||||
}
|
||||
this._signalIds.clear();
|
||||
this.windows = [];
|
||||
}
|
||||
|
||||
_onSettingsChanged() {
|
||||
this._innerGap = this.settings.get_int("inner-gap");
|
||||
this._outerGapVertical = this.settings.get_int("outer-gap-vertical");
|
||||
this._outerGapHorizontal = this.settings.get_int(
|
||||
"outer-gap-horizontal"
|
||||
);
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_loadExceptions() {
|
||||
const file = Gio.File.new_for_path(
|
||||
this._extension.path + "/exceptions.txt"
|
||||
);
|
||||
if (!file.query_exists(null)) {
|
||||
this._exceptions = [];
|
||||
return;
|
||||
}
|
||||
const [ok, data] = file.load_contents(null);
|
||||
if (ok) {
|
||||
this._exceptions = GLib.locale_from_utf8(data)
|
||||
.split("\n")
|
||||
.map((l) => l.trim())
|
||||
.filter((l) => l && !l.startsWith("#"))
|
||||
.map((l) => l.toLowerCase());
|
||||
} else {
|
||||
this._exceptions = [];
|
||||
}
|
||||
}
|
||||
|
||||
_isException(win) {
|
||||
if (!win) return false;
|
||||
const wmClass = (win.get_wm_class() || "").toLowerCase();
|
||||
const appId = (win.get_gtk_application_id() || "").toLowerCase();
|
||||
return this._exceptions.includes(wmClass) || this._exceptions.includes(appId);
|
||||
}
|
||||
|
||||
_isTileable(win) {
|
||||
return (
|
||||
win &&
|
||||
!win.minimized &&
|
||||
!this._isException(win) &&
|
||||
win.get_window_type() === Meta.WindowType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
_centerWindow(win) {
|
||||
const timeoutId = GLib.timeout_add(
|
||||
GLib.PRIORITY_DEFAULT,
|
||||
this._centeringDelay,
|
||||
() => {
|
||||
const index = this._centerTimeoutIds.indexOf(timeoutId);
|
||||
if (index > -1) this._centerTimeoutIds.splice(index, 1);
|
||||
|
||||
if (!win || !win.get_display()) return GLib.SOURCE_REMOVE;
|
||||
if (win.get_maximized())
|
||||
win.unmaximize(Meta.MaximizeFlags.BOTH);
|
||||
|
||||
const monitorIndex = win.get_monitor();
|
||||
const workspace = this._workspaceManager.get_active_workspace();
|
||||
const workArea = workspace.get_work_area_for_monitor(
|
||||
monitorIndex
|
||||
);
|
||||
|
||||
const frame = win.get_frame_rect();
|
||||
win.move_frame(
|
||||
true,
|
||||
workArea.x + Math.floor((workArea.width - frame.width) / 2),
|
||||
workArea.y +
|
||||
Math.floor((workArea.height - frame.height) / 2)
|
||||
);
|
||||
|
||||
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
||||
if (win.get_display()) {
|
||||
if (typeof win.set_keep_above === "function")
|
||||
win.set_keep_above(true);
|
||||
else if (typeof win.make_above === "function")
|
||||
win.make_above();
|
||||
}
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
return GLib.SOURCE_REMOVE;
|
||||
}
|
||||
);
|
||||
this._centerTimeoutIds.push(timeoutId);
|
||||
}
|
||||
|
||||
_onWindowMinimizedStateChanged() {
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_onWindowAdded(workspace, win) {
|
||||
if (this.windows.includes(win)) return;
|
||||
if (this._isException(win)) {
|
||||
this._centerWindow(win);
|
||||
return;
|
||||
}
|
||||
if (this._isTileable(win)) {
|
||||
if (this.settings.get_string("new-window-behavior") === "master") {
|
||||
this.windows.unshift(win);
|
||||
} else {
|
||||
this.windows.push(win);
|
||||
}
|
||||
const id = win.get_id();
|
||||
this._signalIds.set(`unmanaged-${id}`, {
|
||||
object: win,
|
||||
id: win.connect("unmanaged", () =>
|
||||
this._onWindowRemoved(null, win)
|
||||
),
|
||||
});
|
||||
this._signalIds.set(`size-changed-${id}`, {
|
||||
object: win,
|
||||
id: win.connect("size-changed", () => {
|
||||
if (!this.grabbedWindow) this.queueTile();
|
||||
}),
|
||||
});
|
||||
this._signalIds.set(`minimized-${id}`, {
|
||||
object: win,
|
||||
id: win.connect("notify::minimized", () =>
|
||||
this._onWindowMinimizedStateChanged()
|
||||
),
|
||||
});
|
||||
this.queueTile();
|
||||
}
|
||||
}
|
||||
|
||||
_onWindowRemoved(workspace, win) {
|
||||
const index = this.windows.indexOf(win);
|
||||
if (index > -1) this.windows.splice(index, 1);
|
||||
|
||||
["unmanaged", "size-changed", "minimized"].forEach((prefix) => {
|
||||
const key = `${prefix}-${win.get_id()}`;
|
||||
if (this._signalIds.has(key)) {
|
||||
const { object, id } = this._signalIds.get(key);
|
||||
try {
|
||||
object.disconnect(id);
|
||||
} catch (e) {}
|
||||
this._signalIds.delete(key);
|
||||
}
|
||||
});
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_onActiveWorkspaceChanged() {
|
||||
this._disconnectFromWorkspace();
|
||||
this._connectToWorkspace();
|
||||
}
|
||||
|
||||
_connectToWorkspace() {
|
||||
const workspace = this._workspaceManager.get_active_workspace();
|
||||
workspace
|
||||
.list_windows()
|
||||
.forEach((win) => this._onWindowAdded(workspace, win));
|
||||
this._signalIds.set("window-added", {
|
||||
object: workspace,
|
||||
id: workspace.connect("window-added", (ws, win) =>
|
||||
this._onWindowAdded(ws, win)
|
||||
),
|
||||
});
|
||||
this._signalIds.set("window-removed", {
|
||||
object: workspace,
|
||||
id: workspace.connect("window-removed", (ws, win) =>
|
||||
this._onWindowRemoved(ws, win)
|
||||
),
|
||||
});
|
||||
this.queueTile();
|
||||
}
|
||||
|
||||
_disconnectFromWorkspace() {
|
||||
this.windows.slice().forEach((win) => this._onWindowRemoved(null, win));
|
||||
["window-added", "window-removed"].forEach((key) => {
|
||||
if (this._signalIds.has(key)) {
|
||||
const { object, id } = this._signalIds.get(key);
|
||||
try {
|
||||
object.disconnect(id);
|
||||
} catch (e) {}
|
||||
this._signalIds.delete(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
queueTile() {
|
||||
if (this._tileInProgress || this._tileTimeoutId) return;
|
||||
this._tileInProgress = true;
|
||||
this._tileTimeoutId = GLib.timeout_add(
|
||||
GLib.PRIORITY_DEFAULT,
|
||||
this._tilingDelay,
|
||||
() => {
|
||||
this._tileWindows();
|
||||
this._tileInProgress = false;
|
||||
this._tileTimeoutId = null;
|
||||
return GLib.SOURCE_REMOVE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
tileNow() {
|
||||
if (!this._tileInProgress) {
|
||||
this._tileWindows();
|
||||
}
|
||||
}
|
||||
|
||||
_splitLayout(windows, area) {
|
||||
if (windows.length === 0) return;
|
||||
if (windows.length === 1) {
|
||||
windows[0].move_resize_frame(
|
||||
true,
|
||||
area.x,
|
||||
area.y,
|
||||
area.width,
|
||||
area.height
|
||||
);
|
||||
return;
|
||||
}
|
||||
const gap = Math.floor(this._innerGap / 2);
|
||||
const primaryWindows = [windows[0]];
|
||||
const secondaryWindows = windows.slice(1);
|
||||
let primaryArea, secondaryArea;
|
||||
if (area.width > area.height) {
|
||||
const primaryWidth = Math.floor(area.width / 2) - gap;
|
||||
primaryArea = {
|
||||
x: area.x,
|
||||
y: area.y,
|
||||
width: primaryWidth,
|
||||
height: area.height,
|
||||
};
|
||||
secondaryArea = {
|
||||
x: area.x + primaryWidth + this._innerGap,
|
||||
y: area.y,
|
||||
width: area.width - primaryWidth - this._innerGap,
|
||||
height: area.height,
|
||||
};
|
||||
} else {
|
||||
const primaryHeight = Math.floor(area.height / 2) - gap;
|
||||
primaryArea = {
|
||||
x: area.x,
|
||||
y: area.y,
|
||||
width: area.width,
|
||||
height: primaryHeight,
|
||||
};
|
||||
secondaryArea = {
|
||||
x: area.x,
|
||||
y: area.y + primaryHeight + this._innerGap,
|
||||
width: area.width,
|
||||
height: area.height - primaryHeight - this._innerGap,
|
||||
};
|
||||
}
|
||||
this._splitLayout(primaryWindows, primaryArea);
|
||||
this._splitLayout(secondaryWindows, secondaryArea);
|
||||
}
|
||||
|
||||
_tileWindows() {
|
||||
const windowsToTile = this.windows.filter((win) => !win.minimized);
|
||||
if (windowsToTile.length === 0) return;
|
||||
|
||||
const monitor = Main.layoutManager.primaryMonitor;
|
||||
const workspace = this._workspaceManager.get_active_workspace();
|
||||
const workArea = workspace.get_work_area_for_monitor(monitor.index);
|
||||
|
||||
const innerArea = {
|
||||
x: workArea.x + this._outerGapHorizontal,
|
||||
y: workArea.y + this._outerGapVertical,
|
||||
width: workArea.width - 2 * this._outerGapHorizontal,
|
||||
height: workArea.height - 2 * this._outerGapVertical,
|
||||
};
|
||||
windowsToTile.forEach((win) => {
|
||||
if (win.get_maximized()) win.unmaximize(Meta.MaximizeFlags.BOTH);
|
||||
});
|
||||
if (windowsToTile.length === 1) {
|
||||
windowsToTile[0].move_resize_frame(
|
||||
true,
|
||||
innerArea.x,
|
||||
innerArea.y,
|
||||
innerArea.width,
|
||||
innerArea.height
|
||||
);
|
||||
return;
|
||||
}
|
||||
const gap = Math.floor(this._innerGap / 2);
|
||||
const masterWidth = Math.floor(innerArea.width / 2) - gap;
|
||||
const master = windowsToTile[0];
|
||||
master.move_resize_frame(
|
||||
true,
|
||||
innerArea.x,
|
||||
innerArea.y,
|
||||
masterWidth,
|
||||
innerArea.height
|
||||
);
|
||||
const stackArea = {
|
||||
x: innerArea.x + masterWidth + this._innerGap,
|
||||
y: innerArea.y,
|
||||
width: innerArea.width - masterWidth - this._innerGap,
|
||||
height: innerArea.height,
|
||||
};
|
||||
this._splitLayout(windowsToTile.slice(1), stackArea);
|
||||
}
|
||||
}
|
||||
|
||||
// --- MODERN EXTENSION WRAPPER ---
|
||||
export default class ModernExtension extends Extension {
|
||||
enable() {
|
||||
this.tiler = new Tiler(this);
|
||||
this.tiler.enable();
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this.tiler) {
|
||||
this.tiler.disable();
|
||||
this.tiler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +1,142 @@
|
||||
// ------------------------------------------------------ //
|
||||
// Extension Settings Menu for Simple Tiling - Version 5 //
|
||||
// © 2025 domoel – MIT //
|
||||
// ------------------------------------------------------ //
|
||||
///////////////////////////////////////////////////////
|
||||
// --- Extension Settings Menu for Simple Tiling --- //
|
||||
// --- © 2025 domoel – MIT --- //
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
// ---------------------------------------------------- //
|
||||
// Global Imports //
|
||||
// ---------------------------------------------------- //
|
||||
"use strict";
|
||||
|
||||
const { Gtk, GObject, Gio } = imports.gi;
|
||||
// --- GLOBAL IMPORTS ---
|
||||
'use strict';
|
||||
|
||||
const { Gtk, GObject, Gio, GLib } = imports.gi;
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
|
||||
const SCHEMA_NAME = "org.gnome.shell.extensions.simple-tiling.domoel";
|
||||
// --- Global Version Checkup ---
|
||||
let Adw;
|
||||
try {
|
||||
Adw = imports.gi.Adw;
|
||||
} catch (e) {
|
||||
Adw = null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------- //
|
||||
// Definition of Row Model //
|
||||
// ---------------------------------------------------- //
|
||||
const COLUMN_ID = 0;
|
||||
const COLUMN_DESC = 1;
|
||||
const COLUMN_KEY = 2;
|
||||
const COLUMN_MODS = 3;
|
||||
|
||||
function init() {}
|
||||
|
||||
function buildPrefsWidget() {
|
||||
const settings = ExtensionUtils.getSettings(SCHEMA_NAME);
|
||||
// --- DEFINITIONS ---
|
||||
|
||||
// --- Definitions for GNOME Shell 40+ ---
|
||||
const ModernPrefs = Adw ? class extends ExtensionPreferences {
|
||||
fillPreferencesWindow(window) {
|
||||
const settings = this.getSettings();
|
||||
const page = new Adw.PreferencesPage();
|
||||
window.add(page);
|
||||
|
||||
// --- Window Gaps ---
|
||||
const groupGaps = new Adw.PreferencesGroup({ title: 'Window Gaps' });
|
||||
page.add(groupGaps);
|
||||
|
||||
const rowInnerGap = new Adw.SpinRow({
|
||||
title: 'Inner Gap',
|
||||
subtitle: 'The gap between windows in pixels.',
|
||||
adjustment: new Gtk.Adjustment({ lower: 0, upper: 100, step_increment: 1 }),
|
||||
});
|
||||
groupGaps.add(rowInnerGap);
|
||||
settings.bind('inner-gap', rowInnerGap, 'value', Gio.SettingsBindFlags.DEFAULT);
|
||||
|
||||
const rowOuterHGap = new Adw.SpinRow({
|
||||
title: 'Outer Gap (horizontal)',
|
||||
subtitle: 'The gap to the left and right screen edges.',
|
||||
adjustment: new Gtk.Adjustment({ lower: 0, upper: 100, step_increment: 1 }),
|
||||
});
|
||||
groupGaps.add(rowOuterHGap);
|
||||
settings.bind('outer-gap-horizontal', rowOuterHGap, 'value', Gio.SettingsBindFlags.DEFAULT);
|
||||
|
||||
const rowOuterVGap = new Adw.SpinRow({
|
||||
title: 'Outer Gap (vertical)',
|
||||
subtitle: 'The gap to the top and bottom screen edges.',
|
||||
adjustment: new Gtk.Adjustment({ lower: 0, upper: 100, step_increment: 1 }),
|
||||
});
|
||||
groupGaps.add(rowOuterVGap);
|
||||
settings.bind('outer-gap-vertical', rowOuterVGap, 'value', Gio.SettingsBindFlags.DEFAULT);
|
||||
|
||||
// --- Window Behavior ---
|
||||
const groupBehavior = new Adw.PreferencesGroup({ title: 'Window Behavior' });
|
||||
page.add(groupBehavior);
|
||||
|
||||
const rowNewWindow = new Adw.ComboRow({
|
||||
title: 'Open new windows as',
|
||||
subtitle: 'Determines if a new window is added as master or stack window.',
|
||||
model: new Gtk.StringList({ strings: ['Stack Window (Default)', 'Master Window'] }),
|
||||
});
|
||||
groupBehavior.add(rowNewWindow);
|
||||
|
||||
const mapping = new Gio.SettingsBindMapping({
|
||||
settings: settings, key: 'new-window-behavior', property: 'selected',
|
||||
get_mapping: (value, variant_type) => value === 'master' ? 1 : 0,
|
||||
set_mapping: (value, param_type) => new GLib.Variant('s', value === 1 ? 'master' : 'stack'),
|
||||
});
|
||||
settings.bind_with_mapping('new-window-behavior', rowNewWindow, 'selected', Gio.SettingsBindFlags.DEFAULT, mapping);
|
||||
|
||||
// --- Keybindings ---
|
||||
const groupKeys = new Adw.PreferencesGroup({ title: 'Keybindings' });
|
||||
page.add(groupKeys);
|
||||
|
||||
const rowKeys = new Adw.ActionRow({
|
||||
title: 'Configure Shortcuts',
|
||||
subtitle: 'All shortcuts can be configured in GNOME\'s main Keyboard settings.',
|
||||
});
|
||||
groupKeys.add(rowKeys);
|
||||
|
||||
const button = new Gtk.Button({ label: 'Open Keyboard Settings', valign: Gtk.Align.CENTER });
|
||||
button.connect('clicked', () => {
|
||||
const appInfo = Gio.AppInfo.create_from_commandline(
|
||||
'gnome-control-center keyboard', null, Gio.AppInfoCreateFlags.NONE
|
||||
);
|
||||
appInfo.launch([], null);
|
||||
});
|
||||
rowKeys.add_suffix(button);
|
||||
rowKeys.set_activatable_widget(button);
|
||||
}
|
||||
} : null;
|
||||
|
||||
|
||||
// --- Definitions for GNOME Shell 3.38 ---
|
||||
const buildLegacyPrefsWidget = () => {
|
||||
const settings = ExtensionUtils.getSettings("org.gnome.shell.extensions.simple-tiling.domoel");
|
||||
const prefsWidget = new Gtk.Box({
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
margin_top: 20,
|
||||
margin_bottom: 20,
|
||||
margin_start: 20,
|
||||
margin_end: 20,
|
||||
margin_top: 20, margin_bottom: 20, margin_start: 20, margin_end: 20,
|
||||
spacing: 18,
|
||||
visible: true,
|
||||
});
|
||||
|
||||
// ---------------------------------------------------- //
|
||||
// Section for Keybindings //
|
||||
// ---------------------------------------------------- //
|
||||
const keysTitle = new Gtk.Label({
|
||||
label: "<b>Tastenkürzel</b>",
|
||||
use_markup: true,
|
||||
halign: Gtk.Align.START,
|
||||
visible: true,
|
||||
});
|
||||
const keysFrame = new Gtk.Frame({
|
||||
label_widget: keysTitle,
|
||||
shadow_type: Gtk.ShadowType.NONE,
|
||||
visible: true,
|
||||
});
|
||||
let keysBox = new Gtk.Box({
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
margin: 12,
|
||||
spacing: 6,
|
||||
visible: true,
|
||||
});
|
||||
// --- Keybindings ---
|
||||
const keysTitle = new Gtk.Label({ label: "<b>Keybindings</b>", use_markup: true, halign: Gtk.Align.START, visible: true });
|
||||
const keysFrame = new Gtk.Frame({ label_widget: keysTitle, shadow_type: Gtk.ShadowType.NONE, visible: true });
|
||||
let keysBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL, margin: 12, spacing: 6, visible: true });
|
||||
keysFrame.add(keysBox);
|
||||
|
||||
let store = new Gtk.ListStore();
|
||||
store.set_column_types([
|
||||
GObject.TYPE_STRING,
|
||||
GObject.TYPE_STRING,
|
||||
GObject.TYPE_INT,
|
||||
GObject.TYPE_INT,
|
||||
]);
|
||||
store.set_column_types([ GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_INT, GObject.TYPE_INT ]);
|
||||
|
||||
addKeybinding(store, settings, "swap-master-window", "Master-Fenster tauschen");
|
||||
const COLUMN_ID = 0, COLUMN_DESC = 1, COLUMN_KEY = 2, COLUMN_MODS = 3;
|
||||
const addKeybinding = (id, desc) => {
|
||||
let [key, mods] = [0, 0];
|
||||
const strv = settings.get_strv(id);
|
||||
if (strv && strv[0]) [key, mods] = Gtk.accelerator_parse(strv[0]);
|
||||
let iter = store.append();
|
||||
store.set(iter, [COLUMN_ID, COLUMN_DESC, COLUMN_KEY, COLUMN_MODS], [id, desc, key, mods]);
|
||||
};
|
||||
|
||||
addKeybinding(store, settings, "swap-up-window", "Fenster nach oben tauschen");
|
||||
addKeybinding(store, settings, "swap-down-window", "Fenster nach unten tauschen");
|
||||
addKeybinding(store, settings, "swap-left-window", "Fenster nach links tauschen");
|
||||
addKeybinding(store, settings, "swap-right-window", "Fenster nach rechts tauschen");
|
||||
addKeybinding("swap-master-window", "Swap current window with master");
|
||||
addKeybinding("swap-up-window", "Swap current window with window above");
|
||||
addKeybinding("swap-down-window", "Swap current window with window below");
|
||||
addKeybinding("swap-left-window", "Swap current window with window to the left");
|
||||
addKeybinding("swap-right-window", "Swap current window with window to the right");
|
||||
addKeybinding("focus-up", "Focus window above");
|
||||
addKeybinding("focus-down", "Focus window below");
|
||||
addKeybinding("focus-left", "Focus window to the left");
|
||||
addKeybinding("focus-right", "Focus window to the right");
|
||||
|
||||
addKeybinding(store, settings, "focus-up", "Fokus nach oben wechseln");
|
||||
addKeybinding(store, settings, "focus-down", "Fokus nach unten wechseln");
|
||||
addKeybinding(store, settings, "focus-left", "Fokus nach links wechseln");
|
||||
addKeybinding(store, settings, "focus-right", "Fokus nach rechts wechseln");
|
||||
|
||||
let treeView = new Gtk.TreeView({
|
||||
model: store,
|
||||
headers_visible: false,
|
||||
hexpand: true,
|
||||
visible: true,
|
||||
});
|
||||
let treeView = new Gtk.TreeView({ model: store, headers_visible: false, hexpand: true, visible: true });
|
||||
keysBox.add(treeView);
|
||||
|
||||
let descRenderer = new Gtk.CellRendererText();
|
||||
@@ -92,26 +145,14 @@ function buildPrefsWidget() {
|
||||
descColumn.add_attribute(descRenderer, "text", COLUMN_DESC);
|
||||
treeView.append_column(descColumn);
|
||||
|
||||
let accelRenderer = new Gtk.CellRendererAccel({
|
||||
"accel-mode": Gtk.CellRendererAccelMode.GTK,
|
||||
editable: true,
|
||||
});
|
||||
let accelColumn = new Gtk.TreeViewColumn();
|
||||
accelColumn.pack_end(accelRenderer, false);
|
||||
accelColumn.add_attribute(accelRenderer, "accel-key", COLUMN_KEY);
|
||||
accelColumn.add_attribute(accelRenderer, "accel-mods", COLUMN_MODS);
|
||||
treeView.append_column(accelColumn);
|
||||
|
||||
let accelRenderer = new Gtk.CellRendererAccel({ "accel-mode": Gtk.CellRendererAccelMode.GTK, editable: true });
|
||||
accelRenderer.connect("accel-edited", (r, path, key, mods) => {
|
||||
let [ok, iter] = store.get_iter_from_string(path);
|
||||
if (ok) {
|
||||
store.set(iter, [COLUMN_KEY, COLUMN_MODS], [key, mods]);
|
||||
settings.set_strv(store.get_value(iter, COLUMN_ID), [
|
||||
Gtk.accelerator_name(key, mods),
|
||||
]);
|
||||
settings.set_strv(store.get_value(iter, COLUMN_ID), [ Gtk.accelerator_name(key, mods) ]);
|
||||
}
|
||||
});
|
||||
|
||||
accelRenderer.connect("accel-cleared", (r, path) => {
|
||||
let [ok, iter] = store.get_iter_from_string(path);
|
||||
if (ok) {
|
||||
@@ -119,129 +160,62 @@ function buildPrefsWidget() {
|
||||
settings.set_strv(store.get_value(iter, COLUMN_ID), []);
|
||||
}
|
||||
});
|
||||
|
||||
let accelColumn = new Gtk.TreeViewColumn();
|
||||
accelColumn.pack_end(accelRenderer, false);
|
||||
accelColumn.add_attribute(accelRenderer, "accel-key", COLUMN_KEY);
|
||||
accelColumn.add_attribute(accelRenderer, "accel-mods", COLUMN_MODS);
|
||||
treeView.append_column(accelColumn);
|
||||
prefsWidget.add(keysFrame);
|
||||
|
||||
// ---------------------------------------------------- //
|
||||
// Section for Window Gaps //
|
||||
// ---------------------------------------------------- //
|
||||
const gapsTitle = new Gtk.Label({
|
||||
label: "<b>Fensterabstände (Gaps)</b>",
|
||||
use_markup: true,
|
||||
halign: Gtk.Align.START,
|
||||
visible: true,
|
||||
});
|
||||
const gapsFrame = new Gtk.Frame({
|
||||
label_widget: gapsTitle,
|
||||
shadow_type: Gtk.ShadowType.NONE,
|
||||
visible: true,
|
||||
});
|
||||
const gapsGrid = new Gtk.Grid({
|
||||
margin: 12,
|
||||
column_spacing: 12,
|
||||
row_spacing: 12,
|
||||
visible: true,
|
||||
});
|
||||
// --- Window Gaps ---
|
||||
const gapsTitle = new Gtk.Label({ label: "<b>Window Gaps</b>", use_markup: true, halign: Gtk.Align.START, visible: true });
|
||||
const gapsFrame = new Gtk.Frame({ label_widget: gapsTitle, shadow_type: Gtk.ShadowType.NONE, visible: true });
|
||||
const gapsGrid = new Gtk.Grid({ margin: 12, column_spacing: 12, row_spacing: 12, visible: true });
|
||||
gapsFrame.add(gapsGrid);
|
||||
|
||||
addSpinButtonRow(gapsGrid, settings, "Innerer Abstand", "inner-gap", 0);
|
||||
addSpinButtonRow(
|
||||
gapsGrid,
|
||||
settings,
|
||||
"Äußerer Abstand (horizontal)",
|
||||
"outer-gap-horizontal",
|
||||
1
|
||||
);
|
||||
addSpinButtonRow(
|
||||
gapsGrid,
|
||||
settings,
|
||||
"Äußerer Abstand (vertikal)",
|
||||
"outer-gap-vertical",
|
||||
2
|
||||
);
|
||||
|
||||
const addSpinButtonRow = (desc, key, pos) => {
|
||||
const label = new Gtk.Label({ label: desc, halign: Gtk.Align.START, visible: true });
|
||||
gapsGrid.attach(label, 0, pos, 1, 1);
|
||||
const adj = new Gtk.Adjustment({ lower: 0, upper: 50, step_increment: 1 });
|
||||
const spin = new Gtk.SpinButton({ adjustment: adj, climb_rate: 1, digits: 0, halign: Gtk.Align.END, visible: true });
|
||||
settings.bind(key, spin, "value", Gio.SettingsBindFlags.DEFAULT);
|
||||
gapsGrid.attach(spin, 1, pos, 1, 1);
|
||||
};
|
||||
addSpinButtonRow("Inner Gap", "inner-gap", 0);
|
||||
addSpinButtonRow("Outer Gap (horizontal)", "outer-gap-horizontal", 1);
|
||||
addSpinButtonRow("Outer Gap (vertical)", "outer-gap-vertical", 2);
|
||||
prefsWidget.add(gapsFrame);
|
||||
|
||||
// ---------------------------------------------------- //
|
||||
// Section for Window Behavior (Master vs. Stack) //
|
||||
// ---------------------------------------------------- //
|
||||
const behaviorTitle = new Gtk.Label({
|
||||
label: "<b>Fensterverhalten</b>",
|
||||
use_markup: true,
|
||||
halign: Gtk.Align.START,
|
||||
visible: true,
|
||||
});
|
||||
const behaviorFrame = new Gtk.Frame({
|
||||
label_widget: behaviorTitle,
|
||||
shadow_type: Gtk.ShadowType.NONE,
|
||||
visible: true,
|
||||
});
|
||||
const behaviorGrid = new Gtk.Grid({
|
||||
margin: 12,
|
||||
column_spacing: 12,
|
||||
row_spacing: 12,
|
||||
visible: true,
|
||||
});
|
||||
// --- Window Behavior ---
|
||||
const behaviorTitle = new Gtk.Label({ label: "<b>Window Behavior</b>", use_markup: true, halign: Gtk.Align.START, visible: true });
|
||||
const behaviorFrame = new Gtk.Frame({ label_widget: behaviorTitle, shadow_type: Gtk.ShadowType.NONE, visible: true });
|
||||
const behaviorGrid = new Gtk.Grid({ margin: 12, column_spacing: 12, row_spacing: 12, visible: true });
|
||||
behaviorFrame.add(behaviorGrid);
|
||||
addComboBoxRow(
|
||||
behaviorGrid,
|
||||
settings,
|
||||
"Neues Fenster öffnen als",
|
||||
"new-window-behavior",
|
||||
0
|
||||
);
|
||||
|
||||
const label = new Gtk.Label({ label: "Open new windows as", halign: Gtk.Align.START, visible: true });
|
||||
behaviorGrid.attach(label, 0, 0, 1, 1);
|
||||
const combo = new Gtk.ComboBoxText({ visible: true, halign: Gtk.Align.END });
|
||||
combo.append("stack", "Stack Window (Default)");
|
||||
combo.append("master", "Master Window");
|
||||
combo.set_active_id(settings.get_string("new-window-behavior"));
|
||||
combo.connect("changed", () => {
|
||||
settings.set_string("new-window-behavior", combo.get_active_id());
|
||||
});
|
||||
behaviorGrid.attach(combo, 1, 0, 1, 1);
|
||||
prefsWidget.add(behaviorFrame);
|
||||
|
||||
return prefsWidget;
|
||||
};
|
||||
|
||||
|
||||
// --- MAIN ENTRY POINTS (called by GNOME Shell) ---
|
||||
|
||||
function init() {}
|
||||
|
||||
function buildPrefsWidget() {
|
||||
return buildLegacyPrefsWidget();
|
||||
}
|
||||
|
||||
function addKeybinding(model, settings, id, desc) {
|
||||
let [key, mods] = [0, 0];
|
||||
const strv = settings.get_strv(id);
|
||||
if (strv && strv[0]) {
|
||||
[key, mods] = Gtk.accelerator_parse(strv[0]);
|
||||
}
|
||||
let iter = model.append();
|
||||
model.set(
|
||||
iter,
|
||||
[COLUMN_ID, COLUMN_DESC, COLUMN_KEY, COLUMN_MODS],
|
||||
[id, desc, key, mods]
|
||||
);
|
||||
}
|
||||
function addSpinButtonRow(grid, settings, desc, key, pos) {
|
||||
const label = new Gtk.Label({
|
||||
label: desc,
|
||||
halign: Gtk.Align.START,
|
||||
visible: true,
|
||||
});
|
||||
grid.attach(label, 0, pos, 1, 1);
|
||||
const adj = new Gtk.Adjustment({ lower: 0, upper: 50, step_increment: 1 });
|
||||
const spin = new Gtk.SpinButton({
|
||||
adjustment: adj,
|
||||
climb_rate: 1,
|
||||
digits: 0,
|
||||
halign: Gtk.Align.END,
|
||||
visible: true,
|
||||
});
|
||||
settings.bind(key, spin, "value", Gio.SettingsBindFlags.DEFAULT);
|
||||
grid.attach(spin, 1, pos, 1, 1);
|
||||
}
|
||||
function addComboBoxRow(grid, settings, desc, key, pos) {
|
||||
const label = new Gtk.Label({
|
||||
label: desc,
|
||||
halign: Gtk.Align.START,
|
||||
visible: true,
|
||||
});
|
||||
grid.attach(label, 0, pos, 1, 1);
|
||||
const combo = new Gtk.ComboBoxText({
|
||||
visible: true,
|
||||
halign: Gtk.Align.END,
|
||||
});
|
||||
combo.append("stack", "Stack-Fenster (Standard)");
|
||||
combo.append("master", "Master-Fenster");
|
||||
combo.set_active_id(settings.get_string(key));
|
||||
combo.connect("changed", () => {
|
||||
settings.set_string(key, combo.get_active_id());
|
||||
});
|
||||
grid.attach(combo, 1, pos, 1, 1);
|
||||
if (Adw) {
|
||||
var defaultExport = ModernPrefs;
|
||||
}
|
||||
|
||||
@@ -4,59 +4,59 @@
|
||||
|
||||
<key name="swap-master-window" type="as">
|
||||
<default><![CDATA[['<Super>Return']]]></default>
|
||||
<summary>Tauscht das fokussierte Fenster mit dem Master.</summary>
|
||||
<summary>Swap current window with master.</summary>
|
||||
</key>
|
||||
<key name="swap-up-window" type="as">
|
||||
<default><![CDATA[['<Super>Up']]]></default>
|
||||
<summary>Tauscht das Fenster mit dem oberen Nachbarn.</summary>
|
||||
<summary>Swap current window with window above.</summary>
|
||||
</key>
|
||||
<key name="swap-down-window" type="as">
|
||||
<default><![CDATA[['<Super>Down']]]></default>
|
||||
<summary>Tauscht das Fenster mit dem unteren Nachbarn.</summary>
|
||||
<summary>Swap current window with window below.</summary>
|
||||
</key>
|
||||
<key name="swap-left-window" type="as">
|
||||
<default><![CDATA[['<Super>Left']]]></default>
|
||||
<summary>Tauscht das Fenster mit dem linken Nachbarn.</summary>
|
||||
<summary>Swap current window with window to the left.</summary>
|
||||
</key>
|
||||
<key name="swap-right-window" type="as">
|
||||
<default><![CDATA[['<Super>Right']]]></default>
|
||||
<summary>Tauscht das Fenster mit dem rechten Nachbarn.</summary>
|
||||
<summary>Swap current window with window to the right.</summary>
|
||||
</key>
|
||||
|
||||
<key name="focus-up" type="as">
|
||||
<default><![CDATA[['<Alt>Up']]]></default>
|
||||
<summary>Fokus zum oberen Fenster wechseln.</summary>
|
||||
<summary>Focus window above.</summary>
|
||||
</key>
|
||||
<key name="focus-down" type="as">
|
||||
<default><![CDATA[['<Alt>Down']]]></default>
|
||||
<summary>Fokus zum unteren Fenster wechseln.</summary>
|
||||
<summary>Focus window below.</summary>
|
||||
</key>
|
||||
<key name="focus-left" type="as">
|
||||
<default><![CDATA[['<Alt>Left']]]></default>
|
||||
<summary>Fokus zum linken Fenster wechseln.</summary>
|
||||
<summary>Focus window to the left.</summary>
|
||||
</key>
|
||||
<key name="focus-right" type="as">
|
||||
<default><![CDATA[['<Alt>Right']]]></default>
|
||||
<summary>Fokus zum rechten Fenster wechseln.</summary>
|
||||
<summary>Focus window to the right.</summary>
|
||||
</key>
|
||||
|
||||
<key name="inner-gap" type="i">
|
||||
<default>10</default>
|
||||
<summary>Der Abstand zwischen den Fenstern in Pixeln.</summary>
|
||||
<summary>The gap between windows in pixels.</summary>
|
||||
</key>
|
||||
<key name="outer-gap-horizontal" type="i">
|
||||
<default>5</default>
|
||||
<summary>Der Abstand zum linken und rechten Bildschirmrand.</summary>
|
||||
<summary>The gap to the left and right screen edges.</summary>
|
||||
</key>
|
||||
<key name="outer-gap-vertical" type="i">
|
||||
<default>5</default>
|
||||
<summary>Der Abstand zum oberen und unteren Bildschirmrand.</summary>
|
||||
<summary>The gap to the top and bottom screen edges.</summary>
|
||||
</key>
|
||||
|
||||
<key name="new-window-behavior" type="s">
|
||||
<default>'stack'</default>
|
||||
<summary>Verhalten für neu geöffnete Fenster.</summary>
|
||||
<description>Legt fest, ob ein neues Fenster als Master oder als Teil des Stacks hinzugefügt wird.</description>
|
||||
<summary>Behavior for newly opened windows.</summary>
|
||||
<description>Determines if a new window is added as master or stack window.</description>
|
||||
</key>
|
||||
|
||||
</schema>
|
||||
|
||||
Reference in New Issue
Block a user