File: actions.rst

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (457 lines) | stat: -rw-r--r-- 16,223 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
Actions
=======

.. versionadded:: 3.5.0

.. contents:: Table of Contents
   :local:

"Actions" are used to trigger certain behavior in modules.
For example, when you click on your volume module (pulseaudio or alsa), polybar
internally sends an action to that module that tells it to mute/unmute the
audio.

These actions are not only used internally, but users can also send these
actions to polybar through `Inter Process Communication
<https://github.com/polybar/polybar/wiki/Inter-process-messaging>`_ (IPC) to
trigger certain behavior in polybar modules.

.. _action-string-format:

Action String Format
--------------------

An action string follows the following format:

::

  #NAME.ACTION[.DATA]

Where ``NAME`` is the name of the target module (not the type!) and ``ACTION``
is the name of the action in that module. ``DATA`` is optional data attached to
an action (for example to say which menu level should be opened).

For example the
`date module <https://github.com/polybar/polybar/wiki/Module:-date>`_ supports
the ``toggle`` action to toggle between the regular and the alternative time and
date format.
If you have the following date module:

.. code-block:: ini

  [module/mydate]
  type = internal/date
  ...

The action string for toggling between the date formats would look like this:

::

  #mydate.toggle

Note that we use the name of the module (``mydate``) and not the type.

As an example for an action string with additional data, take the menu module:

.. code-block:: ini

  [module/powermenu]
  type = custom/menu
  menu-0-0 = Poweroff
  menu-0-0-exec = poweroff
  menu-0-1 = Suspend
  menu-0-1-exec = systemctl suspend

The action name to open a certain menu level is ``open``, so to open level 0
(`menu-0`), the action string additionally has the level attached to it:

::

  #powermenu.open.0

Triggering Actions
------------------

Most modules already use action strings to trigger actions when you click on or
scroll over a module.
But in some cases you may want or need to manually send action strings to
polybar to trigger a certain behavior.

