Inter process messaging

patrick96 edited this page Oct 19, 2017 · 6 revisions

Support for inter-process messaging can be enabled by defining the bar parameter enable-ipc = true.

By default the project is built with a helper tool called polybar-msg used to facilitate ipc messaging.

Message types

Hook message for custom/ipc modules

Format: hook:module/<module-name>/<hook-id>

See the module wiki page for more details on how to setup message hooks.

Action message to simulate mouse action

Format: action:<message>

This could be used to control a menu module, for example:

$ echo action:menu-open-1 >/tmp/polybar_mqueue.<pid>
$ echo action:menu-close >/tmp/polybar_mqueue.<pid>

Command messages to control polybar

Format: cmd:<command>

The following values for <command> are available:

  • quit: Terminates the bar this message was sent to
  • restart: Restarts the bar
  • hide: Hides the bar
  • show: Makes the bar visible again, if it was hidden
  • toggle: Toggles betweend the hidden and visible state

Sending messages

Messages are written to the processes unique FIFO created at /tmp/polybar_mqueue.<pid> on startup.

If you only have one bar running, you could use the following command to send messages:

$ echo message >/tmp/polybar_mqueue.$(pidof polybar)

To write a message to all running instances.

$ echo message >/tmp/polybar_mqueue.*

For setups with multiple bars I'd recommend creating symlinks to each channel after launching the process to make it easier to send messages to a specific instance.

$ polybar mybar1 &
$ ln -s /tmp/polybar_mqueue.$! /tmp/ipc-mybar1
$ polybar mybar2 &
$ ln -s /tmp/polybar_mqueue.$! /tmp/ipc-mybar2

$ echo message >/tmp/ipc-mybar2

By using xprop you could send a message to a specific bar by clicking on it:

$ echo message >/tmp/polybar_mqueue.$(xprop -f c 32 _NET_WM_PID | cut -d ' ' -f 3)

Using polybar-msg

The executable polybar-msg can be used to simplify passing messages to polybar. Instead of writing a message of the form <type>:<payload> to /tmp/polybar_mqueue.<pid>, you can call

polybar-msg -p <pid> <type> <payload>

If you want to send a message to all running bars, execute the command without a pid:

polybar-msg <type> <payload>

For example you can hide all bars like this:

polybar-msg cmd hide
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.