2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
2014-05-20 11:47:20 +02:00
|
|
|
--- Useful client manipulation functions.
|
|
|
|
--
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
2016-03-31 08:36:44 +02:00
|
|
|
-- @module client
|
2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
2017-03-15 06:08:40 +01:00
|
|
|
local gdebug = require("gears.debug")
|
2018-10-01 05:55:57 +02:00
|
|
|
local spawn = nil --TODO v5 deprecate
|
2017-02-02 21:12:47 +01:00
|
|
|
local set_shape = require("awful.client.shape").update.all
|
2016-03-13 08:44:19 +01:00
|
|
|
local object = require("gears.object")
|
2016-05-16 06:57:15 +02:00
|
|
|
local grect = require("gears.geometry").rectangle
|
2017-03-06 17:15:40 +01:00
|
|
|
local gmath = require("gears.math")
|
2017-03-08 21:18:33 +01:00
|
|
|
local gtable = require("gears.table")
|
2019-10-20 00:29:59 +02:00
|
|
|
local amousec = require("awful.mouse.client")
|
2019-11-18 01:48:25 +01:00
|
|
|
local pcommon = require("awful.permissions._common")
|
2008-09-29 16:49:18 +02:00
|
|
|
local pairs = pairs
|
2009-05-18 16:42:03 +02:00
|
|
|
local type = type
|
2008-09-29 16:49:18 +02:00
|
|
|
local ipairs = ipairs
|
|
|
|
local table = table
|
|
|
|
local math = math
|
2008-11-03 23:15:00 +01:00
|
|
|
local setmetatable = setmetatable
|
2008-09-29 16:49:18 +02:00
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
client = client,
|
|
|
|
mouse = mouse,
|
|
|
|
screen = screen,
|
2014-04-10 15:32:52 +02:00
|
|
|
awesome = awesome,
|
2008-09-29 16:49:18 +02:00
|
|
|
}
|
|
|
|
|
2016-02-26 20:16:07 +01:00
|
|
|
local function get_screen(s)
|
|
|
|
return s and capi.screen[s]
|
|
|
|
end
|
|
|
|
|
2015-07-22 02:42:35 +02:00
|
|
|
-- We use a metatable to prevent circular dependency loops.
|
2012-09-28 23:53:58 +02:00
|
|
|
local screen
|
2015-07-22 02:42:35 +02:00
|
|
|
do
|
|
|
|
screen = setmetatable({}, {
|
2016-02-07 15:02:25 +01:00
|
|
|
__index = function(_, k)
|
2015-07-22 02:42:35 +02:00
|
|
|
screen = require("awful.screen")
|
|
|
|
return screen[k]
|
|
|
|
end,
|
2015-07-28 21:29:05 +02:00
|
|
|
__newindex = error -- Just to be sure in case anything ever does this
|
2015-07-22 02:42:35 +02:00
|
|
|
})
|
|
|
|
end
|
2016-03-14 07:21:29 +01:00
|
|
|
local client = {object={}}
|
2008-09-29 16:49:18 +02:00
|
|
|
|
|
|
|
-- Private data
|
2012-06-12 20:13:09 +02:00
|
|
|
client.data = {}
|
|
|
|
client.data.marked = {}
|
2014-04-10 15:32:52 +02:00
|
|
|
client.data.persistent_properties_registered = {} -- keys are names of persistent properties, value always true
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2009-02-07 15:12:57 +01:00
|
|
|
-- Functions
|
2016-04-01 09:46:05 +02:00
|
|
|
client.urgent = require("awful.client.urgent")
|
2012-06-12 20:13:09 +02:00
|
|
|
client.swap = {}
|
|
|
|
client.floating = {}
|
|
|
|
client.dockable = {}
|
|
|
|
client.property = {}
|
2014-04-14 10:04:56 +02:00
|
|
|
client.shape = require("awful.client.shape")
|
2016-03-31 09:16:34 +02:00
|
|
|
client.focus = require("awful.client.focus")
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2018-10-07 01:40:36 +02:00
|
|
|
--- The client default placement on the screen.
|
|
|
|
--
|
|
|
|
-- The default config uses:
|
|
|
|
--
|
|
|
|
-- awful.placement.no_overlap+awful.placement.no_offscreen
|
|
|
|
--
|
2019-10-07 03:21:46 +02:00
|
|
|
-- @DOC_sequences_client_rules_placement_EXAMPLE@
|
|
|
|
--
|
2018-10-07 01:40:36 +02:00
|
|
|
-- @clientruleproperty placement
|
|
|
|
-- @see awful.placement
|
|
|
|
|
|
|
|
--- When applying the placement, honor the screen padding.
|
|
|
|
-- @clientruleproperty honor_padding
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam[opt=true] boolean honor_padding
|
2018-10-07 01:40:36 +02:00
|
|
|
-- @see awful.placement
|
|
|
|
|
|
|
|
--- When applying the placement, honor the screen work area.
|
|
|
|
--
|
|
|
|
-- The workarea is the part of the screen that excludes the bars and docks.
|
|
|
|
--
|
|
|
|
-- @clientruleproperty honor_workarea
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam[opt=true] boolean honor_workarea
|
2018-10-07 01:40:36 +02:00
|
|
|
-- @see awful.placement
|
|
|
|
|
|
|
|
--- The client default tag.
|
2019-10-07 03:21:46 +02:00
|
|
|
--
|
|
|
|
-- @DOC_sequences_client_rules_tags_EXAMPLE@
|
|
|
|
--
|
2018-10-07 01:40:36 +02:00
|
|
|
-- @clientruleproperty tag
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam tag tag
|
2018-10-07 01:40:36 +02:00
|
|
|
-- @see tag
|
|
|
|
-- @see new_tag
|
|
|
|
-- @see tags
|
|
|
|
-- @see switch_to_tags
|
|
|
|
|
|
|
|
--- The client default tags.
|
|
|
|
--
|
|
|
|
-- Avoid using the tag and tags properties at the same time, it will cause
|
|
|
|
-- issues.
|
|
|
|
--
|
|
|
|
-- @clientruleproperty tags
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam[opt={tag}] table tags
|
2018-10-07 01:40:36 +02:00
|
|
|
-- @see tag
|
|
|
|
-- @see new_tag
|
|
|
|
-- @see tags
|
|
|
|
-- @see switch_to_tags
|
|
|
|
|
|
|
|
--- Create a new tag for this client.
|
|
|
|
--
|
|
|
|
-- If the value is `true`, the new tag will be named after the client `class`.
|
|
|
|
-- If it is a string, it will be the tag name.
|
|
|
|
--
|
|
|
|
-- If a table is used, all of its properties will be passed to the tag
|
|
|
|
-- constructor:
|
|
|
|
--
|
2019-10-07 03:21:46 +02:00
|
|
|
-- @DOC_sequences_client_rules_new_tag_EXAMPLE@
|
2018-10-07 01:40:36 +02:00
|
|
|
--
|
|
|
|
-- @tparam[opt=false] table|string|boolean new_tag
|
|
|
|
-- @clientruleproperty new_tag
|
|
|
|
-- @see tag
|
|
|
|
-- @see tags
|
|
|
|
-- @see switch_to_tags
|
|
|
|
|
|
|
|
--- Unselect the current tags and select this client tags.
|
|
|
|
-- Note that this property was called `switchtotag` in previous Awesome versions.
|
2019-10-07 03:21:46 +02:00
|
|
|
--
|
|
|
|
-- @DOC_sequences_client_rules_switch_to_tags_EXAMPLE@
|
|
|
|
--
|
2018-10-07 01:40:36 +02:00
|
|
|
-- @clientruleproperty switch_to_tags
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam[opt=false] boolean switch_to_tags
|
2018-10-07 01:40:36 +02:00
|
|
|
-- @see tag.selected
|
|
|
|
|
|
|
|
--- Define if the client should grab focus by default.
|
|
|
|
--
|
|
|
|
-- The `request::activate` context for this call is `rules`.
|
|
|
|
--
|
|
|
|
-- @clientruleproperty focus
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam[opt=false] boolean focus
|
2018-10-07 01:40:36 +02:00
|
|
|
|
|
|
|
--- Should this client have a titlebar by default.
|
|
|
|
-- @clientruleproperty titlebars_enabled
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam[opt=false] boolean titlebars_enabled
|
2018-10-07 01:40:36 +02:00
|
|
|
-- @see awful.titlebar
|
|
|
|
|
|
|
|
--- A function to call when this client is ready.
|
|
|
|
--
|
|
|
|
-- It can be useful to set extra properties or perform actions.
|
|
|
|
--
|
|
|
|
-- @clientruleproperty callback
|
|
|
|
-- @see awful.spawn
|
|
|
|
|
2014-05-20 11:47:20 +02:00
|
|
|
--- Jump to the given client.
|
|
|
|
-- Takes care of focussing the screen, the right tag, etc.
|
|
|
|
--
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @deprecated awful.client.jumpto
|
|
|
|
-- @see client.jump_to
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c the client to jump to
|
2016-02-28 22:45:15 +01:00
|
|
|
-- @tparam bool|function merge If true then merge tags (select the client's
|
|
|
|
-- first tag additionally) when the client is not visible.
|
|
|
|
-- If it is a function, it will be called with the client and its first
|
|
|
|
-- tag as arguments.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.jumpto(c, merge)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c:jump_to(merge) instead of awful.client.jumpto", {deprecated_in=4})
|
2016-04-02 09:27:45 +02:00
|
|
|
client.object.jump_to(c, merge)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Jump to the given client.
|
|
|
|
-- Takes care of focussing the screen, the right tag, etc.
|
|
|
|
--
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method jump_to
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @tparam bool|function merge If true then merge tags (select the client's
|
|
|
|
-- first tag additionally) when the client is not visible.
|
|
|
|
-- If it is a function, it will be called with the client and its first
|
|
|
|
-- tag as arguments.
|
2019-12-01 07:53:12 +01:00
|
|
|
-- @request client activate client.jumpto granted When a client is activated
|
|
|
|
-- because `c:jump_to()` is called.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @see activate
|
|
|
|
-- @see active
|
2016-04-02 09:27:45 +02:00
|
|
|
function client.object.jump_to(self, merge)
|
2016-02-26 20:16:07 +01:00
|
|
|
local s = get_screen(screen.focused())
|
2012-03-06 23:09:45 +01:00
|
|
|
-- focus the screen
|
2016-04-02 09:27:45 +02:00
|
|
|
if s ~= get_screen(self.screen) then
|
|
|
|
screen.focus(self.screen)
|
2012-03-06 23:09:45 +01:00
|
|
|
end
|
|
|
|
|
2016-04-02 09:27:45 +02:00
|
|
|
self.minimized = false
|
2016-03-01 22:55:27 +01:00
|
|
|
|
2016-02-28 22:45:15 +01:00
|
|
|
-- Try to make client visible, this also covers e.g. sticky.
|
2016-04-02 09:27:45 +02:00
|
|
|
if not self:isvisible() then
|
|
|
|
local t = self.first_tag
|
2012-03-06 23:09:45 +01:00
|
|
|
if merge then
|
2016-02-28 22:45:15 +01:00
|
|
|
if type(merge) == "function" then
|
2016-04-02 09:27:45 +02:00
|
|
|
merge(self, t)
|
2016-02-28 22:45:15 +01:00
|
|
|
elseif t then
|
|
|
|
t.selected = true
|
|
|
|
end
|
|
|
|
elseif t then
|
2016-04-05 09:02:00 +02:00
|
|
|
t:view_only()
|
2012-03-06 23:09:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 09:27:45 +02:00
|
|
|
self:emit_signal("request::activate", "client.jumpto", {raise=true})
|
2012-03-06 23:09:45 +01:00
|
|
|
end
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
--- Get visible clients from a screen.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2016-04-05 09:02:00 +02:00
|
|
|
-- @deprecated awful.client.visible
|
|
|
|
-- @see screen.clients
|
2016-02-26 20:16:07 +01:00
|
|
|
-- @tparam[opt] integer|screen s The screen, or nil for all screens.
|
2015-10-13 12:20:36 +02:00
|
|
|
-- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
|
2015-07-23 16:46:28 +02:00
|
|
|
-- @treturn table A table with all visible clients.
|
2016-02-07 15:02:25 +01:00
|
|
|
function client.visible(s, stacked)
|
|
|
|
local cls = capi.client.get(s, stacked)
|
2008-09-29 16:49:18 +02:00
|
|
|
local vcls = {}
|
2016-02-07 15:02:25 +01:00
|
|
|
for _, c in pairs(cls) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if c:isvisible() then
|
|
|
|
table.insert(vcls, c)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return vcls
|
|
|
|
end
|
|
|
|
|
2008-11-25 16:40:41 +01:00
|
|
|
--- Get visible and tiled clients
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2016-04-05 09:02:00 +02:00
|
|
|
-- @deprecated awful.client.tiled
|
|
|
|
-- @see screen.tiled_clients
|
2016-02-26 20:16:07 +01:00
|
|
|
-- @tparam integer|screen s The screen, or nil for all screens.
|
2015-10-13 12:20:36 +02:00
|
|
|
-- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
|
2015-07-23 16:46:28 +02:00
|
|
|
-- @treturn table A table with all visible and tiled clients.
|
2016-02-07 15:02:25 +01:00
|
|
|
function client.tiled(s, stacked)
|
|
|
|
local clients = client.visible(s, stacked)
|
2008-11-25 16:40:41 +01:00
|
|
|
local tclients = {}
|
|
|
|
-- Remove floating clients
|
2016-02-07 15:02:25 +01:00
|
|
|
for _, c in pairs(clients) do
|
2016-03-14 07:21:29 +01:00
|
|
|
if not client.object.get_floating(c)
|
2013-10-04 12:04:16 +02:00
|
|
|
and not c.fullscreen
|
2017-01-24 11:41:22 +01:00
|
|
|
and not c.maximized
|
2013-10-04 12:04:16 +02:00
|
|
|
and not c.maximized_vertical
|
|
|
|
and not c.maximized_horizontal then
|
2008-11-25 16:40:41 +01:00
|
|
|
table.insert(tclients, c)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return tclients
|
|
|
|
end
|
|
|
|
|
2014-05-20 11:47:20 +02:00
|
|
|
--- Get a client by its relative index to another client.
|
|
|
|
-- If no client is passed, the focused client will be used.
|
|
|
|
--
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.next
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @tparam int i The index. Use 1 to get the next, -1 to get the previous.
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam[opt] client sel The client.
|
2015-10-13 12:20:36 +02:00
|
|
|
-- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @treturn[opt] client|nil A client, or nil if no client is available.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @usage -- focus the next window in the index
|
|
|
|
-- awful.client.next(1)
|
|
|
|
-- -- focus the previous
|
|
|
|
-- awful.client.next(-1)
|
2016-02-07 15:02:25 +01:00
|
|
|
function client.next(i, sel, stacked)
|
2008-09-29 16:49:18 +02:00
|
|
|
-- Get currently focused client
|
2016-02-07 15:02:25 +01:00
|
|
|
sel = sel or capi.client.focus
|
2008-09-29 16:49:18 +02:00
|
|
|
if sel then
|
|
|
|
-- Get all visible clients
|
2015-07-23 16:46:28 +02:00
|
|
|
local cls = client.visible(sel.screen, stacked)
|
2008-11-27 11:18:35 +01:00
|
|
|
local fcls = {}
|
|
|
|
-- Remove all non-normal clients
|
2016-02-07 15:02:25 +01:00
|
|
|
for _, c in ipairs(cls) do
|
2012-06-12 20:13:09 +02:00
|
|
|
if client.focus.filter(c) or c == sel then
|
2008-11-27 11:18:35 +01:00
|
|
|
table.insert(fcls, c)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
2008-11-27 11:18:35 +01:00
|
|
|
cls = fcls
|
2008-09-29 16:49:18 +02:00
|
|
|
-- Loop upon each client
|
|
|
|
for idx, c in ipairs(cls) do
|
|
|
|
if c == sel then
|
|
|
|
-- Cycle
|
2017-03-06 17:15:40 +01:00
|
|
|
return cls[gmath.cycle(#cls, idx + i)]
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-23 16:46:28 +02:00
|
|
|
--- Swap a client with another client in the given direction.
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.swap.bydirection
|
2015-07-23 16:46:28 +02:00
|
|
|
-- @tparam string dir The direction, can be either "up", "down", "left" or "right".
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam[opt=focused] client c The client.
|
2015-10-13 12:20:36 +02:00
|
|
|
-- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @see swap
|
|
|
|
-- @see swapped
|
|
|
|
-- @see awful.client.swap.global_bydirection
|
|
|
|
-- @see awful.client.swap.byidx
|
|
|
|
-- @see awful.client.cycle
|
2015-07-23 16:46:28 +02:00
|
|
|
function client.swap.bydirection(dir, c, stacked)
|
2008-10-06 21:55:06 +02:00
|
|
|
local sel = c or capi.client.focus
|
|
|
|
if sel then
|
2015-07-23 16:46:28 +02:00
|
|
|
local cltbl = client.visible(sel.screen, stacked)
|
2012-09-15 01:11:33 +02:00
|
|
|
local geomtbl = {}
|
|
|
|
for i,cl in ipairs(cltbl) do
|
|
|
|
geomtbl[i] = cl:geometry()
|
|
|
|
end
|
2016-05-16 06:57:15 +02:00
|
|
|
local target = grect.get_in_direction(dir, geomtbl, sel:geometry())
|
2008-10-06 21:55:06 +02:00
|
|
|
|
|
|
|
-- If we found a client to swap with, then go for it
|
|
|
|
if target then
|
2012-09-15 01:11:33 +02:00
|
|
|
cltbl[target]:swap(sel)
|
2008-10-06 21:55:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-08 01:08:05 +02:00
|
|
|
--- Swap a client with another client in the given direction.
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2019-06-08 01:08:05 +02:00
|
|
|
-- Swaps across screens.
|
|
|
|
-- @staticfct awful.client.swap.global_bydirection
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam string dir The direction, can be either "up", "down", "left" or "right".
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam[opt] client sel The client.
|
2019-12-01 07:53:12 +01:00
|
|
|
-- @request client activate client.swap.global_bydirection granted When a client
|
|
|
|
-- could be activated because `awful.client.swap.global_bydirection` was called.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @see swap
|
|
|
|
-- @see swapped
|
|
|
|
-- @see awful.client.swap.bydirection
|
|
|
|
-- @see awful.client.swap.byidx
|
|
|
|
-- @see awful.client.cycle
|
2016-02-07 15:02:25 +01:00
|
|
|
function client.swap.global_bydirection(dir, sel)
|
|
|
|
sel = sel or capi.client.focus
|
2016-02-26 20:16:07 +01:00
|
|
|
local scr = get_screen(sel and sel.screen or screen.focused())
|
2012-09-15 01:11:33 +02:00
|
|
|
|
|
|
|
if sel then
|
|
|
|
-- move focus
|
|
|
|
client.focus.global_bydirection(dir, sel)
|
|
|
|
local c = capi.client.focus
|
|
|
|
|
|
|
|
-- swapping inside a screen
|
2016-02-26 20:16:07 +01:00
|
|
|
if get_screen(sel.screen) == get_screen(c.screen) and sel ~= c then
|
2012-09-15 01:11:33 +02:00
|
|
|
c:swap(sel)
|
|
|
|
|
|
|
|
-- swapping to an empty screen
|
2018-08-21 13:19:02 +02:00
|
|
|
elseif sel == c then
|
2016-04-02 09:27:45 +02:00
|
|
|
sel:move_to_screen(screen.focused())
|
2012-09-15 01:11:33 +02:00
|
|
|
|
2015-06-19 22:24:12 +02:00
|
|
|
-- swapping to a nonempty screen
|
2016-02-26 20:16:07 +01:00
|
|
|
elseif get_screen(sel.screen) ~= get_screen(c.screen) and sel ~= c then
|
2016-04-02 09:27:45 +02:00
|
|
|
sel:move_to_screen(c.screen)
|
2016-04-05 09:02:00 +02:00
|
|
|
c:move_to_screen(scr)
|
2012-09-15 01:11:33 +02:00
|
|
|
end
|
|
|
|
|
2012-09-28 23:53:58 +02:00
|
|
|
screen.focus(sel.screen)
|
2015-06-19 22:24:12 +02:00
|
|
|
sel:emit_signal("request::activate", "client.swap.global_bydirection",
|
|
|
|
{raise=false})
|
2012-09-15 01:11:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
--- Swap a client by its relative index.
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.swap.byidx
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam integer i The index.
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam[opt] client c The client, otherwise focused one is used.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @see swap
|
|
|
|
-- @see swapped
|
|
|
|
-- @see awful.client.swap.bydirection
|
|
|
|
-- @see awful.client.swap.global_bydirection
|
|
|
|
-- @see awful.client.cycle
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.swap.byidx(i, c)
|
2008-09-29 16:49:18 +02:00
|
|
|
local sel = c or capi.client.focus
|
2012-06-19 20:37:03 +02:00
|
|
|
local target = client.next(i, sel)
|
2008-09-29 16:49:18 +02:00
|
|
|
if target then
|
|
|
|
target:swap(sel)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-31 00:17:23 +01:00
|
|
|
--- Cycle through the clients to change the focus.
|
|
|
|
--
|
|
|
|
-- This will swap the client from one position to the next
|
|
|
|
-- in the layout.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.cycle
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam boolean clockwise True to cycle clients clockwise.
|
|
|
|
-- @tparam[opt] screen s The screen where to cycle clients.
|
2015-10-13 12:20:36 +02:00
|
|
|
-- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @see swap
|
|
|
|
-- @see swapped
|
|
|
|
-- @see awful.client.swap.bydirection
|
|
|
|
-- @see awful.client.swap.global_bydirection
|
|
|
|
-- @see awful.client.swap.byidx
|
2015-09-10 20:16:53 +02:00
|
|
|
function client.cycle(clockwise, s, stacked)
|
2015-07-22 02:42:35 +02:00
|
|
|
s = s or screen.focused()
|
2015-09-10 20:16:53 +02:00
|
|
|
local cls = client.visible(s, stacked)
|
2009-02-14 17:53:03 +01:00
|
|
|
-- We can't rotate without at least 2 clients, buddy.
|
|
|
|
if #cls >= 2 then
|
|
|
|
local c = table.remove(cls, 1)
|
|
|
|
if clockwise then
|
|
|
|
for i = #cls, 1, -1 do
|
|
|
|
c:swap(cls[i])
|
|
|
|
end
|
|
|
|
else
|
|
|
|
for _, rc in pairs(cls) do
|
|
|
|
c:swap(rc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-20 02:45:26 +02:00
|
|
|
--- Append a keybinding.
|
|
|
|
--
|
|
|
|
-- @method append_keybinding
|
|
|
|
-- @tparam awful.key key The key.
|
|
|
|
-- @see remove_keybinding
|
|
|
|
-- @see append_mousebinding
|
|
|
|
-- @see remove_mousebinding
|
|
|
|
|
|
|
|
--- Remove a keybinding.
|
|
|
|
--
|
|
|
|
-- @method remove_keybinding
|
|
|
|
-- @tparam awful.key key The key.
|
|
|
|
|
|
|
|
--- Append a mousebinding.
|
|
|
|
--
|
|
|
|
-- @method append_mousebinding
|
|
|
|
-- @tparam awful.button button The button.
|
|
|
|
|
|
|
|
--- Remove a mousebinding.
|
|
|
|
--
|
|
|
|
-- @method remove_mousebinding
|
|
|
|
-- @tparam awful.button button The button.
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
--- Get the master window.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2016-04-02 10:02:43 +02:00
|
|
|
-- @legacylayout awful.client.getmaster
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam[opt=awful.screen.focused()] screen s The screen.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @treturn client The master client.
|
2015-07-22 02:42:35 +02:00
|
|
|
function client.getmaster(s)
|
|
|
|
s = s or screen.focused()
|
2012-06-12 20:13:09 +02:00
|
|
|
return client.visible(s)[1]
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2012-08-11 23:55:25 +02:00
|
|
|
--- Set the client as master: put it at the beginning of other windows.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2016-04-02 10:02:43 +02:00
|
|
|
-- @legacylayout awful.client.setmaster
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The window to set as master.
|
2012-08-11 23:55:25 +02:00
|
|
|
function client.setmaster(c)
|
2017-03-08 21:18:33 +01:00
|
|
|
local cls = gtable.reverse(capi.client.get(c.screen))
|
2016-02-07 15:02:25 +01:00
|
|
|
for _, v in pairs(cls) do
|
2012-08-11 23:55:25 +02:00
|
|
|
c:swap(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-27 10:58:02 +01:00
|
|
|
--- Set the client as slave: put it at the end of other windows.
|
2016-04-02 10:02:43 +02:00
|
|
|
-- @legacylayout awful.client.setslave
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The window to set as slave.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.setslave(c)
|
2012-05-06 18:52:00 +02:00
|
|
|
local cls = capi.client.get(c.screen)
|
2016-02-07 15:02:25 +01:00
|
|
|
for _, v in pairs(cls) do
|
2008-09-29 16:49:18 +02:00
|
|
|
c:swap(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Move/resize a client relative to current coordinates.
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @deprecated awful.client.moveresize
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam integer x The relative x coordinate.
|
|
|
|
-- @tparam integer y The relative y coordinate.
|
|
|
|
-- @tparam integer w The relative width.
|
|
|
|
-- @tparam integer h The relative height.
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam[opt] client c The client, otherwise focused one is used.
|
2016-04-05 09:02:00 +02:00
|
|
|
-- @see client.relative_move
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.moveresize(x, y, w, h, c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c:relative_move(x, y, w, h) instead of awful.client.moveresize", {deprecated_in=4})
|
2016-04-05 09:02:00 +02:00
|
|
|
client.object.relative_move(c or capi.client.focus, x, y, w, h)
|
2016-04-02 09:27:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Move/resize a client relative to current coordinates.
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method relative_move
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @see geometry
|
|
|
|
-- @tparam[opt=c.x] number x The relative x coordinate.
|
|
|
|
-- @tparam[opt=c.y] number y The relative y coordinate.
|
|
|
|
-- @tparam[opt=c.width] number w The relative width.
|
|
|
|
-- @tparam[opt=c.height] number h The relative height.
|
2016-04-05 09:02:00 +02:00
|
|
|
function client.object.relative_move(self, x, y, w, h)
|
2016-04-02 09:27:45 +02:00
|
|
|
local geometry = self:geometry()
|
2009-08-21 21:15:19 +02:00
|
|
|
geometry['x'] = geometry['x'] + x
|
|
|
|
geometry['y'] = geometry['y'] + y
|
|
|
|
geometry['width'] = geometry['width'] + w
|
|
|
|
geometry['height'] = geometry['height'] + h
|
2016-04-02 09:27:45 +02:00
|
|
|
self:geometry(geometry)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Move a client to a tag.
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @deprecated awful.client.movetotag
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam tag target The tag to move the client to.
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam[opt] client c The client to move, otherwise the focused one is used.
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @see client.move_to_tag
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.movetotag(target, c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c:move_to_tag(target) instead of awful.client.movetotag", {deprecated_in=4})
|
2016-04-02 09:27:45 +02:00
|
|
|
client.object.move_to_tag(c or capi.client.focus, target)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Move a client to a tag.
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method move_to_tag
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @tparam tag target The tag to move the client to.
|
2019-12-01 07:53:12 +01:00
|
|
|
-- @request client activate client.movetotag granted When a client could be
|
|
|
|
-- activated because `c:move_to_tag()` was called.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @see tags
|
2016-04-02 09:27:45 +02:00
|
|
|
function client.object.move_to_tag(self, target)
|
2016-04-05 09:02:00 +02:00
|
|
|
local s = target.screen
|
2016-04-02 09:27:45 +02:00
|
|
|
if self and s then
|
|
|
|
if self == capi.client.focus then
|
|
|
|
self:emit_signal("request::activate", "client.movetotag", {raise=true})
|
2015-09-09 22:15:43 +02:00
|
|
|
end
|
2009-08-24 16:09:56 +02:00
|
|
|
-- Set client on the same screen as the tag.
|
2016-04-02 09:27:45 +02:00
|
|
|
self.screen = s
|
|
|
|
self:tags({ target })
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Toggle a tag on a client.
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @deprecated awful.client.toggletag
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam tag target The tag to toggle.
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam[opt] client c The client to toggle, otherwise the focused one is used.
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @see client.toggle_tag
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @see tags
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.toggletag(target, c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c:toggle_tag(target) instead of awful.client.toggletag", {deprecated_in=4})
|
2016-04-02 09:27:45 +02:00
|
|
|
client.object.toggle_tag(c or capi.client.focus, target)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Toggle a tag on a client.
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method toggle_tag
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @tparam tag target The tag to move the client to.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @see tags
|
2016-04-02 09:27:45 +02:00
|
|
|
function client.object.toggle_tag(self, target)
|
2008-09-29 16:49:18 +02:00
|
|
|
-- Check that tag and client screen are identical
|
2016-04-05 09:02:00 +02:00
|
|
|
if self and get_screen(self.screen) == get_screen(target.screen) then
|
2016-04-02 09:27:45 +02:00
|
|
|
local tags = self:tags()
|
2009-04-23 12:53:24 +02:00
|
|
|
local index = nil;
|
|
|
|
for i, v in ipairs(tags) do
|
|
|
|
if v == target then
|
|
|
|
index = i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if index then
|
2008-09-29 16:49:18 +02:00
|
|
|
-- If it's the only tag for the window, stop.
|
|
|
|
if #tags == 1 then return end
|
2009-04-23 12:53:24 +02:00
|
|
|
tags[index] = nil
|
2008-09-29 16:49:18 +02:00
|
|
|
else
|
2009-04-23 12:53:24 +02:00
|
|
|
tags[#tags + 1] = target
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2016-04-02 09:27:45 +02:00
|
|
|
self:tags(tags)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Move a client to a screen. Default is next screen, cycling.
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @deprecated awful.client.movetoscreen
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client to move.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam screen s The screen, default to current + 1.
|
2016-04-03 09:59:58 +02:00
|
|
|
-- @see screen
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @see client.move_to_screen
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.movetoscreen(c, s)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c:move_to_screen(s) instead of awful.client.movetoscreen", {deprecated_in=4})
|
2016-04-02 09:27:45 +02:00
|
|
|
client.object.move_to_screen(c or capi.client.focus, s)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Move a client to a screen. Default is next screen, cycling.
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method move_to_screen
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @tparam[opt=c.screen.index+1] screen s The screen, default to current + 1.
|
|
|
|
-- @see screen
|
|
|
|
-- @see request::activate
|
2019-12-01 07:53:12 +01:00
|
|
|
-- @request client activate client.movetoscreen granted When a client could be
|
|
|
|
-- activated because `c:move_to_screen()` was called.
|
2016-04-02 09:27:45 +02:00
|
|
|
function client.object.move_to_screen(self, s)
|
|
|
|
if self then
|
2008-09-29 16:49:18 +02:00
|
|
|
local sc = capi.screen.count()
|
|
|
|
if not s then
|
2016-04-02 09:27:45 +02:00
|
|
|
s = self.screen.index + 1
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2016-03-29 17:03:07 +02:00
|
|
|
if type(s) == "number" then
|
|
|
|
if s > sc then s = 1 elseif s < 1 then s = sc end
|
|
|
|
end
|
2016-02-26 20:16:07 +01:00
|
|
|
s = get_screen(s)
|
2016-04-02 09:27:45 +02:00
|
|
|
if get_screen(self.screen) ~= s then
|
2019-11-11 00:39:26 +01:00
|
|
|
local sel_is_focused = self.active
|
2016-04-02 09:27:45 +02:00
|
|
|
self.screen = s
|
2015-02-03 12:45:30 +01:00
|
|
|
screen.focus(s)
|
|
|
|
|
|
|
|
if sel_is_focused then
|
2016-04-02 09:27:45 +02:00
|
|
|
self:emit_signal("request::activate", "client.movetoscreen",
|
2015-10-08 00:12:00 +02:00
|
|
|
{raise=true})
|
2015-02-03 12:45:30 +01:00
|
|
|
end
|
|
|
|
end
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-05 09:02:00 +02:00
|
|
|
--- Tag a client with the set of current tags.
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method to_selected_tags
|
2016-04-05 09:02:00 +02:00
|
|
|
-- @see screen.selected_tags
|
|
|
|
function client.object.to_selected_tags(self)
|
|
|
|
local tags = {}
|
|
|
|
|
|
|
|
for _, t in ipairs(self:tags()) do
|
|
|
|
if get_screen(t.screen) == get_screen(self.screen) then
|
|
|
|
table.insert(tags, t)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-25 21:12:10 +02:00
|
|
|
if self.screen then
|
|
|
|
if #tags == 0 then
|
|
|
|
tags = self.screen.selected_tags
|
|
|
|
end
|
2016-04-05 09:02:00 +02:00
|
|
|
|
2016-04-25 21:12:10 +02:00
|
|
|
if #tags == 0 then
|
|
|
|
tags = self.screen.tags
|
|
|
|
end
|
2016-04-05 09:02:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if #tags ~= 0 then
|
|
|
|
self:tags(tags)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-03 09:50:04 +02:00
|
|
|
--- If a client is marked or not.
|
|
|
|
--
|
|
|
|
-- @property marked
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam boolean marked
|
|
|
|
-- @emits marked (for legacy reasons, use `property::marked`)
|
|
|
|
-- @emits unmarker (for legacy reasons, use `property::marked`)
|
|
|
|
-- @emits property::marked
|
2016-04-03 09:50:04 +02:00
|
|
|
|
|
|
|
--- The border color when the client is focused.
|
|
|
|
--
|
|
|
|
-- @beautiful beautiful.border_marked
|
|
|
|
-- @param string
|
|
|
|
--
|
|
|
|
|
|
|
|
function client.object.set_marked(self, value)
|
|
|
|
local is_marked = self.marked
|
|
|
|
|
|
|
|
if value == false and is_marked then
|
|
|
|
for k, v in pairs(client.data.marked) do
|
|
|
|
if self == v then
|
|
|
|
table.remove(client.data.marked, k)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
2016-04-03 09:50:04 +02:00
|
|
|
self:emit_signal("unmarked")
|
|
|
|
elseif not is_marked and value then
|
|
|
|
self:emit_signal("marked")
|
|
|
|
table.insert(client.data.marked, self)
|
|
|
|
end
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2016-04-03 09:50:04 +02:00
|
|
|
client.property.set(self, "marked", value)
|
|
|
|
end
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2016-04-03 09:50:04 +02:00
|
|
|
function client.object.get_marked(self)
|
|
|
|
return client.property.get(self, "marked")
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2016-04-03 09:50:04 +02:00
|
|
|
--- Mark a client, and then call 'marked' hook.
|
|
|
|
-- @deprecated awful.client.mark
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client to mark, the focused one if not specified.
|
2016-04-03 09:50:04 +02:00
|
|
|
function client.mark(c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c.marked = true instead of awful.client.mark", {deprecated_in=4})
|
2016-04-03 09:50:04 +02:00
|
|
|
client.object.set_marked(c or capi.client.focus, true)
|
|
|
|
end
|
2016-03-14 07:21:29 +01:00
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
--- Unmark a client and then call 'unmarked' hook.
|
2016-04-03 09:50:04 +02:00
|
|
|
-- @deprecated awful.client.unmark
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client to unmark, or the focused one if not specified.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.unmark(c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c.marked = false instead of awful.client.unmark", {deprecated_in=4})
|
2016-04-03 09:50:04 +02:00
|
|
|
client.object.set_marked(c or capi.client.focus, false)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Check if a client is marked.
|
2016-04-03 09:50:04 +02:00
|
|
|
-- @deprecated awful.client.ismarked
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client to check, or the focused one otherwise.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.ismarked(c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c.marked instead of awful.client.ismarked", {deprecated_in=4})
|
2016-04-03 09:50:04 +02:00
|
|
|
return client.object.get_marked(c or capi.client.focus)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Toggle a client as marked.
|
2016-04-03 09:50:04 +02:00
|
|
|
-- @deprecated awful.client.togglemarked
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client to toggle mark.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.togglemarked(c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c.marked = not c.marked instead of awful.client.togglemarked", {deprecated_in=4})
|
2016-02-07 15:02:25 +01:00
|
|
|
c = c or capi.client.focus
|
2016-04-03 09:50:04 +02:00
|
|
|
if c then
|
|
|
|
c.marked = not c.marked
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Return the marked clients and empty the marked table.
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @deprecated awful.client.getmarked
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @treturn table A table with all marked clients.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.getmarked()
|
2017-03-08 21:18:33 +01:00
|
|
|
local copy = gtable.clone(client.data.marked, false)
|
2016-04-03 09:50:04 +02:00
|
|
|
|
|
|
|
for _, v in pairs(copy) do
|
|
|
|
client.property.set(v, "marked", false)
|
2009-08-11 15:27:31 +02:00
|
|
|
v:emit_signal("unmarked")
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
client.data.marked = {}
|
2016-04-03 09:50:04 +02:00
|
|
|
|
|
|
|
return copy
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2009-01-14 14:55:56 +01:00
|
|
|
--- Set a client floating state, overriding auto-detection.
|
2008-12-01 16:26:41 +01:00
|
|
|
-- Floating client are not handled by tiling layouts.
|
2016-03-14 07:21:29 +01:00
|
|
|
-- @deprecated awful.client.floating.set
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c A client.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam boolean s True or false.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.floating.set(c, s)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c.floating = true instead of awful.client.floating.set", {deprecated_in=4})
|
2016-03-14 07:21:29 +01:00
|
|
|
client.object.set_floating(c, s)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Set a client floating state, overriding auto-detection.
|
|
|
|
-- Floating client are not handled by tiling layouts.
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c A client.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam boolan s True or false.
|
2016-03-14 07:21:29 +01:00
|
|
|
function client.object.set_floating(c, s)
|
2016-02-07 15:02:25 +01:00
|
|
|
c = c or capi.client.focus
|
2012-06-12 20:13:09 +02:00
|
|
|
if c and client.property.get(c, "floating") ~= s then
|
|
|
|
client.property.set(c, "floating", s)
|
2012-09-28 23:53:58 +02:00
|
|
|
local scr = c.screen
|
2009-03-12 20:11:52 +01:00
|
|
|
if s == true then
|
2012-06-12 20:13:09 +02:00
|
|
|
c:geometry(client.property.get(c, "floating_geometry"))
|
2009-03-12 20:11:52 +01:00
|
|
|
end
|
2012-09-28 23:53:58 +02:00
|
|
|
c.screen = scr
|
2019-11-11 02:47:43 +01:00
|
|
|
|
|
|
|
if s then
|
|
|
|
c:emit_signal("request::border", "floating", {})
|
|
|
|
else
|
|
|
|
c:emit_signal("request::border", (c.active and "" or "in").."active", {})
|
|
|
|
end
|
2008-12-01 16:26:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-10 18:12:19 +02:00
|
|
|
local function store_floating_geometry(c)
|
2016-03-14 07:21:29 +01:00
|
|
|
if client.object.get_floating(c) then
|
2012-06-12 20:13:09 +02:00
|
|
|
client.property.set(c, "floating_geometry", c:geometry())
|
2009-03-12 20:11:52 +01:00
|
|
|
end
|
2009-08-10 18:12:19 +02:00
|
|
|
end
|
|
|
|
|
2009-09-22 15:56:58 +02:00
|
|
|
-- Store the initial client geometry.
|
2016-02-07 15:02:25 +01:00
|
|
|
capi.client.connect_signal("new", function(cl)
|
2009-09-22 15:56:58 +02:00
|
|
|
local function store_init_geometry(c)
|
2012-06-12 20:13:09 +02:00
|
|
|
client.property.set(c, "floating_geometry", c:geometry())
|
2011-12-09 03:45:59 +01:00
|
|
|
c:disconnect_signal("property::border_width", store_init_geometry)
|
2009-09-22 15:56:58 +02:00
|
|
|
end
|
2016-02-07 15:02:25 +01:00
|
|
|
cl:connect_signal("property::border_width", store_init_geometry)
|
2009-09-22 15:56:58 +02:00
|
|
|
end)
|
|
|
|
|
2014-03-23 19:48:07 +01:00
|
|
|
capi.client.connect_signal("property::geometry", store_floating_geometry)
|
2009-03-12 20:11:52 +01:00
|
|
|
|
2016-04-01 07:29:06 +02:00
|
|
|
--- Return if a client has a fixed size or not.
|
|
|
|
-- This function is deprecated, use `c.is_fixed`
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client.
|
2016-04-01 07:29:06 +02:00
|
|
|
-- @deprecated awful.client.isfixed
|
|
|
|
-- @see is_fixed
|
|
|
|
-- @see size_hints_honor
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.isfixed(c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c.is_fixed instead of awful.client.isfixed", {deprecated_in=4})
|
2016-02-07 15:02:25 +01:00
|
|
|
c = c or capi.client.focus
|
2016-04-01 07:29:06 +02:00
|
|
|
return client.object.is_fixed(c)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Return if a client has a fixed size or not.
|
|
|
|
--
|
|
|
|
-- This property is read only.
|
|
|
|
-- @property is_fixed
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam[opt=false] boolean is_fixed The fixed size state
|
|
|
|
-- @propemits false false
|
2016-04-01 07:29:06 +02:00
|
|
|
-- @see size_hints
|
|
|
|
-- @see size_hints_honor
|
|
|
|
|
|
|
|
function client.object.is_fixed(c)
|
2008-12-09 14:56:01 +01:00
|
|
|
if not c then return end
|
|
|
|
local h = c.size_hints
|
2009-01-06 11:11:21 +01:00
|
|
|
if h.min_width and h.max_width
|
2008-12-09 14:56:01 +01:00
|
|
|
and h.max_height and h.min_height
|
|
|
|
and h.min_width > 0 and h.max_width > 0
|
|
|
|
and h.max_height > 0 and h.min_height > 0
|
|
|
|
and h.min_width == h.max_width
|
2009-01-06 11:11:21 +01:00
|
|
|
and h.min_height == h.max_height then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
2008-12-09 14:56:01 +01:00
|
|
|
end
|
|
|
|
|
2017-10-25 15:36:00 +02:00
|
|
|
--- Is the client immobilized horizontally?
|
|
|
|
--
|
|
|
|
-- Does the client have a fixed horizontal position and width, i.e. is it
|
|
|
|
-- fullscreen, maximized, or horizontally maximized?
|
|
|
|
--
|
|
|
|
-- This property is read only.
|
2019-05-25 12:17:26 +02:00
|
|
|
-- @property immobilized_horizontal
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam[opt=false] boolean immobilized_horizontal The immobilized state
|
2017-10-25 15:36:00 +02:00
|
|
|
-- @see maximized
|
|
|
|
-- @see maximized_horizontal
|
|
|
|
-- @see fullscreen
|
|
|
|
|
|
|
|
function client.object.is_immobilized_horizontal(c)
|
|
|
|
return c.fullscreen or c.maximized or c.maximized_horizontal
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Is the client immobilized vertically?
|
|
|
|
--
|
|
|
|
-- Does the client have a fixed vertical position and width, i.e. is it
|
|
|
|
-- fullscreen, maximized, or vertically maximized?
|
|
|
|
--
|
|
|
|
-- This property is read only.
|
2019-05-25 12:17:26 +02:00
|
|
|
-- @property immobilized_vertical
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam[opt=false] boolean immobilized_vertical The immobilized state
|
2017-10-25 15:36:00 +02:00
|
|
|
-- @see maximized
|
|
|
|
-- @see maximized_vertical
|
|
|
|
-- @see fullscreen
|
|
|
|
|
|
|
|
function client.object.is_immobilized_vertical(c)
|
|
|
|
return c.fullscreen or c.maximized or c.maximized_vertical
|
|
|
|
end
|
|
|
|
|
2008-12-01 16:26:41 +01:00
|
|
|
--- Get a client floating state.
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c A client.
|
2016-03-14 07:21:29 +01:00
|
|
|
-- @see floating
|
|
|
|
-- @deprecated awful.client.floating.get
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @treturn boolean True or false. Note that some windows might be floating even if you
|
2008-12-01 16:26:41 +01:00
|
|
|
-- did not set them manually. For example, windows with a type different than
|
|
|
|
-- normal.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.floating.get(c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c.floating instead of awful.client.floating.get", {deprecated_in=4})
|
2016-03-14 07:21:29 +01:00
|
|
|
return client.object.get_floating(c)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- The client floating state.
|
2019-12-01 07:53:12 +01:00
|
|
|
--
|
2016-03-14 07:21:29 +01:00
|
|
|
-- If the client is part of the tiled layout or free floating.
|
|
|
|
--
|
|
|
|
-- Note that some windows might be floating even if you
|
|
|
|
-- did not set them manually. For example, windows with a type different than
|
|
|
|
-- normal.
|
|
|
|
--
|
|
|
|
-- @property floating
|
2019-12-01 07:53:12 +01:00
|
|
|
-- @tparam boolean floating The floating state.
|
|
|
|
-- @request client border floating granted When a border update is required
|
|
|
|
-- because the client focus status changed.
|
|
|
|
-- @request client border active granted When a client becomes active and is not
|
|
|
|
-- floating.
|
|
|
|
-- @request client border inactive granted When a client stop being active and
|
|
|
|
-- is not floating.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @propemits false false
|
2016-03-14 07:21:29 +01:00
|
|
|
|
|
|
|
function client.object.get_floating(c)
|
2016-02-07 15:02:25 +01:00
|
|
|
c = c or capi.client.focus
|
2008-12-01 16:26:41 +01:00
|
|
|
if c then
|
2012-06-12 20:13:09 +02:00
|
|
|
local value = client.property.get(c, "floating")
|
2009-02-07 15:19:37 +01:00
|
|
|
if value ~= nil then
|
|
|
|
return value
|
2008-12-01 16:26:41 +01:00
|
|
|
end
|
2017-05-11 16:22:16 +02:00
|
|
|
return client.property.get(c, "_implicitly_floating") or false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- When a client is not explicitly assigned a floating state, it might
|
|
|
|
-- implicitly end up being floating. The following makes sure that
|
|
|
|
-- property::floating is still emitted if this implicit floating state changes.
|
|
|
|
|
|
|
|
local function update_implicitly_floating(c)
|
|
|
|
local explicit = client.property.get(c, "floating")
|
|
|
|
if explicit ~= nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local cur = client.property.get(c, "_implicitly_floating")
|
|
|
|
local new = c.type ~= "normal"
|
2008-12-01 16:26:41 +01:00
|
|
|
or c.fullscreen
|
|
|
|
or c.maximized_vertical
|
2008-12-09 14:56:01 +01:00
|
|
|
or c.maximized_horizontal
|
2017-01-24 11:41:22 +01:00
|
|
|
or c.maximized
|
2017-05-11 16:22:16 +02:00
|
|
|
or client.object.is_fixed(c)
|
|
|
|
if cur ~= new then
|
|
|
|
client.property.set(c, "_implicitly_floating", new)
|
|
|
|
c:emit_signal("property::floating")
|
2019-11-11 02:47:43 +01:00
|
|
|
|
|
|
|
-- Don't send the border signals as they would be sent twice (with this
|
|
|
|
-- one having the wrong context). There is some `property::` signal
|
|
|
|
-- sent before `request::manage`.
|
|
|
|
if client.property.get(c, "_border_init") then
|
|
|
|
if cur then
|
|
|
|
c:emit_signal("request::border", "floating", {})
|
|
|
|
else
|
|
|
|
c:emit_signal("request::border", (c.active and "" or "in").."active", {})
|
|
|
|
end
|
|
|
|
end
|
2008-12-01 16:26:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-11 16:22:16 +02:00
|
|
|
capi.client.connect_signal("property::type", update_implicitly_floating)
|
|
|
|
capi.client.connect_signal("property::fullscreen", update_implicitly_floating)
|
|
|
|
capi.client.connect_signal("property::maximized_vertical", update_implicitly_floating)
|
|
|
|
capi.client.connect_signal("property::maximized_horizontal", update_implicitly_floating)
|
|
|
|
capi.client.connect_signal("property::maximized", update_implicitly_floating)
|
|
|
|
capi.client.connect_signal("property::size_hints", update_implicitly_floating)
|
2019-11-10 07:12:43 +01:00
|
|
|
capi.client.connect_signal("request::manage", update_implicitly_floating)
|
2017-05-11 16:22:16 +02:00
|
|
|
|
2009-01-14 14:55:56 +01:00
|
|
|
--- Toggle the floating state of a client between 'auto' and 'true'.
|
2016-03-14 07:21:29 +01:00
|
|
|
-- Use `c.floating = not c.floating`
|
|
|
|
-- @deprecated awful.client.floating.toggle
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c A client.
|
2016-03-14 07:21:29 +01:00
|
|
|
-- @see floating
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.floating.toggle(c)
|
2016-02-07 15:02:25 +01:00
|
|
|
c = c or capi.client.focus
|
2009-01-14 14:55:56 +01:00
|
|
|
-- If it has been set to floating
|
2016-03-14 07:21:29 +01:00
|
|
|
client.object.set_floating(c, not client.object.get_floating(c))
|
2008-12-01 16:26:41 +01:00
|
|
|
end
|
|
|
|
|
2016-03-14 07:21:29 +01:00
|
|
|
-- Remove the floating information on a client.
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.floating.delete(c)
|
2016-03-14 07:21:29 +01:00
|
|
|
client.object.set_floating(c, nil)
|
2008-12-01 16:26:41 +01:00
|
|
|
end
|
|
|
|
|
2016-05-10 06:01:12 +02:00
|
|
|
--- The x coordinates.
|
|
|
|
--
|
|
|
|
-- @property x
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam integer x
|
|
|
|
-- @emits property::geometry
|
|
|
|
-- @emitstparam property::geometry table geo The
|
|
|
|
-- geometry (with `x`, `y`, `width`, `height`).
|
|
|
|
-- @emits property::x
|
|
|
|
-- @emits property::position
|
2016-05-10 06:01:12 +02:00
|
|
|
|
|
|
|
--- The y coordinates.
|
|
|
|
--
|
|
|
|
-- @property y
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam integer y
|
|
|
|
-- @emits property::geometry
|
|
|
|
-- @emitstparam property::geometry table geo The
|
|
|
|
-- geometry (with `x`, `y`, `width`, `height`).
|
|
|
|
-- @emits property::y
|
|
|
|
-- @emits property::position
|
2016-05-10 06:01:12 +02:00
|
|
|
|
2017-06-14 10:42:50 +02:00
|
|
|
--- The width of the client.
|
2016-05-10 06:01:12 +02:00
|
|
|
--
|
|
|
|
-- @property width
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam integer width
|
|
|
|
-- @emits property::geometry
|
|
|
|
-- @emitstparam property::geometry table geo The
|
|
|
|
-- geometry (with `x`, `y`, `width`, `height`).
|
|
|
|
-- @emits property::width
|
|
|
|
-- @emits property::size
|
2016-05-10 06:01:12 +02:00
|
|
|
|
2017-06-14 10:42:50 +02:00
|
|
|
--- The height of the client.
|
2016-05-10 06:01:12 +02:00
|
|
|
--
|
|
|
|
-- @property height
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam integer height
|
|
|
|
-- @emits property::geometry
|
|
|
|
-- @emitstparam property::geometry table geo The
|
|
|
|
-- geometry (with `x`, `y`, `width`, `height`).
|
|
|
|
-- @emits property::height
|
|
|
|
-- @emits property::size
|
2016-05-10 06:01:12 +02:00
|
|
|
|
|
|
|
-- Add the geometry helpers to match the wibox API
|
|
|
|
for _, v in ipairs {"x", "y", "width", "height"} do
|
|
|
|
client.object["get_"..v] = function(c)
|
|
|
|
return c:geometry()[v]
|
|
|
|
end
|
|
|
|
|
|
|
|
client.object["set_"..v] = function(c, value)
|
|
|
|
return c:geometry({[v] = value})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-02-19 21:44:30 +01:00
|
|
|
--- Restore (=unminimize) a random client.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.restore
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam screen s The screen to use.
|
|
|
|
-- @treturn client The restored client if some client was restored, otherwise nil.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.restore(s)
|
2015-07-22 02:42:35 +02:00
|
|
|
s = s or screen.focused()
|
2011-02-19 21:44:30 +01:00
|
|
|
local cls = capi.client.get(s)
|
2016-04-05 09:02:00 +02:00
|
|
|
local tags = s.selected_tags
|
2016-02-07 15:02:25 +01:00
|
|
|
for _, c in pairs(cls) do
|
2011-02-19 21:44:30 +01:00
|
|
|
local ctags = c:tags()
|
|
|
|
if c.minimized then
|
2016-02-07 15:02:25 +01:00
|
|
|
for _, t in ipairs(tags) do
|
2017-03-08 21:18:33 +01:00
|
|
|
if gtable.hasitem(ctags, t) then
|
2011-02-19 21:44:30 +01:00
|
|
|
c.minimized = false
|
2012-09-14 14:32:06 +02:00
|
|
|
return c
|
2011-02-19 21:44:30 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-09-14 14:32:06 +02:00
|
|
|
return nil
|
2011-02-19 21:44:30 +01:00
|
|
|
end
|
|
|
|
|
2019-06-08 01:08:05 +02:00
|
|
|
--- Normalize a set of numbers to 1.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam table set the set of numbers to normalize.
|
|
|
|
-- @tparam number num the number of numbers to normalize.
|
2009-01-13 20:31:37 +01:00
|
|
|
local function normalize(set, num)
|
2016-02-07 15:02:25 +01:00
|
|
|
num = num or #set
|
2009-01-13 20:31:37 +01:00
|
|
|
local total = 0
|
|
|
|
if num then
|
|
|
|
for i = 1,num do
|
|
|
|
total = total + set[i]
|
|
|
|
end
|
|
|
|
for i = 1,num do
|
|
|
|
set[i] = set[i] / total
|
|
|
|
end
|
|
|
|
else
|
2016-02-07 15:02:25 +01:00
|
|
|
for _,v in ipairs(set) do
|
2009-01-13 20:31:37 +01:00
|
|
|
total = total + v
|
|
|
|
end
|
|
|
|
|
|
|
|
for i,v in ipairs(set) do
|
|
|
|
set[i] = v / total
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Calculate a client's column number, index in that column, and
|
|
|
|
-- number of visible clients in this column.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2016-04-02 10:02:43 +02:00
|
|
|
-- @legacylayout awful.client.idx
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c the client
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @treturn integer col The column number.
|
|
|
|
-- @treturn integer idx Index of the client in the column.
|
|
|
|
-- @treturn integer num The number of visible clients in the column.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.idx(c)
|
2016-02-07 15:02:25 +01:00
|
|
|
c = c or capi.client.focus
|
2009-01-13 20:31:37 +01:00
|
|
|
if not c then return end
|
|
|
|
|
2015-12-29 13:45:01 +01:00
|
|
|
-- Only check the tiled clients, the others un irrelevant
|
2012-06-12 20:13:09 +02:00
|
|
|
local clients = client.tiled(c.screen)
|
2009-01-13 20:31:37 +01:00
|
|
|
local idx = nil
|
|
|
|
for k, cl in ipairs(clients) do
|
|
|
|
if cl == c then
|
|
|
|
idx = k
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-05 09:02:00 +02:00
|
|
|
local t = c.screen.selected_tag
|
2016-04-11 06:50:46 +02:00
|
|
|
local nmaster = t.master_count
|
2015-12-29 13:45:01 +01:00
|
|
|
|
|
|
|
-- This will happen for floating or maximized clients
|
|
|
|
if not idx then return nil end
|
|
|
|
|
2009-01-13 20:31:37 +01:00
|
|
|
if idx <= nmaster then
|
|
|
|
return {idx = idx, col=0, num=nmaster}
|
|
|
|
end
|
|
|
|
local nother = #clients - nmaster
|
|
|
|
idx = idx - nmaster
|
|
|
|
|
|
|
|
-- rather than regenerate the column number we can calculate it
|
|
|
|
-- based on the how the tiling algorithm places clients we calculate
|
|
|
|
-- the column, we could easily use the for loop in the program but we can
|
|
|
|
-- calculate it.
|
2016-04-11 06:30:05 +02:00
|
|
|
local ncol = t.column_count
|
2009-01-13 20:31:37 +01:00
|
|
|
-- minimum number of clients per column
|
|
|
|
local percol = math.floor(nother / ncol)
|
|
|
|
-- number of columns with an extra client
|
2012-06-14 22:48:18 +02:00
|
|
|
local overcol = math.fmod(nother, ncol)
|
2009-01-13 20:31:37 +01:00
|
|
|
-- number of columns filled with [percol] clients
|
|
|
|
local regcol = ncol - overcol
|
|
|
|
|
|
|
|
local col = math.floor( (idx - 1) / percol) + 1
|
|
|
|
if col > regcol then
|
|
|
|
-- col = math.floor( (idx - (percol*regcol) - 1) / (percol + 1) ) + regcol + 1
|
|
|
|
-- simplified
|
|
|
|
col = math.floor( (idx + regcol + percol) / (percol+1) )
|
|
|
|
-- calculate the index in the column
|
|
|
|
idx = idx - percol*regcol - (col - regcol - 1) * (percol+1)
|
|
|
|
percol = percol+1
|
|
|
|
else
|
|
|
|
idx = idx - percol*(col-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
return {idx = idx, col=col, num=percol}
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--- Set the window factor of a client
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2016-04-02 10:02:43 +02:00
|
|
|
-- @legacylayout awful.client.setwfact
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam number wfact the window factor value
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c the client
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @emits property::windowfact
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.setwfact(wfact, c)
|
2009-01-13 20:31:37 +01:00
|
|
|
-- get the currently selected window
|
2016-02-07 15:02:25 +01:00
|
|
|
c = c or capi.client.focus
|
2010-12-11 14:20:42 +01:00
|
|
|
if not c or not c:isvisible() then return end
|
2009-01-13 20:31:37 +01:00
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
local w = client.idx(c)
|
2009-01-13 20:31:37 +01:00
|
|
|
|
2015-12-29 13:45:01 +01:00
|
|
|
if not w then return end
|
|
|
|
|
2016-04-05 09:02:00 +02:00
|
|
|
local t = c.screen.selected_tag
|
2015-12-29 13:45:01 +01:00
|
|
|
|
2009-01-13 20:31:37 +01:00
|
|
|
-- n is the number of windows currently visible for which we have to be concerned with the properties
|
2016-04-05 09:02:00 +02:00
|
|
|
local data = t.windowfact or {}
|
2009-01-13 20:31:37 +01:00
|
|
|
local colfact = data[w.col]
|
|
|
|
|
2015-07-14 07:39:03 +02:00
|
|
|
local need_normalize = colfact ~= nil
|
|
|
|
|
|
|
|
if not need_normalize then
|
|
|
|
colfact = {}
|
|
|
|
end
|
|
|
|
|
2009-01-13 20:31:37 +01:00
|
|
|
colfact[w.idx] = wfact
|
2015-07-14 07:39:03 +02:00
|
|
|
|
|
|
|
if not need_normalize then
|
|
|
|
t:emit_signal("property::windowfact")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-08-06 17:11:58 +02:00
|
|
|
local rest = 1-wfact
|
2009-01-13 20:31:37 +01:00
|
|
|
|
|
|
|
-- calculate the current denominator
|
|
|
|
local total = 0
|
|
|
|
for i = 1,w.num do
|
|
|
|
if i ~= w.idx then
|
|
|
|
total = total + colfact[i]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- normalize the windows
|
|
|
|
for i = 1,w.num do
|
|
|
|
if i ~= w.idx then
|
|
|
|
colfact[i] = (colfact[i] * rest) / total
|
|
|
|
end
|
|
|
|
end
|
2009-07-14 20:15:18 +02:00
|
|
|
|
2009-08-11 15:27:31 +02:00
|
|
|
t:emit_signal("property::windowfact")
|
2009-01-13 20:31:37 +01:00
|
|
|
end
|
|
|
|
|
2016-11-09 21:46:58 +01:00
|
|
|
--- Change window factor of a client.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2016-04-02 10:02:43 +02:00
|
|
|
-- @legacylayout awful.client.incwfact
|
2016-11-09 21:46:58 +01:00
|
|
|
-- @tparam number add Amount to increase/decrease the client's window factor.
|
|
|
|
-- Should be between `-current_window_factor` and something close to
|
|
|
|
-- infinite. The normalisation then ensures that the sum of all factors is 1.
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c the client.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @emits property::windowfact
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.incwfact(add, c)
|
2016-02-07 15:02:25 +01:00
|
|
|
c = c or capi.client.focus
|
2009-01-13 20:31:37 +01:00
|
|
|
if not c then return end
|
|
|
|
|
2016-04-05 09:02:00 +02:00
|
|
|
local t = c.screen.selected_tag
|
2012-06-12 20:13:09 +02:00
|
|
|
local w = client.idx(c)
|
2018-05-26 23:55:14 +02:00
|
|
|
if not w then return end
|
|
|
|
|
2016-04-05 09:02:00 +02:00
|
|
|
local data = t.windowfact or {}
|
2015-07-14 07:39:03 +02:00
|
|
|
local colfact = data[w.col] or {}
|
2016-02-07 15:02:25 +01:00
|
|
|
local curr = colfact[w.idx] or 1
|
2009-01-13 20:31:37 +01:00
|
|
|
colfact[w.idx] = curr + add
|
|
|
|
|
|
|
|
-- keep our ratios normalized
|
|
|
|
normalize(colfact, w.num)
|
2009-07-14 20:15:18 +02:00
|
|
|
|
2009-08-11 15:27:31 +02:00
|
|
|
t:emit_signal("property::windowfact")
|
2009-01-13 20:31:37 +01:00
|
|
|
end
|
|
|
|
|
2016-12-31 00:40:17 +01:00
|
|
|
--- Get a client's dockable state.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c A client.
|
2016-12-31 00:40:17 +01:00
|
|
|
-- @treturn bool
|
2016-03-31 09:30:20 +02:00
|
|
|
-- @deprecated awful.client.dockable.get
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.dockable.get(c)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c.dockable instead of awful.client.dockable.get", {deprecated_in=4})
|
2016-03-31 09:30:20 +02:00
|
|
|
return client.object.get_dockable(c)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- If the client is dockable.
|
2016-12-31 00:40:17 +01:00
|
|
|
--
|
2016-03-31 09:30:20 +02:00
|
|
|
-- A dockable client is an application confined to the edge of the screen. The
|
2016-12-31 00:40:17 +01:00
|
|
|
-- space it occupies is substracted from the `screen.workarea`.
|
|
|
|
--
|
|
|
|
-- Clients with a type of "utility", "toolbar" or "dock" are dockable by
|
|
|
|
-- default.
|
2016-03-31 09:30:20 +02:00
|
|
|
--
|
|
|
|
-- @property dockable
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam boolean dockable The dockable state
|
|
|
|
-- @propemits false false
|
2016-03-31 09:30:20 +02:00
|
|
|
|
|
|
|
function client.object.get_dockable(c)
|
2012-06-12 20:13:09 +02:00
|
|
|
local value = client.property.get(c, "dockable")
|
2009-03-26 22:22:05 +01:00
|
|
|
|
|
|
|
-- Some sane defaults
|
|
|
|
if value == nil then
|
|
|
|
if (c.type == "utility" or c.type == "toolbar" or c.type == "dock") then
|
|
|
|
value = true
|
|
|
|
else
|
|
|
|
value = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return value
|
|
|
|
end
|
|
|
|
|
2016-12-31 00:40:17 +01:00
|
|
|
--- Set a client's dockable state, overriding auto-detection.
|
|
|
|
--
|
2009-03-26 22:22:05 +01:00
|
|
|
-- With this enabled you can dock windows by moving them from the center
|
|
|
|
-- to the edge of the workarea.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c A client.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam boolean value True or false.
|
2016-03-31 09:30:20 +02:00
|
|
|
-- @deprecated awful.client.dockable.set
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.dockable.set(c, value)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c.dockable = value instead of awful.client.dockable.set", {deprecated_in=4})
|
2012-06-12 20:13:09 +02:00
|
|
|
client.property.set(c, "dockable", value)
|
2009-03-26 22:22:05 +01:00
|
|
|
end
|
|
|
|
|
2018-08-22 13:23:20 +02:00
|
|
|
--- If the client requests not to be decorated with a titlebar.
|
|
|
|
--
|
|
|
|
-- The motif wm hints allow a client to request not to be decorated by the WM in
|
|
|
|
-- various ways. This property uses the motif MWM_DECOR_TITLE hint and
|
|
|
|
-- interprets it as the client (not) wanting a titlebar.
|
|
|
|
--
|
|
|
|
-- @property requests_no_titlebar
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam boolean requests_no_titlebar Whether the client
|
|
|
|
-- requests not to get a titlebar.
|
|
|
|
-- @propemits false false
|
2018-08-22 13:23:20 +02:00
|
|
|
|
|
|
|
function client.object.get_requests_no_titlebar(c)
|
|
|
|
local hints = c.motif_wm_hints
|
|
|
|
if not hints then return false end
|
|
|
|
|
2018-11-12 09:26:16 +01:00
|
|
|
local decor = hints.decorations
|
2018-08-22 13:23:20 +02:00
|
|
|
if not decor then return false end
|
|
|
|
|
|
|
|
local result = not decor.title
|
|
|
|
if decor.all then
|
|
|
|
-- The "all" bit inverts the meaning of the other bits
|
|
|
|
result = not result
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
capi.client.connect_signal("property::motif_wm_hints", function(c)
|
|
|
|
-- We cannot be sure that the property actually changes, but whatever
|
|
|
|
c:emit_signal("property::requests_no_titlebar")
|
|
|
|
end)
|
|
|
|
|
2009-02-07 15:12:57 +01:00
|
|
|
--- Get a client property.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2016-03-31 09:30:20 +02:00
|
|
|
-- This method is deprecated. It is now possible to use `c.value` directly.
|
|
|
|
--
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam string prop The property name.
|
|
|
|
-- @return The property value.
|
2016-03-31 09:30:20 +02:00
|
|
|
-- @deprecated awful.client.property.get
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.property.get(c, prop)
|
2019-10-13 03:01:18 +02:00
|
|
|
if not c._private._persistent_properties_loaded then
|
|
|
|
c._private._persistent_properties_loaded = true
|
2014-04-10 15:32:52 +02:00
|
|
|
for p in pairs(client.data.persistent_properties_registered) do
|
2015-02-08 02:46:40 +01:00
|
|
|
local value = c:get_xproperty("awful.client.property." .. p)
|
2014-04-10 15:32:52 +02:00
|
|
|
if value ~= nil then
|
|
|
|
client.property.set(c, p, value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-10-13 03:01:18 +02:00
|
|
|
if c._private.awful_client_properties then
|
|
|
|
return c._private.awful_client_properties[prop]
|
2009-02-07 15:12:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Set a client property.
|
2016-03-31 09:30:20 +02:00
|
|
|
--
|
|
|
|
-- This method is deprecated. It is now possible to use `c.value = value`
|
|
|
|
-- directly.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam string prop The property name.
|
|
|
|
-- @param value The property value.
|
2016-03-31 09:30:20 +02:00
|
|
|
-- @deprecated awful.client.property.set
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.property.set(c, prop, value)
|
2019-10-13 03:01:18 +02:00
|
|
|
if not c._private.awful_client_properties then
|
|
|
|
c._private.awful_client_properties = {}
|
2009-02-07 15:12:57 +01:00
|
|
|
end
|
2019-10-13 03:01:18 +02:00
|
|
|
if c._private.awful_client_properties[prop] ~= value then
|
2015-07-07 13:01:53 +02:00
|
|
|
if client.data.persistent_properties_registered[prop] then
|
|
|
|
c:set_xproperty("awful.client.property." .. prop, value)
|
|
|
|
end
|
2019-10-13 03:01:18 +02:00
|
|
|
c._private.awful_client_properties[prop] = value
|
2015-07-07 13:01:53 +02:00
|
|
|
c:emit_signal("property::" .. prop)
|
2014-04-10 15:32:52 +02:00
|
|
|
end
|
2009-02-07 15:12:57 +01:00
|
|
|
end
|
|
|
|
|
2014-04-10 15:32:52 +02:00
|
|
|
--- Set a client property to be persistent across restarts (via X properties).
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.property.persist
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam string prop The property name.
|
|
|
|
-- @tparam string kind The type (used for register_xproperty).
|
2014-05-20 11:47:20 +02:00
|
|
|
-- One of "string", "number" or "boolean".
|
2016-02-07 15:02:25 +01:00
|
|
|
function client.property.persist(prop, kind)
|
2014-04-10 15:32:52 +02:00
|
|
|
local xprop = "awful.client.property." .. prop
|
2016-02-07 15:02:25 +01:00
|
|
|
capi.awesome.register_xproperty(xprop, kind)
|
2014-04-10 15:32:52 +02:00
|
|
|
client.data.persistent_properties_registered[prop] = true
|
|
|
|
|
|
|
|
-- Make already-set properties persistent
|
2020-02-28 13:18:48 +01:00
|
|
|
for _, c in ipairs(capi.client.get()) do
|
2019-10-13 03:01:18 +02:00
|
|
|
if c._private.awful_client_properties and c._private.awful_client_properties[prop] ~= nil then
|
|
|
|
c:set_xproperty(xprop, c._private.awful_client_properties[prop])
|
2014-04-10 15:32:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-08 01:08:05 +02:00
|
|
|
--- Returns an iterator to cycle through clients.
|
|
|
|
--
|
|
|
|
-- Starting from the client in focus or the given index, all clients that match
|
|
|
|
-- a given criteria.
|
2012-04-02 13:36:12 +02:00
|
|
|
--
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam function filter a function that returns true to indicate a positive match.
|
|
|
|
-- @tparam integer start what index to start iterating from. Defaults to using the
|
2014-05-20 11:47:20 +02:00
|
|
|
-- index of the currently focused client.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam screen s which screen to use. nil means all screens.
|
2012-04-02 13:36:12 +02:00
|
|
|
--
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.iterate
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @usage -- un-minimize all urxvt instances
|
2014-08-28 19:45:46 +02:00
|
|
|
-- local urxvt = function (c)
|
2019-10-07 03:53:08 +02:00
|
|
|
-- return ruled.client.match(c, {class = "URxvt"})
|
2014-08-28 19:45:46 +02:00
|
|
|
-- end
|
|
|
|
--
|
|
|
|
-- for c in awful.client.iterate(urxvt) do
|
|
|
|
-- c.minimized = false
|
|
|
|
-- end
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.iterate(filter, start, s)
|
2012-02-16 22:02:28 +01:00
|
|
|
local clients = capi.client.get(s)
|
|
|
|
local focused = capi.client.focus
|
2017-03-08 21:18:33 +01:00
|
|
|
start = start or gtable.hasitem(clients, focused)
|
|
|
|
return gtable.iterate(clients, filter, start)
|
2012-02-16 22:02:28 +01:00
|
|
|
end
|
|
|
|
|
2014-05-20 11:47:20 +02:00
|
|
|
--- Switch to a client matching the given condition if running, else spawn it.
|
2012-03-31 12:03:01 +02:00
|
|
|
-- If multiple clients match the given condition then the next one is
|
2014-08-28 19:45:46 +02:00
|
|
|
-- focussed.
|
2012-03-31 12:03:01 +02:00
|
|
|
--
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @tparam string cmd the command to execute
|
|
|
|
-- @tparam function matcher a function that returns true to indicate a matching client
|
2016-02-28 22:45:15 +01:00
|
|
|
-- @tparam bool|function merge If true then merge tags (select the client's
|
|
|
|
-- first tag additionally) when the client is not visible.
|
|
|
|
-- If it is a function, it will be called with the client as argument.
|
2018-10-01 05:55:57 +02:00
|
|
|
-- @see awful.spawn.once
|
|
|
|
-- @see awful.spawn.single_instance
|
2018-10-01 22:12:26 +02:00
|
|
|
-- @see awful.spawn.raise_or_spawn
|
2012-03-31 12:03:01 +02:00
|
|
|
--
|
2018-10-01 05:55:57 +02:00
|
|
|
-- @deprecated awful.client.run_or_raise
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @usage -- run or raise urxvt (perhaps, with tabs) on modkey + semicolon
|
2014-08-28 19:45:46 +02:00
|
|
|
-- awful.key({ modkey, }, 'semicolon', function ()
|
2014-05-20 11:47:20 +02:00
|
|
|
-- local matcher = function (c)
|
2019-10-07 03:53:08 +02:00
|
|
|
-- return ruled.client.match(c, {class = 'URxvt'})
|
2014-05-20 11:47:20 +02:00
|
|
|
-- end
|
|
|
|
-- awful.client.run_or_raise('urxvt', matcher)
|
2012-03-31 12:03:01 +02:00
|
|
|
-- end);
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.run_or_raise(cmd, matcher, merge)
|
2018-10-01 05:55:57 +02:00
|
|
|
gdebug.deprecate("Use awful.spawn.single_instance instead of"..
|
|
|
|
"awful.client.run_or_raise", {deprecated_in=5})
|
|
|
|
|
|
|
|
spawn = spawn or require("awful.spawn")
|
2012-03-31 12:03:01 +02:00
|
|
|
local clients = capi.client.get()
|
2017-03-08 21:18:33 +01:00
|
|
|
local findex = gtable.hasitem(clients, capi.client.focus) or 1
|
2017-03-06 17:15:40 +01:00
|
|
|
local start = gmath.cycle(#clients, findex + 1)
|
2012-03-31 12:03:01 +02:00
|
|
|
|
2016-02-07 15:02:25 +01:00
|
|
|
local c = client.iterate(matcher, start)()
|
|
|
|
if c then
|
2016-08-10 13:02:02 +02:00
|
|
|
c:jump_to(merge)
|
2016-02-07 15:02:25 +01:00
|
|
|
else
|
|
|
|
-- client not found, spawn it
|
|
|
|
spawn(cmd)
|
2012-03-31 12:03:01 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-29 20:18:29 +02:00
|
|
|
--- Get a matching transient_for client (if any).
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @deprecated awful.client.get_transient_for_matching
|
|
|
|
-- @see client.get_transient_for_matching
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client.
|
2015-03-29 20:18:29 +02:00
|
|
|
-- @tparam function matcher A function that should return true, if
|
|
|
|
-- a matching parent client is found.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @treturn client|nil The matching parent client or nil.
|
2015-03-29 20:18:29 +02:00
|
|
|
function client.get_transient_for_matching(c, matcher)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c:get_transient_for_matching(matcher) instead of"..
|
|
|
|
"awful.client.get_transient_for_matching", {deprecated_in=4})
|
2016-04-02 09:27:45 +02:00
|
|
|
|
|
|
|
return client.object.get_transient_for_matching(c, matcher)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Get a matching transient_for client (if any).
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method get_transient_for_matching
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @tparam function matcher A function that should return true, if
|
|
|
|
-- a matching parent client is found.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @treturn client|nil The matching parent client or nil.
|
|
|
|
-- @see transient_for
|
|
|
|
-- @see modal
|
|
|
|
-- @see is_transient_for
|
2016-04-02 09:27:45 +02:00
|
|
|
function client.object.get_transient_for_matching(self, matcher)
|
|
|
|
local tc = self.transient_for
|
2015-03-29 20:18:29 +02:00
|
|
|
while tc do
|
|
|
|
if matcher(tc) then
|
|
|
|
return tc
|
|
|
|
end
|
|
|
|
tc = tc.transient_for
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Is a client transient for another one?
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2016-04-02 09:27:45 +02:00
|
|
|
-- @deprecated awful.client.is_transient_for
|
|
|
|
-- @see client.is_transient_for
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The child client (having transient_for).
|
|
|
|
-- @tparam client c2 The parent client to check.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @treturn client|nil The parent client or nil.
|
2015-03-29 20:18:29 +02:00
|
|
|
function client.is_transient_for(c, c2)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("Use c:is_transient_for(c2) instead of"..
|
|
|
|
"awful.client.is_transient_for", {deprecated_in=4})
|
2016-04-02 09:27:45 +02:00
|
|
|
return client.object.is_transient_for(c, c2)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Is a client transient for another one?
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2020-01-19 01:34:10 +01:00
|
|
|
-- This will traverse the chain formed by the `transient_for` property of `self`
|
|
|
|
-- until a client `c` with `c.transient_for == c2` is found. The found client
|
|
|
|
-- `c` is returned. If no client is found, `nil` is returned.
|
|
|
|
--
|
|
|
|
-- While `transient_for` chains are technically possible, they are unlikely, so
|
|
|
|
-- the most likely return values are `self` and `nil`.
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method is_transient_for
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c2 The parent client to check.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @treturn client|nil The parent client or nil.
|
|
|
|
-- @see transient_for
|
|
|
|
-- @see modal
|
|
|
|
-- @see client.get_transient_for_matching
|
2016-04-02 09:27:45 +02:00
|
|
|
function client.object.is_transient_for(self, c2)
|
|
|
|
local tc = self
|
2015-03-29 20:18:29 +02:00
|
|
|
while tc.transient_for do
|
|
|
|
if tc.transient_for == c2 then
|
|
|
|
return tc
|
|
|
|
end
|
|
|
|
tc = tc.transient_for
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2018-12-27 03:16:33 +01:00
|
|
|
object.properties._legacy_accessors(client, "buttons", "_buttons", true, function(new_btns)
|
|
|
|
return new_btns[1] and (
|
|
|
|
type(new_btns[1]) == "button" or new_btns[1]._is_capi_button
|
|
|
|
) or false
|
2019-10-20 02:45:26 +02:00
|
|
|
end, true, true, "mousebinding")
|
2018-12-27 03:16:33 +01:00
|
|
|
|
2018-12-27 03:58:34 +01:00
|
|
|
object.properties._legacy_accessors(client, "keys", "_keys", true, function(new_btns)
|
|
|
|
return new_btns[1] and (
|
|
|
|
type(new_btns[1]) == "key" or new_btns[1]._is_capi_key
|
|
|
|
) or false
|
2019-10-20 02:45:26 +02:00
|
|
|
end, true, true, "keybinding")
|
2018-12-27 03:58:34 +01:00
|
|
|
|
2017-02-02 21:12:47 +01:00
|
|
|
--- Set the client shape.
|
2019-12-31 00:17:23 +01:00
|
|
|
--
|
2017-02-02 21:12:47 +01:00
|
|
|
-- @property shape
|
|
|
|
-- @tparam gears.shape A gears.shape compatible function.
|
2019-12-31 00:17:23 +01:00
|
|
|
-- @propemits true false
|
2017-02-02 21:12:47 +01:00
|
|
|
-- @see gears.shape
|
|
|
|
function client.object.set_shape(self, shape)
|
|
|
|
client.property.set(self, "_shape", shape)
|
|
|
|
set_shape(self)
|
2019-12-31 00:17:23 +01:00
|
|
|
self:emit_signal("property::shape", shape)
|
2017-02-02 21:12:47 +01:00
|
|
|
end
|
|
|
|
|
2019-11-11 02:47:43 +01:00
|
|
|
-- Proxy those properties to decorate their accessors with an extra flag to
|
|
|
|
-- define when they are set by the user. This allows to "manage" the value of
|
|
|
|
-- those properties internally until they are manually overridden.
|
|
|
|
for _, prop in ipairs { "border_width", "border_color", "opacity" } do
|
|
|
|
client.object["get_"..prop] = function(self)
|
|
|
|
return self["_"..prop]
|
|
|
|
end
|
|
|
|
client.object["set_"..prop] = function(self, value)
|
2020-03-08 01:31:58 +01:00
|
|
|
if value ~= nil then
|
|
|
|
self._private["_user_"..prop] = true
|
|
|
|
self["_"..prop] = value
|
|
|
|
end
|
2019-11-11 02:47:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-20 00:29:59 +02:00
|
|
|
--- Activate (focus) a client.
|
|
|
|
--
|
|
|
|
-- This method is the correct way to focus a client. While
|
|
|
|
-- `client.focus = my_client` works and is commonly used in older code, it has
|
|
|
|
-- some drawbacks. The most obvious one is that it bypasses the activate
|
|
|
|
-- filters. It also doesn't handle minimized clients well and requires a lot
|
|
|
|
-- of boilerplate code to make work properly.
|
|
|
|
--
|
|
|
|
-- The valid `args.actions` are:
|
|
|
|
--
|
|
|
|
-- * **mouse_move**: Move the client when the mouse cursor moves until the
|
|
|
|
-- mouse buttons are release.
|
|
|
|
-- * **mouse_resize**: Resize the client when the mouse cursor moves until the
|
|
|
|
-- mouse buttons are release.
|
|
|
|
-- * **mouse_center**: Move the mouse cursor to the center of the client if it
|
|
|
|
-- isn't already within its geometry,
|
|
|
|
-- * **toggle_minimization**: If the client is already active, minimize it.
|
|
|
|
--
|
|
|
|
-- @method activate
|
|
|
|
-- @tparam table args
|
|
|
|
-- @tparam[opt=other] string args.context Why was this activate called?
|
|
|
|
-- @tparam[opt=true] boolean args.raise Raise the client to the top of its layer.
|
|
|
|
-- @tparam[opt=false] boolean args.force Force the activation even for unfocusable
|
|
|
|
-- clients.
|
|
|
|
-- @tparam[opt=false] boolean args.switch_to_tags
|
|
|
|
-- @tparam[opt=false] boolean args.switch_to_tag
|
|
|
|
-- @tparam[opt=false] boolean args.action Once activated, perform an action.
|
|
|
|
-- @tparam[opt=false] boolean args.toggle_minimization
|
2019-11-18 00:46:22 +01:00
|
|
|
-- @see awful.permissions.add_activate_filter
|
2019-10-20 00:29:59 +02:00
|
|
|
-- @see request::activate
|
2019-11-11 00:24:09 +01:00
|
|
|
-- @see active
|
2019-10-20 00:29:59 +02:00
|
|
|
function client.object.activate(c, args)
|
|
|
|
local new_args = setmetatable({}, {__index = args or {}})
|
|
|
|
|
|
|
|
-- Set the default arguments.
|
|
|
|
new_args.raise = new_args.raise == nil and true or args.raise
|
|
|
|
|
|
|
|
if c == capi.client.focus and new_args.action == "toggle_minimization" then
|
|
|
|
c.minimized = true
|
|
|
|
else
|
|
|
|
c:emit_signal(
|
|
|
|
"request::activate",
|
|
|
|
new_args.context or "other",
|
|
|
|
new_args
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if new_args.action and new_args.action == "mouse_move" then
|
|
|
|
amousec.move(c)
|
|
|
|
elseif new_args.action and new_args.action == "mouse_resize" then
|
|
|
|
amousec.resize(c)
|
|
|
|
elseif new_args.action and new_args.action == "mouse_center" then
|
|
|
|
local coords, geo = mouse.mouse.coords(), c:geometry()
|
|
|
|
coords.width, coords.height = 1,1
|
|
|
|
|
|
|
|
if not grect.area_intersect_area(geo, coords) then
|
|
|
|
-- Do not use `awful.placement` to avoid an useless circular
|
|
|
|
-- dependency. Centering is *very* simple.
|
|
|
|
mouse.mouse.coords {
|
|
|
|
x = geo.x + math.ceil(geo.width /2),
|
|
|
|
y = geo.y + math.ceil(geo.height/2)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-18 01:48:25 +01:00
|
|
|
--- Grant a permission for a client.
|
|
|
|
--
|
|
|
|
-- @method grant
|
|
|
|
-- @tparam string permission The permission name (just the name, no `request::`).
|
|
|
|
-- @tparam string context The reason why this permission is requested.
|
|
|
|
-- @see awful.permissions
|
|
|
|
|
|
|
|
--- Deny a permission for a client.
|
|
|
|
--
|
|
|
|
-- @method deny
|
|
|
|
-- @tparam string permission The permission name (just the name, no `request::`).
|
|
|
|
-- @tparam string context The reason why this permission is requested.
|
|
|
|
-- @see awful.permissions
|
|
|
|
|
|
|
|
pcommon.setup_grant(client.object, "client")
|
|
|
|
|
2019-11-11 00:24:09 +01:00
|
|
|
--- Return true if the client is active (has focus).
|
|
|
|
--
|
|
|
|
-- This property is **READ ONLY**. Use `c:activate { context = "myreason" }`
|
|
|
|
-- to change the focus.
|
|
|
|
--
|
|
|
|
-- The reason for this is that directly setting the focus
|
|
|
|
-- (which can also be done using `client.focus = c`) will bypass the focus
|
|
|
|
-- stealing filters. This is easy at first, but as this gets called from more
|
|
|
|
-- and more places, it quickly become unmanageable. This coding style is
|
|
|
|
-- recommended for maintainable code:
|
|
|
|
--
|
|
|
|
-- -- Check if a client has focus:
|
|
|
|
-- if c.active then
|
|
|
|
-- -- do something
|
|
|
|
-- end
|
|
|
|
--
|
|
|
|
-- -- Check if there is a active (focused) client:
|
|
|
|
-- if client.focus ~= nil then
|
|
|
|
-- -- do something
|
|
|
|
-- end
|
|
|
|
--
|
|
|
|
-- -- Get the active (focused) client:
|
|
|
|
-- local c = client.focus
|
|
|
|
--
|
|
|
|
-- -- Set the focus:
|
|
|
|
-- c:activate {
|
|
|
|
-- context = "myreason",
|
|
|
|
-- switch_to_tag = true,
|
|
|
|
-- }
|
|
|
|
--
|
2019-11-11 01:42:52 +01:00
|
|
|
-- -- Get notified when a client gets or loses the focus:
|
|
|
|
-- c:connect_signal("property::active", function(c, is_active)
|
|
|
|
-- -- do something
|
|
|
|
-- end)
|
|
|
|
--
|
|
|
|
-- -- Get notified when any client gets or loses the focus:
|
|
|
|
-- client.connect_signal("property::active", function(c, is_active)
|
|
|
|
-- -- do something
|
|
|
|
-- end)
|
|
|
|
--
|
|
|
|
-- -- Get notified when any client gets the focus:
|
|
|
|
-- client.connect_signal("focus", function(c)
|
|
|
|
-- -- do something
|
|
|
|
-- end)
|
|
|
|
--
|
|
|
|
-- -- Get notified when any client loses the focus:
|
|
|
|
-- client.connect_signal("unfocus", function(c)
|
|
|
|
-- -- do something
|
|
|
|
-- end)
|
|
|
|
--
|
2019-11-11 00:24:09 +01:00
|
|
|
-- @property active
|
|
|
|
-- @tparam boolean active
|
2019-12-01 07:53:12 +01:00
|
|
|
-- @request client border active granted When a client becomes active.
|
|
|
|
-- @request client border inactive granted When a client stop being active.
|
2019-11-11 00:24:09 +01:00
|
|
|
-- @see activate
|
|
|
|
-- @see request::activate
|
2019-11-18 00:46:22 +01:00
|
|
|
-- @see awful.permissions.add_activate_filter
|
2019-11-11 00:24:09 +01:00
|
|
|
|
|
|
|
function client.object.get_active(c)
|
|
|
|
return capi.client.focus == c
|
|
|
|
end
|
|
|
|
|
|
|
|
function client.object.set_active(c, value)
|
|
|
|
if value then
|
|
|
|
-- Do it, but print an error popup. Setting the focus without a context
|
|
|
|
-- breaks the filters. This seems a good idea at first, then cause
|
|
|
|
-- endless pain. QtWidgets also enforces this.
|
|
|
|
c:activate()
|
|
|
|
assert(false, "You cannot set `active` directly, use `c:activate()`.")
|
|
|
|
else
|
|
|
|
-- Be permissive given the alternative is a bit convoluted.
|
|
|
|
capi.client.focus = nil
|
|
|
|
gdebug.print_warning(
|
|
|
|
"Consider using `client.focus = nil` instead of `c.active = false"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-11 02:47:43 +01:00
|
|
|
capi.client.connect_signal("property::active", function(c)
|
|
|
|
c:emit_signal("request::border", (c.active and "" or "in").."active", {})
|
|
|
|
end)
|
2016-03-31 10:14:42 +02:00
|
|
|
|
|
|
|
--- The last geometry when client was floating.
|
|
|
|
-- @signal property::floating_geometry
|
|
|
|
|
2016-04-14 09:13:06 +02:00
|
|
|
--- Emited when a client need to get a titlebar.
|
|
|
|
-- @signal request::titlebars
|
|
|
|
-- @tparam[opt=nil] string content The context (like "rules")
|
|
|
|
-- @tparam[opt=nil] table hints Some hints.
|
2019-12-31 07:45:43 +01:00
|
|
|
-- @classsignal
|
2016-04-14 09:13:06 +02:00
|
|
|
|
2019-11-10 07:12:43 +01:00
|
|
|
--- The client marked signal.
|
|
|
|
-- @deprecatedsignal marked
|
2016-03-31 10:14:42 +02:00
|
|
|
|
2019-11-10 07:12:43 +01:00
|
|
|
--- The client unmarked signal.
|
|
|
|
-- @deprecatedsignal unmarked
|
2010-08-25 23:00:36 +02:00
|
|
|
|
2019-11-11 02:47:43 +01:00
|
|
|
--- Emited when the border client might need to be update.
|
|
|
|
--
|
|
|
|
-- The context are:
|
|
|
|
--
|
|
|
|
-- * **added**: When a new client is created.
|
|
|
|
-- * **active**: When client gains the focus (or stop being urgent/floating
|
|
|
|
-- but is active).
|
|
|
|
-- * **inactive**: When client loses the focus (or stop being urgent/floating
|
|
|
|
-- and is not active.
|
|
|
|
-- * **urgent**: When a client becomes urgent.
|
|
|
|
-- * **floating**: When the floating or maximization state changes.
|
|
|
|
--
|
|
|
|
-- @signal request::border
|
2019-12-31 07:45:43 +01:00
|
|
|
-- @tparam string context The context.
|
|
|
|
-- @tparam table hints The hints.
|
|
|
|
-- @classsignal
|
2019-11-18 00:46:22 +01:00
|
|
|
-- @see awful.permissions.update_border
|
2019-11-11 02:47:43 +01:00
|
|
|
|
2015-10-13 12:02:09 +02:00
|
|
|
-- Add clients during startup to focus history.
|
2019-11-18 00:46:22 +01:00
|
|
|
-- This used to happen through permissions.activate, but that only handles visible
|
2015-10-13 12:02:09 +02:00
|
|
|
-- clients now.
|
2019-11-10 07:12:43 +01:00
|
|
|
capi.client.connect_signal("request::manage", function (c)
|
|
|
|
if capi.awesome.startup
|
|
|
|
and not c.size_hints.user_position
|
|
|
|
and not c.size_hints.program_position then
|
|
|
|
-- Prevent clients from being unreachable after screen count changes.
|
|
|
|
require("awful.placement").no_offscreen(c)
|
|
|
|
end
|
|
|
|
|
2019-12-31 00:17:23 +01:00
|
|
|
if capi.awesome.startup then
|
2015-10-13 12:02:09 +02:00
|
|
|
client.focus.history.add(c)
|
|
|
|
end
|
2019-11-11 02:47:43 +01:00
|
|
|
|
|
|
|
client.property.set(c, "_border_init", true)
|
|
|
|
c:emit_signal("request::border", "added", {})
|
2015-10-13 12:02:09 +02:00
|
|
|
end)
|
2019-11-10 07:12:43 +01:00
|
|
|
capi.client.connect_signal("request::unmanage", client.focus.history.delete)
|
|
|
|
|
|
|
|
capi.client.connect_signal("request::unmanage", client.floating.delete)
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2019-11-10 07:12:43 +01:00
|
|
|
-- Print a warning when the old `manage` signal is used.
|
|
|
|
capi.client.connect_signal("manage::connected", function()
|
|
|
|
gdebug.deprecate(
|
|
|
|
"Use `request::manage` rather than `manage`",
|
|
|
|
{deprecated_in=5}
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
capi.client.connect_signal("unmanage::connected", function()
|
|
|
|
gdebug.deprecate(
|
|
|
|
"Use `request::unmanage` rather than `unmanage`",
|
|
|
|
{deprecated_in=5}
|
|
|
|
)
|
|
|
|
end)
|
2012-06-12 20:13:09 +02:00
|
|
|
|
2019-12-31 22:01:10 +01:00
|
|
|
for _, sig in ipairs {"marked", "unmarked"} do
|
|
|
|
capi.client.connect_signal(sig.."::connected", function()
|
|
|
|
gdebug.deprecate(
|
|
|
|
"Use `property::marked` rather than `".. sig .. "`",
|
|
|
|
{deprecated_in=4}
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2016-05-14 16:12:12 +02:00
|
|
|
-- Connect to "focus" signal, and allow to disable tracking.
|
|
|
|
do
|
|
|
|
local disabled_count = 1
|
|
|
|
--- Disable history tracking.
|
|
|
|
--
|
|
|
|
-- See `awful.client.focus.history.enable_tracking` to enable it again.
|
|
|
|
-- @treturn int The internal value of `disabled_count` (calls to this
|
|
|
|
-- function without calling `awful.client.focus.history.enable_tracking`).
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.focus.history.disable_tracking
|
2016-05-14 16:12:12 +02:00
|
|
|
function client.focus.history.disable_tracking()
|
|
|
|
disabled_count = disabled_count + 1
|
|
|
|
if disabled_count == 1 then
|
|
|
|
capi.client.disconnect_signal("focus", client.focus.history.add)
|
|
|
|
end
|
|
|
|
return disabled_count
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Enable history tracking.
|
|
|
|
--
|
|
|
|
-- This is the default, but can be disabled
|
|
|
|
-- through `awful.client.focus.history.disable_tracking`.
|
|
|
|
-- @treturn boolean True if history tracking has been enabled.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.focus.history.enable_tracking
|
2016-05-14 16:12:12 +02:00
|
|
|
function client.focus.history.enable_tracking()
|
|
|
|
assert(disabled_count > 0)
|
|
|
|
disabled_count = disabled_count - 1
|
|
|
|
if disabled_count == 0 then
|
|
|
|
capi.client.connect_signal("focus", client.focus.history.add)
|
|
|
|
end
|
|
|
|
return disabled_count == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Is history tracking enabled?
|
|
|
|
-- @treturn bool True if history tracking is enabled.
|
|
|
|
-- @treturn int The number of times that tracking has been disabled.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.client.focus.history.is_enabled
|
2016-05-14 16:12:12 +02:00
|
|
|
function client.focus.history.is_enabled()
|
|
|
|
return disabled_count == 0, disabled_count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
client.focus.history.enable_tracking()
|
|
|
|
|
2014-04-10 15:32:52 +02:00
|
|
|
-- Register persistent properties
|
2014-04-21 19:30:03 +02:00
|
|
|
client.property.persist("floating", "boolean")
|
2014-04-10 15:32:52 +02:00
|
|
|
|
2016-03-13 08:44:19 +01:00
|
|
|
-- Extend the luaobject
|
|
|
|
object.properties(capi.client, {
|
2016-03-14 07:21:29 +01:00
|
|
|
getter_class = client.object,
|
|
|
|
setter_class = client.object,
|
2016-03-13 08:44:19 +01:00
|
|
|
getter_fallback = client.property.get,
|
|
|
|
setter_fallback = client.property.set,
|
|
|
|
})
|
|
|
|
|
2019-06-06 22:32:53 +02:00
|
|
|
--@DOC_object_COMMON@
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
return client
|
2008-12-01 16:26:41 +01:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|