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
|
|
|
|
-- @release @AWESOME_VERSION@
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @module awful.client
|
2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local util = require("awful.util")
|
2008-11-15 09:53:21 +01:00
|
|
|
local tag = require("awful.tag")
|
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
|
|
|
}
|
|
|
|
|
2012-09-28 23:53:58 +02:00
|
|
|
-- we use require("awful.screen") inside functions to prevent circular dependencies.
|
|
|
|
local screen
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
local client = {}
|
2008-09-29 16:49:18 +02:00
|
|
|
|
|
|
|
-- Private data
|
2012-06-12 20:13:09 +02:00
|
|
|
client.data = {}
|
|
|
|
client.data.focus = {}
|
|
|
|
client.data.urgent = {}
|
|
|
|
client.data.marked = {}
|
|
|
|
client.data.properties = setmetatable({}, { __mode = 'k' })
|
2014-04-10 15:32:52 +02:00
|
|
|
client.data.persistent_properties_registered = {} -- keys are names of persistent properties, value always true
|
|
|
|
client.data.persistent_properties_loaded = setmetatable({}, { __mode = 'k' }) -- keys are clients, value always true
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2009-02-07 15:12:57 +01:00
|
|
|
-- Functions
|
2012-06-12 20:13:09 +02:00
|
|
|
client.urgent = {}
|
|
|
|
client.focus = {}
|
|
|
|
client.focus.history = {}
|
|
|
|
client.swap = {}
|
|
|
|
client.floating = {}
|
|
|
|
client.dockable = {}
|
|
|
|
client.property = {}
|
2014-04-14 10:04:56 +02:00
|
|
|
client.shape = require("awful.client.shape")
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2014-05-20 11:47:20 +02:00
|
|
|
--- Jump to the given client.
|
|
|
|
-- Takes care of focussing the screen, the right tag, etc.
|
|
|
|
--
|
|
|
|
-- @client c the client to jump to
|
|
|
|
-- @tparam bool merge If true then merge tags when clients are not visible.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.jumpto(c, merge)
|
2012-03-06 23:09:45 +01:00
|
|
|
local s = capi.client.focus and capi.client.focus.screen or capi.mouse.screen
|
|
|
|
-- focus the screen
|
|
|
|
if s ~= c.screen then
|
|
|
|
capi.mouse.screen = c.screen
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Try to make client visible, this also covers e.g. sticky
|
|
|
|
local t = c:tags()[1]
|
|
|
|
if t and not c:isvisible() then
|
|
|
|
if merge then
|
|
|
|
t.selected = true
|
|
|
|
else
|
|
|
|
tag.viewonly(t)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-19 22:24:12 +02:00
|
|
|
c: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 the first client that got the urgent hint.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @treturn client The first urgent client.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.urgent.get()
|
|
|
|
if #client.data.urgent > 0 then
|
|
|
|
return client.data.urgent[1]
|
2008-09-29 16:49:18 +02:00
|
|
|
else
|
|
|
|
-- fallback behaviour: iterate through clients and get the first urgent
|
|
|
|
local clients = capi.client.get()
|
|
|
|
for k, cl in pairs(clients) do
|
|
|
|
if cl.urgent then
|
|
|
|
return cl
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Jump to the client that received the urgent hint first.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @tparam bool merge If true then merge tags when clients are not visible.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.urgent.jumpto(merge)
|
|
|
|
local c = client.urgent.get()
|
2008-09-29 16:49:18 +02:00
|
|
|
if c then
|
2012-06-12 20:13:09 +02:00
|
|
|
client.jumpto(c, merge)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Adds client to urgent stack.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @client c The client object.
|
2009-08-21 21:15:19 +02:00
|
|
|
-- @param prop The property which is updated.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.urgent.add(c, prop)
|
2009-08-21 21:15:19 +02:00
|
|
|
if type(c) == "client" and prop == "urgent" and c.urgent then
|
2012-06-12 20:13:09 +02:00
|
|
|
table.insert(client.data.urgent, c)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Remove client from urgent stack.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @client c The client object.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.urgent.delete(c)
|
|
|
|
for k, cl in ipairs(client.data.urgent) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if c == cl then
|
2012-06-12 20:13:09 +02:00
|
|
|
table.remove(client.data.urgent, k)
|
2008-09-29 16:49:18 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Remove a client from the focus history
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @client c The client that must be removed.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.focus.history.delete(c)
|
|
|
|
for k, v in ipairs(client.data.focus) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if v == c then
|
2012-06-12 20:13:09 +02:00
|
|
|
table.remove(client.data.focus, k)
|
2008-09-29 16:49:18 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Filter out window that we do not want handled by focus.
|
|
|
|
-- This usually means that desktop, dock and splash windows are
|
|
|
|
-- not registered and cannot get focus.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @client c A client.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @return The same client if it's ok, nil otherwise.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.focus.filter(c)
|
2008-09-29 16:49:18 +02:00
|
|
|
if c.type == "desktop"
|
|
|
|
or c.type == "dock"
|
2010-08-12 13:18:40 +02:00
|
|
|
or c.type == "splash"
|
|
|
|
or not c.focusable then
|
2008-09-29 16:49:18 +02:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return c
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Update client focus history.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @client c The client that has been focused.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.focus.history.add(c)
|
2012-04-06 12:19:12 +02:00
|
|
|
-- Remove the client if its in stack
|
2012-06-12 20:13:09 +02:00
|
|
|
client.focus.history.delete(c)
|
2012-04-06 12:19:12 +02:00
|
|
|
-- Record the client has latest focused
|
2012-06-12 20:13:09 +02:00
|
|
|
table.insert(client.data.focus, 1, c)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the latest focused client for a screen in history.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2015-05-25 15:23:30 +02:00
|
|
|
-- @tparam int screen The screen number to look for.
|
|
|
|
-- @tparam int idx The index: 0 will return first candidate,
|
2014-05-20 11:47:20 +02:00
|
|
|
-- 1 will return second, etc.
|
2015-06-10 21:39:50 +02:00
|
|
|
-- @tparam function filter An optional filter. If no client is found in the
|
|
|
|
-- first iteration, client.focus.filter is used by default to get any
|
|
|
|
-- client.
|
2015-05-25 15:23:30 +02:00
|
|
|
-- @treturn client A client.
|
|
|
|
function client.focus.history.get(screen, idx, filter)
|
2008-09-29 16:49:18 +02:00
|
|
|
-- When this counter is equal to idx, we return the client
|
|
|
|
local counter = 0
|
2012-06-12 20:13:09 +02:00
|
|
|
local vc = client.visible(screen)
|
|
|
|
for k, c in ipairs(client.data.focus) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if c.screen == screen then
|
2015-05-25 15:23:30 +02:00
|
|
|
if not filter or filter(c) then
|
|
|
|
for j, vcc in ipairs(vc) do
|
|
|
|
if vcc == c then
|
|
|
|
if counter == idx then
|
|
|
|
return c
|
|
|
|
end
|
|
|
|
-- We found one, increment the counter only.
|
|
|
|
counter = counter + 1
|
|
|
|
break
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- Argh nobody found in history, give the first one visible if there is one
|
2008-12-29 11:51:46 +01:00
|
|
|
-- that passes the filter.
|
2015-05-25 15:23:30 +02:00
|
|
|
local filter = filter or client.focus.filter
|
2008-09-29 16:49:18 +02:00
|
|
|
if counter == 0 then
|
2008-12-29 11:51:46 +01:00
|
|
|
for k, v in ipairs(vc) do
|
2015-05-25 15:23:30 +02:00
|
|
|
if filter(v) then
|
2008-12-29 11:51:46 +01:00
|
|
|
return v
|
|
|
|
end
|
|
|
|
end
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Focus the previous client in history.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.focus.history.previous()
|
2008-09-29 16:49:18 +02:00
|
|
|
local sel = capi.client.focus
|
|
|
|
local s
|
|
|
|
if sel then
|
|
|
|
s = sel.screen
|
|
|
|
else
|
|
|
|
s = capi.mouse.screen
|
|
|
|
end
|
2012-06-12 20:13:09 +02:00
|
|
|
local c = client.focus.history.get(s, 1)
|
2015-05-13 13:36:28 +02:00
|
|
|
if c then
|
2015-06-19 22:24:12 +02:00
|
|
|
c:emit_signal("request::activate", "client.focus.history.previous",
|
|
|
|
{raise=false})
|
2015-05-13 13:36:28 +02:00
|
|
|
end
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get visible clients from a screen.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2008-11-21 15:35:56 +01:00
|
|
|
-- @param screen The screen number, or nil for all screens.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @return A table with all visible clients.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.visible(screen)
|
2008-09-29 16:49:18 +02:00
|
|
|
local cls = capi.client.get(screen)
|
|
|
|
local vcls = {}
|
|
|
|
for k, c in pairs(cls) do
|
|
|
|
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
|
|
|
--
|
2008-11-25 16:40:41 +01:00
|
|
|
-- @param screen The screen number, or nil for all screens.
|
2012-07-01 15:07:12 +02:00
|
|
|
-- @return A table with all visible and tiled clients.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.tiled(screen)
|
|
|
|
local clients = client.visible(screen)
|
2008-11-25 16:40:41 +01:00
|
|
|
local tclients = {}
|
|
|
|
-- Remove floating clients
|
|
|
|
for k, c in pairs(clients) do
|
2013-10-04 12:04:16 +02:00
|
|
|
if not client.floating.get(c)
|
|
|
|
and not c.fullscreen
|
|
|
|
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.
|
|
|
|
--
|
|
|
|
-- @tparam int i The index. Use 1 to get the next, -1 to get the previous.
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @return 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)
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.next(i, c)
|
2008-09-29 16:49:18 +02:00
|
|
|
-- Get currently focused client
|
|
|
|
local sel = c or capi.client.focus
|
|
|
|
if sel then
|
|
|
|
-- Get all visible clients
|
2012-06-12 20:13:09 +02:00
|
|
|
local cls = client.visible(sel.screen)
|
2008-11-27 11:18:35 +01:00
|
|
|
local fcls = {}
|
|
|
|
-- Remove all non-normal clients
|
2008-09-29 16:49:18 +02:00
|
|
|
for idx, 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
|
|
|
|
return cls[util.cycle(#cls, idx + i)]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-15 01:11:33 +02:00
|
|
|
--- Focus a client by the given direction.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2015-02-20 15:21:51 +01:00
|
|
|
-- @tparam string dir The direction, can be either
|
2014-05-20 11:47:20 +02:00
|
|
|
-- `"up"`, `"down"`, `"left"` or `"right"`.
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client.
|
2012-09-15 01:11:33 +02:00
|
|
|
function client.focus.bydirection(dir, c)
|
2008-09-29 16:49:18 +02:00
|
|
|
local sel = c or capi.client.focus
|
|
|
|
if sel then
|
2012-09-15 01:11:33 +02:00
|
|
|
local cltbl = client.visible(sel.screen)
|
|
|
|
local geomtbl = {}
|
|
|
|
for i,cl in ipairs(cltbl) do
|
|
|
|
geomtbl[i] = cl:geometry()
|
|
|
|
end
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2012-09-15 01:11:33 +02:00
|
|
|
local target = util.get_rectangle_in_direction(dir, geomtbl, sel:geometry())
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2012-09-15 01:11:33 +02:00
|
|
|
-- If we found a client to focus, then do it.
|
|
|
|
if target then
|
2015-06-19 22:24:12 +02:00
|
|
|
cltbl[target]:emit_signal("request::activate",
|
|
|
|
"client.focus.bydirection", {raise=false})
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2008-10-06 21:55:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-15 01:11:33 +02:00
|
|
|
--- Focus a client by the given direction. Moves across screens.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2008-10-06 21:55:06 +02:00
|
|
|
-- @param dir The direction, can be either "up", "down", "left" or "right".
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client.
|
2012-09-15 01:11:33 +02:00
|
|
|
function client.focus.global_bydirection(dir, c)
|
2012-09-28 23:53:58 +02:00
|
|
|
screen = screen or require("awful.screen")
|
2008-10-06 21:55:06 +02:00
|
|
|
local sel = c or capi.client.focus
|
2012-09-15 01:11:33 +02:00
|
|
|
local scr = capi.mouse.screen
|
2008-10-06 21:55:06 +02:00
|
|
|
if sel then
|
2012-09-15 01:11:33 +02:00
|
|
|
scr = sel.screen
|
|
|
|
end
|
2008-10-06 21:55:06 +02:00
|
|
|
|
2012-09-15 01:11:33 +02:00
|
|
|
-- change focus inside the screen
|
|
|
|
client.focus.bydirection(dir, sel)
|
|
|
|
|
|
|
|
-- if focus not changed, we must change screen
|
|
|
|
if sel == capi.client.focus then
|
2012-09-28 23:53:58 +02:00
|
|
|
screen.focus_bydirection(dir, scr)
|
2012-09-15 01:11:33 +02:00
|
|
|
if scr ~= capi.mouse.screen then
|
|
|
|
local cltbl = client.visible(capi.mouse.screen)
|
|
|
|
local geomtbl = {}
|
|
|
|
for i,cl in ipairs(cltbl) do
|
|
|
|
geomtbl[i] = cl:geometry()
|
|
|
|
end
|
|
|
|
local target = util.get_rectangle_in_direction(dir, geomtbl, capi.screen[scr].geometry)
|
|
|
|
|
|
|
|
if target then
|
2015-06-19 22:24:12 +02:00
|
|
|
cltbl[target]:emit_signal("request::activate",
|
|
|
|
"client.focus.global_bydirection",
|
|
|
|
{raise=false})
|
2012-09-15 01:11:33 +02:00
|
|
|
end
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Focus a client by its relative index.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param i The index.
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.focus.byidx(i, c)
|
|
|
|
local target = client.next(i, c)
|
2008-09-29 16:49:18 +02:00
|
|
|
if target then
|
2015-06-19 22:24:12 +02:00
|
|
|
target:emit_signal("request::activate", "client.focus.byidx",
|
|
|
|
{raise=true})
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-06 21:55:06 +02:00
|
|
|
--- Swap a client with another client in the given direction
|
|
|
|
-- @param dir The direction, can be either "up", "down", "left" or "right".
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.swap.bydirection(dir, c)
|
2008-10-06 21:55:06 +02:00
|
|
|
local sel = c or capi.client.focus
|
|
|
|
if sel then
|
2012-09-15 01:11:33 +02:00
|
|
|
local cltbl = client.visible(sel.screen)
|
|
|
|
local geomtbl = {}
|
|
|
|
for i,cl in ipairs(cltbl) do
|
|
|
|
geomtbl[i] = cl:geometry()
|
|
|
|
end
|
|
|
|
local target = util.get_rectangle_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
|
|
|
|
|
2012-09-15 01:11:33 +02:00
|
|
|
--- Swap a client with another client in the given direction. Swaps across screens.
|
|
|
|
-- @param dir The direction, can be either "up", "down", "left" or "right".
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client.
|
2012-09-15 01:11:33 +02:00
|
|
|
function client.swap.global_bydirection(dir, c)
|
2012-09-28 23:53:58 +02:00
|
|
|
screen = screen or require("awful.screen")
|
2012-09-15 01:11:33 +02:00
|
|
|
local sel = c or capi.client.focus
|
2012-09-28 23:53:58 +02:00
|
|
|
local scr = capi.mouse.screen
|
2012-09-15 01:11:33 +02:00
|
|
|
if sel then
|
2012-09-28 23:53:58 +02:00
|
|
|
scr = sel.screen
|
2012-09-15 01:11:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if sel then
|
|
|
|
-- move focus
|
|
|
|
client.focus.global_bydirection(dir, sel)
|
|
|
|
local c = capi.client.focus
|
|
|
|
|
|
|
|
-- swapping inside a screen
|
|
|
|
if sel.screen == c.screen and sel ~= c then
|
|
|
|
c:swap(sel)
|
|
|
|
|
|
|
|
-- swapping to an empty screen
|
|
|
|
elseif sel.screen ~= c.screen and sel == c then
|
2012-09-28 23:53:58 +02:00
|
|
|
client.movetoscreen(sel, capi.mouse.screen)
|
2012-09-15 01:11:33 +02:00
|
|
|
|
2015-06-19 22:24:12 +02:00
|
|
|
-- swapping to a nonempty screen
|
2012-09-15 01:11:33 +02:00
|
|
|
elseif sel.screen ~= c.screen and sel ~= c then
|
2012-09-28 23:53:58 +02:00
|
|
|
client.movetoscreen(sel, c.screen)
|
|
|
|
client.movetoscreen(c, 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.
|
|
|
|
-- @param i The index.
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client, otherwise focused one is used.
|
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
|
|
|
|
|
2009-02-14 17:53:03 +01:00
|
|
|
--- Cycle clients.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2009-02-14 17:53:03 +01:00
|
|
|
-- @param clockwise True to cycle clients clockwise.
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @param[opt] screen The screen where to cycle clients.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.cycle(clockwise, screen)
|
2009-02-14 17:53:03 +01:00
|
|
|
local screen = screen or capi.mouse.screen
|
2012-06-12 20:13:09 +02:00
|
|
|
local cls = client.visible(screen)
|
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
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
--- Get the master window.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @param[opt] screen The screen number, otherwise screen mouse is used.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @return The master window.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.getmaster(screen)
|
2008-09-29 16:49:18 +02:00
|
|
|
local s = screen or capi.mouse.screen
|
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
|
|
|
--
|
|
|
|
-- @client c The window to set as master.
|
2012-08-11 23:55:25 +02:00
|
|
|
function client.setmaster(c)
|
|
|
|
local cls = util.table.reverse(capi.client.get(c.screen))
|
|
|
|
for k, v in pairs(cls) do
|
|
|
|
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.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @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)
|
2008-09-29 16:49:18 +02:00
|
|
|
for k, v in pairs(cls) do
|
|
|
|
c:swap(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Move/resize a client relative to current coordinates.
|
|
|
|
-- @param x The relative x coordinate.
|
|
|
|
-- @param y The relative y coordinate.
|
|
|
|
-- @param w The relative width.
|
|
|
|
-- @param h The relative height.
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client, otherwise focused one is used.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.moveresize(x, y, w, h, c)
|
2009-08-21 21:15:19 +02:00
|
|
|
local sel = c or capi.client.focus
|
|
|
|
local geometry = sel:geometry()
|
|
|
|
geometry['x'] = geometry['x'] + x
|
|
|
|
geometry['y'] = geometry['y'] + y
|
|
|
|
geometry['width'] = geometry['width'] + w
|
|
|
|
geometry['height'] = geometry['height'] + h
|
|
|
|
sel:geometry(geometry)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Move a client to a tag.
|
|
|
|
-- @param target The tag to move the client to.
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client to move, otherwise the focused one is used.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.movetotag(target, c)
|
2008-09-29 16:49:18 +02:00
|
|
|
local sel = c or capi.client.focus
|
2012-10-20 17:33:32 +02:00
|
|
|
local s = tag.getscreen(target)
|
|
|
|
if sel and s then
|
2009-08-24 16:09:56 +02:00
|
|
|
-- Set client on the same screen as the tag.
|
2012-10-20 17:33:32 +02:00
|
|
|
sel.screen = s
|
2008-09-29 16:49:18 +02:00
|
|
|
sel:tags({ target })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Toggle a tag on a client.
|
|
|
|
-- @param target The tag to toggle.
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @client[opt] c The client to toggle, otherwise the focused one is used.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.toggletag(target, c)
|
2008-09-29 16:49:18 +02:00
|
|
|
local sel = c or capi.client.focus
|
|
|
|
-- Check that tag and client screen are identical
|
2012-11-19 18:56:18 +01:00
|
|
|
if sel and sel.screen == tag.getscreen(target) then
|
2008-09-29 16:49:18 +02:00
|
|
|
local tags = sel: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
|
|
|
|
sel:tags(tags)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Move a client to a screen. Default is next screen, cycling.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c The client to move.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param s The screen number, default to current + 1.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.movetoscreen(c, s)
|
2012-09-28 23:53:58 +02:00
|
|
|
screen = screen or require("awful.screen")
|
2008-09-29 16:49:18 +02:00
|
|
|
local sel = c or capi.client.focus
|
|
|
|
if sel then
|
|
|
|
local sc = capi.screen.count()
|
|
|
|
if not s then
|
|
|
|
s = sel.screen + 1
|
|
|
|
end
|
|
|
|
if s > sc then s = 1 elseif s < 1 then s = sc end
|
2014-03-26 14:28:04 +01:00
|
|
|
sel.screen = s
|
|
|
|
screen.focus(s)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Mark a client, and then call 'marked' hook.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c The client to mark, the focused one if not specified.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @return True if the client has been marked. False if the client was already marked.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.mark(c)
|
2008-09-29 16:49:18 +02:00
|
|
|
local cl = c or capi.client.focus
|
|
|
|
if cl then
|
2012-06-12 20:13:09 +02:00
|
|
|
for k, v in pairs(client.data.marked) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if cl == v then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
table.insert(client.data.marked, cl)
|
2008-09-29 16:49:18 +02:00
|
|
|
|
|
|
|
-- Call callback
|
2009-08-11 15:27:31 +02:00
|
|
|
cl:emit_signal("marked")
|
2008-09-29 16:49:18 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Unmark a client and then call 'unmarked' hook.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c The client to unmark, or the focused one if not specified.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @return True if the client has been unmarked. False if the client was not marked.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.unmark(c)
|
2008-09-29 16:49:18 +02:00
|
|
|
local cl = c or capi.client.focus
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
for k, v in pairs(client.data.marked) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if cl == v then
|
2012-06-12 20:13:09 +02:00
|
|
|
table.remove(client.data.marked, k)
|
2009-08-11 15:27:31 +02:00
|
|
|
cl:emit_signal("unmarked")
|
2008-09-29 16:49:18 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Check if a client is marked.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c The client to check, or the focused one otherwise.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.ismarked(c)
|
2008-09-29 16:49:18 +02:00
|
|
|
local cl = c or capi.client.focus
|
|
|
|
if cl then
|
2012-06-12 20:13:09 +02:00
|
|
|
for k, v in pairs(client.data.marked) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if cl == v then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Toggle a client as marked.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c The client to toggle mark.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.togglemarked(c)
|
2008-09-29 16:49:18 +02:00
|
|
|
local cl = c or capi.client.focus
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
if not client.mark(c) then
|
|
|
|
client.unmark(c)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Return the marked clients and empty the marked table.
|
|
|
|
-- @return A table with all marked clients.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.getmarked()
|
|
|
|
for k, v in pairs(client.data.marked) do
|
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
|
|
|
t = client.data.marked
|
|
|
|
client.data.marked = {}
|
2008-09-29 16:49:18 +02:00
|
|
|
return t
|
|
|
|
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.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c A client.
|
2009-03-26 22:58:17 +01:00
|
|
|
-- @param s True or false.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.floating.set(c, s)
|
2008-12-01 16:26:41 +01:00
|
|
|
local 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
|
2008-12-01 16:26:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-10 18:12:19 +02:00
|
|
|
local function store_floating_geometry(c)
|
2012-06-12 20:13:09 +02:00
|
|
|
if client.floating.get(c) then
|
|
|
|
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.
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.client.connect_signal("new", function(c)
|
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
|
2011-12-09 03:45:59 +01:00
|
|
|
c: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
|
|
|
|
2008-12-09 14:56:01 +01:00
|
|
|
--- Return if a client has a fixe size or not.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c The client.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.isfixed(c)
|
2009-01-06 11:11:21 +01:00
|
|
|
local c = c or capi.client.focus
|
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
|
|
|
|
|
2008-12-01 16:26:41 +01:00
|
|
|
--- Get a client floating state.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c A client.
|
2008-12-01 16:26:41 +01:00
|
|
|
-- @return True or false. Note that some windows might be floating even if you
|
|
|
|
-- 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)
|
2008-12-01 16:26:41 +01:00
|
|
|
local c = c or capi.client.focus
|
|
|
|
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
|
2009-01-06 11:11:21 +01:00
|
|
|
if 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
|
2012-06-12 20:13:09 +02:00
|
|
|
or client.isfixed(c) then
|
2009-01-06 11:11:21 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
2008-12-01 16:26:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-14 14:55:56 +01:00
|
|
|
--- Toggle the floating state of a client between 'auto' and 'true'.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c A client.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.floating.toggle(c)
|
2009-02-24 11:08:22 +01:00
|
|
|
local c = c or capi.client.focus
|
2009-01-14 14:55:56 +01:00
|
|
|
-- If it has been set to floating
|
2012-06-12 20:13:09 +02:00
|
|
|
if client.floating.get(c) then
|
|
|
|
client.floating.set(c, false)
|
2009-01-14 14:55:56 +01:00
|
|
|
else
|
2012-06-12 20:13:09 +02:00
|
|
|
client.floating.set(c, true)
|
2009-01-14 14:55:56 +01:00
|
|
|
end
|
2008-12-01 16:26:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Remove the floating information on a client.
|
2015-02-15 22:33:23 +01:00
|
|
|
-- @client c The client.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.floating.delete(c)
|
|
|
|
client.floating.set(c, nil)
|
2008-12-01 16:26:41 +01:00
|
|
|
end
|
|
|
|
|
2011-02-19 21:44:30 +01:00
|
|
|
--- Restore (=unminimize) a random client.
|
|
|
|
-- @param s The screen to use.
|
2012-09-14 14:32:06 +02:00
|
|
|
-- @return The restored client if some client was restored, otherwise nil.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.restore(s)
|
2011-03-01 02:23:18 +01:00
|
|
|
local s = s or (capi.client.focus and capi.client.focus.screen) or capi.mouse.screen
|
2011-02-19 21:44:30 +01:00
|
|
|
local cls = capi.client.get(s)
|
|
|
|
local tags = tag.selectedlist(s)
|
|
|
|
local mcls = {}
|
|
|
|
for k, c in pairs(cls) do
|
|
|
|
local ctags = c:tags()
|
|
|
|
if c.minimized then
|
|
|
|
for k, t in ipairs(tags) do
|
|
|
|
if util.table.hasitem(ctags, t) then
|
|
|
|
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
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Normalize a set of numbers to 1
|
2009-01-13 20:31:37 +01:00
|
|
|
-- @param set the set of numbers to normalize
|
|
|
|
-- @param num the number of numbers to normalize
|
|
|
|
local function normalize(set, num)
|
|
|
|
local num = num or #set
|
|
|
|
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
|
|
|
|
for i,v in ipairs(set) do
|
|
|
|
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
|
|
|
--
|
|
|
|
-- @client c the client
|
2009-01-13 20:31:37 +01:00
|
|
|
-- @return col the column number
|
|
|
|
-- @return idx index of the client in the column
|
|
|
|
-- @return num the number of visible clients in the column
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.idx(c)
|
2009-01-13 20:31:37 +01:00
|
|
|
local c = c or capi.client.focus
|
|
|
|
if not c then return end
|
|
|
|
|
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
|
|
|
|
|
2009-08-26 14:35:44 +02:00
|
|
|
local t = tag.selected(c.screen)
|
2009-01-13 20:31:37 +01:00
|
|
|
local nmaster = tag.getnmaster(t)
|
|
|
|
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.
|
|
|
|
local ncol = tag.getncol(t)
|
|
|
|
-- 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
|
|
|
--
|
2009-01-13 20:31:37 +01:00
|
|
|
-- @param wfact the window factor value
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c the client
|
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
|
2010-12-11 14:20:42 +01:00
|
|
|
local c = c or capi.client.focus
|
|
|
|
if not c or not c:isvisible() then return end
|
2009-01-13 20:31:37 +01:00
|
|
|
|
|
|
|
local t = tag.selected(c.screen)
|
2012-06-12 20:13:09 +02:00
|
|
|
local w = client.idx(c)
|
2009-01-13 20:31:37 +01:00
|
|
|
|
2012-10-31 22:13:30 +01:00
|
|
|
local cls = client.tiled(tag.getscreen(t))
|
2009-01-13 20:31:37 +01:00
|
|
|
local nmaster = tag.getnmaster(t)
|
|
|
|
|
|
|
|
-- n is the number of windows currently visible for which we have to be concerned with the properties
|
|
|
|
local data = tag.getproperty(t, "windowfact") or {}
|
|
|
|
local colfact = data[w.col]
|
|
|
|
|
|
|
|
colfact[w.idx] = wfact
|
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
|
|
|
|
|
|
|
|
--- Increment a client's window factor
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
2009-01-13 20:31:37 +01:00
|
|
|
-- @param add amount to increase the client's window
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @client c the client
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.incwfact(add, c)
|
2009-01-13 20:31:37 +01:00
|
|
|
local c = c or capi.client.focus
|
|
|
|
if not c then return end
|
|
|
|
|
|
|
|
local t = tag.selected(c.screen)
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
local w = client.idx(c)
|
2009-01-13 20:31:37 +01:00
|
|
|
|
|
|
|
local nmaster = tag.getnmaster(t)
|
|
|
|
local data = tag.getproperty(t, "windowfact") or {}
|
|
|
|
local colfact = data[w.col]
|
|
|
|
curr = colfact[w.idx] or 1
|
|
|
|
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
|
|
|
|
|
2009-03-26 22:22:05 +01:00
|
|
|
--- Get a client dockable state.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @client c A client.
|
2009-03-26 22:22:05 +01:00
|
|
|
-- @return True or false. Note that some windows might be dockable even if you
|
2014-05-20 11:47:20 +02:00
|
|
|
-- did not set them manually. For example, windows with a type "utility",
|
|
|
|
-- "toolbar" or "dock"
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.dockable.get(c)
|
|
|
|
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
|
|
|
|
|
|
|
|
--- Set a client dockable state, overriding auto-detection.
|
|
|
|
-- 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
|
|
|
--
|
|
|
|
-- @client c A client.
|
2009-03-26 22:22:05 +01:00
|
|
|
-- @param value True or false.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.dockable.set(c, value)
|
|
|
|
client.property.set(c, "dockable", value)
|
2009-03-26 22:22:05 +01:00
|
|
|
end
|
|
|
|
|
2009-02-07 15:12:57 +01:00
|
|
|
--- Get a client property.
|
2014-05-20 11:47:20 +02:00
|
|
|
--
|
|
|
|
-- @client c The client.
|
2009-02-07 15:12:57 +01:00
|
|
|
-- @param prop The property name.
|
|
|
|
-- @return The property.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.property.get(c, prop)
|
2014-04-10 15:32:52 +02:00
|
|
|
if not client.data.persistent_properties_loaded[c] then
|
|
|
|
client.data.persistent_properties_loaded[c] = true
|
|
|
|
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
|
2012-06-12 20:13:09 +02:00
|
|
|
if client.data.properties[c] then
|
|
|
|
return client.data.properties[c][prop]
|
2009-02-07 15:12:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Set a client property.
|
2014-05-20 11:47:20 +02:00
|
|
|
-- These properties are internal to awful. Some are used to move clients, etc.
|
|
|
|
--
|
|
|
|
-- @client c The client.
|
2009-02-07 15:12:57 +01:00
|
|
|
-- @param prop The property name.
|
|
|
|
-- @param value The value.
|
2012-06-12 20:13:09 +02:00
|
|
|
function client.property.set(c, prop, value)
|
|
|
|
if not client.data.properties[c] then
|
|
|
|
client.data.properties[c] = {}
|
2009-02-07 15:12:57 +01:00
|
|
|
end
|
2014-04-10 15:32:52 +02:00
|
|
|
if client.data.persistent_properties_registered[prop] then
|
|
|
|
c:set_xproperty("awful.client.property." .. prop, value)
|
|
|
|
end
|
2012-06-12 20:13:09 +02:00
|
|
|
client.data.properties[c][prop] = value
|
2009-08-26 15:22:46 +02:00
|
|
|
c:emit_signal("property::" .. prop)
|
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
|
|
|
--
|
2014-04-10 15:32:52 +02:00
|
|
|
-- @param prop The property name.
|
|
|
|
-- @param type The type (used for register_xproperty).
|
2014-05-20 11:47:20 +02:00
|
|
|
-- One of "string", "number" or "boolean".
|
2014-04-21 19:30:03 +02:00
|
|
|
function client.property.persist(prop, type)
|
2014-04-10 15:32:52 +02:00
|
|
|
local xprop = "awful.client.property." .. prop
|
|
|
|
capi.awesome.register_xproperty(xprop, type)
|
|
|
|
client.data.persistent_properties_registered[prop] = true
|
|
|
|
|
|
|
|
-- Make already-set properties persistent
|
|
|
|
for c, tab in pairs(client.data.properties) do
|
|
|
|
if client.data.properties[c] and client.data.properties[c][prop] ~= nil then
|
|
|
|
c:set_xproperty(xprop, client.data.properties[c][prop])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-16 22:02:28 +01:00
|
|
|
---
|
|
|
|
-- Returns an iterator to cycle through, 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
|
|
|
--
|
2012-02-16 22:02:28 +01:00
|
|
|
-- @param filter a function that returns true to indicate a positive match
|
|
|
|
-- @param 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.
|
|
|
|
-- @param s which screen to use. nil means all screens.
|
2012-04-02 13:36:12 +02:00
|
|
|
--
|
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)
|
|
|
|
-- return awful.rules.match(c, {class = "URxvt"})
|
|
|
|
-- 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
|
|
|
|
local start = start or util.table.hasitem(clients, focused)
|
2012-04-02 13:36:12 +02:00
|
|
|
return util.table.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
|
|
|
--
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @param cmd the command to execute
|
2012-03-31 12:03:01 +02:00
|
|
|
-- @param matcher a function that returns true to indicate a matching client
|
2014-05-20 11:47:20 +02:00
|
|
|
-- @param merge if true then merge tags when clients are not visible
|
2012-03-31 12:03:01 +02:00
|
|
|
--
|
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)
|
|
|
|
-- return awful.rules.match(c, {class = 'URxvt'})
|
|
|
|
-- 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)
|
2012-03-31 12:03:01 +02:00
|
|
|
local clients = capi.client.get()
|
|
|
|
local findex = util.table.hasitem(clients, capi.client.focus) or 1
|
|
|
|
local start = util.cycle(#clients, findex + 1)
|
|
|
|
|
2012-08-04 22:23:14 +02:00
|
|
|
for c in client.iterate(matcher, start) do
|
2012-06-12 20:13:09 +02:00
|
|
|
client.jumpto(c, merge)
|
2012-03-31 12:03:01 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- client not found, spawn it
|
|
|
|
util.spawn(cmd)
|
|
|
|
end
|
|
|
|
|
2009-08-10 18:12:19 +02:00
|
|
|
-- Register standards signals
|
2010-08-25 23:00:36 +02:00
|
|
|
capi.client.add_signal("property::floating_geometry")
|
|
|
|
capi.client.add_signal("property::floating")
|
2010-08-27 21:42:14 +02:00
|
|
|
capi.client.add_signal("property::dockable")
|
2014-03-23 16:34:04 +01:00
|
|
|
capi.client.add_signal("marked")
|
|
|
|
capi.client.add_signal("unmarked")
|
2010-08-25 23:00:36 +02:00
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
capi.client.connect_signal("focus", client.focus.history.add)
|
|
|
|
capi.client.connect_signal("unmanage", client.focus.history.delete)
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2014-03-23 19:48:07 +01:00
|
|
|
capi.client.connect_signal("property::urgent", client.urgent.add)
|
2012-06-12 20:13:09 +02:00
|
|
|
capi.client.connect_signal("focus", client.urgent.delete)
|
|
|
|
capi.client.connect_signal("unmanage", client.urgent.delete)
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
capi.client.connect_signal("unmanage", client.floating.delete)
|
|
|
|
|
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
|
|
|
|
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
|