-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.lua
54 lines (42 loc) · 1.37 KB
/
screen.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
-- Basically wraps `base` to add a signal for focused screen changes.
-- The signal is automatically emitted when a client on a different screen is focused,
-- and when a client's screen property changes while it is focused.
-- example: `screen.connect_signal("focused", function(s) do_stuff(s.index) end)`
local base = require("awful.screen")
local gmath = require("gears.math")
local capi = {
screen = screen,
client = client
}
local screen = {}
local function get_screen(s)
return s and capi.screen[s]
end
function screen.focus(s)
s = get_screen(s)
if s and s ~= base.focused() then
base.focus(s)
capi.screen.emit_signal("_focused", s)
end
end
function screen.focus_bydirection(dir, s)
s = get_screen(s or base.focused())
local target = s:get_next_in_direction(dir)
if target then
screen.focus(target)
end
end
function screen.focus_relative(offset)
screen.focus(gmath.cycle(capi.screen.count(),
base.focused().index + offset))
end
capi.screen.connect_signal("_focused", function(s)
s:emit_signal("focused")
end)
capi.client.connect_signal("focus", function(c)
screen.focus(c.screen)
end)
capi.client.connect_signal("property::screen", function(c)
if capi.client.focus == c then screen.focus(c.screen) end
end)
return setmetatable(screen, { __index = function(_, k) return rawget(base, k) end })