awful.tag: Move functions to awful.client and screen

This commit is contained in:
Emmanuel Lepage Vallee 2016-04-05 03:02:00 -04:00
parent 643e35af22
commit dd52f1ce86
21 changed files with 787 additions and 265 deletions

View File

@ -141,7 +141,7 @@ mypromptbox = {}
mylayoutbox = {}
mytaglist = {}
mytaglist.buttons = awful.util.table.join(
awful.button({ }, 1, awful.tag.viewonly),
awful.button({ }, 1, function(t) t:view_only() end),
awful.button({ modkey }, 1, function(t)
if client.focus then
client.focus:move_to_tag(t)
@ -153,8 +153,8 @@ mytaglist.buttons = awful.util.table.join(
client.focus:toggle_tag(t)
end
end),
awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
awful.button({ }, 4, function(t) awful.tag.viewnext(t.screen) end),
awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end)
)
mytasklist = {}
@ -166,8 +166,8 @@ mytasklist.buttons = awful.util.table.join(
-- Without this, the following
-- :isvisible() makes no sense
c.minimized = false
if not c:isvisible() then
awful.tag.viewonly(c.first_tag)
if not c:isvisible() and c.first_tag then
c.first_tag:view_only()
end
-- This will also un-minimize
-- the client, if needed
@ -371,9 +371,9 @@ for i = 1, 9 do
awful.key({ modkey }, "#" .. i + 9,
function ()
local screen = awful.screen.focused()
local tag = awful.tag.gettags(screen)[i]
local tag = screen.tags[i]
if tag then
awful.tag.viewonly(tag)
tag:view_only()
end
end,
{description = "view tag #"..i, group = "tag"}),
@ -381,7 +381,7 @@ for i = 1, 9 do
awful.key({ modkey, "Control" }, "#" .. i + 9,
function ()
local screen = awful.screen.focused()
local tag = awful.tag.gettags(screen)[i]
local tag = screen.tags[i]
if tag then
awful.tag.viewtoggle(tag)
end
@ -391,7 +391,7 @@ for i = 1, 9 do
awful.key({ modkey, "Shift" }, "#" .. i + 9,
function ()
if client.focus then
local tag = awful.tag.gettags(client.focus.screen)[i]
local tag = client.focus.screen.tags[i]
if tag then
client.focus:move_to_tag(tag)
end
@ -402,7 +402,7 @@ for i = 1, 9 do
awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
function ()
if client.focus then
local tag = awful.tag.gettags(client.focus.screen)[i]
local tag = client.focus.screen.tags[i]
if tag then
client.focus:toggle_tag(tag)
end

View File

@ -12,7 +12,6 @@
local client = client
local aclient = require("awful.client")
local atag = require("awful.tag")
local timer = require("gears.timer")
--- Give focus when clients appear/disappear.
@ -39,7 +38,7 @@ end
--
-- @param tag A tag object
local function check_focus_tag(t)
local s = atag.getscreen(t)
local s = t.screen
if not s then return end
s = screen[s]
check_focus({ screen = s })

View File

@ -11,7 +11,6 @@
local util = require("awful.util")
local spawn = require("awful.spawn")
local object = require("gears.object")
local tag = require("awful.tag")
local pairs = pairs
local type = type
local ipairs = ipairs
@ -102,7 +101,7 @@ function client.object.jump_to(self, merge)
t.selected = true
end
elseif t then
tag.viewonly(t)
t:view_only()
end
end
@ -111,7 +110,8 @@ end
--- Get visible clients from a screen.
--
-- @function awful.client.visible
-- @deprecated awful.client.visible
-- @see screen.clients
-- @tparam[opt] integer|screen s The screen, or nil for all screens.
-- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
-- @treturn table A table with all visible clients.
@ -128,7 +128,8 @@ end
--- Get visible and tiled clients
--
-- @function awful.client.tiled
-- @deprecated awful.client.tiled
-- @see screen.tiled_clients
-- @tparam integer|screen s The screen, or nil for all screens.
-- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
-- @treturn table A table with all visible and tiled clients.
@ -230,7 +231,7 @@ function client.swap.global_bydirection(dir, sel)
-- swapping to a nonempty screen
elseif get_screen(sel.screen) ~= get_screen(c.screen) and sel ~= c then
sel:move_to_screen(c.screen)
sel:move_to_screen(scr)
c:move_to_screen(scr)
end
screen.focus(sel.screen)
@ -313,20 +314,20 @@ end
-- @param w The relative width.
-- @param h The relative height.
-- @client[opt] c The client, otherwise focused one is used.
-- @see client.move_resize
-- @see client.relative_move
function client.moveresize(x, y, w, h, c)
util.deprecate "Use c:move_resize(x, y, w, h) instead of awful.client.moveresize"
client.object.move_resize(c or capi.client.focus, x, y, w, h)
util.deprecate "Use c:relative_move(x, y, w, h) instead of awful.client.moveresize"
client.object.relative_move(c or capi.client.focus, x, y, w, h)
end
--- Move/resize a client relative to current coordinates.
-- @function client.move_resize
-- @function client.relative_move
-- @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.
function client.object.move_resize(self, x, y, w, h)
function client.object.relative_move(self, x, y, w, h)
local geometry = self:geometry()
geometry['x'] = geometry['x'] + x
geometry['y'] = geometry['y'] + y
@ -349,7 +350,7 @@ end
-- @function client.move_to_tag
-- @tparam tag target The tag to move the client to.
function client.object.move_to_tag(self, target)
local s = tag.getscreen(target)
local s = target.screen
if self and s then
if self == capi.client.focus then
self:emit_signal("request::activate", "client.movetotag", {raise=true})
@ -375,7 +376,7 @@ end
-- @tparam tag target The tag to move the client to.
function client.object.toggle_tag(self, target)
-- Check that tag and client screen are identical
if self and get_screen(self.screen) == get_screen(tag.getscreen(target)) then
if self and get_screen(self.screen) == get_screen(target.screen) then
local tags = self:tags()
local index = nil;
for i, v in ipairs(tags) do
@ -435,6 +436,31 @@ function client.object.move_to_screen(self, s)
end
end
--- Tag a client with the set of current tags.
-- @function client.to_selected_tags
-- @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
if #tags == 0 then
tags = self.screen.selected_tags
end
if #tags == 0 then
tags = self.screen.tags
end
if #tags ~= 0 then
self:tags(tags)
end
end
--- If a client is marked or not.
--
-- **Signal:**
@ -678,7 +704,7 @@ end
function client.restore(s)
s = s or screen.focused()
local cls = capi.client.get(s)
local tags = tag.selectedlist(s)
local tags = s.selected_tags
for _, c in pairs(cls) do
local ctags = c:tags()
if c.minimized then
@ -739,8 +765,8 @@ function client.idx(c)
end
end
local t = tag.selected(c.screen)
local nmaster = tag.getnmaster(t)
local t = c.screen.selected_tag
local nmaster = t.nmaster
-- This will happen for floating or maximized clients
if not idx then return nil end
@ -755,7 +781,7 @@ function client.idx(c)
-- 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)
local ncol = t.ncol
-- minimum number of clients per column
local percol = math.floor(nother / ncol)
-- number of columns with an extra client
@ -793,10 +819,10 @@ function client.setwfact(wfact, c)
if not w then return end
local t = tag.selected(c.screen)
local t = c.screen.selected_tag
-- 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 data = t.windowfact or {}
local colfact = data[w.col]
local need_normalize = colfact ~= nil
@ -841,11 +867,11 @@ function client.incwfact(add, c)
c = c or capi.client.focus
if not c then return end
local t = tag.selected(c.screen)
local t = c.screen.selected_tag
local w = client.idx(c)
local data = tag.getproperty(t, "windowfact") or {}
local data = t.windowfact or {}
local colfact = data[w.col] or {}
local curr = colfact[w.idx] or 1
colfact[w.idx] = curr + add

View File

@ -12,7 +12,6 @@ local client = client
local screen = screen
local ipairs = ipairs
local math = math
local atag = require("awful.tag")
local aclient = require("awful.client")
local ewmh = {}
@ -182,7 +181,7 @@ function ewmh.tag(c, t)
if not t then
c.sticky = true
else
c.screen = atag.getscreen(t)
c.screen = t.screen
c:tags({ t })
end
end

View File

@ -20,6 +20,7 @@ local capi = {
}
local tag = require("awful.tag")
local client = require("awful.client")
local ascreen = require("awful.screen")
local timer = require("gears.timer")
local function get_screen(s)
@ -63,7 +64,8 @@ local delayed_arrange = {}
-- @param screen The screen.
-- @return The layout function.
function layout.get(screen)
local t = tag.selected(screen)
screen = screen or capi.mouse.screen
local t = get_screen(screen).selected_tag
return tag.getproperty(t, "layout") or layout.suit.floating
end
@ -77,8 +79,8 @@ function layout.inc(i, s, layouts)
-- this was changed so that 'layouts' can be an optional parameter
layouts, i, s = i, s, layouts
end
s = get_screen(s)
local t = tag.selected(s)
s = get_screen(s or ascreen.focused())
local t = s.selected_tag
layouts = layouts or layout.layouts
if t then
local curlayout = layout.get(s)
@ -108,10 +110,10 @@ end
--- Set the layout function of the current tag.
-- @param _layout Layout name.
-- @param t The tag to modify, if null tag.selected() is used.
-- @tparam[opt=mouse.screen.selected_tag] tag t The tag to modify.
function layout.set(_layout, t)
t = t or tag.selected()
tag.setproperty(t, "layout", _layout)
t = t or capi.mouse.screen.selected_tag
t.layout = _layout
end
--- Get the layout parameters used for the screen
@ -129,13 +131,13 @@ end
-- "geometries" table with client as keys and geometry as value
function layout.parameters(t, screen)
screen = get_screen(screen)
t = t or tag.selected(screen)
t = t or screen.selected_tag
screen = get_screen(t and tag.getscreen(t) or 1)
screen = get_screen(t and t.screen or 1)
local p = {}
local useless_gap = t and tag.getgap(t, #client.tiled(screen)) or 0
local useless_gap = t and t.gap or 0
p.workarea = screen:get_bounding_geometry {
honor_padding = true,
@ -212,7 +214,7 @@ capi.client.connect_signal("property::screen", function(c, old_screen)
end)
local function arrange_tag(t)
layout.arrange(tag.getscreen(t))
layout.arrange(t.screen)
end
capi.screen.add_signal("arrange")

View File

@ -11,6 +11,7 @@
-- Grab environment we need
local ipairs = ipairs
local math = math
local capi = {screen = screen}
local tag = require("awful.tag")
--- Actually arrange clients of p.clients for corner layout
@ -19,7 +20,7 @@ local tag = require("awful.tag")
-- @param orientation String indicating in which corner is the master window.
-- Available values are : NE, NW, SW, SE
local function do_corner(p, orientation)
local t = p.tag or tag.selected(p.screen)
local t = p.tag or capi.screen[p.screen].selected_tag
local wa = p.workarea
local cls = p.clients
@ -29,9 +30,9 @@ local function do_corner(p, orientation)
local column = {}
local row = {}
-- Use the nmaster field of the tag in a cheaty way
local row_privileged = ((tag.getnmaster(tag.selected(cls[1].screen)) % 2) == 0)
local row_privileged = ((cls[1].screen.selected_tag.nmaster % 2) == 0)
local master_factor = tag.getmwfact(tag.selected(cls[1].screen))
local master_factor = cls[1].screen.selected_tag.mwfact
master.width = master_factor * wa.width
master.height = master_factor * wa.height

View File

@ -10,7 +10,6 @@
-- Grab environment we need
local ipairs = ipairs
local math = math
local tag = require("awful.tag")
local capi =
{
client = client,
@ -40,7 +39,7 @@ function magnifier.mouse_resize_handler(c, corner, x, y)
-- New master width factor
local mwfact = dist / maxdist_pow
tag.setmwfact(math.min(math.max(0.01, mwfact), 0.99), tag.selected(c.screen))
c.screen.selected_tag.mwfact = math.min(math.max(0.01, mwfact), 0.99)
return true
end
end
@ -53,8 +52,8 @@ function magnifier.arrange(p)
local area = p.workarea
local cls = p.clients
local focus = p.focus or capi.client.focus
local t = p.tag or tag.selected(p.screen)
local mwfact = tag.getmwfact(t)
local t = p.tag or capi.screen[p.screen].selected_tag
local mwfact = t.mwfact
local fidx
-- Check that the focused window is on the right screen

View File

@ -29,7 +29,7 @@ tile.resize_jump_to_corner = true
local function mouse_resize_handler(c, _, _, _, orientation)
orientation = orientation or "tile"
local wa = capi.screen[c.screen].workarea
local mwfact = tag.getmwfact()
local mwfact = c.screen.selected_tag.mwfact
local cursor
local g = c:geometry()
local offset = 0
@ -126,7 +126,7 @@ local function mouse_resize_handler(c, _, _, _, orientation)
wfact = wfact_x
end
tag.setmwfact(math.min(math.max(new_mwfact, 0.01), 0.99), tag.selected(c.screen))
c.screen.selected_tag.mwfact = math.min(math.max(new_mwfact, 0.01), 0.99)
client.setwfact(math.min(math.max(wfact,0.01), 0.99), c)
return true
end
@ -195,7 +195,7 @@ local function tile_group(gs, cls, wa, orientation, fact, group)
end
local function do_tile(param, orientation)
local t = param.tag or tag.selected(param.screen)
local t = param.tag or capi.screen[param.screen].selected_tag
orientation = orientation or "right"
-- This handles all different orientations.
@ -208,12 +208,12 @@ local function do_tile(param, orientation)
local gs = param.geometries
local cls = param.clients
local nmaster = math.min(tag.getnmaster(t), #cls)
local nmaster = math.min(t.nmaster, #cls)
local nother = math.max(#cls - nmaster,0)
local mwfact = tag.getmwfact(t)
local mwfact = t.mwfact
local wa = param.workarea
local ncol = tag.getncol(t)
local ncol = t.ncol
local data = tag.getdata(t).windowfact
@ -229,7 +229,7 @@ local function do_tile(param, orientation)
place_master = false
end
local grow_master = tag.getmfpol(t) == "expand"
local grow_master = t.master_fill_policy == "expand"
-- this was easier than writing functions because there is a lot of data we need
for _ = 1,2 do
if place_master and nmaster > 0 then

View File

@ -609,7 +609,7 @@ end
-- terms[i] =
-- {c.name,
-- function()
-- awful.tag.viewonly(c.first_tag)
-- c.first_tag:view_only()
-- client.focus = c
-- end,
-- c.icon

View File

@ -229,8 +229,8 @@ function mouse.client.dragtotag.border(c)
capi.mouse.coords({ x = wa.x + 1 })
end
if not button_down then
local tags = tag.gettags(c.screen)
local t = tag.selected()
local tags = c.screen.tags
local t = c.screen.selected_tag
local idx
for i, v in ipairs(tags) do
if v == t then

View File

@ -13,7 +13,6 @@ local table = table
local type = type
local ipairs = ipairs
local pairs = pairs
local atag = require("awful.tag")
local rules = {}
@ -199,10 +198,10 @@ function rules.execute(c, props, callbacks)
value = value(c)
end
if property == "tag" then
c.screen = atag.getscreen(value)
c.screen = value.screen
c:tags({ value })
elseif property == "switchtotag" and value and props.tag then
atag.viewonly(props.tag)
props.tag:view_only()
elseif property == "height" or property == "width" or
property == "x" or property == "y" then
local geo = c:geometry();

View File

@ -306,8 +306,13 @@ end
-- Minimized and unmanaged clients are not included in this list as they are
-- technically not on the screen.
--
-- The clients on tags currently not visible are not part of this list.
--
-- @property clients
-- @param table The clients list, ordered top to bottom
-- @see all_clients
-- @see hidden_clients
-- @see client.get
function screen.object.get_clients(s)
local cls = capi.client.get(s, true)
@ -322,6 +327,44 @@ end
function screen.object.set_clients() end
--- Get the list of the clients assigned to the screen but not currently
-- visible.
--
-- This include minimized clients and clients on hidden tags.
--
-- @property hidden_clients
-- @param table The clients list, ordered top to bottom
-- @see clients
-- @see all_clients
-- @see client.get
function screen.object.get_hidden_clients(s)
local cls = capi.client.get(s, true)
local vcls = {}
for _, c in pairs(cls) do
if not c:isvisible() then
table.insert(vcls, c)
end
end
return vcls
end
function screen.object.set_hidden_clients() end
--- Get all clients assigned to the screen.
--
-- @property all_clients
-- @param table The clients list, ordered top to bottom
-- @see clients
-- @see hidden_clients
-- @see client.get
function screen.object.get_all_clients(s)
return capi.client.get(s, true)
end
function screen.object.set_all_clients() end
--- Get the list of the screen tiled clients.
--
-- Same as s.clients, but excluding:
@ -368,6 +411,71 @@ function screen.disconnect_for_each_screen(func)
capi.screen.disconnect_signal("added", func)
end
--- A list of all tags on the screen.
--
-- This property is read only, use `tag.screen`, `awful.tag.add`, `awful.tag.new`
-- or `t:delete()` to alter this list.
--
-- @property tags
-- @param table
-- @treturn table A table with all available tags
function screen.object.get_tags(s, unordered)
local tags = {}
for _, t in ipairs(root.tags()) do
if get_screen(t.screen) == s then
table.insert(tags, t)
end
end
-- Avoid infinite loop, + save some time
if not unordered then
table.sort(tags, function(a, b)
return (a.index or 9999) < (b.index or 9999)
end)
end
return tags
end
function screen.object.set_tags() end
--- A list of all selected tags on the screen.
-- @property selected_tags
-- @param table
-- @treturn table A table with all selected tags.
-- @see tag.selected
-- @see client.to_selected_tags
function screen.object.get_selected_tags(s)
local tags = screen.object.get_tags(s, true)
local vtags = {}
for _, t in pairs(tags) do
if t.selected then
vtags[#vtags + 1] = t
end
end
return vtags
end
function screen.object.set_selected_tags() end
--- The first selected tag.
-- @property selected_tag
-- @param table
-- @treturn ?tag The first selected tag or nil
-- @see tag.selected
-- @see selected_tags
function screen.object.get_selected_tag(s)
return screen.object.get_selected_tags(s)[1]
end
function screen.object.set_selected_tag() end
--- When the tag history changed.
-- @signal tag::history::update

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ local function update(w, screen)
end
local function update_from_tag(t)
local screen = get_screen(tag.getscreen(t))
local screen = get_screen(t.screen)
local w = boxes[screen]
if w then
update(w, screen)

View File

@ -111,8 +111,8 @@ function taglist.taglist_label(t, args)
text = text .. "</span>"
end
if not taglist_disable_icon then
if tag.geticon(t) then
icon = surface.load(tag.geticon(t))
if t.icon then
icon = surface.load(t.icon)
end
end
@ -121,7 +121,7 @@ end
local function taglist_update(s, w, buttons, filter, data, style, update_function)
local tags = {}
for _, t in ipairs(tag.gettags(s)) do
for _, t in ipairs(s.tags) do
if not tag.getproperty(t, "hide") and filter(t) then
table.insert(tags, t)
end
@ -185,7 +185,7 @@ function taglist.new(screen, filter, buttons, style, update_function, base_widge
end
end
local uc = function (c) return u(c.screen) end
local ut = function (t) return u(tag.getscreen(t)) end
local ut = function (t) return u(t.screen) end
capi.client.connect_signal("focus", uc)
capi.client.connect_signal("unfocus", uc)
tag.attached_connect_signal(nil, "property::selected", ut)

View File

@ -276,7 +276,7 @@ function tasklist.filter.currenttags(c, screen)
if get_screen(c.screen) ~= screen then return false end
-- Include sticky client too
if c.sticky then return true end
local tags = tag.gettags(screen)
local tags = screen.tags
for _, t in ipairs(tags) do
if t.selected then
local ctags = c:tags()
@ -302,7 +302,7 @@ function tasklist.filter.minimizedcurrenttags(c, screen)
if not c.minimized then return false end
-- Include sticky client
if c.sticky then return true end
local tags = tag.gettags(screen)
local tags = screen.tags
for _, t in ipairs(tags) do
-- Select only minimized clients
if t.selected then

View File

@ -8,7 +8,7 @@ local function _shim_fake_class()
local meta = {
__index = function()end,
__new_index = function()end,
__newindex = function()end,
}
obj._connect_signal = obj.connect_signal
@ -28,7 +28,7 @@ local function _shim_fake_class()
end
function obj.set_newindex_miss_handler(handler)
meta.__new_index = handler
meta.__newindex = handler
end
function obj.emit_signal(name, c, ...)

View File

@ -2,7 +2,7 @@ local gears_obj = require("gears.object")
local clients = {}
local client = awesome._shim_fake_class()
local client, meta = awesome._shim_fake_class()
local function add_signals(c)
c:add_signal("property::width")
@ -119,7 +119,10 @@ function client.gen_fake(args)
client.emit_signal("manage", ret)
assert(not args.screen or (args.screen == ret.screen))
return ret
return setmetatable(ret, {
__index = function(...) return meta.__index(...) end,
__newindex = function(...) return meta.__newindex(...) end
})
end
function client.get(s)

View File

@ -8,6 +8,7 @@ local function create_screen(args)
local s = gears_obj()
s:add_signal("property::workarea")
s:add_signal("property::index")
s:add_signal("padding")
-- Copy the geo in case the args are mutated
@ -46,7 +47,7 @@ local function create_screen(args)
return meta.__index(_, key)
end
end,
__new_index = function(...) return meta.__new_index(...) end
__newindex = function(...) return meta.__newindex(...) end
})
end

View File

@ -35,7 +35,7 @@ local function new_tag(_, args)
return setmetatable(ret, {
__index = function(...) return meta.__index(...) end,
__new_index = function(...) return meta.__new_index(...) end
__newindex = function(...) return meta.__newindex(...) end
})
end

View File

@ -32,7 +32,7 @@ local steps = {
if count == 1 then -- Setup.
urgent_cb_done = false
-- Select first tag.
awful.tag.viewonly(tags[awful.screen.focused()][1])
tags[awful.screen.focused()][1]:view_only()
runner.add_to_default_rules({ rule = { class = "XTerm" },
properties = { tag = tags[awful.screen.focused()][2], focus = true } })
@ -72,7 +72,7 @@ local steps = {
urgent_cb_done = false
-- Select first tag.
awful.tag.viewonly(tags[awful.screen.focused()][1])
tags[awful.screen.focused()][1]:view_only()
runner.add_to_default_rules({ rule = { class = "XTerm" },
properties = { tag = tags[awful.screen.focused()][2], focus = true, switchtotag = true }})