Skip to content

Commit 2986911

Browse files
feat: add optional max window width setting
Co-authored-by: Jacob Kauffmann <[email protected]>
1 parent 104269e commit 2986911

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

schemas/org.gnome.shell.extensions.pop-shell.gschema.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
<key type="u" name="gap-inner">
2222
<default>2</default>
23-
<summary>Gap between tiled windows</summary>
23+
<summary>Gap between tiled windows, in pixels</summary>
2424
</key>
2525

2626
<key type="u" name="gap-outer">
2727
<default>2</default>
28-
<summary>Gap surrounding tiled windows</summary>
28+
<summary>Gap surrounding tiled windows, in pixels</summary>
2929
</key>
3030

3131
<key type="b" name="show-title">
@@ -79,6 +79,11 @@
7979
<summary>Allow for stacking windows as a result of dragging a window with mouse</summary>
8080
</key>
8181

82+
<key type="u" name="max-window-width">
83+
<default>0</default>
84+
<summary>Maximum width of tiled windows, in pixels (0 to disable)</summary>
85+
</key>
86+
8287
<!-- Focus Shifting -->
8388
<key type="as" name="focus-left">
8489
<default><![CDATA[['<Super>Left','<Super>KP_Left','<Super>h']]]></default>

src/prefs.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface AppWidgets {
2020
window_titles: any;
2121
mouse_cursor_focus_position: any;
2222
log_level: any;
23+
max_window_width: any;
2324
}
2425

2526
export default class PopShellPreferences extends ExtensionPreferences {
@@ -113,6 +114,15 @@ function settings_dialog_new(): Gtk.Container {
113114
Settings.sync();
114115
});
115116

117+
app.max_window_width.set_text(String(ext.max_window_width()));
118+
app.max_window_width.connect('activate', (widget: any) => {
119+
let parsed = parseInt((widget.get_text() as string).trim());
120+
if (!isNaN(parsed)) {
121+
ext.set_max_window_width(parsed);
122+
Settings.sync();
123+
}
124+
});
125+
116126
return grid;
117127
}
118128

@@ -162,6 +172,11 @@ function settings_dialog_view(): [AppWidgets, Gtk.Container] {
162172
xalign: 0.0,
163173
});
164174

175+
const max_window_width_label = new Gtk.Label({
176+
label: 'Max window width (in pixels); 0 to disable',
177+
xalign: 0.0,
178+
});
179+
165180
const [inner_gap, outer_gap] = gaps_section(grid, 9);
166181

167182
const settings = {
@@ -176,6 +191,7 @@ function settings_dialog_view(): [AppWidgets, Gtk.Container] {
176191
mouse_cursor_follows_active_window: new Gtk.Switch({ halign: Gtk.Align.END }),
177192
mouse_cursor_focus_position: build_combo(grid, 7, focus.FocusPosition, 'Mouse Cursor Focus Position'),
178193
log_level: build_combo(grid, 8, log.LOG_LEVELS, 'Log Level'),
194+
max_window_width: number_entry(),
179195
};
180196

181197
grid.attach(win_label, 0, 0, 1, 1);
@@ -199,6 +215,9 @@ function settings_dialog_view(): [AppWidgets, Gtk.Container] {
199215
grid.attach(mouse_cursor_follows_active_window_label, 0, 6, 1, 1);
200216
grid.attach(settings.mouse_cursor_follows_active_window, 1, 6, 1, 1);
201217

218+
grid.attach(max_window_width_label, 0, 12, 1, 1);
219+
grid.attach(settings.max_window_width, 1, 12, 1, 1);
220+
202221
return [settings, grid];
203222
}
204223

@@ -220,7 +239,7 @@ function gaps_section(grid: any, top: number): [any, any] {
220239
let inner_entry = number_entry();
221240

222241
let section_label = new Gtk.Label({
223-
label: 'Gaps',
242+
label: 'Gaps (in pixels)',
224243
xalign: 0.0,
225244
});
226245

src/settings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const LOG_LEVEL = 'log-level';
6868
const SHOW_SKIPTASKBAR = 'show-skip-taskbar';
6969
const MOUSE_CURSOR_FOLLOWS_ACTIVE_WINDOW = 'mouse-cursor-follows-active-window';
7070
const MOUSE_CURSOR_FOCUS_LOCATION = 'mouse-cursor-focus-location';
71+
const MAX_WINDOW_WIDTH = 'max-window-width';
7172

7273
export class ExtensionSettings {
7374
ext: Settings = settings_new_schema('org.gnome.shell.extensions.pop-shell');
@@ -173,6 +174,10 @@ export class ExtensionSettings {
173174
return this.ext.get_uint(MOUSE_CURSOR_FOCUS_LOCATION);
174175
}
175176

177+
max_window_width(): number {
178+
return this.ext.get_uint(MAX_WINDOW_WIDTH);
179+
}
180+
176181
// Setters
177182

178183
set_active_hint(set: boolean) {
@@ -252,4 +257,8 @@ export class ExtensionSettings {
252257
set_mouse_cursor_focus_location(set: number) {
253258
this.ext.set_uint(MOUSE_CURSOR_FOCUS_LOCATION, set);
254259
}
260+
261+
set_max_window_width(set: number) {
262+
this.ext.set_uint(MAX_WINDOW_WIDTH, set);
263+
}
255264
}

src/window.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ShellWindow {
6363
ignore_detach: boolean = false;
6464
was_attached_to?: [Entity, boolean | number];
6565
destroying: boolean = false;
66-
66+
6767
// Awaiting reassignment after a display update
6868
reassignment: boolean = false;
6969

@@ -269,7 +269,7 @@ export class ShellWindow {
269269
// look I guess I'll hack something together in here if at all possible
270270
// Because Meta.Window.is_client_decorated() was removed in Meta 15, using it breaks the extension in gnome 47 or higher
271271
//return this.meta.window_type == Meta.WindowType.META_WINDOW_OVERRIDE_OTHER;
272-
const xid = this.xid()
272+
const xid = this.xid();
273273
const extents = xid ? xprop.get_frame_extents(xid) : false;
274274
if (!extents) return false;
275275
return true;
@@ -360,6 +360,13 @@ export class ShellWindow {
360360
}
361361

362362
this.hide_border();
363+
364+
const max_width = ext.settings.max_window_width();
365+
if (max_width > 0 && rect.width > max_width) {
366+
rect.x += (rect.width - max_width) / 2;
367+
rect.width = max_width;
368+
}
369+
363370
const clone = Rect.Rectangle.from_meta(rect);
364371
const meta = this.meta;
365372
const actor = meta.get_compositor_private();

0 commit comments

Comments
 (0)