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
|
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")
|
2017-01-25 10:00:33 +01:00
|
|
|
local beautiful = require("beautiful")
|
2009-10-05 17:13:29 +02:00
|
|
|
|
2016-09-28 22:17:08 +02:00
|
|
|
local ewmh = {
|
|
|
|
generic_activate_filters = {},
|
|
|
|
contextual_activate_filters = {},
|
|
|
|
}
|
|
|
|
|
2017-01-25 10:00:33 +01:00
|
|
|
--- Honor the screen padding when maximizing.
|
|
|
|
-- @beautiful beautiful.maximized_honor_padding
|
|
|
|
-- @tparam[opt=true] boolean maximized_honor_padding
|
|
|
|
|
2017-01-26 09:06:05 +01:00
|
|
|
--- Hide the border on fullscreen clients.
|
|
|
|
-- @beautiful beautiful.fullscreen_hide_border
|
|
|
|
-- @tparam[opt=true] boolean fullscreen_hide_border
|
|
|
|
|
2016-09-28 22:17:08 +02:00
|
|
|
--- The list of all registered generic request::activate (focus stealing)
|
|
|
|
-- filters. If a filter is added to only one context, it will be in
|
|
|
|
-- `ewmh.contextual_activate_filters`["context_name"].
|
|
|
|
-- @table[opt={}] generic_activate_filters
|
|
|
|
-- @see ewmh.activate
|
|
|
|
-- @see ewmh.add_activate_filter
|
|
|
|
-- @see ewmh.remove_activate_filter
|
|
|
|
|
|
|
|
--- The list of all registered contextual request::activate (focus stealing)
|
|
|
|
-- filters. If a filter is added to only one context, it will be in
|
|
|
|
-- `ewmh.generic_activate_filters`.
|
|
|
|
-- @table[opt={}] contextual_activate_filters
|
|
|
|
-- @see ewmh.activate
|
|
|
|
-- @see ewmh.add_activate_filter
|
|
|
|
-- @see ewmh.remove_activate_filter
|
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.
|
2017-01-25 10:51:10 +01:00
|
|
|
local repair_geometry_lock = false
|
|
|
|
local function repair_geometry(window)
|
|
|
|
if repair_geometry_lock then return end
|
|
|
|
repair_geometry_lock = true
|
|
|
|
|
|
|
|
-- Re-apply the geometry locking properties to what they should be.
|
|
|
|
for _, prop in ipairs {
|
|
|
|
"fullscreen", "maximized", "maximized_vertical", "maximized_horizontal"
|
|
|
|
} do
|
|
|
|
if window[prop] then
|
|
|
|
window:emit_signal("request::geometry", prop, {
|
|
|
|
store_geometry = false
|
|
|
|
})
|
|
|
|
break
|
|
|
|
end
|
2012-05-16 23:03:32 +02:00
|
|
|
end
|
2015-01-31 11:58:49 +01:00
|
|
|
|
2017-01-25 10:51:10 +01:00
|
|
|
repair_geometry_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
|
|
|
|
|
2016-09-28 22:17:08 +02:00
|
|
|
local found, ret = false
|
|
|
|
|
|
|
|
-- Execute the filters until something handle the request
|
|
|
|
for _, tab in ipairs {
|
|
|
|
ewmh.contextual_activate_filters[context] or {},
|
|
|
|
ewmh.generic_activate_filters
|
|
|
|
} do
|
|
|
|
for i=#tab, 1, -1 do
|
|
|
|
ret = tab[i](c, context, hints)
|
|
|
|
if ret ~= nil then found=true; break end
|
|
|
|
end
|
|
|
|
|
|
|
|
if found then break end
|
|
|
|
end
|
|
|
|
|
|
|
|
if ret ~= false and c:isvisible() then
|
2015-09-25 00:18:33 +02:00
|
|
|
client.focus = c
|
2016-09-28 22:17:08 +02:00
|
|
|
elseif ret == false and not hints.force then
|
|
|
|
return
|
2015-09-25 00:18:33 +02:00
|
|
|
end
|
2016-09-28 22:17:08 +02:00
|
|
|
|
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-09-28 22:17:08 +02:00
|
|
|
--- Add an activate (focus stealing) filter function.
|
|
|
|
--
|
|
|
|
-- The callback takes the following parameters:
|
|
|
|
--
|
|
|
|
-- * **c** (*client*) The client requesting the activation
|
|
|
|
-- * **context** (*string*) The activation context.
|
|
|
|
-- * **hints** (*table*) Some additional hints (depending on the context)
|
|
|
|
--
|
|
|
|
-- If the callback returns `true`, the client will be activated unless the `force`
|
|
|
|
-- hint is set. If the callback returns `false`, the activation request is
|
|
|
|
-- cancelled. If the callback returns `nil`, the previous callback will be
|
|
|
|
-- executed. This will continue until either a callback handles the request or
|
|
|
|
-- when it runs out of callbacks. In that case, the request will be granted if
|
|
|
|
-- the client is visible.
|
|
|
|
--
|
|
|
|
-- For example, to block Firefox from stealing the focus, use:
|
|
|
|
--
|
|
|
|
-- awful.ewmh.add_activate_filter(function(c, "ewmh")
|
|
|
|
-- if c.class == "Firefox" then return false end
|
|
|
|
-- end)
|
|
|
|
--
|
|
|
|
-- @tparam function f The callback
|
|
|
|
-- @tparam[opt] string context The `request::activate` context
|
|
|
|
-- @see generic_activate_filters
|
|
|
|
-- @see contextual_activate_filters
|
|
|
|
-- @see remove_activate_filter
|
|
|
|
function ewmh.add_activate_filter(f, context)
|
|
|
|
if not context then
|
|
|
|
table.insert(ewmh.generic_activate_filters, f)
|
|
|
|
else
|
|
|
|
ewmh.contextual_activate_filters[context] =
|
|
|
|
ewmh.contextual_activate_filters[context] or {}
|
|
|
|
|
|
|
|
table.insert(ewmh.contextual_activate_filters[context], f)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Remove an activate (focus stealing) filter function.
|
|
|
|
-- This is an helper to avoid dealing with `ewmh.add_activate_filter` directly.
|
|
|
|
-- @tparam function f The callback
|
|
|
|
-- @tparam[opt] string context The `request::activate` context
|
|
|
|
-- @treturn boolean If the callback existed
|
|
|
|
-- @see generic_activate_filters
|
|
|
|
-- @see contextual_activate_filters
|
|
|
|
-- @see add_activate_filter
|
|
|
|
function ewmh.remove_activate_filter(f, context)
|
|
|
|
local tab = context and (ewmh.contextual_activate_filters[context] or {})
|
|
|
|
or ewmh.generic_activate_filters
|
|
|
|
|
|
|
|
for k, v in ipairs(tab) do
|
|
|
|
if v == f then
|
|
|
|
table.remove(tab, k)
|
|
|
|
|
|
|
|
-- In case the callback is there multiple time.
|
|
|
|
ewmh.remove_activate_filter(f, context)
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
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
|
2017-01-25 12:11:11 +01:00
|
|
|
if c.transient_for and not (hints and hints.reason == "screen") then
|
2016-08-23 05:18:07 +02:00
|
|
|
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
|
|
|
|
|
2016-12-10 05:55:13 +01:00
|
|
|
--- Handle client urgent request
|
|
|
|
-- @signalhandler awful.ewmh.urgent
|
|
|
|
-- @client c A client
|
|
|
|
-- @tparam boolean urgent If the client should be urgent
|
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",
|
2017-01-24 10:19:45 +01:00
|
|
|
maximized = "maximize",
|
2016-04-15 11:09:41 +02:00
|
|
|
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
|
2017-01-25 10:51:10 +01:00
|
|
|
local original = repair_geometry_lock
|
|
|
|
repair_geometry_lock = true
|
2016-04-15 11:09:41 +02:00
|
|
|
aplace.restore(c,{context=context})
|
2017-01-25 10:51:10 +01:00
|
|
|
repair_geometry_lock = original
|
2016-04-15 11:09:41 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local honor_default = original_context ~= "fullscreen"
|
|
|
|
|
|
|
|
if props.honor_workarea == nil then
|
|
|
|
props.honor_workarea = honor_default
|
|
|
|
end
|
|
|
|
|
2017-01-25 10:00:33 +01:00
|
|
|
if props.honor_padding == nil and props.honor_workarea and context:match("maximize") then
|
|
|
|
props.honor_padding = beautiful.maximized_honor_padding ~= false
|
|
|
|
end
|
|
|
|
|
2017-01-26 09:06:05 +01:00
|
|
|
if original_context == "fullscreen" and beautiful.fullscreen_hide_border ~= false then
|
|
|
|
props.ignore_border_width = true
|
|
|
|
end
|
|
|
|
|
2016-04-15 11:09:41 +02:00
|
|
|
aplace[context](c, props)
|
2017-01-26 09:06:05 +01:00
|
|
|
|
|
|
|
-- Remove the border to get a "real" fullscreen.
|
|
|
|
if original_context == "fullscreen" and beautiful.fullscreen_hide_border ~= false then
|
|
|
|
local original = repair_geometry_lock
|
|
|
|
repair_geometry_lock = true
|
|
|
|
c.border_width = 0
|
|
|
|
repair_geometry_lock = original
|
|
|
|
end
|
2016-04-15 11:09:41 +02:00
|
|
|
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)
|
2017-01-25 10:51:10 +01:00
|
|
|
client.connect_signal("property::border_width", repair_geometry)
|
|
|
|
client.connect_signal("property::screen", repair_geometry)
|
2016-02-21 16:44:40 +01:00
|
|
|
screen.connect_signal("property::workarea", function(s)
|
|
|
|
for _, c in pairs(client.get(s)) do
|
2017-01-25 10:51:10 +01:00
|
|
|
repair_geometry(c)
|
2016-02-21 16:44:40 +01:00
|
|
|
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
|