diff --git a/keybindings.js b/keybindings.js index e5f9de721..499881b22 100644 --- a/keybindings.js +++ b/keybindings.js @@ -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)); diff --git a/prefsKeybinding.js b/prefsKeybinding.js index 55ad66f3b..a668157bf 100644 --- a/prefsKeybinding.js +++ b/prefsKeybinding.js @@ -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', diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index 1a76f213c..9af901fb0 100644 Binary files a/schemas/gschemas.compiled and b/schemas/gschemas.compiled differ diff --git a/schemas/org.gnome.shell.extensions.paperwm.gschema.xml b/schemas/org.gnome.shell.extensions.paperwm.gschema.xml index 5fc7d7caa..87fc8cf64 100644 --- a/schemas/org.gnome.shell.extensions.paperwm.gschema.xml +++ b/schemas/org.gnome.shell.extensions.paperwm.gschema.xml @@ -114,6 +114,11 @@ Switch between Window Focus Modes (e.g. default, center) + + o']]]> + Switch columns layout + + period']]]> Switch to the next window diff --git a/tiling.js b/tiling.js index d4ee4c65f..e780e8f8e 100644 --- a/tiling.js +++ b/tiling.js @@ -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' }) @@ -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', @@ -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"}); @@ -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; @@ -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; } @@ -882,6 +891,7 @@ var Space = class Space extends Array { let metaWindow = space.getWindow(index, row); ensureViewport(metaWindow, space); + if (autoWidth) setAutoWidth(metaWindow) } /** @@ -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()]; @@ -3654,6 +3683,15 @@ 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) + }); +} + /** * "Fit" values such that they sum to `targetSum` */