Debian Codegraph @

vicious/docs/source/usage-awesome.rst

raw
1 Usage within Awesome
2 ====================
3
4 To use Vicious with awesome_, install the package from your operating system
5 provider, or download the source code and move it to your awesome
6 configuration directory in ``$XDG_CONFIG_HOME`` (usually ``~/.config``)::
7
8 git clone https://github.com/vicious-widgets/vicious.git
9 mv vicious $XDG_CONFIG_HOME/awesome/
10
11 Vicious will only load modules for widget types you intend to use in
12 your awesome configuration, to avoid having useless modules sitting in
13 your memory.
14
15 Then add the following to the top of your ``rc.lua``:
16
17 .. code-block:: lua
18
19 local vicious = require("vicious")
20
21 vicious.register
22 ----------------
23
24 Once you create a widget (a textbox, graph or a progressbar),
25 call ``vicious.register`` to register it with Vicious:
26
27 .. lua:function:: vicious.register(widget, wtype, format, interval, warg)
28
29 Register a widget.
30
31 :param widget: awesome widget created from
32 ``awful.widget`` or ``wibox.widget``
33
34 :param wtype: either of
35
36 * Vicious widget type: any widget type
37 :ref:`provided by Vicious <widgets>` or customly defined.
38 * ``function``: custom function from your own
39 awesome configuration can be registered as widget types
40 (see :ref:`custom-wtype`).
41
42 :param format: either of
43
44 * string: ``$key`` will be replaced by respective value in the table
45 ``t`` returned by the widget type, i.e. use ``$1``, ``$2``, etc.
46 to retrieve data from an integer-indexed table (a.k.a. array);
47 ``${foo bar}`` will be substituted by ``t["{foo bar}"]``.
48 * ``function (widget, args)`` can be used to manipulate data returned
49 by the widget type (see :ref:`format-func`).
50
51 :param interval: number of seconds between updates of the widget
52 (default: 2). See :ref:`caching` for more information.
53
54 :param warg: arguments to be passed to widget types, e.g. the battery ID.
55
56 ``vicious.register`` alone is not much different from awful.widget.watch_,
57 which has been added to Awesome since version 4.0. However, Vicious offers
58 more advanced control of widgets' behavior by providing the following functions.
59
60 vicious.unregister
61 ------------------
62
63 .. lua:function:: vicious.unregister(widget, keep)
64
65 Unregister a widget.
66
67 :param widget: awesome widget created from
68 ``awful.widget`` or ``wibox.widget``
69 :param keep: if true suspend ``widget`` and wait for activation
70 :type keep: bool
71
72 vicious.suspend
73 ---------------
74
75 .. lua:function:: vicious.suspend()
76
77 Suspend all widgets.
78
79 See `example automation script`_ for the "laptop-mode-tools" start-stop module.
80
81 vicious.activate
82 ----------------
83
84 .. lua:function:: vicious.activate([widget])
85
86 Restart suspended widget(s).
87
88 :param widget: if provided only that widget will be activated
89
90 vicious.cache
91 -------------
92
93 .. lua:function:: vicious.cache(wtype)
94
95 Enable caching of values returned by a widget type.
96
97 vicious.force
98 --------------
99
100 .. lua:function:: vicious.force(wtable)
101
102 Force update of given widgets.
103
104 :param wtable: table of one or more widgets to be updated
105
106 vicious.call[_async]
107 --------------------
108
109 .. lua:function:: vicious.call(wtype, format, warg)
110
111 Get formatted data from a synchronous widget type
112 (:ref:`example <call-example>`).
113
114 :param wtype: either of
115
116 * Vicious widget type: any synchronous widget type
117 :ref:`provided by Vicious <widgets>` or customly defined.
118 * ``function``: custom function from your own
119 awesome configuration can be registered as widget types
120 (see :ref:`custom-wtype`).
121
122 :param format: either of
123
124 * string: ``$key`` will be replaced by respective value in the table
125 ``t`` returned by the widget type, i.e. use ``$1``, ``$2``, etc.
126 to retrieve data from an integer-indexed table (a.k.a. array);
127 ``${foo bar}`` will be substituted by ``t["{foo bar}"]``.
128 * ``function (widget, args)`` can be used to manipulate data returned
129 by the widget type (see :ref:`format-func`).
130
131 :param warg: arguments to be passed to the widget type, e.g. the battery ID.
132
133 :return: ``nil`` if the widget type is asynchronous,
134 otherwise the formatted data from with widget type.
135
136 .. lua:function:: vicious.call_async(wtype, format, warg, callback)
137
138 Get formatted data from an asynchronous widget type.
139
140 :param wtype: any asynchronous widget type
141 :ref:`provided by Vicious <widgets>` or customly defined.
142
143 :param format: either of
144
145 * string: ``$key`` will be replaced by respective value in the table
146 ``t`` returned by the widget type, i.e. use ``$1``, ``$2``, etc.
147 to retrieve data from an integer-indexed table (a.k.a. array);
148 ``${foo bar}`` will be substituted by ``t["{foo bar}"]``.
149 * ``function (widget, args)`` can be used to manipulate data returned
150 by the widget type (see :ref:`format-func`).
151
152 :param warg: arguments to be passed to the widget type.
153
154 :param callback: function taking the formatted data from with widget type.
155 If the given widget type happens to be synchronous,
156 ``nil`` will be passed to ``callback``.
157
158 .. _awesome: https://awesomewm.org/
159 .. _awful.widget.watch:
160 https://awesomewm.org/doc/api/classes/awful.widget.watch.html
161 .. _example automation script:
162 http://sysphere.org/~anrxc/local/sources/lmt-vicious.sh