@@ -34,37 +34,27 @@ config.popup_bar_border_color = '#535d6c66'
3434local function worker (user_args )
3535 local args = user_args or {}
3636
37- if beautiful ~= nil then
38- config .widget_bar_color = beautiful .fg_normal
39- config .widget_border_color = beautiful .bg_focus
40- config .widget_onclick_bg = beautiful .bg_focus
41- config .widget_background_color = beautiful .bg_normal
42-
43- config .popup_bg = beautiful .bg_normal
44- config .popup_border_color = beautiful .bg_focus
45- config .popup_bar_color = beautiful .fg_normal
46- config .popup_bar_border_color = beautiful .bg_focus
47- config .popup_bar_background_color = beautiful .bg_normal
48- config .popup_bar_border_color = beautiful .bg_focus
49- end
50-
51- for prop , value in pairs (args ) do
52- config [prop ] = value
37+ -- Setup config for the widget instance.
38+ -- The `_config` table will keep the first existing value after checking
39+ -- in this order: user parameter > beautiful > module default.
40+ local _config = {}
41+ for prop , value in pairs (config ) do
42+ _config [prop ] = args [prop ] or beautiful [prop ] or value
5343 end
5444
5545 storage_bar_widget = wibox .widget {
5646 {
5747 id = ' progressbar' ,
58- color = config .widget_bar_color ,
48+ color = _config .widget_bar_color ,
5949 max_value = 100 ,
6050 forced_height = 20 ,
61- forced_width = config .widget_width ,
51+ forced_width = _config .widget_width ,
6252 paddings = 2 ,
6353 margins = 4 ,
6454 border_width = 1 ,
6555 border_radius = 2 ,
66- border_color = config .widget_border_color ,
67- background_color = config .widget_background_color ,
56+ border_color = _config .widget_border_color ,
57+ background_color = _config .widget_background_color ,
6858 widget = wibox .widget .progressbar
6959 },
7060 shape = function (cr , width , height )
@@ -99,12 +89,12 @@ local function worker(user_args)
9989 disk_header :ajust_ratio (1 , 0 , 0.3 , 0.7 )
10090
10191 local popup = awful .popup {
102- bg = config .popup_bg ,
92+ bg = _config .popup_bg ,
10393 ontop = true ,
10494 visible = false ,
10595 shape = gears .shape .rounded_rect ,
106- border_width = config .popup_border_width ,
107- border_color = config .popup_border_color ,
96+ border_width = _config .popup_border_width ,
97+ border_color = _config .popup_border_color ,
10898 maximum_width = 400 ,
10999 offset = { y = 5 },
110100 widget = {}
@@ -117,15 +107,15 @@ local function worker(user_args)
117107 popup .visible = not popup .visible
118108 storage_bar_widget :set_bg (' #00000000' )
119109 else
120- storage_bar_widget :set_bg (config .widget_background_color )
110+ storage_bar_widget :set_bg (_config .widget_background_color )
121111 popup :move_next_to (mouse .current_widget_geometry )
122112 end
123113 end )
124114 )
125115 )
126116
127117 local disks = {}
128- watch ([[ bash -c "df | tail -n +2"]] , config .refresh_rate ,
118+ watch ([[ bash -c "df | tail -n +2"]] , _config .refresh_rate ,
129119 function (widget , stdout )
130120 for line in stdout :gmatch (" [^\r\n $]+" ) do
131121 local filesystem , size , used , avail , perc , mount =
@@ -139,12 +129,12 @@ local function worker(user_args)
139129 disks [mount ].perc = perc
140130 disks [mount ].mount = mount
141131
142- if disks [mount ].mount == config .mounts [1 ] then
132+ if disks [mount ].mount == _config .mounts [1 ] then
143133 widget :set_value (tonumber (disks [mount ].perc ))
144134 end
145135 end
146136
147- for k , v in ipairs (config .mounts ) do
137+ for k , v in ipairs (_config .mounts ) do
148138
149139 local row = wibox .widget {
150140 {
@@ -153,17 +143,17 @@ local function worker(user_args)
153143 widget = wibox .widget .textbox
154144 },
155145 {
156- color = config .popup_bar_color ,
146+ color = _config .popup_bar_color ,
157147 max_value = 100 ,
158148 value = tonumber (disks [v ].perc ),
159149 forced_height = 20 ,
160150 paddings = 1 ,
161151 margins = 4 ,
162152 border_width = 1 ,
163- border_color = config .popup_bar_border_color ,
164- background_color = config .popup_bar_background_color ,
153+ border_color = _config .popup_bar_border_color ,
154+ background_color = _config .popup_bar_background_color ,
165155 bar_border_width = 1 ,
166- bar_border_color = config .popup_bar_border_color ,
156+ bar_border_color = _config .popup_bar_border_color ,
167157 widget = wibox .widget .progressbar ,
168158 },
169159 {
0 commit comments