-
Notifications
You must be signed in to change notification settings - Fork 29
/
hammerspoon_mocks.lua
77 lines (63 loc) · 1.59 KB
/
hammerspoon_mocks.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
local lu = require('luaunit')
local hotkey = {
bindings = {},
}
local defaultScreenRect = { x = 0, y = 0, w = 1200, h = 800 }
local defaultWindowRect = { x = 100, y = 100, w = 1000, h = 600 }
function hotkey.bind(mods, key, fn)
lu.assertNotNil(mods)
lu.assertNotNil(key)
lu.assertIsFunction(fn)
table.insert(hotkey.bindings, { mods, key, fn })
end
local screen = {
rect = defaultScreenRect,
}
function screen:frame()
return self.rect
end
local window = {
rect = defaultWindowRect,
_id = 42,
_screen = screen,
}
function window.focusedWindow()
return window
end
function window:frame()
return self.rect
end
function window:id()
return self._id
end
function window:screen()
return self._screen
end
function window:move(rect, _, _, _)
lu.assertIsNumber(rect.x)
lu.assertIsNumber(rect.y)
lu.assertIsNumber(rect.w)
lu.assertIsNumber(rect.h)
-- If the position contains a period (.), it is a relative coordinate
-- so multiply it with the screen size
if string.match(tostring(rect.x), '%.') ~= nil then
rect = {
x = self._screen.rect.x + (rect.x * self._screen.rect.w),
y = self._screen.rect.y + (rect.y * self._screen.rect.h),
w = rect.w * self._screen.rect.w,
h = rect.h * self._screen.rect.h,
}
end
self.rect = rect
end
local mocks = {
hotkey = hotkey,
window = window,
}
function mocks:reset()
self.hotkey.bindings = {}
self.window.rect = defaultWindowRect
self.window._id = 42
self.window._screen.rect = defaultScreenRect
end
return mocks