awful: comments some functions

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-20 09:15:20 +02:00
parent 46ead6ea3f
commit 1530486e9d
1 changed files with 116 additions and 85 deletions

View File

@ -34,8 +34,6 @@ local io = io
-- Reset env -- Reset env
setfenv(1, P) setfenv(1, P)
-- Hook functions, wrappers around awesome's hooks. functions so we
-- can easily add multiple functions per hook.
P.hooks = {} P.hooks = {}
P.myhooks = {} P.myhooks = {}
P.menu = {} P.menu = {}
@ -45,71 +43,91 @@ P.completion = {}
P.client = {} P.client = {}
P.tag = {} P.tag = {}
-- Create a new userhook (for external libs) --- Create a new userhook (for external libs).
-- @param name Hook name.
local function userhook_create(name) local function userhook_create(name)
P.myhooks[name] = {} P.myhooks[name] = {}
P.hooks[name] = function (f) P.hooks[name] = function (f)
table.insert(P.myhooks[name], {callback = f}) table.insert(P.myhooks[name], { callback = f })
end end
end end
-- Call a created userhook (for external libs --- Call a created userhook (for external libs).
-- @param name Hook name.
local function userhook_call(name, args) local function userhook_call(name, args)
for i,o in pairs(P.myhooks[name]) do for i, o in pairs(P.myhooks[name]) do
P.myhooks[name][i]['callback'](unpack(args)) P.myhooks[name][i]['callback'](unpack(args))
end end
end end
-- Function to the good value in table, cycling --- Make i cycle.
local function array_boundandcycle(t, i) -- @param t A length.
if i > #t then -- @param i An absolute index to fit into #t.
i = 1 -- @return The object at new index.
elseif i < 1 then local function cycle(t, i)
i = #t while i > t do i = i - t end
end while i < 1 do i = i + t end
return i return i
end end
-- Function to get a client by its relative index: --- Get a client by its relative index to the focused window.
-- set i to 1 to get next, -1 to get previous. -- @usage Set i to 1 to get next, -1 to get previous.
function P.client.next(i) -- @param i The index.
-- Get all visible clients -- @param c Optional client.
local cls = client.visible_get(mouse.screen_get()) -- @return A client, or nil if no client is available.
function P.client.next(i, c)
-- Get currently focused client -- Get currently focused client
local sel = client.focus_get() local sel = c or client.focus_get()
if not sel then return end if sel then
-- Get all visible clients
local cls = client.visible_get(sel:screen_get())
-- Loop upon each client -- Loop upon each client
for idx, c in ipairs(cls) do for idx, c in ipairs(cls) do
if c == sel then if c == sel then
return cls[array_boundandcycle(cls, idx + i)] -- Cycle
return cls[cycle(#cls, idx +i)]
end
end end
end end
end end
-- Focus a client by its relative index. --- Focus a client by its relative index.
function P.client.focus(i) -- @param i The index.
local c = P.client.next(i) -- @param c Optional client.
if c then function P.client.focus(i, c)
c:focus_set() local target = P.client.next(i, c)
if target then
target:focus_set()
end end
end end
-- Swap a client by its relative index. --- Swap a client by its relative index.
function P.client.swap(i) -- @param i The index.
local c = P.client.next(i) -- @param c Optional client, otherwise focused one is used.
local sel = client.focus_get() function P.client.swap(i, c)
if c and sel then local sel = c or client.focus_get()
sel:swap(c) local target = P.client.next(i, sel)
if target then
target:swap(c)
end end
end end
function P.client.master() --- Get the master window
return client.visible_get(mouse.screen_get())[1] -- @param screen Optional screen number, otherwise screen mouse is used.
-- @return The master window.
function P.client.master(screen)
local s = screen or mouse.screen_get()
return client.visible_get(screen)[1]
end end
-- Move/resize a client relativ to current coordinates. --- Move/resize a client relative to current coordinates.
function P.client.moveresize(x, y, w, h) -- @param x The relative x coordinate.
local sel = client.focus_get() -- @param y The relative y coordinate.
-- @param w The relative width.
-- @param h The relative height.
-- @param c The optional client, otherwise focused one is used.
function P.client.moveresize(x, y, w, h, c)
local sel = c or client.focus_get()
local coords = sel:coords_get() local coords = sel:coords_get()
coords['x'] = coords['x'] + x coords['x'] = coords['x'] + x
coords['y'] = coords['y'] + y coords['y'] = coords['y'] + y
@ -118,6 +136,8 @@ function P.client.moveresize(x, y, w, h)
sel:coords_set(coords) sel:coords_set(coords)
end end
--- Give the focus to a screen, and move pointer.
-- @param Screen number.
function P.screen.focus(i) function P.screen.focus(i)
local sel = client.focus_get() local sel = client.focus_get()
local s local s
@ -126,132 +146,143 @@ function P.screen.focus(i)
else else
s = mouse.screen_get() s = mouse.screen_get()
end end
local count = screen.count() screen.focus(cycle(screen.count(), s))
s = s + i
if s < 1 then
s = count
elseif s > count then
s = 1
end
screen.focus(s)
-- Move the mouse on the screen -- Move the mouse on the screen
local screen_coords = screen.coords_get(s) local screen_coords = screen.coords_get(s)
mouse.coords_set(screen_coords['x'], screen_coords['y']) mouse.coords_set(screen_coords['x'], screen_coords['y'])
end end
-- Return a table with all visible tags --- Return a table with all visible tags
-- @param s Screen number.
-- @return A table with all selected tags.
function P.tag.selectedlist(s) function P.tag.selectedlist(s)
local idx = 1
local screen = s or mouse.screen_get() local screen = s or mouse.screen_get()
local tags = tag.geti(screen) local tags = tag.geti(screen)
local vtags = {} local vtags = {}
for i, t in pairs(tags) do for i, t in pairs(tags) do
if t:isselected() then if t:isselected() then
vtags[idx] = t vtags[#vtags + 1] = t
idx = idx + 1
end end
end end
return vtags return vtags
end end
-- Return only the first element of all visible tags, --- Return only the first visible tag.
-- so that's the first visible tags. -- @param s Screen number.
function P.tag.selected(s) function P.tag.selected(s)
return P.tag.selectedlist(s)[1] return P.tag.selectedlist(s)[1]
end end
-- Set master width factor --- Set master width factor.
function P.tag.setmwfact(i) -- @param mwfact Master width factor.
function P.tag.setmwfact(mwfact)
local t = P.tag.selected() local t = P.tag.selected()
if t then if t then
t:mwfact_set(i) t:mwfact_set(mwfact)
end end
end end
-- Increase master width factor --- Increase master width factor.
function P.tag.incmwfact(i) -- @param add Value to add to master width factor.
function P.tag.incmwfact(add)
local t = P.tag.selected() local t = P.tag.selected()
if t then if t then
t:mwfact_set(t:mwfact_get() + i) t:mwfact_set(t:mwfact_get() + add)
end end
end end
-- Set number of master windows --- Set the number of master windows.
function P.tag.setnmaster(i) -- @param nmaster The number of master windows.
function P.tag.setnmaster(nmaster)
local t = P.tag.selected() local t = P.tag.selected()
if t then if t then
t:nmaster_set(i) t:nmaster_set(nmaster)
end end
end end
-- Increase number of master windows --- Increase the number of master windows.
function P.tag.incnmaster(i) -- @param add Value to add to number of master windows.
function P.tag.incnmaster(add)
local t = P.tag.selected() local t = P.tag.selected()
if t then if t then
t:nmaster_set(t:nmaster_get() + i) t:nmaster_set(t:nmaster_get() + add)
end end
end end
-- Set number of column windows --- Set number of column windows.
function P.tag.setncol(i) -- @param ncol The number of column.
function P.tag.setncol(ncol)
local t = P.tag.selected() local t = P.tag.selected()
if t then if t then
t:ncol_set(i) t:ncol_set(ncol)
end end
end end
-- Increase number of column windows --- Increase number of column windows.
function P.tag.incncol(i) -- @param add Value to add to number of column windows.
function P.tag.incncol(add)
local t = P.tag.selected() local t = P.tag.selected()
if t then if t then
t:ncol_set(t:ncol_get() + i) t:ncol_set(t:ncol_get() + add)
end end
end end
-- View no tag --- View no tag.
function P.tag.viewnone() -- @param Optional screen number.
local tags = tag.get(mouse.screen_get()) function P.tag.viewnone(screen)
local tags = tag.get(screen or mouse.screen_get())
for i, t in pairs(tags) do for i, t in pairs(tags) do
t:view(false) t:view(false)
end end
end end
function P.tag.viewidx(r) --- View a tag by its index.
local tags = tag.geti(mouse.screen_get()) -- @param i The relative index to see.
-- @param screen Optional screen number.
function P.tag.viewidx(i, screen)
local tags = tag.geti(screen or mouse.screen_get())
local sel = P.tag.selected() local sel = P.tag.selected()
P.tag.viewnone() P.tag.viewnone()
for i, t in ipairs(tags) do for k, t in ipairs(tags) do
if t == sel then if t == sel then
tags[array_boundandcycle(tags, i + r)]:view(true) tags[cycle(#tags, k + i)]:view(true)
end end
end end
end end
-- View next tag --- View next tag. This is the same as tag.viewidx(1).
function P.tag.viewnext() function P.tag.viewnext()
return P.tag.viewidx(1) return P.tag.viewidx(1)
end end
-- View previous tag --- View previous tag. This is the same a tag.viewidx(-1).
function P.tag.viewprev() function P.tag.viewprev()
return P.tag.viewidx(-1) return P.tag.viewidx(-1)
end end
--- View only a tag.
-- @param t The tag object.
function P.tag.viewonly(t) function P.tag.viewonly(t)
P.tag.viewnone() P.tag.viewnone()
t:view(true) t:view(true)
end end
function P.tag.viewmore(tags) --- View only a set of tags.
P.tag.viewnone() -- @param tags A table with tags to view only.
-- @param screen Optional screen number of the tags.
function P.tag.viewmore(tags, screen)
P.tag.viewnone(screen)
for i, t in pairs(tags) do for i, t in pairs(tags) do
t:view(true) t:view(true)
end end
end end
--- Move a client to a tag.
-- @param target The tag to move the client to.
-- @para c Optional client to move, otherwise the focused one is used.
function P.client.movetotag(target, c) function P.client.movetotag(target, c)
local sel = c or client.focus_get(); local sel = c or client.focus_get();
local tags = tag.get(mouse.screen_get()) local tags = tag.get(c:screen_get())
for k, t in pairs(tags) do for k, t in pairs(tags) do
sel:tag(t, false) sel:tag(t, false)
end end