diff --git a/README.md b/README.md index 61c89f83..19b289af 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Users are enouraged to submit [issues](https://github.com/paperwm/PaperWM/issues Most functionality is available using a mouse, eg. activating a window at the edge of the monitor by clicking on it. Wayland support gestures (See the [Touchpad Gestures](#touchpad-gestures) section). PaperWM is designed to work work well with keyboard + mouse, trackpads etc. -Most keybindings start with the Super modifier (by default), which is usually the Windows key, or on mac keyboards it's the Command key. It's possible to modify the keyboard layout so that Super is switched with Alt making all the keybindings easier to reach. This can be done through Gnome Tweaks under `Keybard & Mouse` ⟶ `Additional Layout Options` ⟶ `Alt/Win key behavior` ⟶ `Left Alt is swapped with Left Win`. +Most keybindings start with the Super modifier (by default), which is usually the Windows key, or on mac keyboards it's the Command key. It's possible to modify the keyboard layout so that Super is switched with Alt making all the keybindings easier to reach. This can be done through Gnome Tweaks under `Keyboard & Mouse` ⟶ `Additional Layout Options` ⟶ `Alt/Win key behavior` ⟶ `Left Alt is swapped with Left Win`. Most keybindings will grab the keyboard while Super is held down, only switching focus when Super is released. Escape will abort the navigation taking you back to the previously active window. diff --git a/keybindings.js b/keybindings.js index f3d14d42..efe18151 100644 --- a/keybindings.js +++ b/keybindings.js @@ -300,7 +300,15 @@ export function setupActions(settings) { Meta.KeyBindingFlags.PER_WINDOW); registerPaperAction("center-horizontally", - Tiling.centerWindowHorizontally, + (mw, _space) => Tiling.centerWindow(mw, true, false), + Meta.KeyBindingFlags.PER_WINDOW); + + registerPaperAction("center-vertically", + (mw, _space) => Tiling.centerWindow(mw, false, true), + Meta.KeyBindingFlags.PER_WINDOW); + + registerPaperAction("center", + (mw, _space) => Tiling.centerWindow(mw, true, true), Meta.KeyBindingFlags.PER_WINDOW); registerPaperAction('new-window', diff --git a/metadata.json b/metadata.json index a5fa59ee..a3316e8d 100644 --- a/metadata.json +++ b/metadata.json @@ -5,7 +5,7 @@ "url": "https://github.com/paperwm/PaperWM", "settings-schema": "org.gnome.shell.extensions.paperwm", "shell-version": [ "45", "46" ], - "version-name": "46.15.1", + "version-name": "46.16.0", "donations": { "buymeacoffee": "jaytaala", "patreon": "valpackett" diff --git a/prefsKeybinding.js b/prefsKeybinding.js index 988c52df..c74d5362 100644 --- a/prefsKeybinding.js +++ b/prefsKeybinding.js @@ -73,6 +73,8 @@ const actions = { 'barf-out', 'barf-out-active', 'center-horizontally', + 'center-vertically', + 'center', 'paper-toggle-fullscreen', 'toggle-maximize-width', 'resize-h-inc', diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index 24a8efbe..484bc328 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 613a160a..d4d5cf3f 100644 --- a/schemas/org.gnome.shell.extensions.paperwm.gschema.xml +++ b/schemas/org.gnome.shell.extensions.paperwm.gschema.xml @@ -420,6 +420,16 @@ Center window horizontally + + v']]]> + Center window vertically (non-tiled window) + + + + + Center window + + f']]]> Maximize the width of the active window diff --git a/tiling.js b/tiling.js index a9ac47c6..449ca950 100644 --- a/tiling.js +++ b/tiling.js @@ -801,7 +801,7 @@ export class Space extends Array { // if only one column on space, then center it if (centerIfOne && this.length === 1) { const mw = this.getWindows()[0]; - centerWindowHorizontally(mw); + centerWindow(mw); } callback && callback(); @@ -3746,6 +3746,10 @@ export function resizeHandler(metaWindow) { // Resizing from within a size-changed signal is troube (#73). Queue instead. space.queueLayout(true, { callback, centerIfOne: false }); } + + if (space.length === 1) { + centerWindow(metaWindow); + } } /** @@ -4947,15 +4951,17 @@ function activateWindowAfterRendered(actor, mw) { /** * Centers the currently selected window. */ -export function centerWindowHorizontally(metaWindow) { +export function centerWindow(metaWindow, horizontal = true, vertical = false) { const frame = metaWindow.get_frame_rect(); const space = spaces.spaceOfWindow(metaWindow); const monitor = space.monitor; const workArea = space.workArea(); - const targetX = workArea.x + Math.round((workArea.width - frame.width) / 2); + const targetX = horizontal ? workArea.x + Math.round((workArea.width - frame.width) / 2) : frame.x; + let targetY = vertical ? workArea.y + Math.round((workArea.height - frame.height) / 2) : frame.y; + targetY = Math.max(targetY, workArea.y); if (space.indexOf(metaWindow) === -1) { - Scratch.easeScratch(metaWindow, targetX + monitor.x, frame.y); + Scratch.easeScratch(metaWindow, targetX + monitor.x, targetY); } else { move_to(space, metaWindow, { x: targetX, @@ -5003,7 +5009,7 @@ export function setFocusMode(mode, space) { } else { space.unfocusXPosition = workArea.width; } - centerWindowHorizontally(selectedWin); + centerWindow(selectedWin); } break; default: