2009-10-05 17:13:29 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local client = client
|
|
|
|
local screen = screen
|
|
|
|
local ipairs = ipairs
|
|
|
|
local math = math
|
|
|
|
|
|
|
|
--- Implements EWMH requests handling.
|
2012-06-12 20:13:09 +02:00
|
|
|
-- awful.ewmh
|
2014-03-06 17:47:55 +01:00
|
|
|
local ewmh = {}
|
2009-10-05 17:13:29 +02:00
|
|
|
|
|
|
|
local data = setmetatable({}, { __mode = 'k' })
|
|
|
|
|
|
|
|
local function store_geometry(window, reqtype)
|
|
|
|
if not data[window] then data[window] = {} end
|
|
|
|
if not data[window][reqtype] then data[window][reqtype] = {} end
|
|
|
|
data[window][reqtype] = window:geometry()
|
|
|
|
data[window][reqtype].screen = window.screen
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Maximize a window horizontally.
|
|
|
|
-- @param window The window.
|
|
|
|
-- @param set Set or unset the maximized values.
|
|
|
|
local function maximized_horizontal(window, set)
|
|
|
|
if set then
|
2012-03-01 04:46:48 +01:00
|
|
|
store_geometry(window, "maximized_horizontal")
|
2009-10-05 17:13:29 +02:00
|
|
|
local g = screen[window.screen].workarea
|
2012-03-02 00:06:39 +01:00
|
|
|
local bw = window.border_width or 0
|
|
|
|
window:geometry { width = g.width - 2*bw, x = g.x }
|
2012-03-01 04:46:48 +01:00
|
|
|
elseif data[window] and data[window].maximized_horizontal
|
|
|
|
and data[window].maximized_horizontal.x
|
|
|
|
and data[window].maximized_horizontal.width then
|
|
|
|
local g = data[window].maximized_horizontal
|
|
|
|
window:geometry { width = g.width, x = g.x }
|
2009-10-05 17:13:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Maximize a window vertically.
|
|
|
|
-- @param window The window.
|
|
|
|
-- @param set Set or unset the maximized values.
|
|
|
|
local function maximized_vertical(window, set)
|
|
|
|
if set then
|
2012-03-01 04:46:48 +01:00
|
|
|
store_geometry(window, "maximized_vertical")
|
2009-10-05 17:13:29 +02:00
|
|
|
local g = screen[window.screen].workarea
|
2012-03-02 00:06:39 +01:00
|
|
|
local bw = window.border_width or 0
|
|
|
|
window:geometry { height = g.height - 2*bw, y = g.y }
|
2012-03-01 04:46:48 +01:00
|
|
|
elseif data[window] and data[window].maximized_vertical
|
|
|
|
and data[window].maximized_vertical.y
|
|
|
|
and data[window].maximized_vertical.height then
|
|
|
|
local g = data[window].maximized_vertical
|
|
|
|
window:geometry { height = g.height, y = g.y }
|
2009-10-05 17:13:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Fullscreen a window.
|
|
|
|
-- @param window The window.
|
|
|
|
-- @param set Set or unset the fullscreen values.
|
|
|
|
local function fullscreen(window, set)
|
|
|
|
if set then
|
|
|
|
store_geometry(window, "fullscreen")
|
|
|
|
data[window].fullscreen.border_width = window.border_width
|
|
|
|
local g = screen[window.screen].geometry
|
|
|
|
window:geometry(screen[window.screen].geometry)
|
|
|
|
window.border_width = 0
|
|
|
|
elseif data[window] and data[window].fullscreen then
|
|
|
|
window:geometry(data[window].fullscreen)
|
|
|
|
window.border_width = data[window].fullscreen.border_width
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function screen_change(window)
|
|
|
|
if data[window] then
|
2012-03-02 14:39:28 +01:00
|
|
|
for _, reqtype in ipairs({ "maximized_vertical", "maximized_horizontal", "fullscreen" }) do
|
2009-10-05 17:13:29 +02:00
|
|
|
if data[window][reqtype] then
|
|
|
|
if data[window][reqtype].width then
|
|
|
|
data[window][reqtype].width = math.min(data[window][reqtype].width,
|
|
|
|
screen[window.screen].workarea.width)
|
2012-03-02 14:39:28 +01:00
|
|
|
if reqtype == "maximized_horizontal" then
|
|
|
|
local bw = window.border_width or 0
|
|
|
|
data[window][reqtype].width = data[window][reqtype].width - 2*bw
|
|
|
|
end
|
2009-10-05 17:13:29 +02:00
|
|
|
end
|
|
|
|
if data[window][reqtype].height then
|
|
|
|
data[window][reqtype].height = math.min(data[window][reqtype].height,
|
|
|
|
screen[window.screen].workarea.height)
|
2012-03-02 14:39:28 +01:00
|
|
|
if reqtype == "maximized_vertical" then
|
|
|
|
local bw = window.border_width or 0
|
|
|
|
data[window][reqtype].height = data[window][reqtype].height - 2*bw
|
|
|
|
end
|
2009-10-05 17:13:29 +02:00
|
|
|
end
|
|
|
|
if data[window][reqtype].screen then
|
|
|
|
local from = screen[data[window][reqtype].screen].workarea
|
|
|
|
local to = screen[window.screen].workarea
|
|
|
|
local new_x, new_y
|
|
|
|
if data[window][reqtype].x then
|
|
|
|
new_x = to.x + data[window][reqtype].x - from.x
|
|
|
|
if new_x > to.x + to.width then new_x = to.x end
|
|
|
|
data[window][reqtype].x = new_x
|
|
|
|
end
|
|
|
|
if data[window][reqtype].y then
|
|
|
|
new_y = to.y + data[window][reqtype].y - from.y
|
|
|
|
if new_y > to.y + to.width then new_y = to.y end
|
|
|
|
data[window][reqtype].y = new_y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-06 22:08:00 +01:00
|
|
|
-- Update a client's settings when its border width changes
|
|
|
|
local function border_change(window)
|
2012-05-16 23:03:32 +02:00
|
|
|
-- Fix up the geometry in case this window needs to cover the whole screen.
|
|
|
|
local bw = window.border_width or 0
|
|
|
|
local g = screen[window.screen].workarea
|
|
|
|
if window.maximized_vertical then
|
|
|
|
window:geometry { height = g.height - 2*bw, y = g.y }
|
|
|
|
end
|
|
|
|
if window.maximized_horizontal then
|
2014-03-06 17:58:03 +01:00
|
|
|
window:geometry { width = g.width - 2*bw, x = g.x }
|
2012-05-16 23:03:32 +02:00
|
|
|
end
|
|
|
|
if window.fullscreen then
|
|
|
|
-- This *will* cause an endless loop if some other property::border_width
|
|
|
|
-- signal dares to change the border width, too, so don't do that!
|
|
|
|
window.border_width = 0
|
|
|
|
window:geometry(screen[window.screen].geometry)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-06 17:47:55 +01:00
|
|
|
-- Activate a window
|
|
|
|
function ewmh.activate(c)
|
|
|
|
if c:isvisible() then
|
|
|
|
client.focus = c
|
|
|
|
c:raise()
|
|
|
|
else
|
|
|
|
c.urgent = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
client.connect_signal("request::activate", ewmh.activate)
|
2010-08-26 18:42:38 +02:00
|
|
|
client.connect_signal("request::maximized_horizontal", maximized_horizontal)
|
|
|
|
client.connect_signal("request::maximized_vertical", maximized_vertical)
|
|
|
|
client.connect_signal("request::fullscreen", fullscreen)
|
|
|
|
client.connect_signal("property::screen", screen_change)
|
2014-03-06 22:08:00 +01:00
|
|
|
client.connect_signal("property::border_width", border_change)
|
2009-10-05 17:13:29 +02:00
|
|
|
|
2014-03-06 17:47:55 +01:00
|
|
|
return ewmh
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|