Skip to content

Commit 00ee215

Browse files
authored
Merge pull request #21 from peterklijn/multi-column-and-row-grid
Multi column and row grid
2 parents 33a284e + d32bc93 commit 00ee215

7 files changed

+427
-40
lines changed

README.md

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Install Hammerspoon if you haven't yet. Download the [latest release here](https
1212

1313
Alternatively you can install it using brew:
1414
```bash
15-
brew install --cask hammerspoon
15+
brew install --cask hammerspoon
1616
```
1717

1818
#### Step 2
@@ -46,6 +46,13 @@ Go to `System Preferences > Security & Privacy > Accessibility` and make sure Ha
4646

4747
_If you just enabled permissions for Hammerspoon, you might need to restart the application for the permissions to take effect._
4848

49+
#### Step 5 (optional)
50+
51+
Configure the Shiftit spoon to your preference.
52+
53+
- [Multiple window cycle sizes](https://github.com/peterklijn/hammerspoon-shiftit#configure-multiple-window-cycle-sizes) allows you to override the default 50% window size for snapping to [sides](https://github.com/peterklijn/hammerspoon-shiftit#snap-to-sides) and [corners](https://github.com/peterklijn/hammerspoon-shiftit#snap-to-corners)
54+
- [Override key mappings](https://github.com/peterklijn/hammerspoon-shiftit#overriding-key-mappings) allows you to override the default key bindings.
55+
4956
The ShiftIt spoon is now ready to use, enjoy.
5057

5158
Having issues? Check out the [Known issues](https://github.com/peterklijn/hammerspoon-shiftit#known-issues) section, have a look in the [issues section](https://github.com/peterklijn/hammerspoon-shiftit/issues), or create a new issue.
@@ -112,34 +119,52 @@ The default key mapping looks like this:
112119

113120
```lua
114121
{
115-
left = {{ 'ctrl', 'alt', 'cmd' }, 'left' },
116-
right = {{ 'ctrl', 'alt', 'cmd' }, 'right' },
117-
up = {{ 'ctrl', 'alt', 'cmd' }, 'up' },
118-
down = {{ 'ctrl', 'alt', 'cmd' }, 'down' },
119-
upleft = {{ 'ctrl', 'alt', 'cmd' }, '1' },
120-
upright = {{ 'ctrl', 'alt', 'cmd' }, '2' },
121-
botleft = {{ 'ctrl', 'alt', 'cmd' }, '3' },
122-
botright = {{ 'ctrl', 'alt', 'cmd' }, '4' },
123-
maximum = {{ 'ctrl', 'alt', 'cmd' }, 'm' },
124-
toggleFullScreen = {{ 'ctrl', 'alt', 'cmd' }, 'f' },
125-
toggleZoom = {{ 'ctrl', 'alt', 'cmd' }, 'z' },
126-
center = {{ 'ctrl', 'alt', 'cmd' }, 'c' },
127-
nextScreen = {{ 'ctrl', 'alt', 'cmd' }, 'n' },
128-
previousScreen = {{ 'ctrl', 'alt', 'cmd' }, 'p' },
129-
resizeOut = {{ 'ctrl', 'alt', 'cmd' }, '=' },
130-
resizeIn = {{ 'ctrl', 'alt', 'cmd' }, '-' }
122+
left = { { 'ctrl', 'alt', 'cmd' }, 'left' },
123+
right = { { 'ctrl', 'alt', 'cmd' }, 'right' },
124+
up = { { 'ctrl', 'alt', 'cmd' }, 'up' },
125+
down = { { 'ctrl', 'alt', 'cmd' }, 'down' },
126+
upleft = { { 'ctrl', 'alt', 'cmd' }, '1' },
127+
upright = { { 'ctrl', 'alt', 'cmd' }, '2' },
128+
botleft = { { 'ctrl', 'alt', 'cmd' }, '3' },
129+
botright = { { 'ctrl', 'alt', 'cmd' }, '4' },
130+
maximum = { { 'ctrl', 'alt', 'cmd' }, 'm' },
131+
toggleFullScreen = { { 'ctrl', 'alt', 'cmd' }, 'f' },
132+
toggleZoom = { { 'ctrl', 'alt', 'cmd' }, 'z' },
133+
center = { { 'ctrl', 'alt', 'cmd' }, 'c' },
134+
nextScreen = { { 'ctrl', 'alt', 'cmd' }, 'n' },
135+
previousScreen = { { 'ctrl', 'alt', 'cmd' }, 'p' },
136+
resizeOut = { { 'ctrl', 'alt', 'cmd' }, '=' },
137+
resizeIn = { { 'ctrl', 'alt', 'cmd' }, '-' }
131138
}
132139
```
133140

141+
### Configure multiple window cycle sizes
142+
143+
You can configure multiple window cycle sizes by adding the following line after loading the ShiftIt spoon:
144+
145+
```lua
146+
spoon.ShiftIt:setWindowCyclingSizes({ 50, 33, 67 }, { 50 })
147+
```
148+
149+
The first argument (`{ 50, 33, 67 }`) sets the horizontal window cycle sizes, in the provided order.
150+
The second argument (`{ 50 }`) sets the vertical window cycle sizes, in this example it only sets one.
151+
152+
The above settings will toggle the window through these steps, when repeatingly hitting `ctrl(^) + alt(⌥) + cmd(⌘) + left`:
153+
154+
![Window Cycling Sizes visualised for left action](https://github.com/peterklijn/hammerspoon-shiftit/blob/master/images/window-cycling-sizes-visualised.png?raw=true)
155+
134156
### Overriding key mappings
135157

136158
You can pass the part of the key mappings that you want to override to the `bindHotkeys()` function. For example:
137159

138160
```lua
161+
-- Use Vim arrow keys
139162
spoon.ShiftIt:bindHotkeys({
140-
upleft = {{ 'ctrl', 'alt', 'cmd' }, 'q' },
141-
upright = {{ 'ctrl', 'alt', 'cmd' }, 'w' },
142-
});
163+
left = { { 'ctrl', 'alt', 'cmd' }, 'h' },
164+
down = { { 'ctrl', 'alt', 'cmd' }, 'j' },
165+
up = { { 'ctrl', 'alt', 'cmd' }, 'k' },
166+
right = { { 'ctrl', 'alt', 'cmd' }, 'l' },
167+
})
143168
```
144169

145170
## Alternative installations

Spoons/ShiftIt.spoon.zip

772 Bytes
Binary file not shown.

docs/window-cycling-sizes.html

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
.screen {
6+
width: 800px;
7+
height: 450px;
8+
background-color: #fffbf3;
9+
}
10+
11+
.menubar {
12+
float: left;
13+
width: 792px;
14+
height: 12px;
15+
padding: 4px;
16+
font-size: 12px;
17+
background-color: #ddd;
18+
color: #777;
19+
}
20+
.dock {
21+
float: left;
22+
width: 600px;
23+
height: 40px;
24+
margin: 0 100px;
25+
background-color: #eee;
26+
border-radius: 4px;
27+
}
28+
.icon {
29+
float: left;
30+
width: 32px;
31+
height: 32px;
32+
margin: 4px;
33+
border-radius: 4px;
34+
background: #abcf90
35+
}
36+
.icon:nth-child(2), .icon:nth-child(6), .icon:nth-child(10), .icon:nth-child(14) {
37+
background: #dc9e78
38+
}
39+
.icon:nth-child(3), .icon:nth-child(7), .icon:nth-child(11), .icon:nth-child(15) {
40+
background: #b4bcf7
41+
}
42+
.icon:nth-child(4), .icon:nth-child(8), .icon:nth-child(12), .icon:nth-child(16) {
43+
background: #e7e775;
44+
}
45+
46+
.window-size {
47+
float: left;
48+
border: solid 1px;
49+
margin: 1px;
50+
}
51+
.window-size span {
52+
width: auto;
53+
float: right;
54+
color: white;
55+
font: status-bar;
56+
font-size: 12px;
57+
padding: 1px 3px;
58+
}
59+
60+
61+
.size-a {
62+
margin: 0;
63+
width: 534px;
64+
height: 388px;
65+
border-color: green;
66+
}
67+
.size-a span {
68+
background-color: green;
69+
}
70+
71+
.size-b {
72+
width: 396px;
73+
height: 384px;
74+
border-color: red;
75+
}
76+
.size-b span {
77+
background-color: red;
78+
}
79+
.size-c {
80+
width: 256px;
81+
height: 380px;
82+
border-color: blue;
83+
}
84+
.size-c span {
85+
background-color: blue;
86+
}
87+
88+
</style>
89+
</head>
90+
<body>
91+
<div class="screen">
92+
<div class="menubar"></div>
93+
<div class="window-size size-a">
94+
<div class="window-size size-b">
95+
<div class="window-size size-c">
96+
<span>step 2: 33%</span>
97+
</div>
98+
<span>step 1: 50%</span>
99+
</div>
100+
<span>step 3: 67%</span>
101+
</div>
102+
<div class="dock">
103+
<div class="icon"></div>
104+
<div class="icon"></div>
105+
<div class="icon"></div>
106+
<div class="icon"></div>
107+
<div class="icon"></div>
108+
<div class="icon"></div>
109+
<div class="icon"></div>
110+
<div class="icon"></div>
111+
<div class="icon"></div>
112+
<div class="icon"></div>
113+
<div class="icon"></div>
114+
<div class="icon"></div>
115+
<div class="icon"></div>
116+
<div class="icon"></div>
117+
<div class="icon"></div>
118+
</div>
119+
</div>
120+
</body>
121+
</html>

hammerspoon_mocks.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ end
2424

2525
local window = {
2626
rect = defaultWindowRect,
27+
_id = 42,
2728
_screen = screen,
2829
}
2930

@@ -35,6 +36,10 @@ function window:frame()
3536
return self.rect
3637
end
3738

39+
function window:id()
40+
return self._id
41+
end
42+
3843
function window:screen()
3944
return self._screen
4045
end
@@ -44,6 +49,16 @@ function window:move(rect, _, _, _)
4449
lu.assertIsNumber(rect.y)
4550
lu.assertIsNumber(rect.w)
4651
lu.assertIsNumber(rect.h)
52+
-- If the position contains a period (.), it is a relative coordinate
53+
-- so multiply it with the screen size
54+
if string.match(tostring(rect.x), '%.') ~= nil then
55+
rect = {
56+
x = self._screen.rect.x + (rect.x * self._screen.rect.w),
57+
y = self._screen.rect.y + (rect.y * self._screen.rect.h),
58+
w = rect.w * self._screen.rect.w,
59+
h = rect.h * self._screen.rect.h,
60+
}
61+
end
4762
self.rect = rect
4863
end
4964

@@ -55,6 +70,7 @@ local mocks = {
5570
function mocks:reset()
5671
self.hotkey.bindings = {}
5772
self.window.rect = defaultWindowRect
73+
self.window._id = 42
5874
self.window._screen.rect = defaultScreenRect
5975
end
6076

47.2 KB
Loading

0 commit comments

Comments
 (0)