|
|
@ -9,11 +9,14 @@ local awmtk = {} |
|
|
|
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 |
|
|
|
return setmetatable(instance_delta,{ |
|
|
|
|
|
|
|
-- 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(self,k) then |
|
|
|
return rawget(self,k) |
|
|
|
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 |
|
|
@ -29,11 +32,13 @@ 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, |
|
|
|
(overrides and overrides[name]) or {}, |
|
|
|
(beautiful.widgets and beautiful.widgets[style_name]) or {}, |
|
|
|
odelta, |
|
|
|
cdelta, |
|
|
|
parent_class |
|
|
|
) |
|
|
|
end |
|
|
@ -52,7 +57,7 @@ end |
|
|
|
|
|
|
|
awmtk.build_templates = function(templates,style) |
|
|
|
local new_templates = {} |
|
|
|
for name,template in pairs(awmtk.templates) do |
|
|
|
for name,template in pairs(awmtk.proto_templates) do |
|
|
|
new_templates[name] = templates[name](style) |
|
|
|
end |
|
|
|
return new_templates |
|
|
@ -70,16 +75,25 @@ end |
|
|
|
-- {{{ Default style |
|
|
|
|
|
|
|
-- Default style |
|
|
|
awmtk.default = { |
|
|
|
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, |
|
|
@ -92,43 +106,50 @@ awmtk.default = { |
|
|
|
} |
|
|
|
|
|
|
|
-- Subclasses |
|
|
|
awmtk.default.container = awmtk.create_delta("container",{ |
|
|
|
},awmtk.default,awmtk.default.base) |
|
|
|
awmtk.proto_style.container = awmtk.create_delta("container",{ |
|
|
|
},awmtk.proto_style,awmtk.proto_style.base) |
|
|
|
|
|
|
|
awmtk.default.button = awmtk.create_delta("button",{ |
|
|
|
awmtk.proto_style.button = awmtk.create_delta("button",{ |
|
|
|
margins = 3 |
|
|
|
},awmtk.default,awmtk.default.base) |
|
|
|
},awmtk.proto_style,awmtk.proto_style.base) |
|
|
|
|
|
|
|
awmtk.default.icon = awmtk.create_delta("icon",{ |
|
|
|
awmtk.proto_style.icon = awmtk.create_delta("icon",{ |
|
|
|
margins = 1 |
|
|
|
},awmtk.default,awmtk.default.base) |
|
|
|
},awmtk.proto_style,awmtk.proto_style.base) |
|
|
|
|
|
|
|
awmtk.default.textbox = awmtk.create_delta("textbox",{ |
|
|
|
awmtk.proto_style.textbox = awmtk.create_delta("textbox",{ |
|
|
|
font = beautiful.font or "sans 8" |
|
|
|
}, awmtk.default,awmtk.default.base) |
|
|
|
}, awmtk.proto_style,awmtk.proto_style.base) |
|
|
|
|
|
|
|
awmtk.default.separator = awmtk.create_delta("separator",{ |
|
|
|
awmtk.proto_style.separator = awmtk.create_delta("separator",{ |
|
|
|
thickness = 1, |
|
|
|
color = beautiful.bg_focus, |
|
|
|
border_width = 0 |
|
|
|
}, awmtk.default,awmtk.default.base) |
|
|
|
}, awmtk.proto_style,awmtk.proto_style.base) |
|
|
|
|
|
|
|
awmtk.default.article = awmtk.create_delta("article", { |
|
|
|
awmtk.proto_style.article = awmtk.create_delta("article", { |
|
|
|
icon_size = 16, |
|
|
|
small_font = beautiful.font or "sans 8", |
|
|
|
small_font = beautiful.small_font or beautiful.font, |
|
|
|
font_align = "left", |
|
|
|
small_font_align = "left" |
|
|
|
}, awmtk.default,awmtk.default.base) |
|
|
|
}, awmtk.proto_style,awmtk.proto_style.base) |
|
|
|
|
|
|
|
awmtk.proto_style.popup = awmtk.create_delta("popup", { |
|
|
|
}, awmtk.proto_style,awmtk.proto_style.base) |
|
|
|
|
|
|
|
awmtk.default.popup = awmtk.create_delta("popup", { |
|
|
|
}, awmtk.default,awmtk.default.base) |
|
|
|
awmtk.proto_style.titlebar = awmtk.create_delta("titlebar", { |
|
|
|
margins = 1 |
|
|
|
}, awmtk.proto_style,awmtk.proto_style.base) |
|
|
|
-- }}} |
|
|
|
|
|
|
|
-- {{{ Generic templates |
|
|
|
awmtk.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({ |
|
|
|
{ |
|
|
@ -136,6 +157,7 @@ awmtk.templates = { |
|
|
|
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 |
|
|
@ -144,6 +166,9 @@ awmtk.templates = { |
|
|
|
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({ |
|
|
|
{ |
|
|
@ -151,6 +176,7 @@ awmtk.templates = { |
|
|
|
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 |
|
|
@ -158,8 +184,8 @@ awmtk.templates = { |
|
|
|
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, |
|
|
@ -169,8 +195,9 @@ awmtk.templates = { |
|
|
|
end, |
|
|
|
|
|
|
|
hseparator = function(style) |
|
|
|
-- Wow, i guess? |
|
|
|
return function(options) |
|
|
|
awmtk.merge({ |
|
|
|
return awmtk.merge({ |
|
|
|
widget = wibox.widget.separator, |
|
|
|
orientation = "horizontal", |
|
|
|
thickness = style.separator.thickness, |
|
|
@ -181,8 +208,9 @@ awmtk.templates = { |
|
|
|
end, |
|
|
|
|
|
|
|
vseparator = function(style) |
|
|
|
-- I'm running out of comments |
|
|
|
return function(options) |
|
|
|
awmtk.merge({ |
|
|
|
return awmtk.merge({ |
|
|
|
widget = wibox.widget.separator, |
|
|
|
orientation = "vertical", |
|
|
|
thickness = style.separator.thickness, |
|
|
@ -192,9 +220,10 @@ awmtk.templates = { |
|
|
|
end |
|
|
|
end, |
|
|
|
|
|
|
|
-- Article is a template that contains an icon, a headline and a |
|
|
|
-- short description, side by side. Useful for menus and notifications. |
|
|
|
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 { |
|
|
@ -237,30 +266,49 @@ awmtk.templates = { |
|
|
|
}, |
|
|
|
spacing = style.article.spacing, |
|
|
|
layout = wibox.layout.fixed.horizontal, |
|
|
|
bg = style.article.bg_normal, |
|
|
|
widget = wibox.container.background |
|
|
|
}, 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 |
|
|
|
}, |
|
|
|
bg = style.popup.bg_normal, |
|
|
|
widget = wibox.container.background |
|
|
|
}, |
|
|
|
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 |