Skip to content

Commit d0df37b

Browse files
committed
feat: auto width
1 parent e86f4d1 commit d0df37b

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

keybindings.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ function init() {
164164
dynamic_function_ref("switchToNextFocusMode",
165165
Tiling));
166166

167+
registerPaperAction("switch-columns-layout",
168+
dynamic_function_ref("switchColumnsLayout",
169+
Tiling));
170+
167171
registerPaperAction("develop-set-globals",
168172
dynamic_function_ref("setDevGlobals",
169173
Utils));

prefsKeybinding.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const actions = {
3838
'live-alt-tab',
3939
'live-alt-tab-backward',
4040
'switch-focus-mode',
41+
'switch-columns-layout',
4142
'move-left',
4243
'move-right',
4344
'move-up',

schemas/gschemas.compiled

56 Bytes
Binary file not shown.

schemas/org.gnome.shell.extensions.paperwm.gschema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@
114114
<summary>Switch between Window Focus Modes (e.g. default, center)</summary>
115115
</key>
116116

117+
<key type="as" name="switch-columns-layout">
118+
<default><![CDATA[['<Super><Shift>o']]]></default>
119+
<summary>Switch columns layout</summary>
120+
</key>
121+
117122
<key type="as" name="switch-next">
118123
<default><![CDATA[['<Super>period']]]></default>
119124
<summary>Switch to the next window</summary>

tiling.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ var Me = Extension.imports.tiling;
4646

4747
var prefs = Settings.prefs;
4848

49+
var columns = 1;
50+
var autoWidth = true;
51+
4952
var backgroundSettings = new Gio.Settings({
5053
schema_id: 'org.gnome.desktop.background'
5154
})
@@ -147,6 +150,7 @@ var Space = class Space extends Array {
147150

148151
// default focusMode (can be overriden by saved user pref in Space.init method)
149152
this.focusMode = FocusModes.DEFAULT;
153+
150154
this.focusModeIcon = new TopBar.FocusIcon({
151155
name: 'panel',
152156
style_class: 'space-focus-mode-icon',
@@ -158,6 +162,9 @@ var Space = class Space extends Array {
158162
this.showFocusModeIcon();
159163
this.unfocusXPosition = null; // init
160164

165+
this.columns = columns;
166+
this.autoWidth = autoWidth;
167+
161168
let clip = new Clutter.Actor({name: "clip"});
162169
this.clip = clip;
163170
let actor = new Clutter.Actor({name: "space-actor"});
@@ -265,6 +272,7 @@ var Space = class Space extends Array {
265272

266273
this.getWindows().forEach(w => {
267274
animateWindow(w);
275+
if (this.autoWidth) setAutoWidth(w)
268276
});
269277

270278
let selected = this.selectedWindow;
@@ -705,6 +713,7 @@ var Space = class Space extends Array {
705713
this.targetX = workArea.x + Math.round((workArea.width - this.cloneContainer.width)/2);
706714
}
707715
this.emit('window-added', metaWindow, index, row);
716+
if (autoWidth) setAutoWidth(metaWindow)
708717
return true;
709718
}
710719

@@ -882,6 +891,7 @@ var Space = class Space extends Array {
882891

883892
let metaWindow = space.getWindow(index, row);
884893
ensureViewport(metaWindow, space);
894+
if (autoWidth) setAutoWidth(metaWindow)
885895
}
886896

887897
/**
@@ -3365,6 +3375,25 @@ function toggleMaximizeHorizontally(metaWindow) {
33653375
}
33663376
}
33673377

3378+
function setAutoWidth(metaWindow) {
3379+
metaWindow = metaWindow || display.focus_window;
3380+
3381+
if (metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
3382+
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
3383+
metaWindow.unmaximizedRect = null;
3384+
return;
3385+
}
3386+
3387+
let space = spaces.spaceOfWindow(metaWindow);
3388+
let workArea = space.workArea();
3389+
let frame = metaWindow.get_frame_rect();
3390+
let reqWidth = (workArea.width - prefs.minimum_margin) / space.columns - prefs.minimum_margin;
3391+
3392+
let x = workArea.x + space.monitor.x + prefs.minimum_margin;
3393+
metaWindow.unmaximizedRect = frame;
3394+
metaWindow.move_resize_frame(true, x, frame.y, reqWidth, frame.height);
3395+
}
3396+
33683397
function resizeHInc(metaWindow) {
33693398
let frame = metaWindow.get_frame_rect();
33703399
let monitor = Main.layoutManager.monitors[metaWindow.get_monitor()];
@@ -3654,6 +3683,16 @@ function switchToNextFocusMode(space) {
36543683
setFocusMode(nextMode, space);
36553684
}
36563685

3686+
function switchColumnsLayout(space) {
3687+
space = space ?? spaces.getActiveSpace();
3688+
space.columns = space.columns == 1 ? 2 : 1
3689+
3690+
space.getWindows().forEach(w => {
3691+
setAutoWidth(w)
3692+
ensureViewport(w, space);
3693+
});
3694+
}
3695+
36573696
/**
36583697
* "Fit" values such that they sum to `targetSum`
36593698
*/

0 commit comments

Comments
 (0)