You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
314 lines
11 KiB
314 lines
11 KiB
local wibox = require("wibox")
|
|
local awful = require("awful")
|
|
local gears = require("gears")
|
|
local beautiful = require("beautiful")
|
|
|
|
local awmtk = {}
|
|
|
|
-- {{{ Utils
|
|
awmtk.create_delta = function(name,instance_delta,class_delta,parent_delta)
|
|
-- To save memory, we create proxies for lower layers called "deltas"
|
|
-- This function creates that proxy layer using metatables
|
|
|
|
-- Fun story - i used instance_delta instead of {} at first.
|
|
-- The results were horrifying and confusing.
|
|
return setmetatable({},{
|
|
__index = function(self,k)
|
|
-- Per-instance overrides are top priority
|
|
if rawget(instance_delta,k) then
|
|
return rawget(instance_delta,k)
|
|
-- Class-wide overrides are second in priority
|
|
elseif type(class_delta[name]) == "table"
|
|
and rawget(class_delta[name],k) then
|
|
return rawget(class_delta[name],k)
|
|
-- Parent is fallback
|
|
elseif parent_delta[k] then
|
|
return parent_delta[k]
|
|
end
|
|
end
|
|
})
|
|
end
|
|
|
|
awmtk.create_style = function(name,parent,overrides)
|
|
-- A style is essentially a layer of deltas upon the previous (parent) style
|
|
local new_style = {}
|
|
local odelta = (overrides and overrides[name]) or {}
|
|
local cdelta = (beautiful.widgets and beautiful.widgets[name]) or {}
|
|
for name,parent_class in pairs(parent) do
|
|
new_style[name] = awmtk.create_delta(
|
|
name,
|
|
odelta,
|
|
cdelta,
|
|
parent_class
|
|
)
|
|
end
|
|
return new_style
|
|
end
|
|
|
|
awmtk.create_template_lib = function(name,parent,overrides)
|
|
-- same thing but beautiful.templates
|
|
return awmtk.create_delta(
|
|
name,
|
|
overrides or {},
|
|
beautiful.templates or {},
|
|
parent
|
|
)
|
|
end
|
|
|
|
awmtk.build_templates = function(templates,style)
|
|
local new_templates = {}
|
|
for name,template in pairs(awmtk.proto_templates) do
|
|
new_templates[name] = templates[name](style)
|
|
end
|
|
return new_templates
|
|
end
|
|
|
|
awmtk.merge = function(base,overrides)
|
|
for k,v in pairs(overrides) do
|
|
base[k] = v
|
|
end
|
|
return base
|
|
end
|
|
-- }}}
|
|
|
|
|
|
-- {{{ Default style
|
|
|
|
-- Default style
|
|
awmtk.proto_style = {
|
|
base = setmetatable({
|
|
-- { Backgrounds
|
|
-- custom background color for highlighting elements
|
|
bg_highlight = beautiful.bg_highlight or beautiful.bg_focus,
|
|
-- allow more complex themes to define background images
|
|
bgimage_focus = beautiful.bgimage_focus,
|
|
bgimage_normal = beautiful.bgimage_normal,
|
|
-- }
|
|
-- { Borders
|
|
-- Borders for popups
|
|
shape_border_width = beautiful.shape_border_width or 0,
|
|
shape_border_color = beautiful.shape_border_color or beautiful.bg_normal,
|
|
-- { Callbacks
|
|
-- a tiny bit more complex thing to account for more extensibility
|
|
-- the stub functions do nothing - you should implement functionality inside theme
|
|
onpress = function() end,
|
|
onrelease = function() end,
|
|
-- }
|
|
-- }
|
|
-- { Shapes
|
|
margins = 5,
|
|
spacing = 5,
|
|
shape = function(cr, width, height)
|
|
return require("gears").shape.rounded_rect(cr,width,height,5)
|
|
end,
|
|
-- }
|
|
},{__index = beautiful})
|
|
}
|
|
|
|
-- Subclasses
|
|
awmtk.proto_style.container = awmtk.create_delta("container",{
|
|
},awmtk.proto_style,awmtk.proto_style.base)
|
|
|
|
awmtk.proto_style.button = awmtk.create_delta("button",{
|
|
margins = 3
|
|
},awmtk.proto_style,awmtk.proto_style.base)
|
|
|
|
awmtk.proto_style.icon = awmtk.create_delta("icon",{
|
|
margins = 1
|
|
},awmtk.proto_style,awmtk.proto_style.base)
|
|
|
|
awmtk.proto_style.textbox = awmtk.create_delta("textbox",{
|
|
font = beautiful.font or "sans 8"
|
|
}, awmtk.proto_style,awmtk.proto_style.base)
|
|
|
|
awmtk.proto_style.separator = awmtk.create_delta("separator",{
|
|
thickness = 1,
|
|
color = beautiful.bg_focus,
|
|
border_width = 0
|
|
}, awmtk.proto_style,awmtk.proto_style.base)
|
|
|
|
awmtk.proto_style.article = awmtk.create_delta("article", {
|
|
icon_size = 16,
|
|
small_font = beautiful.small_font or beautiful.font,
|
|
font_align = "left",
|
|
small_font_align = "left"
|
|
}, awmtk.proto_style,awmtk.proto_style.base)
|
|
|
|
awmtk.proto_style.popup = awmtk.create_delta("popup", {
|
|
}, awmtk.proto_style,awmtk.proto_style.base)
|
|
|
|
awmtk.proto_style.titlebar = awmtk.create_delta("titlebar", {
|
|
margins = 1
|
|
}, awmtk.proto_style,awmtk.proto_style.base)
|
|
-- }}}
|
|
|
|
-- {{{ Generic templates
|
|
awmtk.proto_templates = {
|
|
-- Templates are built first using the given style, then applied to contents
|
|
-- through returned function
|
|
container = function(style)
|
|
-- Container is practically any "box" that contains buttons, textboxes,
|
|
-- and anything you want to put into the container. Do not confuse with
|
|
-- popup - containers are designed to separate contents within a popup.
|
|
return function(layout,options)
|
|
return awmtk.merge({
|
|
{
|
|
layout,
|
|
margins = (options and options.margins) or style.container.margins,
|
|
widget = wibox.container.margin
|
|
},
|
|
bgimage = style.container.bgimage,
|
|
bg = style.container.bg_normal,
|
|
shape = style.container.shape,
|
|
widget = wibox.container.background
|
|
},options or {})
|
|
end
|
|
end,
|
|
|
|
button = function(style)
|
|
-- Self explanatory. Notice that this does not bear any function -
|
|
-- only the visual part of the button. By design, onpress and onrelease
|
|
-- callbacks should be connected to button events for animations
|
|
return function(layout,options)
|
|
return awmtk.merge({
|
|
{
|
|
layout,
|
|
margins = (options and options.margins) or style.button.margins,
|
|
widget = wibox.container.margin
|
|
},
|
|
bgimage = style.button.bgimage,
|
|
bg = style.button.bg_normal,
|
|
shape = style.button.shape,
|
|
widget = wibox.container.background
|
|
},options or {})
|
|
end
|
|
end,
|
|
|
|
textbox = function(style)
|
|
-- Nothing fancy here, but you can set per-widget fonts using beautiful.
|
|
return function(options)
|
|
return awmtk.merge({
|
|
font = style.textbox.font,
|
|
widget = wibox.widget.textbox
|
|
},options or {})
|
|
end
|
|
end,
|
|
|
|
hseparator = function(style)
|
|
-- Wow, i guess?
|
|
return function(options)
|
|
return awmtk.merge({
|
|
widget = wibox.widget.separator,
|
|
orientation = "horizontal",
|
|
thickness = style.separator.thickness,
|
|
color = style.separator.color,
|
|
border_width = style.separator.border_width
|
|
},options or {})
|
|
end
|
|
end,
|
|
|
|
vseparator = function(style)
|
|
-- I'm running out of comments
|
|
return function(options)
|
|
return awmtk.merge({
|
|
widget = wibox.widget.separator,
|
|
orientation = "vertical",
|
|
thickness = style.separator.thickness,
|
|
color = style.separator.color,
|
|
border_width = style.separator.border_width
|
|
},options or {})
|
|
end
|
|
end,
|
|
|
|
article = function(style)
|
|
-- Article is a template that combines 3 common pieces of a full item:
|
|
-- Icon, name and description. Designed to be placed within a container
|
|
-- or a button.
|
|
return function(options)
|
|
return awmtk.merge({
|
|
(options.icon and {
|
|
{
|
|
{
|
|
image = options.icon,
|
|
resize = options.resize,
|
|
widget = wibox.widget.imagebox
|
|
},
|
|
strategy = "exact",
|
|
height = options.icon_size or
|
|
style.article.icon_size,
|
|
width = options.icon_size or
|
|
style.article.icon_size,
|
|
widget = wibox.container.constraint
|
|
},
|
|
widget = wibox.container.place,
|
|
valign = "center",
|
|
halign = "center"
|
|
}),
|
|
{
|
|
{
|
|
markup = options.title or "",
|
|
widget = wibox.widget.textbox,
|
|
font = options.font or style.article.font,
|
|
align = options.font_align or
|
|
style.article.font_align,
|
|
valign = "center"
|
|
},
|
|
(options.description and {
|
|
markup = options.description,
|
|
widget = wibox.widget.textbox,
|
|
font = options.small_font or style.article.small_font,
|
|
align = options.small_font_align or
|
|
style.article.small_font_align,
|
|
valign = "center"
|
|
}),
|
|
spacing = style.article.spacing,
|
|
layout = wibox.layout.flex.vertical
|
|
},
|
|
spacing = style.article.spacing,
|
|
layout = wibox.layout.fixed.horizontal,
|
|
}, options or {})
|
|
end
|
|
end,
|
|
|
|
popup = function(style)
|
|
-- Popup is a distinct template designed to accomodate the "root" of
|
|
-- a popup, allowing one to add titlebars to popups, for example.
|
|
return function(widget,options)
|
|
return awmtk.merge({
|
|
widget = {
|
|
widget,
|
|
margins = (options and options.margins) or style.popup.margins,
|
|
widget = wibox.container.margin
|
|
},
|
|
bgimage = style.popup.bgimage,
|
|
shape = style.popup.shape,
|
|
visible = false,
|
|
ontop = true
|
|
},options or {})
|
|
end
|
|
end,
|
|
|
|
titlebar = function(style)
|
|
-- Titlebar is a separate class specifically for window and popup
|
|
-- titlebars. The decision to make it a separate class was due to
|
|
-- the fact that much customization is done through default theme table
|
|
return function(layout,options)
|
|
return awmtk.merge({
|
|
layout,
|
|
margins = (options and options.margins) or
|
|
style.titlebar.margins,
|
|
widget = wibox.container.margin,
|
|
left = style.titlebar.left,
|
|
right = style.titlebar.right,
|
|
bottom = style.titlebar.bottom,
|
|
top = style.titlebar.top
|
|
},options or {})
|
|
end
|
|
end
|
|
}
|
|
|
|
-- yes
|
|
awmtk.default = awmtk.create_style("default",awmtk.proto_style,{})
|
|
awmtk.templates = awmtk.create_template_lib("templates",awmtk.proto_templates,{})
|
|
-- }}}
|
|
return awmtk
|