Skip to content

Commit 279c5cc

Browse files
committed
feat: move active window using a hotkey #80
1 parent 96a0edd commit 279c5cc

File tree

3 files changed

+83
-35
lines changed

3 files changed

+83
-35
lines changed

README.md

+31-29
Original file line numberDiff line numberDiff line change
@@ -92,35 +92,37 @@ Additional information about individual entries can be found in the comments sec
9292
### Shortcuts
9393
The default keyboard shortcuts are assigned as shown below.
9494
If some of them are already in use by your system, update the default values in the `[keys]` section of the configuration file:
95-
| Keys | Description |
96-
| ------------------------------------------------------- | --------------------------------------------- |
97-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Home</kbd> | Enable tiling on the current screen |
98-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>End</kbd> | Disable tiling on the current screen |
99-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>T</kbd> | Toggle between enable and disable |
100-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>D</kbd> | Toggle window decoration on and off |
101-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>R</kbd> | Disable tiling and restore windows |
102-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>BackSpace</kbd> | Reset layouts to default proportions |
103-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Next</kbd> | Cycle through next layouts |
104-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Prior</kbd> | Cycle through previous layouts |
105-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Left</kbd> | Activate vertical-left layout |
106-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Right</kbd> | Activate vertical-right layout |
107-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Up</kbd> | Activate horizontal-top layout |
108-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Down</kbd> | Activate horizontal-bottom layout |
109-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Space</kbd> | Activate maximized layout |
110-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Return</kbd> | Activate fullscreen layout |
111-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Plus</kbd> | Increase number of maximum slave windows |
112-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Minus</kbd> | Decrease number of maximum slave windows |
113-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_Add</kbd> | Increase number of master windows |
114-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_Subtract</kbd> | Decrease number of master windows |
115-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_2</kbd> | Move focus to the next window |
116-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_8</kbd> | Move focus to the previous window |
117-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_9</kbd> | Move the active window to the next screen |
118-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_7</kbd> | Move the active window to the previous screen |
119-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_5</kbd> | Make the active window master |
120-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_6</kbd> | Make the next window master |
121-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_4</kbd> | Make the previous window master |
122-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_3</kbd> | Increase proportion of master-slave area |
123-
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_1</kbd> | Decrease proportion of master-slave area |
95+
| Keys | Description |
96+
| ------------------------------------------------------- | ----------------------------------------------- |
97+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Home</kbd> | Enable tiling on the current screen |
98+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>End</kbd> | Disable tiling on the current screen |
99+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>T</kbd> | Toggle between enable and disable |
100+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>D</kbd> | Toggle window decoration on and off |
101+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>R</kbd> | Disable tiling and restore windows |
102+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>BackSpace</kbd> | Reset layouts to default proportions |
103+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Next</kbd> | Cycle through next layouts |
104+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Prior</kbd> | Cycle through previous layouts |
105+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Left</kbd> | Activate vertical-left layout |
106+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Right</kbd> | Activate vertical-right layout |
107+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Up</kbd> | Activate horizontal-top layout |
108+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Down</kbd> | Activate horizontal-bottom layout |
109+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Space</kbd> | Activate maximized layout |
110+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Return</kbd> | Activate fullscreen layout |
111+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Plus</kbd> | Increase number of maximum slave windows |
112+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Minus</kbd> | Decrease number of maximum slave windows |
113+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_Add</kbd> | Increase number of master windows |
114+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_Subtract</kbd> | Decrease number of master windows |
115+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_2</kbd> | Move focus to the next window |
116+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_8</kbd> | Move focus to the previous window |
117+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_3</kbd> | Move the active window to the next position |
118+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_1</kbd> | Move the active window to the previous position |
119+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_9</kbd> | Move the active window to the next screen |
120+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_7</kbd> | Move the active window to the previous screen |
121+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_5</kbd> | Make the active window master |
122+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_6</kbd> | Make the next window master |
123+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>KP_4</kbd> | Make the previous window master |
124+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Insert</kbd> | Increase proportion of master-slave area |
125+
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Delete</kbd> | Decrease proportion of master-slave area |
124126

