2009-10-05 17:13:29 +02:00
|
|
|
---------------------------------------------------------------------------
|
2014-05-20 13:02:39 +02:00
|
|
|
--- Implements EWMH requests handling.
|
|
|
|
--
|
2009-10-05 17:13:29 +02:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @module awful.ewmh
|
2009-10-05 17:13:29 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local client = client
|
|
|
|
local screen = screen
|
|
|
|
local ipairs = ipairs
|
2016-04-15 11:09:41 +02:00
|
|
|
local util = require("awful.util")
|
2014-04-16 06:32:44 +02:00
|
|
|
local aclient = require("awful.client")
|
2016-04-15 11:09:41 +02:00
|
|
|
local aplace = require("awful.placement")
|
2016-04-28 22:46:09 +02:00
|
|
|
local asuit = require("awful.layout.suit")
|
2009-10-05 17:13:29 +02:00
|
|
|
|
2014-03-06 17:47:55 +01:00
|
|
|
local ewmh = {}
|
2009-10-05 17:13:29 +02:00
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Update a client's settings when its geometry changes, skipping signals
|
2015-01-31 11:58:49 +01:00
|
|
|
-- resulting from calls within.
|
|
|
|
local geometry_change_lock = false
|
|
|
|
local function geometry_change(window)
|
|
|
|
if geometry_change_lock then return end
|
|
|
|
geometry_change_lock = true
|
|
|
|
|
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
|
2016-09-11 08:05:30 +02:00
|
|
|
local g = window.screen.workarea
|
2012-05-16 23:03:32 +02:00
|
|
|
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
|
|
|
|
window.border_width = 0
|
2016-09-11 08:05:30 +02:00
|
|
|
window:geometry(window.screen.geometry)
|
2012-05-16 23:03:32 +02:00
|
|
|
end
|
2015-01-31 11:58:49 +01:00
|
|
|
|
|
|
|
geometry_change_lock = false
|
2012-05-16 23:03:32 +02:00
|
|
|
end
|
|
|
|
|
2015-10-13 12:00:33 +02:00
|
|
|
--- Activate a window.
|
|
|
|
--
|
|
|
|
-- This sets the focus only if the client is visible.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2015-07-29 04:12:49 +02:00
|
|
|
-- It is the default signal handler for `request::activate` on a `client`.
|
|
|
|
--
|
2016-04-25 04:42:32 +02:00
|
|
|
-- @signalhandler awful.ewmh.activate
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @client c A client to use
|
2015-05-13 13:36:28 +02:00
|
|
|
-- @tparam string context The context where this signal was used.
|
2015-09-10 20:45:29 +02:00
|
|
|
-- @tparam[opt] table hints A table with additional hints:
|
|
|
|
-- @tparam[opt=false] boolean hints.raise should the client be raised?
|
2016-02-07 15:02:25 +01:00
|
|
|
function ewmh.activate(c, context, hints) -- luacheck: no unused args
|
2016-04-15 07:43:58 +02:00
|
|
|
hints = hints or {}
|
|
|
|
|
|
|
|
if c.focusable == false and not hints.force then return end
|
|
|
|
|
2015-09-25 00:18:33 +02:00
|
|
|
if c:isvisible() then
|
|
|
|
client.focus = c
|
|
|
|
end
|
2015-09-10 20:45:29 +02:00
|
|
|
if hints and hints.raise then
|
2015-09-09 22:26:39 +02:00
|
|
|
c:raise()
|
|
|
|
if not awesome.startup and not c:isvisible() then
|
2015-05-13 22:11:07 +02:00
|
|
|
c.urgent = true
|
|
|
|
end
|
|
|
|
end
|
2015-05-13 13:36:28 +02:00
|
|
|
end
|
|
|
|
|
2016-08-23 05:18:07 +02:00
|
|
|
-- Get tags that are on the same screen as the client. This should _almost_
|
|
|
|
-- always return the same content as c:tags().
|
|
|
|
local function get_valid_tags(c, s)
|
|
|
|
local tags, new_tags = c:tags(), {}
|
|
|
|
|
|
|
|
for _, t in ipairs(tags) do
|
2016-09-11 08:05:30 +02:00
|
|
|
if s == t.screen then
|
2016-08-23 05:18:07 +02:00
|
|
|
table.insert(new_tags, t)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return new_tags
|
|
|
|
end
|
|
|
|
|
2016-04-25 04:42:32 +02:00
|
|
|
--- Tag a window with its requested tag.
|
2015-02-20 15:21:51 +01:00
|
|
|
--
|
2016-04-25 04:42:32 +02:00
|
|
|
-- It is the default signal handler for `request::tag` on a `client`.
|
|
|
|
--
|
|
|
|
-- @signalhandler awful.ewmh.tag
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @client c A client to tag
|
2016-08-23 05:18:07 +02:00
|
|
|
-- @tparam[opt] tag|boolean t A tag to use. If true, then the client is made sticky.
|
2016-04-17 09:52:59 +02:00
|
|
|
-- @tparam[opt={}] table hints Extra information
|
|
|
|
function ewmh.tag(c, t, hints) --luacheck: no unused
|
|
|
|
-- There is nothing to do
|
2016-08-23 05:18:07 +02:00
|
|
|
if not t and #get_valid_tags(c, c.screen) > 0 then return end
|
2016-04-17 09:52:59 +02:00
|
|
|
|
2014-03-17 16:15:20 +01:00
|
|
|
if not t then
|
2016-08-23 05:18:07 +02:00
|
|
|
if c.transient_for then
|
|
|
|
c.screen = c.transient_for.screen
|
|
|
|
if not c.sticky then
|
|
|
|
c:tags(c.transient_for:tags())
|
|
|
|
end
|
|
|
|
else
|
|
|
|
c:to_selected_tags()
|
|
|
|
end
|
2016-04-17 09:52:59 +02:00
|
|
|
elseif type(t) == "boolean" and t then
|
2014-03-17 16:15:20 +01:00
|
|
|
c.sticky = true
|
|
|
|
else
|
2016-04-05 09:02:00 +02:00
|
|
|
c.screen = t.screen
|
2014-03-17 16:15:20 +01:00
|
|
|
c:tags({ t })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-16 06:32:44 +02:00
|
|
|
function ewmh.urgent(c, urgent)
|
|
|
|
if c ~= client.focus and not aclient.property.get(c,"ignore_urgent") then
|
|
|
|
c.urgent = urgent
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-15 11:09:41 +02:00
|
|
|
-- Map the state to the action name
|
|
|
|
local context_mapper = {
|
|
|
|
maximized_vertical = "maximize_vertically",
|
|
|
|
maximized_horizontal = "maximize_horizontally",
|
|
|
|
fullscreen = "maximize"
|
|
|
|
}
|
|
|
|
|
|
|
|
--- Move and resize the client.
|
|
|
|
--
|
|
|
|
-- This is the default geometry request handler.
|
|
|
|
--
|
2016-04-25 04:42:32 +02:00
|
|
|
-- @signalhandler awful.ewmh.geometry
|
2016-04-15 11:09:41 +02:00
|
|
|
-- @tparam client c The client
|
|
|
|
-- @tparam string context The context
|
|
|
|
-- @tparam[opt={}] table hints The hints to pass to the handler
|
|
|
|
function ewmh.geometry(c, context, hints)
|
2016-04-28 22:46:09 +02:00
|
|
|
local layout = c.screen.selected_tag and c.screen.selected_tag.layout or nil
|
|
|
|
|
|
|
|
-- Setting the geometry wont work unless the client is floating.
|
|
|
|
if (not c.floating) and (not layout == asuit.floating) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-04-15 11:09:41 +02:00
|
|
|
context = context or ""
|
|
|
|
|
|
|
|
local original_context = context
|
|
|
|
|
|
|
|
-- Now, map it to something useful
|
|
|
|
context = context_mapper[context] or context
|
|
|
|
|
|
|
|
local props = util.table.clone(hints or {}, false)
|
|
|
|
props.store_geometry = props.store_geometry==nil and true or props.store_geometry
|
|
|
|
|
|
|
|
-- If it is a known placement function, then apply it, otherwise let
|
|
|
|
-- other potential handler resize the client (like in-layout resize or
|
|
|
|
-- floating client resize)
|
|
|
|
if aplace[context] then
|
|
|
|
|
|
|
|
-- Check if it correspond to a boolean property
|
|
|
|
local state = c[original_context]
|
|
|
|
|
|
|
|
-- If the property is boolean and it correspond to the undo operation,
|
|
|
|
-- restore the stored geometry.
|
|
|
|
if state == false then
|
|
|
|
aplace.restore(c,{context=context})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local honor_default = original_context ~= "fullscreen"
|
|
|
|
|
|
|
|
if props.honor_workarea == nil then
|
|
|
|
props.honor_workarea = honor_default
|
|
|
|
end
|
|
|
|
|
|
|
|
aplace[context](c, props)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-06 17:47:55 +01:00
|
|
|
client.connect_signal("request::activate", ewmh.activate)
|
2014-03-17 16:15:20 +01:00
|
|
|
client.connect_signal("request::tag", ewmh.tag)
|
2014-04-16 06:32:44 +02:00
|
|
|
client.connect_signal("request::urgent", ewmh.urgent)
|
2016-04-15 11:09:41 +02:00
|
|
|
client.connect_signal("request::geometry", ewmh.geometry)
|
2015-01-31 11:58:49 +01:00
|
|
|
client.connect_signal("property::border_width", geometry_change)
|
|
|
|
client.connect_signal("property::geometry", geometry_change)
|
2016-02-21 16:44:40 +01:00
|
|
|
screen.connect_signal("property::workarea", function(s)
|
|
|
|
for _, c in pairs(client.get(s)) do
|
|
|
|
geometry_change(c)
|
|
|
|
end
|
|
|
|
end)
|
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
|