@@ -6,29 +6,65 @@ local gears = require("gears")
66
77local storage_bar_widget = {}
88
9+ --- Table with widget configuration, consists of three sections:
10+ --- - general - general configuration
11+ --- - widget - configuration of the widget displayed on the wibar
12+ --- - popup - configuration of the popup
13+ local config = {}
14+
15+ -- general
16+ config .mounts = { ' /' }
17+ config .refresh_rate = 60
18+
19+ -- wibar widget
20+ config .widget_width = 40
21+ config .widget_bar_color = ' #aaaaaa'
22+ config .widget_onclick_bg = ' #ff0000'
23+ config .widget_border_color = ' #535d6c66'
24+ config .widget_background_color = ' #22222233'
25+
26+ -- popup
27+ config .popup_bg = ' #22222233'
28+ config .popup_border_width = 1
29+ config .popup_border_color = ' #535d6c66'
30+ config .popup_bar_color = ' #aaaaaa'
31+ config .popup_bar_background_color = ' #22222233'
32+ config .popup_bar_border_color = ' #535d6c66'
33+
934local function worker (user_args )
1035 local args = user_args or {}
11- local mounts = args .mounts or { ' /' }
12- local timeout = args .timeout or 60
36+
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
53+ end
1354
1455 storage_bar_widget = wibox .widget {
1556 {
1657 id = ' progressbar' ,
58+ color = config .widget_bar_color ,
1759 max_value = 100 ,
1860 forced_height = 20 ,
19- forced_width = 35 ,
20- paddings = 1 ,
61+ forced_width = config . widget_width ,
62+ paddings = 2 ,
2163 margins = 4 ,
2264 border_width = 1 ,
2365 border_radius = 2 ,
24- border_color = beautiful .fg_normal ,
25- background_color = beautiful .bg_normal ,
26- bar_border_width = 1 ,
27- bar_border_color = beautiful .bg_focus ,
28- color = " linear:150,0:0,0:0,"
29- .. beautiful .fg_normal
30- .. " :0.3," .. beautiful .bg_urgent .. " :0.6,"
31- .. beautiful .fg_normal ,
66+ border_color = config .widget_border_color ,
67+ background_color = config .widget_background_color ,
3268 widget = wibox .widget .progressbar
3369 },
3470 shape = function (cr , width , height )
@@ -63,11 +99,12 @@ local function worker(user_args)
6399 disk_header :ajust_ratio (1 , 0 , 0.3 , 0.7 )
64100
65101 local popup = awful .popup {
102+ bg = config .popup_bg ,
66103 ontop = true ,
67104 visible = false ,
68105 shape = gears .shape .rounded_rect ,
69- border_width = 1 ,
70- border_color = beautiful . bg_normal ,
106+ border_width = config . popup_border_width ,
107+ border_color = config . popup_border_color ,
71108 maximum_width = 400 ,
72109 offset = { y = 5 },
73110 widget = {}
@@ -80,18 +117,19 @@ local function worker(user_args)
80117 popup .visible = not popup .visible
81118 storage_bar_widget :set_bg (' #00000000' )
82119 else
83- storage_bar_widget :set_bg (beautiful . bg_focus )
120+ storage_bar_widget :set_bg (config . widget_background_color )
84121 popup :move_next_to (mouse .current_widget_geometry )
85122 end
86123 end )
87124 )
88125 )
89126
90127 local disks = {}
91- watch ([[ bash -c "df | tail -n +2"]] , timeout ,
128+ watch ([[ bash -c "df | tail -n +2"]] , config . refresh_rate ,
92129 function (widget , stdout )
93130 for line in stdout :gmatch (" [^\r\n $]+" ) do
94- local filesystem , size , used , avail , perc , mount = line :match (' ([%p%w]+)%s+([%d%w]+)%s+([%d%w]+)%s+([%d%w]+)%s+([%d]+)%%%s+([%p%w]+)' )
131+ local filesystem , size , used , avail , perc , mount =
132+ line :match (' ([%p%w]+)%s+([%d%w]+)%s+([%d%w]+)%s+([%d%w]+)%s+([%d]+)%%%s+([%p%w]+)' )
95133
96134 disks [mount ] = {}
97135 disks [mount ].filesystem = filesystem
@@ -101,12 +139,12 @@ local function worker(user_args)
101139 disks [mount ].perc = perc
102140 disks [mount ].mount = mount
103141
104- if disks [mount ].mount == mounts [1 ] then
142+ if disks [mount ].mount == config . mounts [1 ] then
105143 widget :set_value (tonumber (disks [mount ].perc ))
106144 end
107145 end
108146
109- for k , v in ipairs (mounts ) do
147+ for k , v in ipairs (config . mounts ) do
110148
111149 local row = wibox .widget {
112150 {
@@ -115,22 +153,18 @@ local function worker(user_args)
115153 widget = wibox .widget .textbox
116154 },
117155 {
156+ color = config .popup_bar_color ,
118157 max_value = 100 ,
119158 value = tonumber (disks [v ].perc ),
120159 forced_height = 20 ,
121160 paddings = 1 ,
122161 margins = 4 ,
123162 border_width = 1 ,
124- border_color = beautiful . bg_focus ,
125- background_color = beautiful . bg_normal ,
163+ border_color = config . popup_bar_border_color ,
164+ background_color = config . popup_bar_background_color ,
126165 bar_border_width = 1 ,
127- bar_border_color = beautiful .bg_focus ,
128- color = " linear:150,0:0,0:0,"
129- .. beautiful .fg_normal
130- .. " :0.3," .. beautiful .bg_urgent .. " :0.6,"
131- .. beautiful .fg_normal ,
166+ bar_border_color = config .popup_bar_border_color ,
132167 widget = wibox .widget .progressbar ,
133-
134168 },
135169 {
136170 text = math.floor (disks [v ].used / 1024 / 1024 )
0 commit comments