125127
Hot corner events are defined under the `[corners]` section and are triggered when the pointer enters one of the target areas:
126128
| Corners | Description |

config.toml

+10-4
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ window_next = "Control-Shift-KP_2"
183183
# Move focus to the previous window (KP_8 = Num_8).
184184
window_previous = "Control-Shift-KP_8"
185185

186+
# Move the active window to the next position (KP_3 = Num_3).
187+
position_next = "Control-Shift-KP_3"
188+
189+
# Move the active window to the previous position (KP_1 = Num_1).
190+
position_previous = "Control-Shift-KP_1"
191+
186192
# Move the active window to the next screen (KP_9 = Num_9).
187193
screen_next = "Control-Shift-KP_9"
188194

@@ -198,11 +204,11 @@ master_make_next = "Control-Shift-KP_6"
198204
# Make the previous window a master (KP_4 = Num_4).
199205
master_make_previous = "Control-Shift-KP_4"
200206

201-
# Increase the proportion of master-slave area (KP_3 = Num_3).
202-
proportion_increase = "Control-Shift-KP_3"
207+
# Increase the proportion of master-slave area (Insert = Ins).
208+
proportion_increase = "Control-Shift-Insert"
203209

204-
# Decrease the proportion of master-slave area (KP_1 = Num_1).
205-
proportion_decrease = "Control-Shift-KP_1"
210+
# Decrease the proportion of master-slave area (Delete = Del).
211+
proportion_decrease = "Control-Shift-Delete"
206212

207213
# Some commands above will affect all screens if this key is pressed in addition (Mod1 = Alt_L).
208214
mod_screens = "Mod1"

input/action.go

+42-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func ExecuteAction(action string, tr *desktop.Tracker, ws *desktop.Workspace) bo
8181
success = NextWindow(tr, ws)
8282
case "window_previous":
8383
success = PreviousWindow(tr, ws)
84+
case "position_next":
85+
success = NextPosition(tr, ws)
86+
case "position_previous":
87+
success = PreviousPosition(tr, ws)
8488
case "screen_next":
8589
success = NextScreen(tr, ws)
8690
case "screen_previous":
@@ -445,12 +449,49 @@ func PreviousWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
445449
return true
446450
}
447451

452+
func NextPosition(tr *desktop.Tracker, ws *desktop.Workspace) bool {
453+
if ws.TilingDisabled() {
454+
return false
455+
}
456+
c1 := ws.ActiveLayout().ActiveClient()
457+
if c1 == nil {
458+
return false
459+
}
460+
c2 := ws.ActiveLayout().NextClient()
461+
if c2 == nil {
462+
return false
463+
}
464+
465+
ws.ActiveLayout().SwapClient(c1, c2)
466+
tr.Tile(ws)
467+
468+
return true
469+
}
470+
471+
func PreviousPosition(tr *desktop.Tracker, ws *desktop.Workspace) bool {
472+
if ws.TilingDisabled() {
473+
return false
474+
}
475+
c1 := ws.ActiveLayout().ActiveClient()
476+
if c1 == nil {
477+
return false
478+
}
479+
c2 := ws.ActiveLayout().PreviousClient()
480+
if c2 == nil {
481+
return false
482+
}
483+
484+
ws.ActiveLayout().SwapClient(c1, c2)
485+
tr.Tile(ws)
486+
487+
return true
488+
}
489+
448490
func NextScreen(tr *desktop.Tracker, ws *desktop.Workspace) bool {
449491
c := tr.ActiveClient()
450492
if c == nil {
451493
return false
452494
}
453-
454495
screen := int(c.Latest.Location.Screen) + 1
455496
if screen > int(store.Workplace.ScreenCount)-1 {
456497
return false
@@ -464,7 +505,6 @@ func PreviousScreen(tr *desktop.Tracker, ws *desktop.Workspace) bool {
464505
if c == nil {
465506
return false
466507
}
467-
468508
screen := int(c.Latest.Location.Screen) - 1
469509
if screen < 0 {
470510
return false

0 commit comments

Comments
 (0)