inital commit of clone of old repo
This commit is contained in:
@ -0,0 +1,45 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2008-2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local type = type
|
||||
local button = require("awful.button")
|
||||
local capi = { image = image,
|
||||
widget = widget,
|
||||
mouse = mouse }
|
||||
|
||||
module("awful.widget.button")
|
||||
|
||||
--- Create a button widget. When clicked, the image is deplaced to make it like
|
||||
-- a real button.
|
||||
-- @param args Standard widget table arguments, plus image for the image path or
|
||||
-- the image object.
|
||||
-- @return A textbox widget configured as a button.
|
||||
function new(args)
|
||||
if not args or not args.image then return end
|
||||
local img_release
|
||||
if type(args.image) == "string" then
|
||||
img_release = capi.image(args.image)
|
||||
elseif type(args.image) == "image" then
|
||||
img_release = args.image
|
||||
else
|
||||
return
|
||||
end
|
||||
local img_press = img_release:crop(-2, -2, img_release.width, img_release.height)
|
||||
args.type = "imagebox"
|
||||
local w = capi.widget(args)
|
||||
w.image = img_release
|
||||
w:buttons(button({}, 1, function () w.image = img_press end, function () w.image = img_release end))
|
||||
w:add_signal("mouse::leave", function () w.image = img_release end)
|
||||
w:add_signal("mouse::enter", function ()
|
||||
if capi.mouse.coords().buttons[1] then w.image = img_press end
|
||||
end)
|
||||
return w
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,98 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2008-2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-- Grab environment we need
|
||||
local math = math
|
||||
local type = type
|
||||
local pcall = pcall
|
||||
local ipairs = ipairs
|
||||
local setmetatable = setmetatable
|
||||
local capi = { widget = widget, button = button }
|
||||
|
||||
--- Common widget code
|
||||
module("awful.widget.common")
|
||||
|
||||
-- Private structures
|
||||
tagwidgets = setmetatable({}, { __mode = 'k' })
|
||||
|
||||
function list_update(w, buttons, label, data, widgets, objects)
|
||||
-- Hack: if it has been registered as a widget in a wibox,
|
||||
-- it's w.len since __len meta does not work on table until Lua 5.2.
|
||||
-- Otherwise it's standard #w.
|
||||
local len = (w.len or #w) / 2
|
||||
-- Add more widgets
|
||||
if len < #objects then
|
||||
for i = len * 2 + 1, #objects * 2, 2 do
|
||||
local ib = capi.widget({ type = "imagebox", align = widgets.imagebox.align })
|
||||
local tb = capi.widget({ type = "textbox", align = widgets.textbox.align })
|
||||
|
||||
w[i] = ib
|
||||
w[i + 1] = tb
|
||||
w[i + 1]:margin({ left = widgets.textbox.margin.left, right = widgets.textbox.margin.right })
|
||||
w[i + 1].bg_resize = widgets.textbox.bg_resize or false
|
||||
w[i + 1].bg_align = widgets.textbox.bg_align or ""
|
||||
|
||||
if type(objects[math.floor(i / 2) + 1]) == "tag" then
|
||||
tagwidgets[ib] = objects[math.floor(i / 2) + 1]
|
||||
tagwidgets[tb] = objects[math.floor(i / 2) + 1]
|
||||
end
|
||||
end
|
||||
-- Remove widgets
|
||||
elseif len > #objects then
|
||||
for i = #objects * 2 + 1, len * 2, 2 do
|
||||
w[i] = nil
|
||||
w[i + 1] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- update widgets text
|
||||
for k = 1, #objects * 2, 2 do
|
||||
local o = objects[(k + 1) / 2]
|
||||
if buttons then
|
||||
-- Use a local variable so that the garbage collector doesn't strike
|
||||
-- between now and the :buttons() call.
|
||||
local btns = data[o]
|
||||
if not btns then
|
||||
btns = {}
|
||||
data[o] = btns
|
||||
for kb, b in ipairs(buttons) do
|
||||
-- Create a proxy button object: it will receive the real
|
||||
-- press and release events, and will propagate them the the
|
||||
-- button object the user provided, but with the object as
|
||||
-- argument.
|
||||
local btn = capi.button { modifiers = b.modifiers, button = b.button }
|
||||
btn:add_signal("press", function () b:emit_signal("press", o) end)
|
||||
btn:add_signal("release", function () b:emit_signal("release", o) end)
|
||||
btns[#btns + 1] = btn
|
||||
end
|
||||
end
|
||||
w[k]:buttons(btns)
|
||||
w[k + 1]:buttons(btns)
|
||||
end
|
||||
|
||||
local text, bg, bg_image, icon = label(o)
|
||||
|
||||
-- Check if we got a valid text here, it might contain e.g. broken utf8.
|
||||
if not pcall(function() w[k + 1].text = text end) then
|
||||
w[k + 1].text = "<i>Invalid</i>"
|
||||
end
|
||||
|
||||
w[k + 1].bg, w[k + 1].bg_image = bg, bg_image
|
||||
w[k].bg, w[k].image = bg, icon
|
||||
if not w[k + 1].text then
|
||||
w[k+1].visible = false
|
||||
else
|
||||
w[k+1].visible = true
|
||||
end
|
||||
if not w[k].image then
|
||||
w[k].visible = false
|
||||
else
|
||||
w[k].visible = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,301 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local ipairs = ipairs
|
||||
local math = math
|
||||
local table = table
|
||||
local type = type
|
||||
local capi = { image = image,
|
||||
widget = widget }
|
||||
local layout = require("awful.widget.layout")
|
||||
|
||||
--- A graph widget.
|
||||
module("awful.widget.graph")
|
||||
|
||||
local data = setmetatable({}, { __mode = "k" })
|
||||
|
||||
--- Set the graph border color.
|
||||
-- If the value is nil, no border will be drawn.
|
||||
-- @name set_border_color
|
||||
-- @class function
|
||||
-- @param graph The graph.
|
||||
-- @param color The border color to set.
|
||||
|
||||
--- Set the graph foreground color as a gradient.
|
||||
-- @name set_gradient_colors
|
||||
-- @class function
|
||||
-- @param graph The graph.
|
||||
-- @param gradient_colors A table with gradients colors. The distance between each color
|
||||
-- can also be specified. Example: { "red", "blue" } or { "red", "green",
|
||||
-- "blue", blue = 10 } to specify blue distance from other colors.
|
||||
|
||||
--- Set the graph foreground colors gradient angle. Default is 270 degrees
|
||||
-- (horizontal).
|
||||
-- @name set_gradient_angle
|
||||
-- @class function
|
||||
-- @param graph The graph.
|
||||
-- @param gradient_angle Angle of gradient in degrees.
|
||||
|
||||
--- Set the graph foreground color.
|
||||
-- @name set_color
|
||||
-- @class function
|
||||
-- @param graph The graph.
|
||||
-- @param color The graph color.
|
||||
|
||||
--- Set the graph background color.
|
||||
-- @name set_background_color
|
||||
-- @class function
|
||||
-- @param graph The graph.
|
||||
-- @param color The graph background color.
|
||||
|
||||
--- Set the maximum value the graph should handle.
|
||||
-- If "scale" is also set, the graph never scales up below this value, but it
|
||||
-- automatically scales down to make all data fit.
|
||||
-- @name set_max_value
|
||||
-- @class function
|
||||
-- @param graph The graph.
|
||||
-- @param value The value.
|
||||
|
||||
--- Set the graph to automatically scale its values. Default is false.
|
||||
-- @name set_scale
|
||||
-- @class function
|
||||
-- @param graph The graph.
|
||||
-- @param scale A boolean value
|
||||
|
||||
--- Set the graph to draw stacks. Default is false.
|
||||
-- @name set_stack
|
||||
-- @class function
|
||||
-- @param graph The graph.
|
||||
-- @param stack A boolean value.
|
||||
|
||||
--- Set the graph stacking colors. Order matters.
|
||||
-- @name set_stack_colors
|
||||
-- @class function
|
||||
-- @param graph The graph.
|
||||
-- @param stack_colors A table with stacking colors.
|
||||
|
||||
local properties = { "width", "height", "border_color", "stack",
|
||||
"stack_colors", "gradient_colors", "gradient_angle",
|
||||
"color", "background_color", "max_value", "scale" }
|
||||
|
||||
local function update(graph)
|
||||
-- Create new empty image
|
||||
local img = capi.image.argb32(data[graph].width, data[graph].height, nil)
|
||||
local max_value = data[graph].max_value
|
||||
local values = data[graph].values
|
||||
|
||||
local border_width = 0
|
||||
if data[graph].border_color then
|
||||
border_width = 1
|
||||
end
|
||||
|
||||
-- Draw a stacked graph
|
||||
if data[graph].stack then
|
||||
|
||||
if data[graph].scale then
|
||||
for _, v in ipairs(values) do
|
||||
for __, sv in ipairs(v) do
|
||||
if sv > max_value then
|
||||
max_value = sv
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Draw the background first
|
||||
img:draw_rectangle(border_width, border_width,
|
||||
data[graph].width - (2 * border_width),
|
||||
data[graph].height,
|
||||
true, data[graph].background_color or "#000000aa")
|
||||
|
||||
for i = 0, data[graph].width - (2 * border_width) do
|
||||
local rel_i = 0
|
||||
local rel_x = data[graph].width - border_width - i - 1
|
||||
|
||||
if data[graph].stack_colors then
|
||||
for idx, color in ipairs(data[graph].stack_colors) do
|
||||
local stack_values = values[idx]
|
||||
if stack_values and i < #stack_values then
|
||||
local value = stack_values[#stack_values - i] + rel_i
|
||||
|
||||
img:draw_line(rel_x, border_width - 1 +
|
||||
math.ceil((data[graph].height - 2 * border_width) * (1 - (rel_i / max_value))),
|
||||
rel_x, border_width - 1 +
|
||||
math.ceil((data[graph].height - 2 * border_width) * (1 - (value / max_value))),
|
||||
color or "red")
|
||||
rel_i = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
if data[graph].scale then
|
||||
for _, v in ipairs(values) do
|
||||
if v > max_value then
|
||||
max_value = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Draw full gradient
|
||||
if data[graph].gradient_colors then
|
||||
img:draw_rectangle_gradient(border_width, border_width,
|
||||
data[graph].width - (2 * border_width),
|
||||
data[graph].height - (2 * border_width),
|
||||
data[graph].gradient_colors,
|
||||
data[graph].gradient_angle or 270)
|
||||
else
|
||||
img:draw_rectangle(border_width, border_width,
|
||||
data[graph].width - (2 * border_width),
|
||||
data[graph].height - (2 * border_width),
|
||||
true, data[graph].color or "red")
|
||||
end
|
||||
|
||||
-- Draw the background on no value
|
||||
if #values ~= 0 then
|
||||
-- Draw reverse
|
||||
for i = 0, #values - 1 do
|
||||
local value = values[#values - i]
|
||||
if value >= 0 then
|
||||
value = value / max_value
|
||||
img:draw_line(data[graph].width - border_width - i - 1,
|
||||
border_width - 1 +
|
||||
math.ceil((data[graph].height - 2 * border_width) * (1 - value)),
|
||||
data[graph].width - border_width - i - 1,
|
||||
border_width - 1,
|
||||
data[graph].background_color or "#000000aa")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- If we didn't draw values in full length, draw a square
|
||||
-- over the last, left, part to reset everything to 0
|
||||
if #values < data[graph].width - (2 * border_width) then
|
||||
img:draw_rectangle(border_width, border_width,
|
||||
data[graph].width - (2 * border_width) - #values,
|
||||
data[graph].height - (2 * border_width),
|
||||
true, data[graph].background_color or "#000000aa")
|
||||
end
|
||||
end
|
||||
|
||||
-- Draw the border last so that it overlaps already drawn values
|
||||
if data[graph].border_color then
|
||||
-- Draw the border
|
||||
img:draw_rectangle(0, 0, data[graph].width, data[graph].height,
|
||||
false, data[graph].border_color or "white")
|
||||
end
|
||||
|
||||
-- Update the image
|
||||
graph.widget.image = img
|
||||
end
|
||||
|
||||
--- Add a value to the graph
|
||||
-- @param graph The graph.
|
||||
-- @param value The value between 0 and 1.
|
||||
-- @param group The stack color group index.
|
||||
local function add_value(graph, value, group)
|
||||
if not graph then return end
|
||||
|
||||
local value = value or 0
|
||||
local values = data[graph].values
|
||||
local max_value = data[graph].max_value
|
||||
value = math.max(0, value)
|
||||
if not data[graph].scale then
|
||||
value = math.min(max_value, value)
|
||||
end
|
||||
|
||||
if data[graph].stack and group then
|
||||
if not data[graph].values[group]
|
||||
or type(data[graph].values[group]) ~= "table"
|
||||
then
|
||||
data[graph].values[group] = {}
|
||||
end
|
||||
values = data[graph].values[group]
|
||||
end
|
||||
table.insert(values, value)
|
||||
|
||||
local border_width = 0
|
||||
if data[graph].border then border_width = 2 end
|
||||
|
||||
-- Ensure we never have more data than we can draw
|
||||
while #values > data[graph].width - border_width do
|
||||
table.remove(values, 1)
|
||||
end
|
||||
|
||||
update(graph)
|
||||
return graph
|
||||
end
|
||||
|
||||
|
||||
--- Set the graph height.
|
||||
-- @param graph The graph.
|
||||
-- @param height The height to set.
|
||||
function set_height(graph, height)
|
||||
if height >= 5 then
|
||||
data[graph].height = height
|
||||
update(graph)
|
||||
end
|
||||
return graph
|
||||
end
|
||||
|
||||
--- Set the graph width.
|
||||
-- @param graph The graph.
|
||||
-- @param width The width to set.
|
||||
function set_width(graph, width)
|
||||
if width >= 5 then
|
||||
data[graph].width = width
|
||||
update(graph)
|
||||
end
|
||||
return graph
|
||||
end
|
||||
|
||||
-- Build properties function
|
||||
for _, prop in ipairs(properties) do
|
||||
if not _M["set_" .. prop] then
|
||||
_M["set_" .. prop] = function(graph, value)
|
||||
data[graph][prop] = value
|
||||
update(graph)
|
||||
return graph
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Create a graph widget.
|
||||
-- @param args Standard widget() arguments. You should add width and height
|
||||
-- key to set graph geometry.
|
||||
-- @return A graph widget.
|
||||
function new(args)
|
||||
local args = args or {}
|
||||
args.type = "imagebox"
|
||||
|
||||
local width = args.width or 100
|
||||
local height = args.height or 20
|
||||
|
||||
if width < 5 or height < 5 then return end
|
||||
|
||||
local graph = {}
|
||||
graph.widget = capi.widget(args)
|
||||
graph.widget.resize = false
|
||||
|
||||
data[graph] = { width = width, height = height, values = {}, max_value = 1 }
|
||||
|
||||
-- Set methods
|
||||
graph.add_value = add_value
|
||||
|
||||
for _, prop in ipairs(properties) do
|
||||
graph["set_" .. prop] = _M["set_" .. prop]
|
||||
end
|
||||
|
||||
graph.layout = args.layout or layout.horizontal.leftright
|
||||
|
||||
return graph
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,21 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2008-2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
require("awful.widget.taglist")
|
||||
require("awful.widget.tasklist")
|
||||
require("awful.widget.button")
|
||||
require("awful.widget.launcher")
|
||||
require("awful.widget.prompt")
|
||||
require("awful.widget.progressbar")
|
||||
require("awful.widget.graph")
|
||||
require("awful.widget.layoutbox")
|
||||
require("awful.widget.textclock")
|
||||
require("awful.widget.layout")
|
||||
|
||||
--- Widget module for awful
|
||||
module("awful.widget")
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,35 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2008-2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local util = require("awful.util")
|
||||
local wbutton = require("awful.widget.button")
|
||||
local button = require("awful.button")
|
||||
|
||||
module("awful.widget.launcher")
|
||||
|
||||
--- Create a button widget which will launch a command.
|
||||
-- @param args Standard widget table arguments, plus image for the image path
|
||||
-- and command for the command to run on click, or either menu to create menu.
|
||||
-- @return A launcher widget.
|
||||
function new(args)
|
||||
if not args.command and not args.menu then return end
|
||||
local w = wbutton(args)
|
||||
if not w then return end
|
||||
|
||||
if args.command then
|
||||
b = util.table.join(w:buttons(), button({}, 1, nil, function () util.spawn(args.command) end))
|
||||
elseif args.menu then
|
||||
b = util.table.join(w:buttons(), button({}, 1, nil, function () args.menu:toggle() end))
|
||||
end
|
||||
|
||||
w:buttons(b)
|
||||
return w
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function (_, ...) return new(...) end })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,58 @@
|
||||
-------------------------------------------------
|
||||
-- @author Gregor Best <farhaven@googlemail.com>
|
||||
-- @copyright 2009 Gregor Best
|
||||
-- @release v3.4.10
|
||||
-------------------------------------------------
|
||||
|
||||
-- Grab environment
|
||||
local ipairs = ipairs
|
||||
local type = type
|
||||
local table = table
|
||||
local math = math
|
||||
local setmetatable = setmetatable
|
||||
local util = require("awful.util")
|
||||
|
||||
--- Simple default layout, emulating the fallback C layout
|
||||
module("awful.widget.layout.default")
|
||||
|
||||
local function default(bounds, widgets, screen)
|
||||
local geometries = {
|
||||
free = { x = 0, y = 0, width = 0, height = bounds.height }
|
||||
}
|
||||
|
||||
local width = 0
|
||||
|
||||
local keys = util.table.keys_filter(widgets, "table", "widget")
|
||||
|
||||
for _, k in ipairs(keys) do
|
||||
local v = widgets[k]
|
||||
if type(v) == "table" then
|
||||
local layout = v.layout or default
|
||||
local nbounds = util.table.clone(bounds)
|
||||
local g = layout(nbounds, v, screen)
|
||||
for _, w in ipairs(g) do
|
||||
table.insert(geometries, w)
|
||||
end
|
||||
else
|
||||
if v.visible then
|
||||
local e = v:extents(screen)
|
||||
e.x = 0
|
||||
e.y = 0
|
||||
e.width = math.min(e.width, bounds.width)
|
||||
e.height = bounds.height
|
||||
width = math.max(e.width, width)
|
||||
|
||||
table.insert(geometries, e)
|
||||
else
|
||||
table.insert(geometries, { x = 0, y = 0, width = 0, height = 0 })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
geometries.free.width = bounds.width - width
|
||||
geometries.free.x = width
|
||||
|
||||
return geometries
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return default(...) end })
|
@ -0,0 +1,188 @@
|
||||
-------------------------------------------------
|
||||
-- @author Gregor Best <farhaven@googlemail.com>
|
||||
-- @copyright 2009 Gregor Best
|
||||
-- @release v3.4.10
|
||||
-------------------------------------------------
|
||||
|
||||
-- Grab environment
|
||||
local ipairs = ipairs
|
||||
local type = type
|
||||
local table = table
|
||||
local math = math
|
||||
local util = require("awful.util")
|
||||
local default = require("awful.widget.layout.default")
|
||||
local margins = awful.widget.layout.margins
|
||||
|
||||
--- Horizontal widget layout
|
||||
module("awful.widget.layout.horizontal")
|
||||
|
||||
local function horizontal(direction, bounds, widgets, screen)
|
||||
local geometries = { }
|
||||
local x = 0
|
||||
|
||||
-- we are only interested in tables and widgets
|
||||
local keys = util.table.keys_filter(widgets, "table", "widget")
|
||||
|
||||
for _, k in ipairs(keys) do
|
||||
local v = widgets[k]
|
||||
if type(v) == "table" then
|
||||
local layout = v.layout or default
|
||||
if margins[v] then
|
||||
bounds.width = bounds.width - (margins[v].left or 0) - (margins[v].right or 0)
|
||||
bounds.height = bounds.height - (margins[v].top or 0) - (margins[v].bottom or 0)
|
||||
end
|
||||
local g = layout(bounds, v, screen)
|
||||
if margins[v] then
|
||||
x = x + (margins[v].left or 0)
|
||||
end
|
||||
for _, v in ipairs(g) do
|
||||
v.x = v.x + x
|
||||
v.y = v.y + (margins[v] and (margins[v].top and margins[v].top or 0) or 0)
|
||||
table.insert(geometries, v)
|
||||
end
|
||||
bounds = g.free
|
||||
if margins[v] then
|
||||
x = x + g.free.x + (margins[v].right or 0)
|
||||
bounds.width = bounds.width - (margins[v].right or 0) - (margins[v].left or 0)
|
||||
else
|
||||
x = x + g.free.x
|
||||
end
|
||||
elseif type(v) == "widget" then
|
||||
local g
|
||||
if v.visible then
|
||||
g = v:extents(screen)
|
||||
if margins[v] then
|
||||
g.width = g.width + (margins[v].left or 0) + (margins[v].right or 0)
|
||||
g.height = g.height + (margins[v].top or 0) + (margins[v].bottom or 0)
|
||||
end
|
||||
else
|
||||
g = {
|
||||
width = 0,
|
||||
height = 0,
|
||||
}
|
||||
end
|
||||
|
||||
if v.resize and g.width > 0 and g.height > 0 then
|
||||
local ratio = g.width / g.height
|
||||
g.width = math.floor(bounds.height * ratio)
|
||||
g.height = bounds.height
|
||||
end
|
||||
|
||||
if g.width > bounds.width then
|
||||
g.width = bounds.width
|
||||
end
|
||||
g.height = bounds.height
|
||||
|
||||
if margins[v] then
|
||||
g.y = (margins[v].top or 0)
|
||||
else
|
||||
g.y = 0
|
||||
end
|
||||
|
||||
if direction == "leftright" then
|
||||
if margins[v] then
|
||||
g.x = x + (margins[v].left or 0)
|
||||
else
|
||||
g.x = x
|
||||
end
|
||||
x = x + g.width
|
||||
else
|
||||
if margins[v] then
|
||||
g.x = x + bounds.width - g.width + (margins[v].left or 0)
|
||||
else
|
||||
g.x = x + bounds.width - g.width
|
||||
end
|
||||
end
|
||||
bounds.width = bounds.width - g.width
|
||||
|
||||
table.insert(geometries, g)
|
||||
end
|
||||
end
|
||||
|
||||
geometries.free = util.table.clone(bounds)
|
||||
geometries.free.x = x
|
||||
geometries.free.y = 0
|
||||
|
||||
return geometries
|
||||
end
|
||||
|
||||
function flex(bounds, widgets, screen)
|
||||
local geometries = {
|
||||
free = util.table.clone(bounds)
|
||||
}
|
||||
-- the flex layout always uses the complete available place, thus we return
|
||||
-- no usable free area
|
||||
geometries.free.width = 0
|
||||
|
||||
-- we are only interested in tables and widgets
|
||||
local keys = util.table.keys_filter(widgets, "table", "widget")
|
||||
local nelements = 0
|
||||
|
||||
for _, k in ipairs(keys) do
|
||||
local v = widgets[k]
|
||||
if type(v) == "table" then
|
||||
nelements = nelements + 1
|
||||
elseif type(v) == "widget" then
|
||||
local g = v:extents()
|
||||
if v.resize and g.width > 0 and g.height > 0 then
|
||||
bounds.width = bounds.width - bounds.height
|
||||
elseif g.width > 0 and g.height > 0 then
|
||||
nelements = nelements + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
nelements = (nelements == 0) and 1 or nelements
|
||||
|
||||
local x = 0
|
||||
local width = bounds.width / nelements
|
||||
|
||||
for _, k in ipairs(util.table.keys(widgets)) do
|
||||
local v = widgets[k]
|
||||
if type(v) == "table" then
|
||||
local layout = v.layout or default
|
||||
local g = layout(bounds, v, screen)
|
||||
for _, v in ipairs(g) do
|
||||
v.x = v.x + x
|
||||
table.insert(geometries, v)
|
||||
end
|
||||
bounds = g.free
|
||||
elseif type(v) == "widget" then
|
||||
local g = v:extents(screen)
|
||||
g.resize = v.resize
|
||||
|
||||
if v.resize and g.width > 0 and g.height > 0 then
|
||||
g.width = bounds.height
|
||||
g.height = bounds.height
|
||||
g.x = x
|
||||
g.y = bounds.y
|
||||
x = x + g.width
|
||||
elseif g.width > 0 and g.height > 0 then
|
||||
g.x = x
|
||||
g.y = bounds.y
|
||||
g.width = math.floor(width + 0.5)
|
||||
g.height = bounds.height
|
||||
x = x + width
|
||||
else
|
||||
g.x = 0
|
||||
g.y = 0
|
||||
g.width = 0
|
||||
g.height = 0
|
||||
end
|
||||
|
||||
table.insert(geometries, g)
|
||||
end
|
||||
end
|
||||
|
||||
return geometries
|
||||
end
|
||||
|
||||
function leftright(...)
|
||||
return horizontal("leftright", ...)
|
||||
end
|
||||
|
||||
function rightleft(...)
|
||||
return horizontal("rightleft", ...)
|
||||
end
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,23 @@
|
||||
local setmetatable = setmetatable
|
||||
local require = require
|
||||
|
||||
-- Widget layouts
|
||||
module("awful.widget.layout")
|
||||
|
||||
--- Widgets margins.
|
||||
-- <p>In this table you can set the margin you want the layout to use when
|
||||
-- positionning your widgets.
|
||||
-- For example, if you want to put 10 pixel free on left on a widget, add this:
|
||||
-- <code>
|
||||
-- awful.widget.layout.margins[mywidget] = { left = 10 }
|
||||
-- </code>
|
||||
-- </p>
|
||||
-- @name margins
|
||||
-- @class table
|
||||
margins = setmetatable({}, { __mode = 'k' })
|
||||
|
||||
require("awful.widget.layout.horizontal")
|
||||
require("awful.widget.layout.vertical")
|
||||
require("awful.widget.layout.default")
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,101 @@
|
||||
-------------------------------------------------
|
||||
-- @author Gregor Best <farhaven@googlemail.com>
|
||||
-- @copyright 2009 Gregor Best
|
||||
-- @release v3.4.10
|
||||
-------------------------------------------------
|
||||
|
||||
-- Grab environment
|
||||
local ipairs = ipairs
|
||||
local type = type
|
||||
local table = table
|
||||
local math = math
|
||||
local util = require("awful.util")
|
||||
local default = require("awful.widget.layout.default")
|
||||
|
||||
--- Vertical widget layout
|
||||
module("awful.widget.layout.vertical")
|
||||
|
||||
function flex(bounds, widgets, screen)
|
||||
local geometries = {
|
||||
free = util.table.clone(bounds)
|
||||
}
|
||||
|
||||
local y = 0
|
||||
|
||||
-- we are only interested in tables and widgets
|
||||
local keys = util.table.keys_filter(widgets, "table", "widget")
|
||||
local nelements = 0
|
||||
for _, k in ipairs(keys) do
|
||||
local v = widgets[k]
|
||||
if type(v) == "table" then
|
||||
nelements = nelements + 1
|
||||
else
|
||||
local e = v:extents()
|
||||
if v.visible and e.width > 0 and e.height > 0 then
|
||||
nelements = nelements + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
if nelements == 0 then return geometries end
|
||||
local height = math.floor(bounds.height / nelements)
|
||||
|
||||
for _, k in ipairs(keys) do
|
||||
local v = widgets[k]
|
||||
if type(v) == "table" then
|
||||
local layout = v.layout or default
|
||||
-- we need to modify the height a bit because vertical layouts always span the
|
||||
-- whole height
|
||||
nbounds = util.table.clone(bounds)
|
||||
nbounds.height = height
|
||||
local g = layout(nbounds, v, screen)
|
||||
for _, w in ipairs(g) do
|
||||
w.y = w.y + y
|
||||
table.insert(geometries, w)
|
||||
end
|
||||
y = y + height
|
||||
elseif type(v) == "widget" then
|
||||
local g
|
||||
if v.visible then
|
||||
g = v:extents(screen)
|
||||
else
|
||||
g = {
|
||||
["width"] = 0,
|
||||
["height"] = 0
|
||||
}
|
||||
end
|
||||
|
||||
g.ratio = 1
|
||||
if g.height > 0 and g.width > 0 then
|
||||
g.ratio = g.width / g.height
|
||||
end
|
||||
g.height = height
|
||||
if v.resize then
|
||||
g.width = g.height * g.ratio
|
||||
end
|
||||
g.width = math.min(g.width, bounds.width)
|
||||
geometries.free.x = math.max(geometries.free.x, g.width)
|
||||
|
||||
g.x = 0
|
||||
g.y = y
|
||||
y = y + g.height
|
||||
bounds.height = bounds.height - g.height
|
||||
|
||||
table.insert(geometries, g)
|
||||
end
|
||||
end
|
||||
|
||||
local maxw = 0
|
||||
local maxx = 0
|
||||
for _, v in ipairs(geometries) do
|
||||
if v.width > maxw then maxw = v.width end
|
||||
if v.x > maxx then maxx = v.x end
|
||||
end
|
||||
|
||||
geometries.free.width = geometries.free.width - maxw
|
||||
geometries.free.x = geometries.free.x + maxw
|
||||
|
||||
geometries.free.height = nelements * height
|
||||
geometries.free.y = 0
|
||||
|
||||
return geometries
|
||||
end
|
@ -0,0 +1,53 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local ipairs = ipairs
|
||||
local button = require("awful.button")
|
||||
local layout = require("awful.layout")
|
||||
local tag = require("awful.tag")
|
||||
local beautiful = require("beautiful")
|
||||
local capi = { image = image,
|
||||
screen = screen,
|
||||
widget = widget }
|
||||
|
||||
--- Layoutbox widget.
|
||||
module("awful.widget.layoutbox")
|
||||
|
||||
local function update(w, screen)
|
||||
local layout = layout.getname(layout.get(screen))
|
||||
if layout and beautiful["layout_" ..layout] then
|
||||
w.image = capi.image(beautiful["layout_" ..layout])
|
||||
else
|
||||
w.image = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- Create a layoutbox widget. It draws a picture with the current layout
|
||||
-- symbol of the current tag.
|
||||
-- @param screen The screen number that the layout will be represented for.
|
||||
-- @param args Standard arguments for an imagebox widget.
|
||||
-- @return An imagebox widget configured as a layoutbox.
|
||||
function new(screen, args)
|
||||
local screen = screen or 1
|
||||
local args = args or {}
|
||||
args.type = "imagebox"
|
||||
local w = capi.widget(args)
|
||||
update(w, screen)
|
||||
|
||||
local function update_on_tag_selection(tag)
|
||||
return update(w, tag.screen)
|
||||
end
|
||||
|
||||
tag.attached_add_signal(screen, "property::selected", update_on_tag_selection)
|
||||
tag.attached_add_signal(screen, "property::layout", update_on_tag_selection)
|
||||
|
||||
return w
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,243 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local ipairs = ipairs
|
||||
local math = math
|
||||
local capi = { image = image,
|
||||
widget = widget }
|
||||
local layout = require("awful.widget.layout")
|
||||
|
||||
--- A progressbar widget.
|
||||
module("awful.widget.progressbar")
|
||||
|
||||
local data = setmetatable({}, { __mode = "k" })
|
||||
|
||||
--- Set the progressbar border color.
|
||||
-- If the value is nil, no border will be drawn.
|
||||
-- @name set_border_color
|
||||
-- @class function
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param color The border color to set.
|
||||
|
||||
--- Set the progressbar foreground color as a gradient.
|
||||
-- @name set_gradient_colors
|
||||
-- @class function
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param gradient_colors A table with gradients colors. The distance between each color
|
||||
-- can also be specified. Example: { "red", "blue" } or { "red", "green",
|
||||
-- "blue", blue = 10 } to specify blue distance from other colors.
|
||||
|
||||
--- Set the progressbar foreground color.
|
||||
-- @name set_color
|
||||
-- @class function
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param color The progressbar color.
|
||||
|
||||
--- Set the progressbar background color.
|
||||
-- @name set_background_color
|
||||
-- @class function
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param color The progressbar background color.
|
||||
|
||||
--- Set the progressbar to draw vertically. Default is false.
|
||||
-- @name set_vertical
|
||||
-- @class function
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param vertical A boolean value.
|
||||
|
||||
--- Set the progressbar to draw ticks. Default is false.
|
||||
-- @name set_ticks
|
||||
-- @class function
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param ticks A boolean value.
|
||||
|
||||
--- Set the progressbar ticks gap.
|
||||
-- @name set_ticks_gap
|
||||
-- @class function
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param value The value.
|
||||
|
||||
--- Set the progressbar ticks size.
|
||||
-- @name set_ticks_size
|
||||
-- @class function
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param value The value.
|
||||
|
||||
--- Set the maximum value the progressbar should handle.
|
||||
-- @name set_max_value
|
||||
-- @class function
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param value The value.
|
||||
|
||||
local properties = { "width", "height", "border_color",
|
||||
"gradient_colors", "color", "background_color",
|
||||
"vertical", "value", "max_value",
|
||||
"ticks", "ticks_gap", "ticks_size" }
|
||||
|
||||
local function update(pbar)
|
||||
local width = data[pbar].width or 100
|
||||
local height = data[pbar].height or 20
|
||||
local ticks_gap = data[pbar].ticks_gap or 1
|
||||
local ticks_size = data[pbar].ticks_size or 4
|
||||
|
||||
-- Create new empty image
|
||||
local img = capi.image.argb32(width, height, nil)
|
||||
|
||||
local value = data[pbar].value
|
||||
local max_value = data[pbar].max_value
|
||||
if value >= 0 then
|
||||
value = value / max_value
|
||||
end
|
||||
|
||||
local over_drawn_width = width
|
||||
local over_drawn_height = height
|
||||
local border_width = 0
|
||||
if data[pbar].border_color then
|
||||
-- Draw border
|
||||
img:draw_rectangle(0, 0, width, height, false, data[pbar].border_color)
|
||||
over_drawn_width = width - 2 -- remove 2 for borders
|
||||
over_drawn_height = height - 2 -- remove 2 for borders
|
||||
border_width = 1
|
||||
end
|
||||
|
||||
local angle = 270
|
||||
if data[pbar].vertical then
|
||||
angle = 180
|
||||
end
|
||||
|
||||
-- Draw full gradient
|
||||
if data[pbar].gradient_colors then
|
||||
img:draw_rectangle_gradient(border_width, border_width,
|
||||
over_drawn_width, over_drawn_height,
|
||||
data[pbar].gradient_colors, angle)
|
||||
else
|
||||
img:draw_rectangle(border_width, border_width,
|
||||
over_drawn_width, over_drawn_height,
|
||||
true, data[pbar].color or "red")
|
||||
end
|
||||
|
||||
-- Cover the part that is not set with a rectangle
|
||||
if data[pbar].vertical then
|
||||
local rel_height = math.floor(over_drawn_height * (1 - value))
|
||||
img:draw_rectangle(border_width,
|
||||
border_width,
|
||||
over_drawn_width,
|
||||
rel_height,
|
||||
true, data[pbar].background_color or "#000000aa")
|
||||
|
||||
-- Place smaller pieces over the gradient if ticks are enabled
|
||||
if data[pbar].ticks then
|
||||
for i=0, height / (ticks_size+ticks_gap)-border_width do
|
||||
local rel_offset = over_drawn_height / 1 - (ticks_size+ticks_gap) * i
|
||||
|
||||
if rel_offset >= rel_height then
|
||||
img:draw_rectangle(border_width,
|
||||
rel_offset,
|
||||
over_drawn_width,
|
||||
ticks_gap,
|
||||
true, data[pbar].background_color or "#000000aa")
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
local rel_x = math.ceil(over_drawn_width * value)
|
||||
img:draw_rectangle(border_width + rel_x,
|
||||
border_width,
|
||||
over_drawn_width - rel_x,
|
||||
over_drawn_height,
|
||||
true, data[pbar].background_color or "#000000aa")
|
||||
|
||||
if data[pbar].ticks then
|
||||
for i=0, width / (ticks_size+ticks_gap)-border_width do
|
||||
local rel_offset = over_drawn_width / 1 - (ticks_size+ticks_gap) * i
|
||||
|
||||
if rel_offset <= rel_x then
|
||||
img:draw_rectangle(rel_offset,
|
||||
border_width,
|
||||
ticks_gap,
|
||||
over_drawn_height,
|
||||
true, data[pbar].background_color or "#000000aa")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Update the image
|
||||
pbar.widget.image = img
|
||||
end
|
||||
|
||||
--- Set the progressbar value.
|
||||
-- @param pbar The progress bar.
|
||||
-- @param value The progress bar value between 0 and 1.
|
||||
function set_value(pbar, value)
|
||||
local value = value or 0
|
||||
local max_value = data[pbar].max_value
|
||||
data[pbar].value = math.min(max_value, math.max(0, value))
|
||||
update(pbar)
|
||||
return pbar
|
||||
end
|
||||
|
||||
--- Set the progressbar height.
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param height The height to set.
|
||||
function set_height(progressbar, height)
|
||||
data[progressbar].height = height
|
||||
update(progressbar)
|
||||
return progressbar
|
||||
end
|
||||
|
||||
--- Set the progressbar width.
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param width The width to set.
|
||||
function set_width(progressbar, width)
|
||||
data[progressbar].width = width
|
||||
update(progressbar)
|
||||
return progressbar
|
||||
end
|
||||
|
||||
-- Build properties function
|
||||
for _, prop in ipairs(properties) do
|
||||
if not _M["set_" .. prop] then
|
||||
_M["set_" .. prop] = function(pbar, value)
|
||||
data[pbar][prop] = value
|
||||
update(pbar)
|
||||
return pbar
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Create a progressbar widget.
|
||||
-- @param args Standard widget() arguments. You should add width and height
|
||||
-- key to set progressbar geometry.
|
||||
-- @return A progressbar widget.
|
||||
function new(args)
|
||||
local args = args or {}
|
||||
local width = args.width or 100
|
||||
local height = args.height or 20
|
||||
|
||||
args.type = "imagebox"
|
||||
|
||||
local pbar = {}
|
||||
|
||||
pbar.widget = capi.widget(args)
|
||||
pbar.widget.resize = false
|
||||
|
||||
data[pbar] = { width = width, height = height, value = 0, max_value = 1 }
|
||||
|
||||
-- Set methods
|
||||
for _, prop in ipairs(properties) do
|
||||
pbar["set_" .. prop] = _M["set_" .. prop]
|
||||
end
|
||||
|
||||
pbar.layout = args.layout or layout.horizontal.leftright
|
||||
|
||||
return pbar
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,51 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
|
||||
local capi = { widget = widget }
|
||||
local completion = require("awful.completion")
|
||||
local util = require("awful.util")
|
||||
local prompt = require("awful.prompt")
|
||||
local layout = require("awful.widget.layout")
|
||||
local type = type
|
||||
|
||||
module("awful.widget.prompt")
|
||||
|
||||
--- Run method for promptbox.
|
||||
-- @param promptbox The promptbox to run.
|
||||
local function run(promptbox)
|
||||
return prompt.run({ prompt = promptbox.prompt },
|
||||
promptbox.widget,
|
||||
function (...)
|
||||
local result = util.spawn(...)
|
||||
if type(result) == "string" then
|
||||
promptbox.widget.text = result
|
||||
end
|
||||
end,
|
||||
completion.shell,
|
||||
util.getdir("cache") .. "/history")
|
||||
end
|
||||
|
||||
--- Create a prompt widget which will launch a command.
|
||||
-- @param args Standard widget table arguments, with prompt to change the
|
||||
-- default prompt.
|
||||
-- @return A launcher widget.
|
||||
function new(args)
|
||||
local args = args or {}
|
||||
local promptbox = {}
|
||||
args.type = "textbox"
|
||||
promptbox.widget = capi.widget(args)
|
||||
promptbox.widget.ellipsize = "start"
|
||||
promptbox.run = run
|
||||
promptbox.prompt = args.prompt or "Run: "
|
||||
promptbox.layout = args.layout or layout.horizontal.leftright
|
||||
return promptbox
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function (_, ...) return new(...) end })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,196 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2008-2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-- Grab environment we need
|
||||
local capi = { widget = widget,
|
||||
screen = screen,
|
||||
image = image,
|
||||
client = client }
|
||||
local type = type
|
||||
local setmetatable = setmetatable
|
||||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
local table = table
|
||||
local common = require("awful.widget.common")
|
||||
local util = require("awful.util")
|
||||
local tag = require("awful.tag")
|
||||
local beautiful = require("beautiful")
|
||||
local layout = require("awful.widget.layout")
|
||||
|
||||
--- Taglist widget module for awful
|
||||
module("awful.widget.taglist")
|
||||
|
||||
label = {}
|
||||
|
||||
local function taglist_update (screen, w, label, buttons, data, widgets)
|
||||
local tags = capi.screen[screen]:tags()
|
||||
local showntags = {}
|
||||
for k, t in ipairs(tags) do
|
||||
if not tag.getproperty(t, "hide") then
|
||||
table.insert(showntags, t)
|
||||
end
|
||||
end
|
||||
common.list_update(w, buttons, label, data, widgets, showntags)
|
||||
end
|
||||
|
||||
--- Get the tag object the given widget appears on.
|
||||
-- @param widget The widget the look for.
|
||||
-- @return The tag object.
|
||||
function gettag(widget)
|
||||
return common.tagwidgets[widget]
|
||||
end
|
||||
|
||||
--- Create a new taglist widget.
|
||||
-- @param screen The screen to draw tag list for.
|
||||
-- @param label Label function to use.
|
||||
-- @param buttons A table with buttons binding to set.
|
||||
function new(screen, label, buttons)
|
||||
local w = {
|
||||
layout = layout.horizontal.leftright
|
||||
}
|
||||
local widgets = { }
|
||||
widgets.imagebox = { }
|
||||
widgets.textbox = { ["margin"] = { ["left"] = 0,
|
||||
["right"] = 0},
|
||||
["bg_resize"] = true
|
||||
}
|
||||
local data = setmetatable({}, { __mode = 'kv' })
|
||||
local u = function (s)
|
||||
if s == screen then
|
||||
taglist_update(s, w, label, buttons, data, widgets)
|
||||
end
|
||||
end
|
||||
local uc = function (c) return u(c.screen) end
|
||||
capi.client.add_signal("focus", uc)
|
||||
capi.client.add_signal("unfocus", uc)
|
||||
tag.attached_add_signal(screen, "property::selected", uc)
|
||||
tag.attached_add_signal(screen, "property::icon", uc)
|
||||
tag.attached_add_signal(screen, "property::hide", uc)
|
||||
tag.attached_add_signal(screen, "property::name", uc)
|
||||
capi.screen[screen]:add_signal("tag::attach", function(screen, tag)
|
||||
u(screen.index)
|
||||
end)
|
||||
capi.screen[screen]:add_signal("tag::detach", function(screen, tag)
|
||||
u(screen.index)
|
||||
end)
|
||||
capi.client.add_signal("new", function(c)
|
||||
c:add_signal("property::urgent", uc)
|
||||
c:add_signal("property::screen", function(c)
|
||||
-- If client change screen, refresh it anyway since we don't from
|
||||
-- which screen it was coming :-)
|
||||
u(screen)
|
||||
end)
|
||||
c:add_signal("tagged", uc)
|
||||
c:add_signal("untagged", uc)
|
||||
end)
|
||||
capi.client.add_signal("unmanage", uc)
|
||||
u(screen)
|
||||
return w
|
||||
end
|
||||
|
||||
--- Return labels for a taglist widget with all tag from screen.
|
||||
-- It returns the tag name and set a special
|
||||
-- foreground and background color for selected tags.
|
||||
-- @param t The tag.
|
||||
-- @param args The arguments table.
|
||||
-- bg_focus The background color for selected tag.
|
||||
-- fg_focus The foreground color for selected tag.
|
||||
-- bg_urgent The background color for urgent tags.
|
||||
-- fg_urgent The foreground color for urgent tags.
|
||||
-- squares_sel Optional: a user provided image for selected squares.
|
||||
-- squares_unsel Optional: a user provided image for unselected squares.
|
||||
-- squares_resize Optional: true or false to resize squares.
|
||||
-- @return A string to print, a background color, a background image and a
|
||||
-- background resize value.
|
||||
function label.all(t, args)
|
||||
if not args then args = {} end
|
||||
local theme = beautiful.get()
|
||||
local fg_focus = args.fg_focus or theme.taglist_fg_focus or theme.fg_focus
|
||||
local bg_focus = args.bg_focus or theme.taglist_bg_focus or theme.bg_focus
|
||||
local fg_urgent = args.fg_urgent or theme.taglist_fg_urgent or theme.fg_urgent
|
||||
local bg_urgent = args.bg_urgent or theme.taglist_bg_urgent or theme.bg_urgent
|
||||
local taglist_squares_sel = args.squares_sel or theme.taglist_squares_sel
|
||||
local taglist_squares_unsel = args.squares_unsel or theme.taglist_squares_unsel
|
||||
local taglist_squares_resize = theme.taglist_squares_resize or args.squares_resize or "true"
|
||||
local font = args.font or theme.taglist_font or theme.font or ""
|
||||
local text = "<span font_desc='"..font.."'>"
|
||||
local sel = capi.client.focus
|
||||
local bg_color = nil
|
||||
local fg_color = nil
|
||||
local bg_image
|
||||
local icon
|
||||
local bg_resize = false
|
||||
local is_selected = false
|
||||
if t.selected then
|
||||
bg_color = bg_focus
|
||||
fg_color = fg_focus
|
||||
end
|
||||
if sel then
|
||||
if taglist_squares_sel then
|
||||
-- Check that the selected clients is tagged with 't'.
|
||||
local seltags = sel:tags()
|
||||
for _, v in ipairs(seltags) do
|
||||
if v == t then
|
||||
bg_image = capi.image(taglist_squares_sel)
|
||||
bg_resize = taglist_squares_resize == "true"
|
||||
is_selected = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if not is_selected then
|
||||
local cls = t:clients()
|
||||
if #cls > 0 and taglist_squares_unsel then
|
||||
bg_image = capi.image(taglist_squares_unsel)
|
||||
bg_resize = taglist_squares_resize == "true"
|
||||
end
|
||||
for k, c in pairs(cls) do
|
||||
if c.urgent then
|
||||
if bg_urgent then bg_color = bg_urgent end
|
||||
if fg_urgent then fg_color = fg_urgent end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not tag.getproperty(t, "icon_only") then
|
||||
if fg_color then
|
||||
text = text .. "<span color='"..util.color_strip_alpha(fg_color).."'>"
|
||||
text = " " .. text.. (util.escape(t.name) or "") .." </span>"
|
||||
else
|
||||
text = text .. " " .. (util.escape(t.name) or "") .. " "
|
||||
end
|
||||
end
|
||||
text = text .. "</span>"
|
||||
if tag.geticon(t) and type(tag.geticon(t)) == "image" then
|
||||
icon = tag.geticon(t)
|
||||
elseif tag.geticon(t) then
|
||||
icon = capi.image(tag.geticon(t))
|
||||
end
|
||||
|
||||
return text, bg_color, bg_image, icon
|
||||
end
|
||||
|
||||
--- Return labels for a taglist widget with all *non empty* tags from screen.
|
||||
-- It returns the tag name and set a special
|
||||
-- foreground and background color for selected tags.
|
||||
-- @param t The tag.
|
||||
-- @param args The arguments table.
|
||||
-- bg_focus The background color for selected tag.
|
||||
-- fg_focus The foreground color for selected tag.
|
||||
-- bg_urgent The background color for urgent tags.
|
||||
-- fg_urgent The foreground color for urgent tags.
|
||||
-- @return A string to print, a background color, a background image and a
|
||||
-- background resize value.
|
||||
function label.noempty(t, args)
|
||||
if #t:clients() > 0 or t.selected then
|
||||
return label.all(t, args)
|
||||
end
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,213 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2008-2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-- Grab environment we need
|
||||
local capi = { screen = screen,
|
||||
image = image,
|
||||
client = client }
|
||||
local ipairs = ipairs
|
||||
local type = type
|
||||
local setmetatable = setmetatable
|
||||
local table = table
|
||||
local common = require("awful.widget.common")
|
||||
local beautiful = require("beautiful")
|
||||
local client = require("awful.client")
|
||||
local util = require("awful.util")
|
||||
local tag = require("awful.tag")
|
||||
local layout = require("awful.widget.layout")
|
||||
|
||||
--- Tasklist widget module for awful
|
||||
module("awful.widget.tasklist")
|
||||
|
||||
-- Public structures
|
||||
label = {}
|
||||
|
||||
local function tasklist_update(w, buttons, label, data, widgets)
|
||||
local clients = capi.client.get()
|
||||
local shownclients = {}
|
||||
for k, c in ipairs(clients) do
|
||||
if not (c.skip_taskbar or c.hidden
|
||||
or c.type == "splash" or c.type == "dock" or c.type == "desktop") then
|
||||
table.insert(shownclients, c)
|
||||
end
|
||||
end
|
||||
clients = shownclients
|
||||
|
||||
common.list_update(w, buttons, label, data, widgets, clients)
|
||||
end
|
||||
|
||||
--- Create a new tasklist widget.
|
||||
-- @param label Label function to use.
|
||||
-- @param buttons A table with buttons binding to set.
|
||||
function new(label, buttons)
|
||||
local w = {
|
||||
layout = layout.horizontal.flex
|
||||
}
|
||||
local widgets = { }
|
||||
widgets.imagebox = { }
|
||||
widgets.textbox = { margin = { left = 2,
|
||||
right = 2 },
|
||||
bg_resize = true,
|
||||
bg_align = "right"
|
||||
}
|
||||
local data = setmetatable({}, { __mode = 'kv' })
|
||||
local u = function () tasklist_update(w, buttons, label, data, widgets) end
|
||||
for s = 1, capi.screen.count() do
|
||||
tag.attached_add_signal(s, "property::selected", u)
|
||||
capi.screen[s]:add_signal("tag::attach", u)
|
||||
capi.screen[s]:add_signal("tag::detach", u)
|
||||
end
|
||||
capi.client.add_signal("new", function (c)
|
||||
c:add_signal("property::urgent", u)
|
||||
c:add_signal("property::floating", u)
|
||||
c:add_signal("property::maximized_horizontal", u)
|
||||
c:add_signal("property::maximized_vertical", u)
|
||||
c:add_signal("property::minimized", u)
|
||||
c:add_signal("property::name", u)
|
||||
c:add_signal("property::icon_name", u)
|
||||
c:add_signal("property::icon", u)
|
||||
c:add_signal("property::skip_taskbar", u)
|
||||
c:add_signal("property::hidden", u)
|
||||
c:add_signal("tagged", u)
|
||||
c:add_signal("untagged", u)
|
||||
end)
|
||||
capi.client.add_signal("unmanage", u)
|
||||
capi.client.add_signal("list", u)
|
||||
capi.client.add_signal("focus", u)
|
||||
capi.client.add_signal("unfocus", u)
|
||||
u()
|
||||
return w
|
||||
end
|
||||
|
||||
local function widget_tasklist_label_common(c, args)
|
||||
if not args then args = {} end
|
||||
local theme = beautiful.get()
|
||||
local fg_focus = args.fg_focus or theme.tasklist_fg_focus or theme.fg_focus
|
||||
local bg_focus = args.bg_focus or theme.tasklist_bg_focus or theme.bg_focus
|
||||
local fg_urgent = args.fg_urgent or theme.tasklist_fg_urgent or theme.fg_urgent
|
||||
local bg_urgent = args.bg_urgent or theme.tasklist_bg_urgent or theme.bg_urgent
|
||||
local fg_minimize = args.fg_minimize or theme.tasklist_fg_minimize or theme.fg_minimize
|
||||
local bg_minimize = args.bg_minimize or theme.tasklist_bg_minimize or theme.bg_minimize
|
||||
local floating_icon = args.floating_icon or theme.tasklist_floating_icon
|
||||
local font = args.font or theme.tasklist_font or theme.font or ""
|
||||
local bg = nil
|
||||
local text = "<span font_desc='"..font.."'>"
|
||||
local name
|
||||
local status_image
|
||||
if client.floating.get(c) and floating_icon then
|
||||
status_image = capi.image(floating_icon)
|
||||
end
|
||||
if c.minimized then
|
||||
name = util.escape(c.icon_name) or util.escape(c.name) or util.escape("<untitled>")
|
||||
else
|
||||
name = util.escape(c.name) or util.escape("<untitled>")
|
||||
end
|
||||
if capi.client.focus == c then
|
||||
bg = bg_focus
|
||||
if fg_focus then
|
||||
text = text .. "<span color='"..util.color_strip_alpha(fg_focus).."'>"..name.."</span>"
|
||||
else
|
||||
text = text .. name
|
||||
end
|
||||
elseif c.urgent and fg_urgent then
|
||||
bg = bg_urgent
|
||||
text = text .. "<span color='"..util.color_strip_alpha(fg_urgent).."'>"..name.."</span>"
|
||||
elseif c.minimized and fg_minimize and bg_minimize then
|
||||
bg = bg_minimize
|
||||
text = text .. "<span color='"..util.color_strip_alpha(fg_minimize).."'>"..name.."</span>"
|
||||
else
|
||||
text = text .. name
|
||||
end
|
||||
text = text .. "</span>"
|
||||
-- return text, bg, status_image, c.icon
|
||||
return text, bg, status_image, nil
|
||||
end
|
||||
|
||||
--- Return labels for a tasklist widget with clients from all tags and screen.
|
||||
-- It returns the client name and set a special
|
||||
-- foreground and background color for focused client.
|
||||
-- It also puts a special icon for floating windows.
|
||||
-- @param c The client.
|
||||
-- @param screen The screen we are drawing on.
|
||||
-- @param args The arguments table.
|
||||
-- bg_focus The background color for focused client.
|
||||
-- fg_focus The foreground color for focused client.
|
||||
-- bg_urgent The background color for urgent clients.
|
||||
-- fg_urgent The foreground color for urgent clients.
|
||||
-- @return A string to print, a background color and a status image.
|
||||
function label.allscreen(c, screen, args)
|
||||
return widget_tasklist_label_common(c, args)
|
||||
end
|
||||
|
||||
--- Return labels for a tasklist widget with clients from all tags.
|
||||
-- It returns the client name and set a special
|
||||
-- foreground and background color for focused client.
|
||||
-- It also puts a special icon for floating windows.
|
||||
-- @param c The client.
|
||||
-- @param screen The screen we are drawing on.
|
||||
-- @param args The arguments table.
|
||||
-- bg_focus The background color for focused client.
|
||||
-- fg_focus The foreground color for focused client.
|
||||
-- bg_urgent The background color for urgent clients.
|
||||
-- fg_urgent The foreground color for urgent clients.
|
||||
-- @return A string to print, a background color and a status image.
|
||||
function label.alltags(c, screen, args)
|
||||
-- Only print client on the same screen as this widget
|
||||
if c.screen ~= screen then return end
|
||||
return widget_tasklist_label_common(c, args)
|
||||
end
|
||||
|
||||
--- Return labels for a tasklist widget with clients from currently selected tags.
|
||||
-- It returns the client name and set a special
|
||||
-- foreground and background color for focused client.
|
||||
-- It also puts a special icon for floating windows.
|
||||
-- @param c The client.
|
||||
-- @param screen The screen we are drawing on.
|
||||
-- @param args The arguments table.
|
||||
-- bg_focus The background color for focused client.
|
||||
-- fg_focus The foreground color for focused client.
|
||||
-- bg_urgent The background color for urgent clients.
|
||||
-- fg_urgent The foreground color for urgent clients.
|
||||
-- @return A string to print, a background color and a status image.
|
||||
function label.currenttags(c, screen, args)
|
||||
-- Only print client on the same screen as this widget
|
||||
if c.screen ~= screen then return end
|
||||
-- Include sticky client too
|
||||
if c.sticky then return widget_tasklist_label_common(c, args) end
|
||||
for k, t in ipairs(capi.screen[screen]:tags()) do
|
||||
if t.selected then
|
||||
local ctags = c:tags()
|
||||
for _, v in ipairs(ctags) do
|
||||
if v == t then
|
||||
return widget_tasklist_label_common(c, args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Return label for only the currently focused client.
|
||||
-- It returns the client name and set a special
|
||||
-- foreground and background color for focused client.
|
||||
-- It also puts a special icon for floating windows.
|
||||
-- @param c The client.
|
||||
-- @param screen The screen we are drawing on.
|
||||
-- @param args The arguments table.
|
||||
-- bg_focus The background color for focused client.
|
||||
-- fg_focus The foreground color for focused client.
|
||||
-- bg_urgent The background color for urgent clients.
|
||||
-- fg_urgent The foreground color for urgent clients.
|
||||
-- @return A string to print, a background color and a status image.
|
||||
function label.focused(c, screen, args)
|
||||
-- Only print client on the same screen as this widget
|
||||
if c.screen == screen and capi.client.focus == c then
|
||||
return widget_tasklist_label_common(c, args)
|
||||
end
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
@ -0,0 +1,35 @@
|
||||
---------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2009 Julien Danjou
|
||||
-- @release v3.4.10
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local os = os
|
||||
local capi = { widget = widget,
|
||||
timer = timer }
|
||||
|
||||
--- Text clock widget.
|
||||
module("awful.widget.textclock")
|
||||
|
||||
--- Create a textclock widget. It draws the time it is in a textbox.
|
||||
-- @param args Standard arguments for textbox widget.
|
||||
-- @param format The time format. Default is " %a %b %d, %H:%M ".
|
||||
-- @param timeout How often update the time. Default is 60.
|
||||
-- @return A textbox widget.
|
||||
function new(args, format, timeout)
|
||||
local args = args or {}
|
||||
local format = format or " %a %b %d, %H:%M "
|
||||
local timeout = timeout or 60
|
||||
args.type = "textbox"
|
||||
local w = capi.widget(args)
|
||||
local timer = capi.timer { timeout = timeout }
|
||||
w.text = os.date(format)
|
||||
timer:add_signal("timeout", function() w.text = os.date(format) end)
|
||||
timer:start()
|
||||
return w
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
Reference in New Issue
Block a user