@ -1,11 +1,11 @@
-- This file is part of R eno desktop.
-- this file is part of r eno desktop.
--
-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the L icense, or (at your option) any later version.
-- reno desktop is free software: you can redistribute it and/or modify it under the terms of the gnu general public license as published by the free software foundation, either version 3 of the l icense, or (at your option) any later version.
--
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public L icense for more details.
-- reno desktop is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. see the gnu general public l icense for more details.
--
-- You should have received a copy of the GNU General Public License along with Reno desktop. I f not, see <https://www.gnu.org/licenses/>.
-- RenoTK (formerly AWMTK2) - Template/Granular styling library for R eno
-- you should have received a copy of the gnu general public license along with reno desktop. i f not, see <https://www.gnu.org/licenses/>.
-- renotk (formerly awmtk2) - template/granular styling library for r eno
local wibox = require ( " wibox " )
local awful = require ( " awful " )
local gears = require ( " gears " )
@ -15,23 +15,23 @@ beautiful.templates = beautiful.templates or {}
local awmtk = { }
-- {{{ U tils
-- {{{ u tils
awmtk.create_delta = function ( name , instance_delta , class_delta , parent_delta )
-- T o save memory, we create proxies for lower layers called "deltas"
-- T his function creates that proxy layer using metatables
-- t o save memory, we create proxies for lower layers called "deltas"
-- t his function creates that proxy layer using metatables
-- F un story - i used instance_delta instead of {} at first.
-- T he results were horrifying and confusing.
-- f un story - i used instance_delta instead of {} at first.
-- t he results were horrifying and confusing.
return setmetatable ( { } , {
__index = function ( self , k )
-- P er-instance overrides are top priority
-- p er-instance overrides are top priority
if rawget ( instance_delta , k ) then
return rawget ( instance_delta , k )
-- C lass-wide overrides are second in priority
-- c lass-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 )
-- P arent is fallback
-- p arent is fallback
elseif parent_delta [ k ] then
return parent_delta [ k ]
end
@ -40,7 +40,7 @@ awmtk.create_delta = function(name,instance_delta,class_delta,parent_delta)
end
awmtk.create_style = function ( name , parent , overrides )
-- A style is essentially a layer of deltas upon the previous (parent) style
-- 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 [ name ] or { }
@ -73,35 +73,70 @@ awmtk.build_templates = function(templates,style)
return new_templates
end
awmtk.mask_object_call = function ( obj , call )
local new = { }
for k , v in pairs ( obj ) do
new [ k ] = v
end
return setmetatable ( new , {
__index = obj ,
__call = call
} )
end
awmtk.wrap_hooks = function ( w , callbacks )
-- attach hooks to function
local mcall = getmetatable ( w ) . __call
return awmtk.mask_object_call ( w , function ( ... )
if callbacks and callbacks.on_create_pre then
callbacks.on_create_pre ( ... )
end
local widget = mcall ( ... )
if callbacks and callbacks.on_create then
callbacks.on_create ( widget , ... )
end
if callbacks and callbacks.on_ready then
local func = function ( )
callbacks.on_ready ( widget )
end
widget : connect_signal ( " widget::layout_changed " , func )
widget : connect_signal ( " widget::layout_changed " , function ( )
widget : disconnect_signal ( " widget::layout_changed " , func )
end )
end
return widget
end )
end
awmtk.merge = gears.table . join
-- }}}
-- {{{ Default style
-- {{{ d efault style
-- Prototype style
-- Notice that it's not awmtk.default style - it's used as a base for default.
-- p rototype style
-- n otice that it's not awmtk.default style - it's used as a base for default.
awmtk.proto_style = {
base = setmetatable ( {
-- { Backgrounds
-- { b ackgrounds
-- 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
-- { b orders
-- b orders for popups
shape_border_width = beautiful.shape_border_width or 0 ,
shape_border_color = beautiful.shape_border_color or beautiful.bg_normal ,
-- }
-- { Callbacks
-- { c allbacks
-- 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
-- { s hapes
margins = 5 ,
spacing = 5 ,
shape = function ( cr , width , height )
@ -111,7 +146,7 @@ awmtk.proto_style = {
} , { __index = beautiful } )
}
-- S ubclasses
-- s ubclasses
awmtk.proto_style . container = awmtk.create_delta ( " container " , {
} , awmtk.proto_style , awmtk.proto_style . base )
@ -167,13 +202,13 @@ awmtk.proto_style.checkbox = awmtk.create_delta("checkbox", {
} , awmtk.proto_style , awmtk.proto_style . base )
-- }}}
-- {{{ G eneric templates
-- {{{ g eneric templates
awmtk.proto_templates = {
-- T emplates are built first using the given style, then applied to contents
-- t emplates are built first using the given style, then applied to contents
-- through returned function
container = function ( style )
-- C ontainer is practically any "box" that contains buttons, textboxes,
-- and anything you want to put into the container. D o not confuse with
-- c ontainer is practically any "box" that contains buttons, textboxes,
-- and anything you want to put into the container. d o not confuse with
-- popup - containers are designed to separate contents within a popup.
return function ( layout , options )
return awmtk.merge ( {
@ -188,14 +223,14 @@ awmtk.proto_templates = {
shape = style.container . shape ,
shape_border_color = style.container . shape_border_color ,
shape_border_width = style.container . shape_border_width ,
widget = wibox.container . background
widget = awmtk.wrap_hooks ( wibox.container . background , options )
} , options or { } )
end
end ,
button = function ( style )
-- Self explanatory. N otice that this does not bear any function -
-- only the visual part of the button. B y design, onpress and onrelease
-- self explanatory. n otice that this does not bear any function -
-- only the visual part of the button. b y design, onpress and onrelease
-- callbacks should be connected to button events for animations
return function ( layout , options )
return awmtk.merge ( {
@ -216,7 +251,7 @@ awmtk.proto_templates = {
end ,
textbox = function ( style )
-- N othing fancy here, but you can set per-widget fonts using beautiful.
-- n othing fancy here, but you can set per-widget fonts using beautiful.
return function ( options )
return awmtk.merge ( {
font = style.textbox . font ,
@ -226,7 +261,7 @@ awmtk.proto_templates = {
end ,
hseparator = function ( style )
-- W ow, i guess?
-- w ow, i guess?
return function ( options )
return awmtk.merge ( {
widget = wibox.widget . separator ,
@ -239,7 +274,7 @@ awmtk.proto_templates = {
end ,
vseparator = function ( style )
-- I 'm running out of comments
-- i 'm running out of comments
return function ( options )
return awmtk.merge ( {
widget = wibox.widget . separator ,
@ -252,8 +287,8 @@ awmtk.proto_templates = {
end ,
article = function ( style )
-- A rticle is a template that combines 3 common pieces of a full item:
-- Icon, name and description. D esigned to be placed within a container
-- a rticle is a template that combines 3 common pieces of a full item:
-- icon, name and description. d esigned to be placed within a container
-- or a button.
return function ( options )
return awmtk.merge ( {
@ -323,7 +358,7 @@ awmtk.proto_templates = {
end ,
popup = function ( style )
-- P opup is a distinct template designed to accomodate the "root" of
-- p opup 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 ( {
@ -341,13 +376,13 @@ awmtk.proto_templates = {
end ,
titlebar = function ( style )
-- T itlebar is a separate class specifically for window and popup
-- titlebars. T he decision to make it a separate class was due to
-- t itlebar is a separate class specifically for window and popup
-- titlebars. t he 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 )
-- I f there's one thing that fascinates me, it's how much weird
-- i f there's one thing that fascinates me, it's how much weird
-- bugs i manage to uncover by some sort of miraculous accident.
-- T his one fixes a race condition in margins+(left/right/bottom/top) configuration scenario
-- t his one fixes a race condition in margins+(left/right/bottom/top) configuration scenario
local margins = style.titlebar . margins
if ( style.titlebar . left or
style.titlebar . right or
@ -368,7 +403,7 @@ awmtk.proto_templates = {
end ,
wibar = function ( style )
-- J ust you regular old wibar, but as a style template.
-- j ust you regular old wibar, but as a style template.
return function ( layout , options )
local margins = style.wibar . margins
if ( style.wibar . left or
@ -390,7 +425,7 @@ awmtk.proto_templates = {
end ,
slider = function ( style )
-- Slider widget but wired to work with the AWMTK 2 namespace system
-- slider widget but wired to work with the awmtk 2 namespace system
return function ( args )
return awmtk.merge ( {
handle_shape = style.slider . handle_shape or style.slider . shape ,
@ -426,12 +461,12 @@ awmtk.proto_templates = {
end
}
-- L ast but not least - we export a default template lib and default style.
-- T his is done in order to allow overriding default style behaviour from theme
-- l ast but not least - we export a default template lib and default style.
-- t his is done in order to allow overriding default style behaviour from theme
awmtk.default = awmtk.create_style ( " default " , awmtk.proto_style , { } )
awmtk.templates = awmtk.create_template_lib ( " templates " , awmtk.proto_templates , { } )
-- G eneric styles for widgets that need them
-- g eneric styles for widgets that need them
awmtk.generic = { }
awmtk.generic . menu = awmtk.create_style ( " generic_menu " , awmtk.default , { } )
awmtk.generic . button_list = awmtk.create_style ( " generic_button_list " , awmtk.default , { } )