Lots of random documentation fixes
[awesome.git] / lib / awful / screen.lua.in
blobd174c2c1d84736a198cadd8afdcb6192316a917d
1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2008 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 -- Grab environment we need
8 local capi =
10 mouse = mouse,
11 screen = screen,
12 client = client
14 local util = require("awful.util")
16 -- we use require("awful.client") inside functions to prevent circular dependencies.
17 local client
19 --- Screen module for awful
20 -- awful.screen
21 local screen = {}
23 local data = {}
24 data.padding = {}
26 ---
27 -- Return Xinerama screen number corresponding to the given (pixel) coordinates.
28 -- The number returned can be used as an index into the global
29 -- `screen` table/object.
30 -- @param x The x coordinate
31 -- @param y The y coordinate
32 function screen.getbycoord(x, y)
33 for i = 1, capi.screen:count() do
34 local geometry = capi.screen[i].geometry
35 if((x < 0 or (x >= geometry.x and x < geometry.x + geometry.width))
36 and (y < 0 or (y >= geometry.y and y < geometry.y + geometry.height))) then
37 return i;
38 end
39 end
40 end
42 --- Give the focus to a screen, and move pointer. Keeps relative position of the pointer on the screen.
43 -- @param screen Screen number.
44 function screen.focus(_screen)
45 client = client or require("awful.client")
46 if _screen > capi.screen.count() then _screen = capi.mouse.screen end
48 -- screen and pos for current screen
49 local s = capi.mouse.screen
50 local pos = capi.mouse.coords()
52 -- keep relative mouse position on the new screen
53 local relx = (pos.x - capi.screen[s].geometry.x) / capi.screen[s].geometry.width
54 local rely = (pos.y - capi.screen[s].geometry.y) / capi.screen[s].geometry.height
56 pos.x = capi.screen[_screen].geometry.x + relx * capi.screen[_screen].geometry.width
57 pos.y = capi.screen[_screen].geometry.y + rely * capi.screen[_screen].geometry.height
59 -- move cursor without triggering signals mouse::enter and mouse::leave
60 capi.mouse.screen = _screen
61 capi.mouse.coords(pos, true)
63 local c = client.focus.history.get(_screen, 0)
64 if c then capi.client.focus = c end
65 end
67 --- Give the focus to a screen, and move pointer, by physical position relative to current screen.
68 -- @param dir The direction, can be either "up", "down", "left" or "right".
69 -- @param _screen Screen number.
70 function screen.focus_bydirection(dir, _screen)
71 local sel = _screen or capi.mouse.screen
72 if sel then
73 local geomtbl = {}
74 for s = 1, capi.screen.count() do
75 geomtbl[s] = capi.screen[s].geometry
76 end
77 local target = util.get_rectangle_in_direction(dir, geomtbl, capi.screen[sel].geometry)
78 if target then
79 return screen.focus(target)
80 end
81 end
82 end
84 --- Give the focus to a screen, and move pointer, but relative to the current
85 -- focused screen.
86 -- @param i Value to add to the current focused screen index. 1 will focus next
87 -- screen, -1 would focus the previous one.
88 function screen.focus_relative(i)
89 return screen.focus(util.cycle(capi.screen.count(), capi.mouse.screen + i))
90 end
92 --- Get or set the screen padding.
93 -- @param _screen The screen object to change the padding on
94 -- @param padding The padding, an table with 'top', 'left', 'right' and/or
95 -- 'bottom'. Can be nil if you only want to retrieve padding
96 function screen.padding(_screen, padding)
97 if padding then
98 data.padding[_screen] = padding
99 _screen:emit_signal("padding")
101 return data.padding[_screen]
104 for s = 1, capi.screen.count() do
105 capi.screen[s]:add_signal("padding")
108 return screen
110 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80