@@ -102,137 +102,6 @@ vicious.register(cpuwidget, vicious.widgets.cpu, "$1", 3)
102102```
103103
104104
105- ## <a name =" format-func " ></a >Format functions
106-
107- You can use a function instead of a string as the format parameter.
108- Then you are able to check the value returned by the widget type and
109- change it or perform some action. You can change the color of the
110- battery widget when it goes below a certain point, hide widgets when
111- they return a certain value or maybe use ` string.format ` for padding.
112-
113- Do not confuse this with just coloring the widget, in those cases standard
114- Pango markup can be inserted into the format string.
115-
116- The format function will get the widget as its first argument, table
117- with the values otherwise inserted into the format string as its
118- second argument, and will return the text/data to be used for the
119- widget.
120-
121- ### Examples
122-
123- #### Hide mpd widget when no song is playing
124-
125- ``` lua
126- mpdwidget = wibox .widget .textbox ()
127- vicious .register (
128- mpdwidget ,
129- vicious .widgets .mpd ,
130- function (widget , args )
131- if args [" {state}" ] == " Stop" then
132- return ' '
133- else
134- return (' <span color="white">MPD:</span> %s - %s' ):format (
135- args [" {Artist}" ], args [" {Title}" ])
136- end
137- end )
138- ```
139-
140- #### Use string.format for padding
141-
142- ``` lua
143- uptimewidget = wibox .widget .textbox ()
144- vicious .register (uptimewidget , vicious .widgets .uptime ,
145- function (widget , args )
146- return (" Uptime: %02d %02d:%02d " ):format (
147- args [1 ], args [2 ], args [3 ])
148- end , 61 )
149- ```
150-
151- When it comes to padding it is also useful to mention how a widget can be
152- configured to have a fixed width. You can set a fixed width on your textbox
153- widgets by changing their ` width ` field (by default width is automatically
154- adapted to text width). The following code forces a fixed width of 50 px to the
155- uptime widget, and aligns its text to the right:
156-
157- ``` lua
158- uptimewidget = wibox .widget .textbox ()
159- uptimewidget .width , uptimewidget .align = 50 , " right"
160- vicious .register (uptimewidget , vicious .widgets .uptime , " $1 $2:$3" , 61 )
161- ```
162-
163- #### Stacked graph
164-
165- Stacked graphs are handled specially by Vicious: ` format ` functions passed to
166- the corresponding widget types must return an array instead of a string.
167-
168- ``` lua
169- cpugraph = wibox .widget .graph ()
170- cpugraph :set_stack (true )
171- cpugraph :set_stack_colors ({" red" , " yellow" , " green" , " blue" })
172- vicious .register (cpugraph , vicious .widgets .cpu ,
173- function (widget , args )
174- return {args [2 ], args [3 ], args [4 ], args [5 ]}
175- end , 3 )
176- ```
177-
178- The snipet above enables graph stacking/multigraph and plots usage of all four
179- CPU cores on a single graph.
180-
181- #### Substitute widget types' symbols
182-
183- If you are not happy with default symbols used in volume, battery, cpufreq and
184- other widget types, use your own symbols without any need to modify modules.
185- The following example uses a custom table map to modify symbols representing
186- the mixer state: on or off/mute.
187-
188- ``` lua
189- volumewidget = wibox .widget .textbox ()
190- vicious .register (volumewidget , vicious .widgets .volume ,
191- function (widget , args )
192- local label = {[" ♫" ] = " O" , [" ♩" ] = " M" }
193- return (" Volume: %d%% State: %s" ):format (
194- args [1 ], label [args [2 ]])
195- end , 2 , " PCM" )
196- ```
197-
198- #### <a name =" call-example " ></a >Get data from the widget
199-
200- ` vicious.call ` could be useful for naughty notification and scripts:
201-
202- ``` lua
203- mybattery = wibox .widget .textbox ()
204- vicious .register (mybattery , vicious .widgets .bat , " $2%" , 17 , " 0" )
205- mybattery :buttons (awful .util .table .join (
206- awful .button (
207- {}, 1 ,
208- function ()
209- naughty .notify {title = " Battery indicator" ,
210- text = vicious .call (vicious .widgets .bat ,
211- " Remaining time: $3" , " 0" )}
212- end )))
213- ```
214-
215- Format functions can be used as well:
216-
217- ``` lua
218- mybattery :buttons (awful .util .table .join (
219- awful .button (
220- {}, 1 ,
221- function ()
222- naughty .notify {
223- title = " Battery indicator" ,
224- text = vicious .call (
225- vicious .widgets .bat ,
226- function (widget , args )
227- return (" %s: %10sh\n %s: %14d%%\n %s: %12dW" ):format (
228- " Remaining time" , args [3 ],
229- " Wear level" , args [4 ],
230- " Present rate" , args [5 ])
231- end , " 0" )}
232- end )))
233- ```
234-
235-
236105## Contributing
237106
238107For details, see CONTRIBUTING.md. Vicious is licensed under GNU GPLv2+,
0 commit comments