From 61ff9ce2b7a72fb3c8c70bda7a7384821ae537c9 Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Tue, 12 Jun 2012 20:13:09 +0200 Subject: [PATCH] Ported awful to lua 5.2 Tested with lua 5.1: all good Signed-off-by: Arvydas Sidorenko --- awesomerc.lua.in | 4 +- lib/awful/autofocus.lua.in | 2 +- lib/awful/button.lua.in | 15 +- lib/awful/client.lua.in | 243 ++++++++--------- lib/awful/completion.lua.in | 11 +- lib/awful/dbus.lua.in | 2 +- lib/awful/ewmh.lua.in | 2 +- lib/awful/icccm.lua.in | 4 +- lib/awful/init.lua.in | 47 ++-- lib/awful/key.lua.in | 21 +- lib/awful/keygrabber.lua.in | 11 +- lib/awful/menu.lua.in | 365 +++++++++++++------------- lib/awful/placement.lua.in | 16 +- lib/awful/prompt.lua.in | 11 +- lib/awful/remote.lua.in | 2 +- lib/awful/rules.lua.in | 21 +- lib/awful/screen.lua.in | 27 +- lib/awful/startup_notification.lua.in | 4 +- lib/awful/tag.lua.in | 215 +++++++-------- lib/awful/tooltip.lua.in | 9 +- lib/awful/util.lua.in | 69 ++--- lib/awful/wibox.lua.in | 35 +-- lib/menubar/init.lua.in | 2 +- lib/wibox/layout/mirror.lua.in | 2 +- lib/wibox/layout/rotate.lua.in | 2 +- 25 files changed, 599 insertions(+), 543 deletions(-) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index a2044bce..2385f947 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -1,7 +1,7 @@ -- Standard awesome library -require("awful") +local awful = require("awful") +awful.rules = require("awful.rules") require("awful.autofocus") -require("awful.rules") -- Widget and layout library local wibox = require("wibox") -- Theme handling library diff --git a/lib/awful/autofocus.lua.in b/lib/awful/autofocus.lua.in index e551a633..f697ff61 100644 --- a/lib/awful/autofocus.lua.in +++ b/lib/awful/autofocus.lua.in @@ -11,7 +11,7 @@ local atag = require("awful.tag") --- When loaded, this module makes sure that there's always a client that will have focus -- on event such as tag switching, client unmanaging, etc. -module("awful.autofocus") +-- awful.autofocus -- Give focus when clients appear/disappear. -- @param obj An object that should have a .screen property. diff --git a/lib/awful/button.lua.in b/lib/awful/button.lua.in index 049d38c0..1d3b31c3 100644 --- a/lib/awful/button.lua.in +++ b/lib/awful/button.lua.in @@ -11,7 +11,8 @@ local capi = { button = button } local util = require("awful.util") --- Create easily new buttons objects ignoring certain modifiers. -module("awful.button") +-- awful.button +local button = { mt = {} } --- Modifiers to ignore. -- By default this is initialized as { "Lock", "Mod2" } @@ -19,7 +20,7 @@ module("awful.button") -- when pressing keys. -- @name ignore_modifiers -- @class table -ignore_modifiers = { "Lock", "Mod2" } +local ignore_modifiers = { "Lock", "Mod2" } --- Create a new button to use as binding. -- This function is useful to create several buttons from one, because it will use @@ -31,12 +32,12 @@ ignore_modifiers = { "Lock", "Mod2" } -- CapsLock off. -- @see button -- @return A table with one or several button objects. -function new(mod, button, press, release) +function button.new(mod, _button, press, release) local ret = {} local subsets = util.subsets(ignore_modifiers) for _, set in ipairs(subsets) do ret[#ret + 1] = capi.button({ modifiers = util.table.join(mod, set), - button = button }) + button = _button }) if press then ret[#ret]:connect_signal("press", function(bobj, ...) press(...) end) end @@ -47,6 +48,10 @@ function new(mod, button, press, release) return ret end -setmetatable(_M, { __call = function(_, ...) return new(...) end }) +function button.mt:__call(...) + return button.new(...) +end + +return setmetatable(button, button.mt) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/client.lua.in b/lib/awful/client.lua.in index 1a86634c..35fa8f55 100644 --- a/lib/awful/client.lua.in +++ b/lib/awful/client.lua.in @@ -21,30 +21,31 @@ local capi = } --- Useful client manipulation functions. -module("awful.client") +-- awful.client +local client = {} -- Private data -data = {} -data.focus = {} -data.urgent = {} -data.marked = {} -data.properties = setmetatable({}, { __mode = 'k' }) +client.data = {} +client.data.focus = {} +client.data.urgent = {} +client.data.marked = {} +client.data.properties = setmetatable({}, { __mode = 'k' }) -- Functions -urgent = {} -focus = {} -focus.history = {} -swap = {} -floating = {} -dockable = {} -property = {} +client.urgent = {} +client.focus = {} +client.focus.history = {} +client.swap = {} +client.floating = {} +client.dockable = {} +client.property = {} --- -- Jump to the given client. Takes care of focussing the screen, the right tag, -- etc. -- @param c the client to jump to -- @param merge If true then merge tags when clients are not visible. -function jumpto(c, merge) +function client.jumpto(c, merge) local s = capi.client.focus and capi.client.focus.screen or capi.mouse.screen -- focus the screen if s ~= c.screen then @@ -68,9 +69,9 @@ end --- Get the first client that got the urgent hint. -- @return The first urgent client. -function urgent.get() - if #data.urgent > 0 then - return data.urgent[1] +function client.urgent.get() + if #client.data.urgent > 0 then + return client.data.urgent[1] else -- fallback behaviour: iterate through clients and get the first urgent local clients = capi.client.get() @@ -84,28 +85,28 @@ end --- Jump to the client that received the urgent hint first. -- @param merge If true then merge tags when clients are not visible. -function urgent.jumpto(merge) - local c = urgent.get() +function client.urgent.jumpto(merge) + local c = client.urgent.get() if c then - jumpto(c, merge) + client.jumpto(c, merge) end end --- Adds client to urgent stack. -- @param c The client object. -- @param prop The property which is updated. -function urgent.add(c, prop) +function client.urgent.add(c, prop) if type(c) == "client" and prop == "urgent" and c.urgent then - table.insert(data.urgent, c) + table.insert(client.data.urgent, c) end end --- Remove client from urgent stack. -- @param c The client object. -function urgent.delete(c) - for k, cl in ipairs(data.urgent) do +function client.urgent.delete(c) + for k, cl in ipairs(client.data.urgent) do if c == cl then - table.remove(data.urgent, k) + table.remove(client.data.urgent, k) break end end @@ -113,10 +114,10 @@ end --- Remove a client from the focus history -- @param c The client that must be removed. -function focus.history.delete(c) - for k, v in ipairs(data.focus) do +function client.focus.history.delete(c) + for k, v in ipairs(client.data.focus) do if v == c then - table.remove(data.focus, k) + table.remove(client.data.focus, k) break end end @@ -127,7 +128,7 @@ end -- not registered and cannot get focus. -- @param c A client. -- @return The same client if it's ok, nil otherwise. -function focus.filter(c) +function client.focus.filter(c) if c.type == "desktop" or c.type == "dock" or c.type == "splash" @@ -139,11 +140,11 @@ end --- Update client focus history. -- @param c The client that has been focused. -function focus.history.add(c) +function client.focus.history.add(c) -- Remove the client if its in stack - focus.history.delete(c) + client.focus.history.delete(c) -- Record the client has latest focused - table.insert(data.focus, 1, c) + table.insert(client.data.focus, 1, c) end --- Get the latest focused client for a screen in history. @@ -151,11 +152,11 @@ end -- @param idx The index: 0 will return first candidate, -- 1 will return second, etc. -- @return A client. -function focus.history.get(screen, idx) +function client.focus.history.get(screen, idx) -- When this counter is equal to idx, we return the client local counter = 0 - local vc = visible(screen) - for k, c in ipairs(data.focus) do + local vc = client.visible(screen) + for k, c in ipairs(client.data.focus) do if c.screen == screen then for j, vcc in ipairs(vc) do if vcc == c then @@ -173,7 +174,7 @@ function focus.history.get(screen, idx) -- that passes the filter. if counter == 0 then for k, v in ipairs(vc) do - if focus.filter(v) then + if client.focus.filter(v) then return v end end @@ -181,7 +182,7 @@ function focus.history.get(screen, idx) end --- Focus the previous client in history. -function focus.history.previous() +function client.focus.history.previous() local sel = capi.client.focus local s if sel then @@ -189,14 +190,14 @@ function focus.history.previous() else s = capi.mouse.screen end - local c = focus.history.get(s, 1) + local c = client.focus.history.get(s, 1) if c then capi.client.focus = c end end --- Get visible clients from a screen. -- @param screen The screen number, or nil for all screens. -- @return A table with all visible clients. -function visible(screen) +function client.visible(screen) local cls = capi.client.get(screen) local vcls = {} for k, c in pairs(cls) do @@ -210,12 +211,12 @@ end --- Get visible and tiled clients -- @param screen The screen number, or nil for all screens. -- @return A tabl with all visible and tiled clients. -function tiled(screen) - local clients = visible(screen) +function client.tiled(screen) + local clients = client.visible(screen) local tclients = {} -- Remove floating clients for k, c in pairs(clients) do - if not floating.get(c) then + if not client.floating.get(c) then table.insert(tclients, c) end end @@ -227,16 +228,16 @@ end -- @param i The index. -- @param c Optional client. -- @return A client, or nil if no client is available. -function next(i, c) +function client.next(i, c) -- Get currently focused client local sel = c or capi.client.focus if sel then -- Get all visible clients - local cls = visible(sel.screen) + local cls = client.visible(sel.screen) local fcls = {} -- Remove all non-normal clients for idx, c in ipairs(cls) do - if focus.filter(c) or c == sel then + if client.focus.filter(c) or c == sel then table.insert(fcls, c) end end @@ -307,7 +308,7 @@ local function get_client_in_direction(dir, c) local geometry = sel:geometry() local dist, dist_min local target = nil - local cls = visible(sel.screen) + local cls = client.visible(sel.screen) -- We check each client. for i, c in ipairs(cls) do @@ -332,7 +333,7 @@ end --- Focus a client by the given direction. -- @param dir The direction, can be either "up", "down", "left" or "right". -- @param c Optional client. -function focus.bydirection(dir, c) +function client.focus.bydirection(dir, c) local sel = c or capi.client.focus if sel then local target = get_client_in_direction(dir, sel) @@ -347,8 +348,8 @@ end --- Focus a client by its relative index. -- @param i The index. -- @param c Optional client. -function focus.byidx(i, c) - local target = next(i, c) +function client.focus.byidx(i, c) + local target = client.next(i, c) if target then capi.client.focus = target end @@ -357,7 +358,7 @@ end --- Swap a client with another client in the given direction -- @param dir The direction, can be either "up", "down", "left" or "right". -- @param c Optional client. -function swap.bydirection(dir, c) +function client.swap.bydirection(dir, c) local sel = c or capi.client.focus if sel then local target = get_client_in_direction(dir, sel) @@ -372,7 +373,7 @@ end --- Swap a client by its relative index. -- @param i The index. -- @param c Optional client, otherwise focused one is used. -function swap.byidx(i, c) +function client.swap.byidx(i, c) local sel = c or capi.client.focus local target = next(i, sel) if target then @@ -383,9 +384,9 @@ end --- Cycle clients. -- @param clockwise True to cycle clients clockwise. -- @param screen Optional screen where to cycle clients. -function cycle(clockwise, screen) +function client.cycle(clockwise, screen) local screen = screen or capi.mouse.screen - local cls = visible(screen) + local cls = client.visible(screen) -- We can't rotate without at least 2 clients, buddy. if #cls >= 2 then local c = table.remove(cls, 1) @@ -404,14 +405,14 @@ end --- Get the master window. -- @param screen Optional screen number, otherwise screen mouse is used. -- @return The master window. -function getmaster(screen) +function client.getmaster(screen) local s = screen or capi.mouse.screen - return visible(s)[1] + return client.visible(s)[1] end --- Set the client as slave: put it at the end of other windows. -- @param c The window to set as slave. -function setslave(c) +function client.setslave(c) local cls = capi.client.get(c.screen) for k, v in pairs(cls) do c:swap(v) @@ -424,7 +425,7 @@ end -- @param w The relative width. -- @param h The relative height. -- @param c The optional client, otherwise focused one is used. -function moveresize(x, y, w, h, c) +function client.moveresize(x, y, w, h, c) local sel = c or capi.client.focus local geometry = sel:geometry() geometry['x'] = geometry['x'] + x @@ -437,7 +438,7 @@ end --- Move a client to a tag. -- @param target The tag to move the client to. -- @param c Optional client to move, otherwise the focused one is used. -function movetotag(target, c) +function client.movetotag(target, c) local sel = c or capi.client.focus if sel and target.screen then -- Set client on the same screen as the tag. @@ -449,7 +450,7 @@ end --- Toggle a tag on a client. -- @param target The tag to toggle. -- @param c Optional client to toggle, otherwise the focused one is used. -function toggletag(target, c) +function client.toggletag(target, c) local sel = c or capi.client.focus -- Check that tag and client screen are identical if sel and sel.screen == target.screen then @@ -475,7 +476,7 @@ end --- Move a client to a screen. Default is next screen, cycling. -- @param c The client to move. -- @param s The screen number, default to current + 1. -function movetoscreen(c, s) +function client.movetoscreen(c, s) local sel = c or capi.client.focus if sel then local sc = capi.screen.count() @@ -491,16 +492,16 @@ end --- Mark a client, and then call 'marked' hook. -- @param c The client to mark, the focused one if not specified. -- @return True if the client has been marked. False if the client was already marked. -function mark(c) +function client.mark(c) local cl = c or capi.client.focus if cl then - for k, v in pairs(data.marked) do + for k, v in pairs(client.data.marked) do if cl == v then return false end end - table.insert(data.marked, cl) + table.insert(client.data.marked, cl) -- Call callback cl:emit_signal("marked") @@ -511,12 +512,12 @@ end --- Unmark a client and then call 'unmarked' hook. -- @param c The client to unmark, or the focused one if not specified. -- @return True if the client has been unmarked. False if the client was not marked. -function unmark(c) +function client.unmark(c) local cl = c or capi.client.focus - for k, v in pairs(data.marked) do + for k, v in pairs(client.data.marked) do if cl == v then - table.remove(data.marked, k) + table.remove(client.data.marked, k) cl:emit_signal("unmarked") return true end @@ -527,10 +528,10 @@ end --- Check if a client is marked. -- @param c The client to check, or the focused one otherwise. -function ismarked(c) +function client.ismarked(c) local cl = c or capi.client.focus if cl then - for k, v in pairs(data.marked) do + for k, v in pairs(client.data.marked) do if cl == v then return true end @@ -541,23 +542,23 @@ end --- Toggle a client as marked. -- @param c The client to toggle mark. -function togglemarked(c) +function client.togglemarked(c) local cl = c or capi.client.focus - if not mark(c) then - unmark(c) + if not client.mark(c) then + client.unmark(c) end end --- Return the marked clients and empty the marked table. -- @return A table with all marked clients. -function getmarked() - for k, v in pairs(data.marked) do +function client.getmarked() + for k, v in pairs(client.data.marked) do v:emit_signal("unmarked") end - t = data.marked - data.marked = {} + t = client.data.marked + client.data.marked = {} return t end @@ -565,28 +566,28 @@ end -- Floating client are not handled by tiling layouts. -- @param c A client. -- @param s True or false. -function floating.set(c, s) +function client.floating.set(c, s) local c = c or capi.client.focus - if c and property.get(c, "floating") ~= s then - property.set(c, "floating", s) + if c and client.property.get(c, "floating") ~= s then + client.property.set(c, "floating", s) local screen = c.screen if s == true then - c:geometry(property.get(c, "floating_geometry")) + c:geometry(client.property.get(c, "floating_geometry")) end c.screen = screen end end local function store_floating_geometry(c) - if floating.get(c) then - property.set(c, "floating_geometry", c:geometry()) + if client.floating.get(c) then + client.property.set(c, "floating_geometry", c:geometry()) end end -- Store the initial client geometry. capi.client.connect_signal("new", function(c) local function store_init_geometry(c) - property.set(c, "floating_geometry", c:geometry()) + client.property.set(c, "floating_geometry", c:geometry()) c:disconnect_signal("property::border_width", store_init_geometry) end c:connect_signal("property::border_width", store_init_geometry) @@ -598,7 +599,7 @@ end) --- Return if a client has a fixe size or not. -- @param c The client. -function isfixed(c) +function client.isfixed(c) local c = c or capi.client.focus if not c then return end local h = c.size_hints @@ -618,10 +619,10 @@ end -- @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. -function floating.get(c) +function client.floating.get(c) local c = c or capi.client.focus if c then - local value = property.get(c, "floating") + local value = client.property.get(c, "floating") if value ~= nil then return value end @@ -629,7 +630,7 @@ function floating.get(c) or c.fullscreen or c.maximized_vertical or c.maximized_horizontal - or isfixed(c) then + or client.isfixed(c) then return true end return false @@ -638,26 +639,26 @@ end --- Toggle the floating state of a client between 'auto' and 'true'. -- @param c A client. -function floating.toggle(c) +function client.floating.toggle(c) local c = c or capi.client.focus -- If it has been set to floating - if floating.get(c) then - floating.set(c, false) + if client.floating.get(c) then + client.floating.set(c, false) else - floating.set(c, true) + client.floating.set(c, true) end end --- Remove the floating information on a client. -- @param c The client. -function floating.delete(c) - floating.set(c, nil) +function client.floating.delete(c) + client.floating.set(c, nil) end --- Restore (=unminimize) a random client. -- @param s The screen to use. -- @return True if some client was restored. -function restore(s) +function client.restore(s) local s = s or (capi.client.focus and capi.client.focus.screen) or capi.mouse.screen local cls = capi.client.get(s) local tags = tag.selectedlist(s) @@ -706,11 +707,11 @@ end -- @return col the column number -- @return idx index of the client in the column -- @return num the number of visible clients in the column -function idx(c) +function client.idx(c) local c = c or capi.client.focus if not c then return end - local clients = tiled(c.screen) + local clients = client.tiled(c.screen) local idx = nil for k, cl in ipairs(clients) do if cl == c then @@ -758,15 +759,15 @@ end --- Set the window factor of a client -- @param wfact the window factor value -- @param c the client -function setwfact(wfact, c) +function client.setwfact(wfact, c) -- get the currently selected window local c = c or capi.client.focus if not c or not c:isvisible() then return end local t = tag.selected(c.screen) - local w = idx(c) + local w = client.idx(c) - local cls = tiled(t.screen) + local cls = client.tiled(t.screen) local nmaster = tag.getnmaster(t) -- n is the number of windows currently visible for which we have to be concerned with the properties @@ -797,13 +798,13 @@ end --- Increment a client's window factor -- @param add amount to increase the client's window -- @param c the client -function incwfact(add, c) +function client.incwfact(add, c) local c = c or capi.client.focus if not c then return end local t = tag.selected(c.screen) - local w = idx(c) + local w = client.idx(c) local nmaster = tag.getnmaster(t) local data = tag.getproperty(t, "windowfact") or {} @@ -822,8 +823,8 @@ end -- @return True or false. Note that some windows might be dockable even if you -- did not set them manually. For example, windows with a type "utility", "toolbar" -- or "dock" -function dockable.get(c) - local value = property.get(c, "dockable") +function client.dockable.get(c) + local value = client.property.get(c, "dockable") -- Some sane defaults if value == nil then @@ -842,17 +843,17 @@ end -- to the edge of the workarea. -- @param c A client. -- @param value True or false. -function dockable.set(c, value) - property.set(c, "dockable", value) +function client.dockable.set(c, value) + client.property.set(c, "dockable", value) end --- Get a client property. -- @param c The client. -- @param prop The property name. -- @return The property. -function property.get(c, prop) - if data.properties[c] then - return data.properties[c][prop] +function client.property.get(c, prop) + if client.data.properties[c] then + return client.data.properties[c][prop] end end @@ -861,11 +862,11 @@ end -- @param c The client. -- @param prop The property name. -- @param value The value. -function property.set(c, prop, value) - if not data.properties[c] then - data.properties[c] = {} +function client.property.set(c, prop, value) + if not client.data.properties[c] then + client.data.properties[c] = {} end - data.properties[c][prop] = value + client.data.properties[c][prop] = value c:emit_signal("property::" .. prop) end @@ -888,7 +889,7 @@ end -- c.minimized = false
-- end
--

