2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
mouse = mouse,
|
|
|
|
screen = screen,
|
|
|
|
client = client
|
|
|
|
}
|
|
|
|
local util = require("awful.util")
|
2012-09-28 23:53:58 +02:00
|
|
|
|
|
|
|
-- we use require("awful.client") inside functions to prevent circular dependencies.
|
|
|
|
local client
|
2008-09-29 16:49:18 +02:00
|
|
|
|
|
|
|
--- Screen module for awful
|
2012-06-12 20:13:09 +02:00
|
|
|
-- awful.screen
|
|
|
|
local screen = {}
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2009-05-04 11:09:19 +02:00
|
|
|
local data = {}
|
|
|
|
data.padding = {}
|
|
|
|
|
2012-01-15 11:28:17 +01:00
|
|
|
---
|
|
|
|
-- Return Xinerama screen number corresponding to the given (pixel) coordinates.
|
|
|
|
-- The number returned can be used as an index into the global
|
|
|
|
-- `screen` table/object.
|
|
|
|
-- @param x The x coordinate
|
|
|
|
-- @param y The y coordinate
|
2012-06-12 20:13:09 +02:00
|
|
|
function screen.getbycoord(x, y)
|
2012-01-15 11:28:17 +01:00
|
|
|
for i = 1, capi.screen:count() do
|
|
|
|
local geometry = capi.screen[i].geometry
|
|
|
|
if((x < 0 or (x >= geometry.x and x < geometry.x + geometry.width))
|
|
|
|
and (y < 0 or (y >= geometry.y and y < geometry.y + geometry.height))) then
|
|
|
|
return i;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-14 20:14:22 +02:00
|
|
|
--- Give the focus to a screen, and move pointer. Keeps relative position of the pointer on the screen.
|
2009-08-21 16:05:02 +02:00
|
|
|
-- @param screen Screen number.
|
2012-06-12 20:13:09 +02:00
|
|
|
function screen.focus(_screen)
|
2012-09-28 23:53:58 +02:00
|
|
|
client = client or require("awful.client")
|
2012-06-12 20:13:09 +02:00
|
|
|
if _screen > capi.screen.count() then _screen = capi.mouse.screen end
|
2012-09-14 20:14:22 +02:00
|
|
|
|
|
|
|
-- screen and pos for current screen
|
|
|
|
local s = capi.mouse.screen
|
|
|
|
local pos = capi.mouse.coords()
|
|
|
|
|
|
|
|
-- keep relative mouse position on the new screen
|
|
|
|
local relx = (pos.x - capi.screen[s].geometry.x) / capi.screen[s].geometry.width
|
|
|
|
local rely = (pos.y - capi.screen[s].geometry.y) / capi.screen[s].geometry.height
|
|
|
|
|
|
|
|
pos.x = capi.screen[_screen].geometry.x + relx * capi.screen[_screen].geometry.width
|
|
|
|
pos.y = capi.screen[_screen].geometry.y + rely * capi.screen[_screen].geometry.height
|
|
|
|
|
|
|
|
-- move cursor without triggering signals mouse::enter and mouse::leave
|
|
|
|
capi.mouse.screen = _screen
|
|
|
|
capi.mouse.coords(pos, true)
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
local c = client.focus.history.get(_screen, 0)
|
2008-09-29 16:49:18 +02:00
|
|
|
if c then capi.client.focus = c end
|
2009-08-21 16:05:02 +02:00
|
|
|
end
|
|
|
|
|
2012-09-14 21:49:14 +02:00
|
|
|
--- Give the focus to a screen, and move pointer, by physical position relative to current screen.
|
|
|
|
-- @param dir The direction, can be either "up", "down", "left" or "right".
|
|
|
|
-- @param screen Screen number.
|
|
|
|
function screen.focus_bydirection(dir, _screen)
|
|
|
|
local sel = _screen or capi.mouse.screen
|
|
|
|
if sel then
|
|
|
|
local geomtbl = {}
|
|
|
|
for s = 1, capi.screen.count() do
|
|
|
|
geomtbl[s] = capi.screen[s].geometry
|
|
|
|
end
|
|
|
|
local target = util.get_rectangle_in_direction(dir, geomtbl, capi.screen[sel].geometry)
|
|
|
|
if target then
|
|
|
|
return screen.focus(target)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-21 16:05:02 +02:00
|
|
|
--- Give the focus to a screen, and move pointer, but relative to the current
|
|
|
|
-- focused screen.
|
|
|
|
-- @param i Value to add to the current focused screen index. 1 will focus next
|
|
|
|
-- screen, -1 would focus the previous one.
|
2012-06-12 20:13:09 +02:00
|
|
|
function screen.focus_relative(i)
|
|
|
|
return screen.focus(util.cycle(capi.screen.count(), capi.mouse.screen + i))
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2009-05-04 11:09:19 +02:00
|
|
|
--- Get or set the screen padding.
|
2009-10-07 02:20:39 +02:00
|
|
|
-- @param screen The screen object to change the padding on
|
2009-05-04 11:09:19 +02:00
|
|
|
-- @param padding The padding, an table with 'top', 'left', 'right' and/or
|
|
|
|
-- 'bottom'. Can be nil if you only want to retrieve padding
|
2012-06-12 20:13:09 +02:00
|
|
|
function screen.padding(_screen, padding)
|
2009-05-04 11:09:19 +02:00
|
|
|
if padding then
|
2012-06-12 20:13:09 +02:00
|
|
|
data.padding[_screen] = padding
|
|
|
|
_screen:emit_signal("padding")
|
2009-05-04 11:09:19 +02:00
|
|
|
end
|
2012-06-12 20:13:09 +02:00
|
|
|
return data.padding[_screen]
|
2009-05-04 11:09:19 +02:00
|
|
|
end
|
|
|
|
|
2010-08-25 23:00:36 +02:00
|
|
|
for s = 1, capi.screen.count() do
|
|
|
|
capi.screen[s]:add_signal("padding")
|
|
|
|
end
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
return screen
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|