1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2008 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 -- Grab environment we need
14 local util
= require("awful.util")
16 -- we use require("awful.client") inside functions to prevent circular dependencies.
19 --- Screen module for awful
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 -- @param default Optional default return value. If unspecified, 1 is returned.
33 function screen
.getbycoord(x
, y
, default
)
34 for i
= 1, capi
.screen
:count() do
35 local geometry
= capi
.screen
[i
].geometry
36 if((x
< 0 or (x
>= geometry
.x
and x
< geometry
.x
+ geometry
.width
))
37 and (y
< 0 or (y
>= geometry
.y
and y
< geometry
.y
+ geometry
.height
))) then
41 -- No caller expects a nil result here, so just make something up
42 if default
== nil then return 1 end
46 --- Give the focus to a screen, and move pointer. Keeps relative position of the pointer on the screen.
47 -- @param _screen Screen number.
48 function screen
.focus(_screen
)
49 client
= client
or require("awful.client")
50 if _screen
> capi
.screen
.count() then _screen
= capi
.mouse
.screen
end
52 -- screen and pos for current screen
53 local s
= capi
.mouse
.screen
54 local pos
= capi
.mouse
.coords()
56 -- keep relative mouse position on the new screen
57 local relx
= (pos
.x
- capi
.screen
[s
].geometry
.x
) / capi
.screen
[s
].geometry
.width
58 local rely
= (pos
.y
- capi
.screen
[s
].geometry
.y
) / capi
.screen
[s
].geometry
.height
60 pos
.x
= capi
.screen
[_screen
].geometry
.x
+ relx
* capi
.screen
[_screen
].geometry
.width
61 pos
.y
= capi
.screen
[_screen
].geometry
.y
+ rely
* capi
.screen
[_screen
].geometry
.height
63 -- move cursor without triggering signals mouse::enter and mouse::leave
64 capi
.mouse
.coords(pos
, true)
66 local c
= client
.focus
.history
.get(_screen
, 0)
67 if c
then capi
.client
.focus
= c
end
70 --- Give the focus to a screen, and move pointer, by physical position relative to current screen.
71 -- @param dir The direction, can be either "up", "down", "left" or "right".
72 -- @param _screen Screen number.
73 function screen
.focus_bydirection(dir
, _screen
)
74 local sel
= _screen
or capi
.mouse
.screen
77 for s
= 1, capi
.screen
.count() do
78 geomtbl
[s
] = capi
.screen
[s
].geometry
80 local target
= util
.get_rectangle_in_direction(dir
, geomtbl
, capi
.screen
[sel
].geometry
)
82 return screen
.focus(target
)
87 --- Give the focus to a screen, and move pointer, but relative to the current
89 -- @param i Value to add to the current focused screen index. 1 will focus next
90 -- screen, -1 would focus the previous one.
91 function screen
.focus_relative(i
)
92 return screen
.focus(util
.cycle(capi
.screen
.count(), capi
.mouse
.screen
+ i
))
95 --- Get or set the screen padding.
96 -- @param _screen The screen object to change the padding on
97 -- @param padding The padding, an table with 'top', 'left', 'right' and/or
98 -- 'bottom'. Can be nil if you only want to retrieve padding
99 function screen
.padding(_screen
, padding
)
101 data
.padding
[_screen
] = padding
102 _screen
:emit_signal("padding")
104 return data
.padding
[_screen
]
107 capi
.screen
.add_signal("padding")
111 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80