From 02ccc35fd4c58d875d1db6b2f985d93fe7972435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Sat, 6 Jul 2019 14:56:24 +0200 Subject: [PATCH] examples: cycle-edge-snap --- examples/keybindings.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/examples/keybindings.js b/examples/keybindings.js index de5d683..9d36867 100644 --- a/examples/keybindings.js +++ b/examples/keybindings.js @@ -9,6 +9,7 @@ var Scratch = Extension.imports.scratch; `init` function in "user.js": Extension.imports.examples.keybindings.gotoByIndex(); + */ function gotoByIndex() { @@ -76,6 +77,40 @@ function windowMarks() { } } +function cycleEdgeSnap(binding = "d") { + var Tiling = Extension.imports.tiling; + var Meta = imports.gi.Meta; + + Keybindings.bindkey(binding, "cycle-edge-snap", (mw) => { + // Snaps window to the left/right monitor edge + // Note: mostly the same as quickly switching left+right / right+left + + // Note: We work in monitor relative coordinates here + let margin = Tiling.prefs.horizontal_margin; + let space = Tiling.spaces.spaceOfWindow(mw); + let workarea = Main.layoutManager.getWorkAreaForMonitor(space.monitor.index); + let clone = mw.clone; + + let x = clone.targetX + space.targetX; + let width = clone.width; + let wax = workarea.x - space.monitor.x; + + let leftSnapPos = wax + margin; + let rightSnapPos = wax + workarea.width - width - margin; + + let targetX; + if (x == leftSnapPos) { + targetX = rightSnapPos; + } else if (x == rightSnapPos) { + targetX = leftSnapPos; + } else { + targetX = leftSnapPos; + } + + Tiling.move_to(space, mw, {x: targetX}); + }, {activeInNavigator: true}); +} + function swapNeighbours(binding = "y") { var Tiling = Extension.imports.tiling; var Meta = imports.gi.Meta;