-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.lua
96 lines (76 loc) · 2.23 KB
/
action.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
--
-- Based on https://github.com/mgee/hammerspoon-config
require 'utils'
Action = {}
Action.__index = Action
function Action.Close()
return function(win) win:close() end
end
function Action.Maximize()
return function(win) win:maximize() end
end
function Action.FullScreen()
return function(win) win:setFullScreen(true) end
end
function Action.Snap()
return function(win) hs.grid.snap(win) end
end
function Action.MoveToScreen(screenIndex)
return function(win) utils.pushToScreen(win, hs.screen.allScreens()[screenIndex]) end
end
function Action.MoveToNextScreen()
return function(win) utils.pushToScreen(win, win:screen():next()) end
end
function Action.MoveToPreviousScreen()
return function(win) utils.pushToScreen(win, win:screen():previous()) end
end
function Action.MoveToUnit(x, y, w, h, duration)
return function(win)
win:moveToUnit(hs.geometry.rect(x, y, w, h), duration)
end
end
function Action.MoveToUnitInScreenBounds(x, y, w, h)
return function(win)
local f = win:screen():frame()
win:setFrameInScreenBounds(hs.geometry.rect(f.x + x * f.x, f.y + y * f.h, w * f.w, h * f.h))
end
end
function Action.PositionTopLeft()
return function(win)
local f = win:screen():frame()
win:setTopLeft(hs.geometry.point(f.x, f.y))
end
end
function Action.PositionBottomLeft()
return function(win)
local f = win:screen():frame()
win:setTopLeft(hs.geometry.point(f.x, f.y + f.h - win:size().h))
end
end
function Action.PositionTopRight()
return function(win)
local f = win:screen():frame()
win:setTopLeft(hs.geometry.point(f.x + f.w - win:size().w, f.y))
end
end
function Action.PositionBottomRight()
return function(win)
local f = win:screen():frame()
win:setTopLeft(hs.geometry.point(f.x + f.w - win:size().w, f.y + f.h - win:size().h))
end
end
function Action.Resize(w, h)
return function(win)
win:setSize(hs.geometry.size(w ,h))
end
end
function Action.Frame(x, y, w, h)
return function(win)
win:setFrameInScreenBounds(hs.geometry.rect(x, y, w, h))
end
end
function Action.EnsureIsInScreenBounds()
return function(win) win:ensureIsInScreenBounds() end
end
----------------------------------------------------------------------------------------------------
return Action