initial import: wide tiling extension (gnome shell 50)

This commit is contained in:
Bastian Mäuser committed 2026-11-08 23:40:08 +01:00
commit 3def53e0d8
5 files changed
+140

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
// fallback width when the conky window is not found
const TILE_FRACTION = 2 / 3;
// ignore the conky window as alignment target if the tile would get narrower
const MIN_FRACTION = 0.5;
export default class WideTileExtension extends Extension {
enable() {
this._handlers = new Map();
for (const [binding, dir] of [['toggle-tiled-left', -1],
['toggle-tiled-right', 1]]) {
const handler = () => this._tileSide(dir);
Main.wm.setCustomKeybindingHandler(binding,
Shell.ActionMode.NORMAL, handler);
this._handlers.set(binding, handler);
}
this._prevRects = new WeakMap();
}
disable() {
for (const [binding] of this._handlers)
Main.wm.setCustomKeybindingHandler(binding,
Shell.ActionMode.NORMAL, null);
this._handlers = null;
this._prevRects = null;
}
_tileSide(dir) {
const win = global.display.focus_window;
if (!win || !win.allows_move() || !win.allows_resize())
return;
const wa = win.get_work_area_current_monitor();
const mon = global.display.get_monitor_geometry(win.get_monitor());
// target width: up to the left edge of the conky window on this
// monitor, falling back to a fraction of the work area
let width = Math.floor(wa.width * TILE_FRACTION);
const monIndex = win.get_monitor();
for (const actor of global.get_window_actors()) {
const mw = actor.meta_window;
if (mw.get_wm_class() === 'conky' &&
mw.get_monitor() === monIndex) {
const w = mw.get_frame_rect().x - wa.x;
if (w >= wa.width * MIN_FRACTION)
width = w;
break;
}
}
// reach the monitor's bottom edge even if the work area is a few
// pixels short
const height = mon.y + mon.height - wa.y;
const target = {
x: dir < 0 ? wa.x : wa.x + wa.width - width,
y: wa.y,
width,
height,
};
// toggle: second press restores the pre-tile geometry
const frame = win.get_frame_rect();
if (frame.x === target.x && frame.y === target.y &&
frame.width === target.width && frame.height === target.height) {
const prev = this._prevRects.get(win);
if (prev)
win.move_resize_frame(false, prev.x, prev.y,
prev.width, prev.height);
this._prevRects.delete(win);
return;
}
this._prevRects.set(win, frame);
if (win.maximized_horizontally || win.maximized_vertically)
win.unmaximize(Meta.MaximizeFlags.HORIZONTAL |
Meta.MaximizeFlags.VERTICAL);
win.move_resize_frame(false, target.x, target.y,
target.width, target.height);
}
}