Everywhere where you can specify a command to run on click or scroll, you can
also specify an action string.
For example, in the bar section, you can specify a command that is triggered
when you click anywhere on the bar (where there isn't another click action):

.. code-block:: ini

  [bar/mybar]
  ...
  click-left = #mydate.toggle
  ...

This will then trigger the ``toggle`` action on the ``mydate`` module when you
click anywhere on the bar.

Similarly, we can use action strings in ``%{A}``
`formatting tags <https://github.com/polybar/polybar/wiki/Formatting#action-a>`_
just as we would regular commands:

::

  %{A1:firefox:}%{A3:#mydate.toggle:}Opens firefox on left-click and toggles the
  date on right-click %{A}%{A}

Finally, polybar's `Inter Process Communication
<https://github.com/polybar/polybar/wiki/Inter-process-messaging>`_ (IPC) can
also be used to trigger actions:

.. code-block:: bash

  polybar-msg action "#mydate.toggle"

.. note::

  The quotes around the action string are necessary, otherwise your shell may
  interpret the ``#`` as the beginning of the comment and ignore the rest of the
  line.

Available Actions
-----------------

The following modules have actions available. Most of them are already used by
the module by default for click and scroll events.

All Modules
^^^^^^^^^^^

These actions are available to all modules and are prefixed with ``module_``.

:``module_show``, ``module_hide``:
  Shows/Hides a module. The module is still running in the background when
  hidden, it is just not drawn. The starting state can be configured with the
  `hidden` configuration option.

  .. versionadded:: 3.6.0

:``module_toggle``:
  Toggles the visibility of a module.

  .. versionadded:: 3.6.0

internal/date
^^^^^^^^^^^^^

:``toggle``:
  Toggles the date/time format between ``date``/``time`` and
  ``date-alt``/``time-alt``

internal/alsa
^^^^^^^^^^^^^

:``inc``, ``dec``:
  Increases/Decreases the volume by ``interval`` percentage points, where
  ``interval`` is the config setting in the module. Volume changed like this
  will never go above 100%.

:``toggle``:
  Toggles between muted and unmuted.

internal/pulseaudio
^^^^^^^^^^^^^^^^^^^

:``inc``, ``dec``:
  Increases/Decreases the volume by ``interval`` percentage points, where
  ``interval`` is the config setting in the module. Volume changed like this
  will never go above ~153% (if ``use-ui-max`` is set to ``true``) or 100% (if
  not).

:``toggle``:
  Toggles between muted and unmuted.

internal/xbacklight
^^^^^^^^^^^^^^^^^^^

:``inc``, ``dec``:
  Increases/Decreases screen brightness 5 percentage points.

internal/backlight
^^^^^^^^^^^^^^^^^^

:``inc``, ``dec``:
  Increases/Decreases screen brightness 5 percentage points.

internal/xkeyboard
^^^^^^^^^^^^^^^^^^

:``switch``:
  Cycles through configured keyboard layouts.

internal/mpd
^^^^^^^^^^^^

:``play``: Starts playing the current song.
:``pause``: Pauses the current song.
:``stop``: Stops playing.
:``prev``: Starts playing the previous song.
:``next``: Starts playing the next song.
:``repeat``: Toggles repeat mode.
:``single``: Toggles single mode.
:``random``: Toggles random mode.
:``consume``: Toggles consume mode.
:``seek``: *(Has Data)* Seeks inside the current song.

           The data must be of the form ``[+-]N``, where ``N`` is a number
           between 0 and 100.

           If either ``+`` or ``-`` is used, it will seek forward or backward
           from the current position by ``N%`` (relative to the length of the
           song).
           Otherwise it will seek to ``N%`` of the current song.

internal/xworkspaces
^^^^^^^^^^^^^^^^^^^^

:``focus``: *(Has Data)* Switches to the given workspace.

            The data is the index of the workspace that should be selected.
:``next``: Switches to the next workspace. The behavior of this action is
           affected by the ``pin-workspaces`` setting.
:``prev``: Switches to the previous workspace. The behavior of this action is
           affected by the ``pin-workspaces`` setting.

internal/bspwm
^^^^^^^^^^^^^^

:``focus``: *(Has Data)* Switches to the given workspace.

            The data has the form ``N+M``, where ``N`` is the index of the
            monitor and ``M`` the index of the workspace on that monitor.
            Both indices are 0-based and correspond to the position the monitor
            and workspace appear in the output of ``bspc subscribe report``.
:``next``: Switches to the next workspace. The behavior of this action is
           affected by the ``pin-workspaces`` setting.
:``prev``: Switches to the previous workspace. The behavior of this action is
           affected by the ``pin-workspaces`` setting.


internal/i3
^^^^^^^^^^^

:``focus``: *(Has Data)* Switches to the given workspace.

            The data is the name of the workspace defined in the i3 config.
:``next``: Switches to the next workspace. The behavior of this action is
           affected by the ``pin-workspaces`` setting.
:``prev``: Switches to the previous workspace. The behavior of this action is
           affected by the ``pin-workspaces`` setting.

custom/menu
^^^^^^^^^^^

:``open``: *(Has Data)* Opens the given menu level

           The data is a single number specifying which menu level should be
           opened.
:``close``: Closes the menu
:``exec``: *(Has Data)* Executes the command at the given menu element.

           The data has the form ``N-M`` and the action will execute the command
           in ``menu-N-M-exec``.


.. _actions-ipc:

custom/ipc
^^^^^^^^^^

.. versionadded:: 3.6.0

:``send``: *(Has Data)* Replace the contents of the module with the data passed in this action.
:``hook``: *(Has Data)* Trigger the given hook.

           The data is the 0-based index of the hook to trigger.
:``next``: Switches to the next hook and wrap around when the last hook was displayed.
:``prev``: Switches to the previous hook and wrap around when the first hook was displayed.
:``reset``: Reset the module to its startup state: either empty or according to the ``initial`` setting.


Deprecated Action Names
-----------------------

.. deprecated:: 3.5.0

In earlier versions (< 3.5.0) action strings only included information about the
module type.
This meant in bars that contained multiple different modules of the same type,
actions for these modules were sometimes processed by the wrong module with the
same type.

Since version 3.5.0, this no longer happens. However, this also means we had to
change what actions are recognized by polybar modules.

If you explicitly use any polybar action names in your config or any of your
scripts, you are advised to change them, as they may stop working at some point
in the future.
For now polybar still supports the old action names, will convert them to the
appropriate new action name, and will print a warning to help you find old
action names in your config.

If you use the `menu module
<https://github.com/polybar/polybar/wiki/Module:-menu>`_, you most likely use
old action names to open and close the menu (for example ``menu-open-1`` or
``menu-close``).
The ``i3wm-wsnext``, ``i3wm-wsprev``, ``bspwm-desknext``, and ``bspwm-deskprev``
actions, to switch workspaces in i3 and bspwm, may also appear in your config.

Migration
^^^^^^^^^

Updating your config to use the new action names is quite straightforward.

For each action name, consult the table below to find the new action name.
Afterwards build the complete action string as described in
:ref:`action-string-format`.

Please see :ref:`below <menu-example>` for an example of migrating a typical menu module.

+-------------------------+-----------------------+---------------+
|Module Type              |Deprecated Action Name |New Action Name|
+=========================+=======================+===============+
|``internal/date``        |``datetoggle``         |``toggle``     |
+-------------------------+-----------------------+---------------+
|``internal/alsa``        |``volup``              |``inc``        |
|                         +-----------------------+---------------+
|                         |``voldown``            |``dec``        |
|                         +-----------------------+---------------+
|                         |``volmute``            |``toggle``     |
+-------------------------+-----------------------+---------------+
|``internal/pulseaudio``  |``pa_volup``           |``inc``        |
|                         +-----------------------+---------------+
|                         |``pa_voldown``         |``dec``        |
|                         +-----------------------+---------------+
|                         |``pa_volmute``         |``toggle``     |
+-------------------------+-----------------------+---------------+
|``internal/xbacklight``  |``xbacklight+``        |``inc``        |
|                         +-----------------------+---------------+
|                         |``xbacklight-``        |``dec``        |
+-------------------------+-----------------------+---------------+
|``internal/backlight``   |``backlight+``         |``inc``        |
|                         +-----------------------+---------------+
|                         |``backlight-``         |``dec``        |
+-------------------------+-----------------------+---------------+
|``internal/xkeyboard``   |``xkeyboard/switch``   |``switch``     |
+-------------------------+-----------------------+---------------+
|``internal/mpd``         |``mpdplay``            |``play``       |
|                         +-----------------------+---------------+
|                         |``mpdpause``           |``pause``      |
|                         +-----------------------+---------------+
|                         |``mpdstop``            |``stop``       |
|                         +-----------------------+---------------+
|                         |``mpdprev``            |``prev``       |
|                         +-----------------------+---------------+
|                         |``mpdnext``            |``next``       |
|                         +-----------------------+---------------+
|                         |``mpdrepeat``          |``repeat``     |
|                         +-----------------------+---------------+
|                         |``mpdsingle``          |``single``     |
|                         +-----------------------+---------------+
|                         |``mpdrandom``          |``random``     |
|                         +-----------------------+---------------+
|                         |``mpdconsume``         |``consume``    |
|                         +-----------------------+---------------+
|                         |``mpdseekN``           |``seek.N``     |
+-------------------------+-----------------------+---------------+
|``internal/xworkspaces`` |``xworkspaces-focus=N``|``focus.N``    |
|                         +-----------------------+---------------+
|                         |``xworkspaces-next``   |``next``       |
|                         +-----------------------+---------------+
|                         |``xworkspaces-prev``   |``prev``       |
+-------------------------+-----------------------+---------------+
|``internal/bspwm``       |``bspwm-deskfocusN``   |``focus.N``    |
|                         +-----------------------+---------------+
|                         |``bspwm-desknext``     |``next``       |
|                         +-----------------------+---------------+
|                         |``bspwm-deskprev``     |``prev``       |
+-------------------------+-----------------------+---------------+
|``internal/i3``          |``i3wm-wsfocus-N``     |``focus.N``    |
|                         +-----------------------+---------------+
|                         |``i3-wsnext``          |``next``       |
|                         +-----------------------+---------------+
|                         |``i3-wsprev``          |``prev``       |
+-------------------------+-----------------------+---------------+
|``custom/menu``          |``menu-open-N``        |``open.N``     |
|                         +-----------------------+---------------+
|                         |``menu-close``         |``close``      |
+-------------------------+-----------------------+---------------+

.. note::

   Some deprecated action names are suffixed with ``N``, this means that that
   action has some additional data (represented by that ``N``), in the new
   action names this data will appear in exactly the same way, after a period.

.. _menu-example:

Menu Module Example
"""""""""""""""""""

The menu module is the only module where we have to explicitly use actions for
it to work. Because of this, almost everyone will need to update their menu
module to use the new action format.

Below you can see an example of a menu module:

.. code-block:: ini

  [module/apps]
  type = custom/menu

  label-open = Apps

  menu-0-0 = Browsers
  menu-0-0-exec = menu-open-1
  menu-0-1 = Multimedia
  menu-0-1-exec = menu-open-2

  menu-1-0 = Firefox
  menu-1-0-exec = firefox
  menu-1-1 = Chromium
  menu-1-1-exec = chromium

  menu-2-0 = Gimp
  menu-2-0-exec = gimp
  menu-2-1 = Scrot
  menu-2-1-exec = scrot

This module uses two actions: ``menu-open-1`` and ``menu-open-2``.
These are actions with data, the data specifies which level of the menu should
be opened.

Looking at the table, we see that the new action name for ``menu-open-N`` is
``open.N``, where ``.N`` is the data attached to the action.
Putting this together with the name of the module gives us ``#apps.open.1`` and
``#apps.open.2`` as action strings.
Since your menu module likely has a different name, your action strings will
likely not use ``apps``, but the name of your module.

.. code-block:: ini

  [module/apps]
  type = custom/menu

  label-open = Apps

  menu-0-0 = Browsers
  menu-0-0-exec = #apps.open.1
  menu-0-1 = Multimedia
  menu-0-1-exec = #apps.open.2

  menu-1-0 = Firefox
  menu-1-0-exec = firefox
  menu-1-1 = Chromium
  menu-1-1-exec = chromium

  menu-2-0 = Gimp
  menu-2-0-exec = gimp
  menu-2-1 = Scrot
  menu-2-1-exec = scrot