-function iterate(filter, start, s) +function client.iterate(filter, start, s) local clients = capi.client.get(s) local focused = capi.client.focus local start = start or util.table.hasitem(clients, focused) @@ -913,13 +914,13 @@ end -- awful.client.run_or_raise('urxvt', matcher) -- end); --

-function run_or_raise(cmd, matcher, merge) +function client.run_or_raise(cmd, matcher, merge) local clients = capi.client.get() local findex = util.table.hasitem(clients, capi.client.focus) or 1 local start = util.cycle(#clients, findex + 1) for c in iterate(matcher, start) do - jumpto(c, merge) + client.jumpto(c, merge) return end @@ -932,13 +933,15 @@ capi.client.add_signal("property::floating_geometry") capi.client.add_signal("property::floating") capi.client.add_signal("property::dockable") -capi.client.connect_signal("focus", focus.history.add) -capi.client.connect_signal("unmanage", focus.history.delete) +capi.client.connect_signal("focus", client.focus.history.add) +capi.client.connect_signal("unmanage", client.focus.history.delete) -capi.client.connect_signal("manage", function(c) c:connect_signal("property::urgent", urgent.add) end) -capi.client.connect_signal("focus", urgent.delete) -capi.client.connect_signal("unmanage", urgent.delete) +capi.client.connect_signal("manage", function(c) c:connect_signal("property::urgent", client.urgent.add) end) +capi.client.connect_signal("focus", client.urgent.delete) +capi.client.connect_signal("unmanage", client.urgent.delete) -capi.client.connect_signal("unmanage", floating.delete) +capi.client.connect_signal("unmanage", client.floating.delete) + +return client -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/completion.lua.in b/lib/awful/completion.lua.in index aa32292e..5f0450d9 100644 --- a/lib/awful/completion.lua.in +++ b/lib/awful/completion.lua.in @@ -17,7 +17,8 @@ local util = require("awful.util") --- Completion module. -- This module store a set of function using shell to complete commands name. -module("awful.completion") +-- awful.completion +local completion = {} -- mapping of command/completion function local bashcomp_funcs = {} @@ -26,7 +27,7 @@ local bashcomp_src = "@SYSCONFDIR@/bash_completion" --- Enable programmable bash completion in awful.completion.bash at the price of -- a slight overhead. -- @param src The bash completion source file, /etc/bash_completion by default. -function bashcomp_load(src) +function completion.bashcomp_load(src) if src then bashcomp_src = src end local c, err = io.popen("/usr/bin/env bash -c 'source " .. bashcomp_src .. "; complete -p'") if c then @@ -59,7 +60,7 @@ end -- @param ncomp The element number to complete. -- @param shell The shell to use for completion (bash (default) or zsh). -- @return The new command, the new cursor position, the table of all matches. -function shell(command, cur_pos, ncomp, shell) +function completion.shell(command, cur_pos, ncomp, shell) local wstart = 1 local wend = 1 local words = {} @@ -160,7 +161,7 @@ end -- @param ncomp The number of yet requested completion using current text. -- @param keywords The keywords table uised for completion. -- @return The new match, the new cursor position, the table of all matches. -function generic(text, cur_pos, ncomp, keywords) +function completion.generic(text, cur_pos, ncomp, keywords) -- The keywords table may be empty if #keywords == 0 then return text, #text + 1 @@ -191,4 +192,6 @@ function generic(text, cur_pos, ncomp, keywords) return matches[ncomp], #matches[ncomp] + 1, matches end +return completion + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/dbus.lua.in b/lib/awful/dbus.lua.in index a5ea06ca..323df02f 100644 --- a/lib/awful/dbus.lua.in +++ b/lib/awful/dbus.lua.in @@ -10,7 +10,7 @@ local dbus = dbus --- D-Bus module for awful. -- This module simply request the org.naquadah.awesome.awful name on the D-Bus -- for futur usage by other awful modules. -module("awful.dbus") +-- awful.dbus if dbus then dbus.request_name("session", "org.naquadah.awesome.awful") diff --git a/lib/awful/ewmh.lua.in b/lib/awful/ewmh.lua.in index bb6375ca..a99add15 100644 --- a/lib/awful/ewmh.lua.in +++ b/lib/awful/ewmh.lua.in @@ -11,7 +11,7 @@ local ipairs = ipairs local math = math --- Implements EWMH requests handling. -module("awful.ewmh") +-- awful.ewmh local data = setmetatable({}, { __mode = 'k' }) diff --git a/lib/awful/icccm.lua.in b/lib/awful/icccm.lua.in index eebda171..c7a22652 100644 --- a/lib/awful/icccm.lua.in +++ b/lib/awful/icccm.lua.in @@ -8,12 +8,12 @@ local client = client local math = math --- Implements ICCCM handling. -module("awful.icccm") +-- awful.icccm -- Make sure we don't get into an endless loop local size_hints_lock = false -function apply_size_hints(c) +local function apply_size_hints(c) if size_hints_lock then return end if not c.size_hints_honor then return end -- Fullscreen clients don't get size hints applied! diff --git a/lib/awful/init.lua.in b/lib/awful/init.lua.in index 6c328bda..62cf174e 100644 --- a/lib/awful/init.lua.in +++ b/lib/awful/init.lua.in @@ -4,28 +4,31 @@ -- @release @AWESOME_VERSION@ --------------------------------------------------------------------------- -require("awful.client") -require("awful.completion") -require("awful.layout") -require("awful.placement") -require("awful.prompt") -require("awful.screen") -require("awful.tag") -require("awful.util") -require("awful.widget") -require("awful.keygrabber") -require("awful.menu") -require("awful.mouse") -require("awful.remote") -require("awful.key") -require("awful.button") -require("awful.wibox") -require("awful.startup_notification") -require("awful.tooltip") -require("awful.ewmh") -require("awful.icccm") - --- AWesome Functions very UsefuL -module("awful") +-- awful + +return +{ + client = require("awful.client"); + completion = require("awful.completion"); + layout = require("awful.layout"); + placement = require("awful.placement"); + prompt = require("awful.prompt"); + screen = require("awful.screen"); + tag = require("awful.tag"); + util = require("awful.util"); + widget = require("awful.widget"); + keygrabber = require("awful.keygrabber"); + menu = require("awful.menu"); + mouse = require("awful.mouse"); + remote = require("awful.remote"); + key = require("awful.key"); + button = require("awful.button"); + wibox = require("awful.wibox"); + startup_notification = require("awful.startup_notification"); + tooltip = require("awful.tooltip"); + ewmh = require("awful.ewmh"); + icccm = require("awful.icccm"); +} -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/key.lua.in b/lib/awful/key.lua.in index 10aa9ee6..8f082ce0 100644 --- a/lib/awful/key.lua.in +++ b/lib/awful/key.lua.in @@ -11,7 +11,8 @@ local capi = { key = key } local util = require("awful.util") --- Create easily new key objects ignoring certain modifiers. -module("awful.key") +-- awful.key +local key = { mt = {} } --- Modifiers to ignore. -- By default this is initialized as { "Lock", "Mod2" } @@ -19,7 +20,7 @@ module("awful.key") -- when pressing keys. -- @name ignore_modifiers -- @class table -ignore_modifiers = { "Lock", "Mod2" } +local ignore_modifiers = { "Lock", "Mod2" } --- Create a new key to use as binding. -- This function is useful to create several keys from one, because it will use @@ -31,12 +32,12 @@ ignore_modifiers = { "Lock", "Mod2" } -- CapsLock off. -- @see capi.key -- @return A table with one or several key objects. -function new(mod, key, press, release) +function key.new(mod, _key, press, release) local ret = {} local subsets = util.subsets(ignore_modifiers) for _, set in ipairs(subsets) do ret[#ret + 1] = capi.key({ modifiers = util.table.join(mod, set), - key = key }) + key = _key }) if press then ret[#ret]:connect_signal("press", function(kobj, ...) press(...) end) end @@ -51,11 +52,11 @@ end -- @param key The key object. -- @param pressed_mod The modifiers to compare with. -- @param pressed_key The key to compare with. -function match(key, pressed_mod, pressed_key) +function key.match(_key, pressed_mod, pressed_key) -- First, compare key. - if pressed_key ~= key.key then return false end + if pressed_key ~= _key.key then return false end -- Then, compare mod - local mod = key.modifiers + local mod = _key.modifiers -- For each modifier of the key object, check that the modifier has been -- pressed. for _, m in ipairs(mod) do @@ -70,6 +71,10 @@ function match(key, pressed_mod, pressed_key) return #pressed_mod == #mod end -setmetatable(_M, { __call = function(_, ...) return new(...) end }) +function key.mt:__call(...) + return key.new(...) +end + +return setmetatable(key, key.mt) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/keygrabber.lua.in b/lib/awful/keygrabber.lua.in index 6ee604fa..e1deef80 100644 --- a/lib/awful/keygrabber.lua.in +++ b/lib/awful/keygrabber.lua.in @@ -10,7 +10,8 @@ local capi = { keygrabber = keygrabber } --- Keygrabber Stack -module("awful.keygrabber") +-- awful.keygrabber +local keygrabber = {} -- Private data local grabbers = {} @@ -29,7 +30,7 @@ end --- Stop grabbing the keyboard for the provided callback. -- When no callback is given, the least grabber gets removed (last one added to the stack). -- @param g The key grabber that must be removed. -function stop(g) +function keygrabber.stop(g) for i, v in ipairs(grabbers) do if v == g then table.remove(grabbers, i) @@ -71,9 +72,9 @@ end -- end)
-- end
--

-function run(g) +function keygrabber.run(g) -- Remove the grabber if its in stack - stop(g) + keygrabber.stop(g) -- Record the grabber has latest added table.insert(grabbers, 1, g) -- start the keygrabber if its not running already @@ -84,4 +85,6 @@ function run(g) return g end +return keygrabber + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/menu.lua.in b/lib/awful/menu.lua.in index 07a4953a..66bc24e3 100644 --- a/lib/awful/menu.lua.in +++ b/lib/awful/menu.lua.in @@ -32,7 +32,8 @@ local capi = { client = client } -module("awful.menu") +-- awful.menu +local menu = { mt = {} } local table_update = function (t, set) @@ -98,16 +99,16 @@ local function load_theme(a, b) end -local function item_position(menu, child) +local function item_position(_menu, child) local in_dir, other, a, b = 0, 0, "height", "width" - local dir = menu.layout.get_dir and menu.layout:get_dir() or "y" + local dir = _menu.layout.get_dir and _menu.layout:get_dir() or "y" if dir == "x" then a, b = b, a end - local in_dir, other = 0, menu[b] - local num = util.table.hasitem(menu.child, child) + local in_dir, other = 0, _menu[b] + local num = util.table.hasitem(_menu.child, child) if num then for i = 0, num - 1 do - local item = menu.items[i] + local item = _menu.items[i] if item then other = math.max(other, item[b]) in_dir = in_dir + item[a] @@ -120,104 +121,104 @@ local function item_position(menu, child) end -local function set_coords(menu, screen_idx, m_coords) +local function set_coords(_menu, screen_idx, m_coords) local s_geometry = capi.screen[screen_idx].workarea local screen_w = s_geometry.x + s_geometry.width local screen_h = s_geometry.y + s_geometry.height - menu.width = menu.wibox.width - menu.height = menu.wibox.height + _menu.width = _menu.wibox.width + _menu.height = _menu.wibox.height - menu.x = menu.wibox.x - menu.y = menu.wibox.y + _menu.x = _menu.wibox.x + _menu.y = _menu.wibox.y - if menu.parent then - local w, h = item_position(menu.parent, menu) - w = w + menu.parent.theme.border_width + if _menu.parent then + local w, h = item_position(_menu.parent, _menu) + w = w + _menu.parent.theme.border_width - menu.y = menu.parent.y + h + menu.height > screen_h and - screen_h - menu.height or menu.parent.y + h - menu.x = menu.parent.x + w + menu.width > screen_w and - menu.parent.x - menu.width or menu.parent.x + w + _menu.y = _menu.parent.y + h + _menu.height > screen_h and + screen_h - _menu.height or _menu.parent.y + h + _menu.x = _menu.parent.x + w + _menu.width > screen_w and + _menu.parent.x - _menu.width or _menu.parent.x + w else if m_coords == nil then m_coords = capi.mouse.coords() m_coords.x = m_coords.x + 1 m_coords.y = m_coords.y + 1 end - menu.y = m_coords.y < s_geometry.y and s_geometry.y or m_coords.y - menu.x = m_coords.x < s_geometry.x and s_geometry.x or m_coords.x + _menu.y = m_coords.y < s_geometry.y and s_geometry.y or m_coords.y + _menu.x = m_coords.x < s_geometry.x and s_geometry.x or m_coords.x - menu.y = menu.y + menu.height > screen_h and - screen_h - menu.height or menu.y - menu.x = menu.x + menu.width > screen_w and - screen_w - menu.width or menu.x + _menu.y = _menu.y + _menu.height > screen_h and + screen_h - _menu.height or _menu.y + _menu.x = _menu.x + _menu.width > screen_w and + screen_w - _menu.width or _menu.x end - menu.wibox.x = menu.x - menu.wibox.y = menu.y + _menu.wibox.x = _menu.x + _menu.wibox.y = _menu.y end -local function set_size(menu) +local function set_size(_menu) local in_dir, other, a, b = 0, 0, "height", "width" - local dir = menu.layout.get_dir and menu.layout:get_dir() or "y" + local dir = _menu.layout.get_dir and _menu.layout:get_dir() or "y" if dir == "x" then a, b = b, a end - for _, item in ipairs(menu.items) do + for _, item in ipairs(_menu.items) do other = math.max(other, item[b]) in_dir = in_dir + item[a] end - menu[a], menu[b] = in_dir, other + _menu[a], _menu[b] = in_dir, other if in_dir > 0 and other > 0 then - menu.wibox[a] = in_dir - menu.wibox[b] = other + _menu.wibox[a] = in_dir + _menu.wibox[b] = other return true end return false end -local function check_access_key(menu, key) - for i, item in ipairs(menu.items) do +local function check_access_key(_menu, key) + for i, item in ipairs(_menu.items) do if item.akey == key then - menu:item_enter(i) - menu:exec(i, { exec = true }) + _menu:item_enter(i) + _menu:exec(i, { exec = true }) return end end - if menu.parent then - check_access_key(menu.parent, key) + if _menu.parent then + check_access_key(_menu.parent, key) end end -local function grabber(menu, mod, key, event) +local function grabber(_menu, mod, key, event) if event ~= "press" then return end - local sel = menu.sel or 0 + local sel = _menu.sel or 0 if util.table.hasitem(menu_keys.up, key) then - local sel_new = sel-1 < 1 and #menu.items or sel-1 - menu:item_enter(sel_new) + local sel_new = sel-1 < 1 and #_menu.items or sel-1 + _menu:item_enter(sel_new) elseif util.table.hasitem(menu_keys.down, key) then - local sel_new = sel+1 > #menu.items and 1 or sel+1 - menu:item_enter(sel_new) + local sel_new = sel+1 > #_menu.items and 1 or sel+1 + _menu:item_enter(sel_new) elseif sel > 0 and util.table.hasitem(menu_keys.enter, key) then - menu:exec(sel) + _menu:exec(sel) elseif sel > 0 and util.table.hasitem(menu_keys.exec, key) then - menu:exec(sel, { exec = true }) + _menu:exec(sel, { exec = true }) elseif util.table.hasitem(menu_keys.back, key) then - menu:hide() + _menu:hide() elseif util.table.hasitem(menu_keys.close, key) then - get_root(menu):hide() + menu.get_root(_menu):hide() else - check_access_key(menu, key) + check_access_key(_menu, key) end end -function exec(menu, num, opts) +function menu.exec(_menu, num, opts) opts = opts or {} - local item = menu.items[num] + local item = _menu.items[num] if not item then return end local cmd = item.cmd if type(cmd) == "table" then @@ -228,41 +229,41 @@ function exec(menu, num, opts) end return end - if not menu.child[num] then - menu.child[num] = new(cmd, menu) + if not _menu.child[num] then + _menu.child[num] = menu.new(cmd, _menu) end local can_invoke_action = opts.exec and action and type(action) == "function" and - (not opts.mouse or (opts.mouse and (menu.auto_expand or - (menu.active_child == menu.child[num] and - menu.active_child.wibox.visible)))) + (not opts.mouse or (opts.mouse and (_menu.auto_expand or + (_menu.active_child == _menu.child[num] and + _menu.active_child.wibox.visible)))) if can_invoke_action then - local visible = action(menu.child[num], item) + local visible = action(_menu.child[num], item) if not visible then - get_root(menu):hide() + menu.get_root(_menu):hide() return else - menu.child[num]:update() + _menu.child[num]:update() end end - if menu.active_child and menu.active_child ~= menu.child[num] then - menu.active_child:hide() + if _menu.active_child and _menu.active_child ~= _menu.child[num] then + _menu.active_child:hide() end - menu.active_child = menu.child[num] - if not menu.active_child.visible then - menu.active_child:show() + _menu.active_child = _menu.child[num] + if not _menu.active_child.visible then + _menu.active_child:show() end elseif type(cmd) == "string" then - get_root(menu):hide() + menu.get_root(_menu):hide() util.spawn(cmd) elseif type(cmd) == "function" then - local visible, action = cmd(item, menu) + local visible, action = cmd(item, _menu) if not visible then - get_root(menu):hide() + menu.get_root(_menu):hide() else - menu:update() - if menu.items[num] then - menu:item_enter(num, opts) + _menu:update() + if _menu.items[num] then + _menu:item_enter(num, opts) end end if action and type(action) == "function" then @@ -271,35 +272,35 @@ function exec(menu, num, opts) end end -function item_enter(menu, num, opts) +function menu.item_enter(_menu, num, opts) opts = opts or {} - local item = menu.items[num] - if num == nil or menu.sel == num or not item then + local item = _menu.items[num] + if num == nil or _menu.sel == num or not item then return - elseif menu.sel then - menu:item_leave(menu.sel) + elseif _menu.sel then + _menu:item_leave(_menu.sel) end --print("sel", num, menu.sel, item.theme.bg_focus) item._background:set_fg(item.theme.fg_focus) item._background:set_bg(item.theme.bg_focus) - menu.sel = num + _menu.sel = num - if menu.auto_expand and opts.hover then - if menu.active_child then - menu.active_child:hide() - menu.active_child = nil + if _menu.auto_expand and opts.hover then + if _menu.active_child then + _menu.active_child:hide() + _menu.active_child = nil end if type(item.cmd) == "table" then - menu:exec(num, opts) + _menu:exec(num, opts) end end end -function item_leave(menu, num) +function menu.item_leave(_menu, num) --print("leave", num) - local item = menu.items[num] + local item = _menu.items[num] if item then item._background:set_fg(item.theme.fg_normal) item._background:set_bg(item.theme.bg_normal) @@ -308,77 +309,77 @@ end --- Show a menu. --- @param menu The menu to show. +-- @param _menu The menu to show. -- @param args.coords Menu position defaulting to mouse.coords() -function show(menu, args) +function menu.show(_menu, args) args = args or {} local coords = args.coords or nil local screen_index = capi.mouse.screen - if not set_size(menu) then return end - set_coords(menu, screen_index, coords) + if not set_size(_menu) then return end + set_coords(_menu, screen_index, coords) - keygrabber.run(menu._keygrabber) - menu.wibox.visible = true + keygrabber.run(_menu._keygrabber) + _menu.wibox.visible = true end --- Hide a menu popup. --- @param menu The menu to hide. -function hide(menu) +-- @param _menu The menu to hide. +function menu.hide(_menu) -- Remove items from screen - for i = 1, #menu.items do - menu:item_leave(i) + for i = 1, #_menu.items do + _menu:item_leave(i) end - if menu.active_child then - menu.active_child:hide() - menu.active_child = nil + if _menu.active_child then + _menu.active_child:hide() + _menu.active_child = nil end - menu.sel = nil + _menu.sel = nil - keygrabber.stop(menu._keygrabber) - menu.wibox.visible = false + keygrabber.stop(_menu._keygrabber) + _menu.wibox.visible = false end --- Toggle menu visibility. --- @param menu The menu to show if it's hidden, or to hide if it's shown. +-- @param _menu The menu to show if it's hidden, or to hide if it's shown. -- @param args.coords Menu position {x,y} -function toggle(menu, args) - if menu.wibox.visible then - menu:hide() +function menu.toggle(_menu, args) + if _menu.wibox.visible then + _menu:hide() else - menu:show(args) + _menu:show(args) end end --- Update menu content --- @param menu The mnenu to update. -function update(menu) - if menu.wibox.visible then - menu:show({ coords = { x = menu.x, y = menu.y } }) +-- @param _menu The mnenu to update. +function menu.update(_menu) + if _menu.wibox.visible then + _menu:show({ coords = { x = _menu.x, y = _menu.y } }) end end --- Get the elder parent so for example when you kill -- it, it will destroy the whole family. --- @param menu The sub menu of the menu family. -function get_root(menu) - return menu.parent and get_root(menu.parent) or menu +-- @param _menu The sub menu of the menu family. +function menu.get_root(_menu) + return _menu.parent and menu.get_root(_menu.parent) or _menu end --- Add a new menu entry --- @param menu The parent menu +-- @param _menu The parent menu -- @param args The item params -- @param args.new (Default: awful.menu.entry) The menu entry constructor -- @param args.theme (Optional) The menu entry theme -- @param args.* params needed for the menu entry constructor -- @param index (Optional) the index where the new entry will inserted -function add(menu, args, index) +function menu.add(_menu, args, index) if not args then return end - local theme = load_theme(args.theme or {}, menu.theme) + local theme = load_theme(args.theme or {}, _menu.theme) args.theme = theme - args.new = args.new or entry - local success, item = pcall(args.new, menu, args) + args.new = args.new or menu.entry + local success, item = pcall(args.new, _menu, args) if not success then print("Error while creating menu entry: " .. item) return @@ -387,7 +388,7 @@ function add(menu, args, index) print("Error while checking menu entry: no property widget found.") return end - item.parent = menu + item.parent = _menu item.theme = item.theme or theme item.width = item.width or theme.width item.height = item.height or theme.height @@ -400,69 +401,69 @@ function add(menu, args, index) -- Create bindings item._background:buttons(util.table.join( - button({}, 3, function () menu:hide() end), + button({}, 3, function () _menu:hide() end), button({}, 1, function () - local num = util.table.hasitem(menu.items, item) - menu:item_enter(num, { mouse = true }) - menu:exec(num, { exec = true, mouse = true }) + local num = util.table.hasitem(_menu.items, item) + _menu:item_enter(num, { mouse = true }) + _menu:exec(num, { exec = true, mouse = true }) end ))) item._mouse = function () - local num = util.table.hasitem(menu.items, item) - menu:item_enter(num, { hover = true, moue = true }) + local num = util.table.hasitem(_menu.items, item) + _menu:item_enter(num, { hover = true, moue = true }) end item.widget:connect_signal("mouse::enter", item._mouse) if index then - menu.layout:reset() - table.insert(menu.items, index, item) - for _, i in ipairs(menu.items) do - menu.layout:add(i._background) + _menu.layout:reset() + table.insert(_menu.items, index, item) + for _, i in ipairs(_menu.items) do + _menu.layout:add(i._background) end else - table.insert(menu.items, item) - menu.layout:add(item._background) + table.insert(_menu.items, item) + _menu.layout:add(item._background) end return item end -- Delete menu entry at given position --- @param menu The menu +-- @param _menu The menu -- @param num The position in the table of the menu entry to be deleted; can be also the menu entry itself -function delete(menu, num) +function menu.delete(_menu, num) if type(num) == "table" then - num = util.table.hasitem(menu.items, num) + num = util.table.hasitem(_menu.items, num) end - local item = menu.items[num] + local item = _menu.items[num] if not item then return end item.widget:disconnect_signal("mouse::enter", item._mouse) item.widget.visible = false - table.remove(menu.items, num) - if menu.sel == num then - menu:item_leave(menu.sel) - menu.sel = nil + table.remove(_menu.items, num) + if _menu.sel == num then + _menu:item_leave(_menu.sel) + _menu.sel = nil end - menu.layout:reset() - for _, i in ipairs(menu.items) do - menu.layout:add(i._background) + _menu.layout:reset() + for _, i in ipairs(_menu.items) do + _menu.layout:add(i._background) end - if menu.child[num] then - menu.child[num]:hide() - if menu.active_child == menu.child[num] then - menu.active_child = nil + if _menu.child[num] then + _menu.child[num]:hide() + if _menu.active_child == _menu.child[num] then + _menu.active_child = nil end - table.remove(menu.child, num) + table.remove(_menu.child, num) end end -------------------------------------------------------------------------------- --- Build a popup menu with running clients and shows it. --- @param menu Menu table, see new() function for more informations +-- @param _menu Menu table, see new() function for more informations -- @return The menu. -function clients(menu, args) -- FIXME crude api - menu = menu or {} +function menu.clients(_menu, args) -- FIXME crude api + _menu = _menu or {} local cls = capi.client.get() local cls_t = {} for k, c in pairs(cls) do @@ -492,7 +493,7 @@ end -- @param parent The parent menu -- @param args the item params -- @return table with 'widget', 'cmd', 'akey' and all the properties the user wants to change -function entry(parent, args) +function menu.entry(parent, args) args = args or {} args.text = args[1] or args.text or "" args.cmd = args[2] or args.cmd @@ -616,20 +617,20 @@ end --   awful.menu(terms):show()
-- end
--

-function new(args, parent) +function menu.new(args, parent) args = args or {} args.layout = args.layout or wibox.layout.flex.vertical - local menu = table_update(object(), { - item_enter = item_enter, - item_leave = item_leave, - get_root = get_root, - delete = delete, - update = update, - toggle = toggle, - hide = hide, - show = show, - exec = exec, - add = add, + local _menu = table_update(object(), { + item_enter = menu.item_enter, + item_leave = menu.item_leave, + get_root = menu.get_root, + delete = menu.delete, + update = menu.update, + toggle = menu.toggle, + hide = menu.hide, + show = menu.show, + exec = menu.exec, + add = menu.add, child = {}, items = {}, parent = parent, @@ -637,39 +638,43 @@ function new(args, parent) theme = load_theme(args.theme or {}, parent and parent.theme) }) if parent then - menu.auto_expand = parent.auto_expand + _menu.auto_expand = parent.auto_expand elseif args.auto_expand ~= nil then - menu.auto_expand = args.auto_expand + _menu.auto_expand = args.auto_expand else - menu.auto_expand = true + _menu.auto_expand = true end -- Create items - for i, v in ipairs(args) do menu:add(v) end + for i, v in ipairs(args) do _menu:add(v) end if args.items then - for i, v in pairs(args.items) do menu:add(v) end + for i, v in pairs(args.items) do _menu:add(v) end end - menu._keygrabber = function (...) - grabber(menu, ...) + _menu._keygrabber = function (...) + grabber(_menu, ...) end - menu.wibox = wibox({ + _menu.wibox = wibox({ ontop = true, - fg = menu.theme.fg_normal, - bg = menu.theme.bg_normal, - border_color = menu.theme.border, - border_width = menu.theme.border_width, + fg = _menu.theme.fg_normal, + bg = _menu.theme.bg_normal, + border_color = _menu.theme.border, + border_width = _menu.theme.border_width, type = "popup_menu" }) - menu.wibox.visible = false - menu.wibox:set_widget(menu.layout) - set_size(menu) + _menu.wibox.visible = false + _menu.wibox:set_widget(_menu.layout) + set_size(_menu) - menu.x = menu.wibox.x - menu.y = menu.wibox.y - return menu + _menu.x = _menu.wibox.x + _menu.y = _menu.wibox.y + return _menu end -setmetatable(_M, { __call = function (_, ...) return new(...) end }) +function menu.mt:__call(...) + return menu.new(...) +end + +return setmetatable(menu, menu.mt) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/placement.lua.in b/lib/awful/placement.lua.in index 9520faa8..bc95e3a5 100644 --- a/lib/awful/placement.lua.in +++ b/lib/awful/placement.lua.in @@ -20,7 +20,8 @@ local layout = require("awful.layout") local a_screen = require("awful.screen") --- Places client according to special criteria. -module("awful.placement") +-- awful.placement +local placement = {} -- Check if an area intersect another area. -- @param a The area. @@ -103,7 +104,7 @@ end --- Place the client so no part of it will be outside the screen. -- @param c The client. -- @return The new client geometry. -function no_offscreen(c) +function placement.no_offscreen(c) local c = c or capi.client.focus local geometry = c:geometry() local screen = c.screen or a_screen.getbycoord(geometry.x, geometry.y) @@ -127,7 +128,7 @@ end --- Place the client where there's place available with minimum overlap. -- @param c The client. -function no_overlap(c) +function placement.no_overlap(c) local geometry = c:geometry() local screen = c.screen or a_screen.getbycoord(geometry.x, geometry.y) local cls = client.visible(screen) @@ -180,7 +181,7 @@ end --- Place the client under the mouse. -- @param c The client. -- @return The new client geometry. -function under_mouse(c) +function placement.under_mouse(c) local c = c or capi.client.focus local c_geometry = c:geometry() local m_coords = capi.mouse.coords() @@ -192,7 +193,7 @@ end -- @param c The client. -- @param p The parent (optional, nil for screen centering). -- @return The new client geometry. -function centered(c, p) +function placement.centered(c, p) local c = c or capi.client.focus local c_geometry = c:geometry() local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) @@ -210,7 +211,7 @@ end -- @param c The client. -- @param p The parent (optional, nil for screen centering). -- @return The new client geometry. -function center_horizontal(c, p) +function placement.center_horizontal(c, p) local c = c or capi.client.focus local c_geometry = c:geometry() local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) @@ -227,7 +228,7 @@ end -- @param c The client. -- @param p The parent (optional, nil for screen centering). -- @return The new client geometry. -function center_vertical(c, p) +function placement.center_vertical(c, p) local c = c or capi.client.focus local c_geometry = c:geometry() local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) @@ -240,5 +241,6 @@ function center_vertical(c, p) return c:geometry({ y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 }) end +return placement -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/prompt.lua.in b/lib/awful/prompt.lua.in index 4276728e..62ce2484 100644 --- a/lib/awful/prompt.lua.in +++ b/lib/awful/prompt.lua.in @@ -20,7 +20,8 @@ local util = require("awful.util") local beautiful = require("beautiful") --- Prompt module for awful -module("awful.prompt") +-- awful.prompt +local prompt = {} --- Private data local data = {} @@ -131,7 +132,7 @@ end local function prompt_text_with_cursor(args) local char, spacer, text_start, text_end, ret local text = args.text or "" - local prompt = args.prompt or "" + local _prompt = args.prompt or "" local underline = args.cursor_ul or "none" if args.selectall then @@ -151,7 +152,7 @@ local function prompt_text_with_cursor(args) text_end = util.escape(text:sub(args.cursor_pos + 1)) end - ret = prompt .. text_start .. "" .. char .. "" .. text_end .. spacer + ret = _prompt .. text_start .. "" .. char .. "" .. text_end .. spacer return ret end @@ -165,7 +166,7 @@ end -- @param done_callback Optional parameter: the callback function to always call without arguments, regardless of whether the prompt was cancelled. -- @param changed_callback Optional parameter: the callback function to call with command as argument when a command was changed. -- @param keypressed_callback Optional parameter: the callback function to call with mod table, key and command as arguments when a key was pressed. -function run(args, textbox, exe_callback, completion_callback, history_path, history_max, done_callback, changed_callback, keypressed_callback) +function prompt.run(args, textbox, exe_callback, completion_callback, history_path, history_max, done_callback, changed_callback, keypressed_callback) local grabber local theme = beautiful.get() if not args then args = {} end @@ -465,4 +466,6 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his end) end +return prompt + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/remote.lua.in b/lib/awful/remote.lua.in index c090ba25..d3d7b5e4 100644 --- a/lib/awful/remote.lua.in +++ b/lib/awful/remote.lua.in @@ -15,7 +15,7 @@ local dbus = dbus local type = type --- Remote control module allowing usage of awesome-client. -module("awful.remote") +-- awful.remote if dbus then dbus.connect_signal("org.naquadah.awesome.awful.Remote", function(data, code) diff --git a/lib/awful/rules.lua.in b/lib/awful/rules.lua.in index 2fbde575..0d532061 100644 --- a/lib/awful/rules.lua.in +++ b/lib/awful/rules.lua.in @@ -14,7 +14,8 @@ local aclient = require("awful.client") local atag = require("awful.tag") --- Apply rules to clients at startup. -module("awful.rules") +-- awful.rules +local rules = {} --- This is the global rules table. --

You should fill this table with your rule and properties to apply. @@ -100,13 +101,13 @@ module("awful.rules") -- -- @class table -- @name rules -rules = {} +rules.rules = {} --- Check if a client match a rule. -- @param c The client. -- @param rule The rule to check. -- @return True if it matches, false otherwise. -function match(c, rule) +function rules.match(c, rule) if not rule then return false end for field, value in pairs(rule) do if c[field] then @@ -128,7 +129,7 @@ end -- @param c The client. -- @param rules The rule to check. -- @return True if at least one rule is matched, false otherwise. -function match_any(c, rule) +function rules.match_any(c, rule) if not rule then return false end for field, values in pairs(rule) do if c[field] then @@ -146,12 +147,12 @@ end --- Apply rules to a client. -- @param c The client. -function apply(c) +function rules.apply(c) local props = {} local callbacks = {} - for _, entry in ipairs(rules) do - if (match(c, entry.rule) or match_any(c, entry.rule_any)) and - (not match(c, entry.except) and not match_any(c, entry.except_any)) then + for _, entry in ipairs(rules.rules) do + if (rules.match(c, entry.rule) or rules.match_any(c, entry.rule_any)) and + (not rules.match(c, entry.except) and not rules.match_any(c, entry.except_any)) then if entry.properties then for property, value in pairs(entry.properties) do props[property] = value @@ -202,7 +203,9 @@ function apply(c) end end -client.connect_signal("manage", apply) +client.connect_signal("manage", rules.apply) client.disconnect_signal("manage", atag.withcurrent) +return rules + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/screen.lua.in b/lib/awful/screen.lua.in index 9fba87b8..d9a46258 100644 --- a/lib/awful/screen.lua.in +++ b/lib/awful/screen.lua.in @@ -15,7 +15,8 @@ local util = require("awful.util") local client = require("awful.client") --- Screen module for awful -module("awful.screen") +-- awful.screen +local screen = {} local data = {} data.padding = {} @@ -26,7 +27,7 @@ data.padding = {} -- `screen` table/object. -- @param x The x coordinate -- @param y The y coordinate -function getbycoord(x, y) +function screen.getbycoord(x, y) for i = 1, capi.screen:count() do local geometry = capi.screen[i].geometry if((x < 0 or (x >= geometry.x and x < geometry.x + geometry.width)) @@ -38,36 +39,38 @@ end --- Give the focus to a screen, and move pointer. -- @param screen Screen number. -function focus(screen) - if screen > capi.screen.count() then screen = capi.mouse.screen end - local c = client.focus.history.get(screen, 0) +function screen.focus(_screen) + if _screen > capi.screen.count() then _screen = capi.mouse.screen end + local c = client.focus.history.get(_screen, 0) if c then capi.client.focus = c end -- Move the mouse on the screen - capi.mouse.screen = screen + capi.mouse.screen = _screen end --- Give the focus to a screen, and move pointer, but relative to the current -- focused screen. -- @param i Value to add to the current focused screen index. 1 will focus next -- screen, -1 would focus the previous one. -function focus_relative(i) - return focus(util.cycle(capi.screen.count(), capi.mouse.screen + i)) +function screen.focus_relative(i) + return screen.focus(util.cycle(capi.screen.count(), capi.mouse.screen + i)) end --- Get or set the screen padding. -- @param screen The screen object to change the padding on -- @param padding The padding, an table with 'top', 'left', 'right' and/or -- 'bottom'. Can be nil if you only want to retrieve padding -function padding(screen, padding) +function screen.padding(_screen, padding) if padding then - data.padding[screen] = padding - screen:emit_signal("padding") + data.padding[_screen] = padding + _screen:emit_signal("padding") end - return data.padding[screen] + return data.padding[_screen] end for s = 1, capi.screen.count() do capi.screen[s]:add_signal("padding") end +return screen + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/startup_notification.lua.in b/lib/awful/startup_notification.lua.in index be5420ba..80a0a367 100644 --- a/lib/awful/startup_notification.lua.in +++ b/lib/awful/startup_notification.lua.in @@ -14,11 +14,11 @@ local capi = } --- Startup notification module for awful -module("awful.startup_notification") +-- awful.startup_notification local app_starting = {} -cursor_waiting = "watch" +local cursor_waiting = "watch" local function update_cursor() if #app_starting > 0 then diff --git a/lib/awful/tag.lua.in b/lib/awful/tag.lua.in index 06d7fb03..56fb8d68 100644 --- a/lib/awful/tag.lua.in +++ b/lib/awful/tag.lua.in @@ -20,7 +20,8 @@ local capi = } --- Useful functions for tag manipulation. -module("awful.tag") +-- awful.tag +local tag = { mt = {} } -- Private data local data = {} @@ -28,13 +29,13 @@ data.history = {} data.tags = setmetatable({}, { __mode = 'k' }) -- History functions -history = {} -history.limit = 20 +tag.history = {} +tag.history.limit = 20 --- Move a tag to an absolute position in the screen[]:tags() table. -- @param new_index Integer absolute position in the table to insert. -function move(new_index, target_tag) - local target_tag = target_tag or selected() +function tag.move(new_index, target_tag) + local target_tag = target_tag or tag.selected() local scr = target_tag.screen local tmp_tags = capi.screen[scr]:tags() @@ -57,13 +58,13 @@ end -- @param name The tag name, a string -- @param props The tags properties, a table -- @return The created tag -function add(name, props) +function tag.add(name, props) local properties = props or {} local newtag = capi.tag{name = name} newtag.screen = properties.screen or capi.mouse.screen for k, v in pairs(properties) do - setproperty(newtag, k, v) + tag.setproperty(newtag, k, v) end return newtag @@ -74,11 +75,11 @@ end -- @param screen The tag screen, or 1 if not set. -- @param layout The layout or layout table to set for this tags by default. -- @return A table with all created tags. -function new(names, screen, layout) +function tag.new(names, screen, layout) local screen = screen or 1 local tags = {} for id, name in ipairs(names) do - table.insert(tags, id, add(name, {screen = screen, + table.insert(tags, id, tag.add(name, {screen = screen, layout = (layout and layout[id]) or layout})) -- Select the first tag. @@ -93,9 +94,9 @@ end --- Find a suitable fallback tag. -- @param screen The screen number to look for a tag on. [mouse.screen] -- @param target A table of tags we consider unacceptable. [selectedlist(scr)] -function find_fallback(screen, invalids) +function tag.find_fallback(screen, invalids) local scr = screen or capi.mouse.screen - local t = invalids or selectedlist(scr) + local t = invalids or tag.selectedlist(scr) for _, v in pairs(capi.screen[scr]:tags()) do if not util.table.hasitem(t, v) then return v end @@ -110,9 +111,9 @@ end -- stickied clients are assigned to the optional 'fallback_tag'. -- If after deleting the tag there is no selected tag, try and restore from -- history or select the first tag on the screen. -function delete(target_tag, fallback_tag) +function tag.delete(target_tag, fallback_tag) -- abort if no tag is passed or currently selected - local target_tag = target_tag or selected() + local target_tag = target_tag or tag.selected() if target_tag == nil then return end local ntags = #capi.screen[target_tag.screen]:tags() @@ -124,7 +125,7 @@ function delete(target_tag, fallback_tag) -- No fallback_tag provided, try and get one. if fallback_tag == nil then - fallback_tag = find_fallback(target_scr, {target_tag}) + fallback_tag = tag.find_fallback(target_scr, {target_tag}) end -- Abort if we would have un-tagged clients. @@ -148,9 +149,9 @@ function delete(target_tag, fallback_tag) target_tag.screen = nil -- If no tags are visible, try and view one. - if selected(target_scr) == nil and ntags > 0 then - history.restore() - if selected(target_scr) == nil then + if tag.selected(target_scr) == nil and ntags > 0 then + tag.history.restore() + if tag.selected(target_scr) == nil then capi.screen[target_scr]:tags()[1].selected = true end end @@ -160,9 +161,9 @@ end --- Update the tag history. -- @param obj Screen object. -function history.update(obj) +function tag.history.update(obj) local s = obj.index - local curtags = selectedlist(s) + local curtags = tag.selectedlist(s) -- create history table if not data.history[s] then data.history[s] = {} @@ -170,8 +171,8 @@ function history.update(obj) if data.history[s].current then -- Check that the list is not identical local identical = true - for idx, tag in ipairs(data.history[s].current) do - if curtags[idx] ~= tag then + for idx, _tag in ipairs(data.history[s].current) do + if curtags[idx] ~= _tag then identical = false break end @@ -182,8 +183,8 @@ function history.update(obj) end -- Limit history - if #data.history[s] >= history.limit then - for i = history.limit, #data.history[s] do + if #data.history[s] >= tag.history.limit then + for i = tag.history.limit, #data.history[s] do data.history[s][i] = nil end end @@ -201,20 +202,20 @@ end -- @param idx Index in history. Defaults to "previous" which is a special index -- toggling between last two selected sets of tags. Number (eg 1) will go back -- to the given index in history. -function history.restore(screen, idx) +function tag.history.restore(screen, idx) local s = screen or capi.mouse.screen local i = idx or "previous" - local sel = selectedlist(s) + local sel = tag.selectedlist(s) -- do nothing if history empty if not data.history[s] or not data.history[s][i] then return end -- if all tags been deleted, try next entry if #data.history[s][i] == 0 then if i == "previous" then i = 0 end - history.restore(s, i + 1) + tag.history.restore(s, i + 1) return end -- deselect all tags - viewnone(s) + tag.viewnone(s) -- select tags from the history entry for _, t in ipairs(data.history[s][i]) do t.selected = true @@ -230,7 +231,7 @@ end --- Return a table with all visible tags -- @param s Screen number. -- @return A table with all selected tags. -function selectedlist(s) +function tag.selectedlist(s) local screen = s or capi.mouse.screen local tags = capi.screen[screen]:tags() local vtags = {} @@ -244,96 +245,96 @@ end --- Return only the first visible tag. -- @param s Screen number. -function selected(s) - return selectedlist(s)[1] +function tag.selected(s) + return tag.selectedlist(s)[1] end --- Set master width factor. -- @param mwfact Master width factor. -function setmwfact(mwfact, t) - local t = t or selected() +function tag.setmwfact(mwfact, t) + local t = t or tag.selected() if mwfact >= 0 and mwfact <= 1 then - setproperty(t, "mwfact", mwfact) + tag.setproperty(t, "mwfact", mwfact) end end --- Increase master width factor. -- @param add Value to add to master width factor. -function incmwfact(add, t) - setmwfact(getmwfact(t) + add, t) +function tag.incmwfact(add, t) + tag.setmwfact(tag.getmwfact(t) + add, t) end --- Get master width factor. -- @param t Optional tag. -function getmwfact(t) - local t = t or selected() - return getproperty(t, "mwfact") or 0.5 +function tag.getmwfact(t) + local t = t or tag.selected() + return tag.getproperty(t, "mwfact") or 0.5 end --- Set the number of master windows. -- @param nmaster The number of master windows. -- @param t Optional tag. -function setnmaster(nmaster, t) - local t = t or selected() +function tag.setnmaster(nmaster, t) + local t = t or tag.selected() if nmaster >= 0 then - setproperty(t, "nmaster", nmaster) + tag.setproperty(t, "nmaster", nmaster) end end --- Get the number of master windows. -- @param t Optional tag. -function getnmaster(t) - local t = t or selected() - return getproperty(t, "nmaster") or 1 +function tag.getnmaster(t) + local t = t or tag.selected() + return tag.getproperty(t, "nmaster") or 1 end --- Increase the number of master windows. -- @param add Value to add to number of master windows. -function incnmaster(add, t) - setnmaster(getnmaster(t) + add, t) +function tag.incnmaster(add, t) + tag.setnmaster(tag.getnmaster(t) + add, t) end --- Set the tag icon -- @param icon the icon to set, either path or image object -- @param tag the tag -function seticon(icon, tag) - local tag = tag or selected() - setproperty(tag, "icon", icon) +function tag.seticon(icon, _tag) + local _tag = _tag or tag.selected() + tag.setproperty(_tag, "icon", icon) end --- Get the tag icon -- @param t the tag -function geticon(tag) - local tag = tag or selected() - return getproperty(tag, "icon") +function tag.geticon(_tag) + local _tag = _tag or tag.selected() + return tag.getproperty(_tag, "icon") end --- Set number of column windows. -- @param ncol The number of column. -function setncol(ncol, t) - local t = t or selected() +function tag.setncol(ncol, t) + local t = t or tag.selected() if ncol >= 1 then - setproperty(t, "ncol", ncol) + tag.setproperty(t, "ncol", ncol) end end --- Get number of column windows. -- @param t Optional tag. -function getncol(t) - local t = t or selected() - return getproperty(t, "ncol") or 1 +function tag.getncol(t) + local t = t or tag.selected() + return tag.getproperty(t, "ncol") or 1 end --- Increase number of column windows. -- @param add Value to add to number of column windows. -function incncol(add, t) - setncol(getncol(t) + add, t) +function tag.incncol(add, t) + tag.setncol(tag.getncol(t) + add, t) end --- View no tag. -- @param Optional screen number. -function viewnone(screen) +function tag.viewnone(screen) local tags = capi.screen[screen or capi.mouse.screen]:tags() for i, t in pairs(tags) do t.selected = false @@ -343,17 +344,17 @@ end --- View a tag by its taglist index. -- @param i The relative index to see. -- @param screen Optional screen number. -function viewidx(i, screen) +function tag.viewidx(i, screen) local screen = screen and screen.index or capi.mouse.screen local tags = capi.screen[screen]:tags() local showntags = {} for k, t in ipairs(tags) do - if not getproperty(t, "hide") then + if not tag.getproperty(t, "hide") then table.insert(showntags, t) end end - local sel = selected(screen) - viewnone(screen) + local sel = tag.selected(screen) + tag.viewnone(screen) for k, t in ipairs(showntags) do if t == sel then showntags[util.cycle(#showntags, k + i)].selected = true @@ -365,8 +366,8 @@ end --- Get a tag's index in the screen[]:tags() table. -- @param query_tag The tag object to find. [selected()] -- @return The index of the tag, nil if the tag is not found. -function getidx(query_tag) - local query_tag = query_tag or selected() +function tag.getidx(query_tag) + local query_tag = query_tag or tag.selected() if query_tag == nil then return end for i, t in ipairs(capi.screen[query_tag.screen]:tags()) do @@ -378,24 +379,24 @@ end --- View next tag. This is the same as tag.viewidx(1). -- @param screen The screen number. -function viewnext(screen) - return viewidx(1, screen) +function tag.viewnext(screen) + return tag.viewidx(1, screen) end --- View previous tag. This is the same a tag.viewidx(-1). -- @param screen The screen number. -function viewprev(screen) - return viewidx(-1, screen) +function tag.viewprev(screen) + return tag.viewidx(-1, screen) end --- View only a tag. -- @param t The tag object. -function viewonly(t) +function tag.viewonly(t) local tags = capi.screen[t.screen]:tags() -- First, untag everyone except the viewed tag. - for _, tag in pairs(tags) do - if tag ~= t then - tag.selected = false + for _, _tag in pairs(tags) do + if _tag ~= t then + _tag.selected = false end end -- Then, set this one to selected. @@ -408,22 +409,22 @@ end --- View only a set of tags. -- @param tags A table with tags to view only. -- @param screen Optional screen number of the tags. -function viewmore(tags, screen) +function tag.viewmore(tags, screen) local screen_tags = capi.screen[screen or capi.mouse.screen]:tags() - for _, tag in ipairs(screen_tags) do - if not util.table.hasitem(tags, tag) then - tag.selected = false + for _, _tag in ipairs(screen_tags) do + if not util.table.hasitem(tags, _tag) then + _tag.selected = false end end - for _, tag in ipairs(tags) do - tag.selected = true + for _, _tag in ipairs(tags) do + _tag.selected = true end capi.screen[screen]:emit_signal("tag::history::update") end --- Toggle selection of a tag -- @param tag Tag to be toggled -function viewtoggle(t) +function tag.viewtoggle(t) t.selected = not t.selected capi.screen[t.screen]:emit_signal("tag::history::update") end @@ -431,17 +432,17 @@ end --- Get tag data table. -- @param tag The Tag. -- @return The data table. -function getdata(tag) - return data.tags[tag] +function tag.getdata(_tag) + return data.tags[_tag] end --- Get a tag property. -- @param tag The tag. -- @param prop The property name. -- @return The property. -function getproperty(tag, prop) - if data.tags[tag] then - return data.tags[tag][prop] +function tag.getproperty(_tag, prop) + if data.tags[_tag] then + return data.tags[_tag][prop] end end @@ -451,41 +452,41 @@ end -- @param tag The tag. -- @param prop The property name. -- @param value The value. -function setproperty(tag, prop, value) - if not data.tags[tag] then - data.tags[tag] = {} +function tag.setproperty(_tag, prop, value) + if not data.tags[_tag] then + data.tags[_tag] = {} end - data.tags[tag][prop] = value - tag:emit_signal("property::" .. prop) + data.tags[_tag][prop] = value + _tag:emit_signal("property::" .. prop) end --- Tag a client with the set of current tags. -- @param c The client to tag. -- @param startup Optional: don't do anything if true. -function withcurrent(c, startup) +function tag.withcurrent(c, startup) if startup ~= true then if #c:tags() == 0 then - c:tags(selectedlist(c.screen)) + c:tags(tag.selectedlist(c.screen)) end end end local function attached_connect_signal_screen(screen, sig, func) - capi.screen[screen]:connect_signal("tag::attach", function (s, tag) - tag:connect_signal(sig, func) + capi.screen[screen]:connect_signal("tag::attach", function (s, _tag) + _tag:connect_signal(sig, func) end) - capi.screen[screen]:connect_signal("tag::detach", function (s, tag) - tag:disconnect_signal(sig, func) + capi.screen[screen]:connect_signal("tag::detach", function (s, _tag) + _tag:disconnect_signal(sig, func) end) - for _, tag in ipairs(capi.screen[screen]:tags()) do - tag:connect_signal(sig, func) + for _, _tag in ipairs(capi.screen[screen]:tags()) do + _tag:connect_signal(sig, func) end end --- Add a signal to all attached tag and all tag that will be attached in the -- future. When a tag is detach from the screen, its signal is removed. -- @param screen The screen concerned, or all if nil. -function attached_connect_signal(screen, ...) +function tag.attached_connect_signal(screen, ...) if screen then attached_connect_signal_screen(screen, ...) else @@ -510,10 +511,10 @@ capi.client.connect_signal("manage", function(c, startup) c.screen = capi.mouse.screen end end - c:connect_signal("property::screen", withcurrent) + c:connect_signal("property::screen", tag.withcurrent) end) -capi.client.connect_signal("manage", withcurrent) +capi.client.connect_signal("manage", tag.withcurrent) capi.tag.add_signal("property::hide") capi.tag.add_signal("property::icon") @@ -525,9 +526,13 @@ capi.tag.add_signal("property::windowfact") for s = 1, capi.screen.count() do capi.screen[s]:add_signal("tag::history::update") - capi.screen[s]:connect_signal("tag::history::update", history.update) + capi.screen[s]:connect_signal("tag::history::update", tag.history.update) end -setmetatable(_M, { __call = function (_, ...) return new(...) end }) +function tag.mt:__call(...) + return tag.new(...) +end + +return setmetatable(tag, tag.mt) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/tooltip.lua.in b/lib/awful/tooltip.lua.in index 49b0b7be..aaf12c94 100644 --- a/lib/awful/tooltip.lua.in +++ b/lib/awful/tooltip.lua.in @@ -46,7 +46,8 @@ local ipairs = ipairs -- -- Now the same tooltip is only attached to myclock.
--

-module("awful.tooltip") +-- awful.tooltip +local tooltip = { mt = {} } local data = setmetatable({}, { __mode = 'k' }) @@ -225,6 +226,10 @@ local function new(args) return self end -setmetatable(_M, { __call = function(_, ...) return new(...) end }) +function tooltip.mt:__call(...) + return new(...) +end + +return setmetatable(tooltip, tooltip.mt) -- vim: ft=lua:et:sw=4:ts=4:sts=4:enc=utf-8:tw=78 diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in index 8c326fe9..b225ec78 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -24,13 +24,13 @@ local capi = } --- Utility module for awful -module("awful.util") - -table = {} +-- awful.util +local util = {} +util.table = {} shell = os.getenv("SHELL") or "/bin/sh" -function deprecate(see) +function util.deprecate(see) io.stderr:write("W: awful: function is deprecated") if see then io.stderr:write(", see " .. see) @@ -42,7 +42,7 @@ end --- Strip alpha part of color. -- @param color The color. -- @return The color without alpha channel. -function color_strip_alpha(color) +function util.color_strip_alpha(color) if color:len() == 9 then color = color:sub(1, 7) end @@ -53,7 +53,7 @@ end -- @param t A length. Must be greater than zero. -- @param i An absolute index to fit into #t. -- @return An integer in (1, t) or nil if t is less than or equal to zero. -function cycle(t, i) +function util.cycle(t, i) if t < 1 then return end while i > t do i = i - t end while i < 1 do i = i + t end @@ -63,7 +63,7 @@ end --- Create a directory -- @param dir The directory. -- @return mkdir return code -function mkdir(dir) +function util.mkdir(dir) return os.execute("mkdir -p " .. dir) end @@ -72,7 +72,7 @@ end -- @param sn Enable startup-notification. -- @param screen The screen where to spawn window. -- @return The awesome.spawn return value. -function spawn(cmd, sn, screen) +function util.spawn(cmd, sn, screen) if cmd and cmd ~= "" then if sn == nil then sn = true end return capi.awesome.spawn(cmd, sn, screen or capi.mouse.screen) @@ -82,7 +82,7 @@ end --- Spawn a program using the shell. -- @param cmd The command. -- @param screen The screen where to run the command. -function spawn_with_shell(cmd, screen) +function util.spawn_with_shell(cmd, screen) if cmd and cmd ~= "" then cmd = shell .. " -c \"" .. cmd .. "\"" return capi.awesome.spawn(cmd, false, screen or capi.mouse.screen) @@ -92,7 +92,7 @@ end --- Read a program output and returns its output as a string. -- @param cmd The command to run. -- @return A string with the program output, or the error if one occured. -function pread(cmd) +function util.pread(cmd) if cmd and cmd ~= "" then local f, err = io.popen(cmd, 'r') if f then @@ -107,7 +107,7 @@ end --- Eval Lua code. -- @return The return value of Lua code. -function eval(s) +function util.eval(s) return assert(loadstring(s))() end @@ -116,7 +116,7 @@ local xml_entity_names = { ["'"] = "'", ["\""] = """, ["<"] = "<", -- Useful to set raw text in textbox. -- @param text Text to escape. -- @return Escape text. -function escape(text) +function util.escape(text) return text and text:gsub("['&<>\"]", xml_entity_names) or nil end @@ -124,7 +124,7 @@ local xml_entity_chars = { lt = "<", gt = ">", nbsp = " ", quot = "\"", apos = " --- Unescape a string from entities. -- @param text Text to unescape. -- @return Unescaped text. -function unescape(text) +function util.unescape(text) return text and text:gsub("&(%a+);", xml_entity_chars) or nil end @@ -133,7 +133,7 @@ end -- @param path The file path. -- @return A function if everything is alright, a string with the error -- otherwise. -function checkfile(path) +function util.checkfile(path) local f, e = loadfile(path) -- Return function if function, otherwise return error. if f then return f end @@ -144,8 +144,8 @@ end -- It checks if the configuration file is valid, and then restart if it's ok. -- If it's not ok, the error will be returned. -- @return Never return if awesome restart, or return a string error. -function restart() - local c = checkfile(capi.awesome.conffile) +function util.restart() + local c = util.checkfile(capi.awesome.conffile) if type(c) ~= "function" then return c @@ -159,7 +159,7 @@ end -- default paths. -- @param d The directory to get (either "config" or "cache"). -- @return A string containing the requested path. -function getdir(d) +function util.getdir(d) if d == "config" then local dir = os.getenv("XDG_CONFIG_HOME") if dir then @@ -182,7 +182,7 @@ end -- @param dirs Table of dirs to search, otherwise { '/usr/share/pixmaps/' } -- @param size Optional size. If this is specified, subdirectories x -- of the dirs are searched first -function geticonpath(iconname, exts, dirs, size) +function util.geticonpath(iconname, exts, dirs, size) exts = exts or { 'png', 'gif' } dirs = dirs or { '/usr/share/pixmaps/' } for _, d in pairs(dirs) do @@ -191,12 +191,12 @@ function geticonpath(iconname, exts, dirs, size) if size then icon = string.format("%s%ux%u/%s.%s", d, size, size, iconname, e) - if file_readable(icon) then + if util.file_readable(icon) then return icon end end icon = d .. iconname .. '.' .. e - if file_readable(icon) then + if util.file_readable(icon) then return icon end end @@ -206,7 +206,7 @@ end --- Check if file exists and is readable. -- @param filename The file path -- @return True if file exists and readable. -function file_readable(filename) +function util.file_readable(filename) local file = io.open(filename) if file then io.close(file) @@ -246,7 +246,7 @@ end -- { }, { 10 }, { 15 }, { 34 }, { 10, 15 }, { 10, 34 }, etc. -- @param set A set. -- @return A table with all subset. -function subsets(set) +function util.subsets(set) local mask = {} local ret = {} for i = 1, #set do mask[i] = false end @@ -264,7 +264,7 @@ end -- This will iterate all tables and insert all their keys into a new table. -- @param args A list of tables to join -- @return A new table containing all keys from the arguments. -function table.join(...) +function util.table.join(...) local ret = {} for i, t in ipairs({...}) do if t then @@ -284,7 +284,7 @@ end -- @param t The table. -- @param item The item to look for in values of the table. -- @return The key were the item is found, or nil if not found. -function table.hasitem(t, item) +function util.table.hasitem(t, item) for k, v in pairs(t) do if v == item then return k @@ -297,7 +297,7 @@ end -- @param width Maximum length of each line. Default: 72. -- @param indent Number of spaces added before each wrapped line. Default: 0. -- @return The string with lines wrapped to width. -function linewrap(text, width, indent) +function util.linewrap(text, width, indent) local text = text or "" local width = width or 72 local indent = indent or 0 @@ -315,7 +315,7 @@ end --- Get a sorted table with all integer keys from a table -- @param t the table for which the keys to get -- @return A table with keys -function table.keys(t) +function util.table.keys(t) local keys = { } for k, _ in pairs(t) do rtable.insert(keys, k) @@ -330,8 +330,8 @@ end -- @param t The table to retrieve the keys for -- @param ... the types to look for -- @return A filtered table with keys -function table.keys_filter(t, ...) - local keys = table.keys(t) +function util.table.keys_filter(t, ...) + local keys = util.table.keys(t) local keys_filtered = { } for _, k in pairs(keys) do for _, et in pairs({...}) do @@ -347,7 +347,7 @@ end --- Reverse a table -- @param t the table to reverse -- @return the reversed table -function table.reverse(t) +function util.table.reverse(t) local tr = { } -- reverse all elements with integer keys for _, v in ipairs(t) do @@ -365,11 +365,11 @@ end --- Clone a table -- @param t the table to clone -- @return a clone of t -function table.clone(t) +function util.table.clone(t) local c = { } for k, v in pairs(t) do if type(v) == "table" then - c[k] = table.clone(v) + c[k] = util.table.clone(v) else c[k] = v end @@ -385,7 +385,7 @@ end -- @param filter a function that returns true to indicate a positive match -- @param start what index to start iterating from. Default is 1 (=> start of -- the table) -function table.iterate(t, filter, start) +function util.table.iterate(t, filter, start) local count = 0 local index = start or 1 local length = #t @@ -393,10 +393,13 @@ function table.iterate(t, filter, start) return function () while count < length do local item = t[index] - index = cycle(#t, index + 1) + index = util.cycle(#t, index + 1) count = count + 1 if filter(item) then return item end end end end + +return util + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/awful/wibox.lua.in b/lib/awful/wibox.lua.in index dd312f58..1251564e 100644 --- a/lib/awful/wibox.lua.in +++ b/lib/awful/wibox.lua.in @@ -22,7 +22,8 @@ local beautiful = require("beautiful") --- Wibox module for awful. -- This module allows you to easily create wibox and attach them to the edge of -- a screen. -module("awful.wibox") +-- awful.wibox +local awfulwibox = { mt = {} } -- Array of table with wiboxes inside. -- It's an array so it is ordered. @@ -31,7 +32,7 @@ local wiboxes = {} --- Get a wibox position if it has been set, or return top. -- @param wibox The wibox -- @return The wibox position. -function get_position(wibox) +function awfulwibox.get_position(wibox) for _, wprop in ipairs(wiboxes) do if wprop.wibox == wibox then return wprop.position @@ -45,7 +46,7 @@ end -- @param position The position: top, bottom left or right. -- @param screen If the wibox it not attached to a screen, specified on which -- screen the position should be set. -function set_position(wibox, position, screen) +function awfulwibox.set_position(wibox, position, screen) local area = capi.screen[screen].geometry -- The "length" of a wibox is always chosen to be the optimal size @@ -72,7 +73,7 @@ end -- Reset all wiboxes positions. local function update_all_wiboxes_position() for _, wprop in ipairs(wiboxes) do - set_position(wprop.wibox, wprop.position, wprop.screen) + awfulwibox.set_position(wprop.wibox, wprop.position, wprop.screen) end end @@ -104,7 +105,7 @@ end -- will be attached. -- @param wibox The wibox to attach. -- @param position The position of the wibox: top, bottom, left or right. -function attach(wibox, position, screen) +function awfulwibox.attach(wibox, position, screen) -- Store wibox as attached in a weak-valued table local wibox_prop_table -- Start from end since we sometimes remove items @@ -141,8 +142,8 @@ end -- @param align The alignment: left, right or center. -- @param screen If the wibox is not attached to any screen, you can specify the -- screen where to align. Otherwise 1 is assumed. -function align(wibox, align, screen) - local position = get_position(wibox) +function awfulwibox.align(wibox, align, screen) + local position = awfulwibox.get_position(wibox) local area = capi.screen[screen].workarea if position == "right" then @@ -186,9 +187,9 @@ end --- Stretch a wibox so it takes all screen width or height. -- @param wibox The wibox. -- @param screen The screen to stretch on, or the wibox screen. -function stretch(wibox, screen) +function awfulwibox.stretch(wibox, screen) if screen then - local position = get_position(wibox) + local position = awfulwibox.get_position(wibox) local area = capi.screen[screen].workarea if position == "right" or position == "left" then wibox.height = area.height - (2 * wibox.border_width) @@ -208,7 +209,7 @@ end -- You can also set the screen key with a screen number to attach the wibox. -- If not specified, 1 is assumed. -- @return The wibox created. -function new(arg) +function awfulwibox.new(arg) local arg = arg or {} local position = arg.position or "top" local has_to_stretch = true @@ -251,14 +252,14 @@ function new(arg) w.visible = true - attach(w, position, screen) + awfulwibox.attach(w, position, screen) if has_to_stretch then - stretch(w, screen) + awfulwibox.stretch(w, screen) else - align(w, arg.align, screen) + awfulwibox.align(w, arg.align, screen) end - set_position(w, position, screen) + awfulwibox.set_position(w, position, screen) return w end @@ -275,6 +276,10 @@ end capi.client.connect_signal("property::struts", update_wiboxes_on_struts) capi.client.connect_signal("unmanage", update_wiboxes_on_struts) -setmetatable(_M, { __call = function(_, ...) return new(...) end }) +function awfulwibox.mt:__call(...) + return awfulwibox.new(...) +end + +return setmetatable(awfulwibox, awfulwibox.mt) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/menubar/init.lua.in b/lib/menubar/init.lua.in index 5ae4fb2f..11de99f5 100644 --- a/lib/menubar/init.lua.in +++ b/lib/menubar/init.lua.in @@ -193,7 +193,7 @@ end -- Create the menubar wibox and widgets. local function initialize() instance.wibox = wibox({}) - instance.widget = get() + instance.widget = menubar.get() instance.wibox.ontop = true instance.prompt = awful.widget.prompt() local layout = wibox.layout.fixed.horizontal() diff --git a/lib/wibox/layout/mirror.lua.in b/lib/wibox/layout/mirror.lua.in index ffa17dfc..3251ace4 100644 --- a/lib/wibox/layout/mirror.lua.in +++ b/lib/wibox/layout/mirror.lua.in @@ -107,7 +107,7 @@ local function new() ret.horizontal = false ret.vertical = false - for k, v in pairs(_M) do + for k, v in pairs(mirror) do if type(v) == "function" then ret[k] = v end diff --git a/lib/wibox/layout/rotate.lua.in b/lib/wibox/layout/rotate.lua.in index 760a6a91..f931e35c 100644 --- a/lib/wibox/layout/rotate.lua.in +++ b/lib/wibox/layout/rotate.lua.in @@ -106,7 +106,7 @@ end local function new() local ret = widget_base.make_widget() - for k, v in pairs(_M) do + for k, v in pairs(rotate) do if type(v) == "function" then ret[k] = v end