Skip to content

Commit

Permalink
feat: auto width
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoffmano committed Nov 10, 2024
1 parent e86f4d1 commit d0df37b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions keybindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ function init() {
dynamic_function_ref("switchToNextFocusMode",
Tiling));

registerPaperAction("switch-columns-layout",
dynamic_function_ref("switchColumnsLayout",
Tiling));

registerPaperAction("develop-set-globals",
dynamic_function_ref("setDevGlobals",
Utils));
Expand Down
1 change: 1 addition & 0 deletions prefsKeybinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const actions = {
'live-alt-tab',
'live-alt-tab-backward',
'switch-focus-mode',
'switch-columns-layout',
'move-left',
'move-right',
'move-up',
Expand Down
Binary file modified schemas/gschemas.compiled
Binary file not shown.
5 changes: 5 additions & 0 deletions schemas/org.gnome.shell.extensions.paperwm.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
<summary>Switch between Window Focus Modes (e.g. default, center)</summary>
</key>

<key type="as" name="switch-columns-layout">
<default><![CDATA[['<Super><Shift>o']]]></default>
<summary>Switch columns layout</summary>
</key>

<key type="as" name="switch-next">
<default><![CDATA[['<Super>period']]]></default>
<summary>Switch to the next window</summary>
Expand Down
39 changes: 39 additions & 0 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ var Me = Extension.imports.tiling;

var prefs = Settings.prefs;

var columns = 1;
var autoWidth = true;

var backgroundSettings = new Gio.Settings({
schema_id: 'org.gnome.desktop.background'
})
Expand Down Expand Up @@ -147,6 +150,7 @@ var Space = class Space extends Array {

// default focusMode (can be overriden by saved user pref in Space.init method)
this.focusMode = FocusModes.DEFAULT;

this.focusModeIcon = new TopBar.FocusIcon({
name: 'panel',
style_class: 'space-focus-mode-icon',
Expand All @@ -158,6 +162,9 @@ var Space = class Space extends Array {
this.showFocusModeIcon();
this.unfocusXPosition = null; // init

this.columns = columns;
this.autoWidth = autoWidth;

let clip = new Clutter.Actor({name: "clip"});
this.clip = clip;
let actor = new Clutter.Actor({name: "space-actor"});
Expand Down Expand Up @@ -265,6 +272,7 @@ var Space = class Space extends Array {

this.getWindows().forEach(w => {
animateWindow(w);
if (this.autoWidth) setAutoWidth(w)
});

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

Expand Down Expand Up @@ -882,6 +891,7 @@ var Space = class Space extends Array {

let metaWindow = space.getWindow(index, row);
ensureViewport(metaWindow, space);
if (autoWidth) setAutoWidth(metaWindow)
}

/**
Expand Down Expand Up @@ -3365,6 +3375,25 @@ function toggleMaximizeHorizontally(metaWindow) {
}
}

function setAutoWidth(metaWindow) {
metaWindow = metaWindow || display.focus_window;

if (metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
metaWindow.unmaximizedRect = null;
return;
}

let space = spaces.spaceOfWindow(metaWindow);
let workArea = space.workArea();
let frame = metaWindow.get_frame_rect();
let reqWidth = (workArea.width - prefs.minimum_margin) / space.columns - prefs.minimum_margin;

let x = workArea.x + space.monitor.x + prefs.minimum_margin;
metaWindow.unmaximizedRect = frame;
metaWindow.move_resize_frame(true, x, frame.y, reqWidth, frame.height);
}

function resizeHInc(metaWindow) {
let frame = metaWindow.get_frame_rect();
let monitor = Main.layoutManager.monitors[metaWindow.get_monitor()];
Expand Down Expand Up @@ -3654,6 +3683,16 @@ function switchToNextFocusMode(space) {
setFocusMode(nextMode, space);
}

function switchColumnsLayout(space) {
space = space ?? spaces.getActiveSpace();
space.columns = space.columns == 1 ? 2 : 1

space.getWindows().forEach(w => {
setAutoWidth(w)
ensureViewport(w, space);
});
}

/**
* "Fit" values such that they sum to `targetSum`
*/
Expand Down

0 comments on commit d0df37b

Please sign in to comment.