-
-
Notifications
You must be signed in to change notification settings - Fork 44
modules: Executor
The Executor module displays an icon, and a label, on the basis of a script output, refreshed in user-defined intervals or on a signal. You may assign mouse events to it.
Output of the "script"
command should return 1 or 2 lines.
By default we expect the icon path in the first line, and some text in the second one, e.g:
$ psuinfo -IM
/usr/share/psuinfo/mem.svg
3.1/21.5 GB
The Executor module will also accept an icon name:
$ /home/piotr/.config/nwg-panel/executors/arch_updates.py
software-update-urgent
1/2
We expect either a line of text:
$ psuinfo -CM
3.2/21.5 GB
or an icon path, or icon name.
The "continuous output" feature known from tint2 is not supported.
Executors database is a common file to store your executors in. You may add your executor to it, and then import it to any other panel. Available since v0.5.7.
Also check Some useful executors.
Starting from v0.7.15 you can give up on the refresh interval (set the value to 0), and force refreshing executors on a signal in range SIGRTMIN - SIGRTMAX:
The example executor below shows the current keyboard layout, and switches layouts on left click. Read comments for details.
#!/usr/bin/env python3
"""
Sway keyboard layout label & switcher, as an executor for nwg-panel
Author: Piotr Miller
e-mail: nwg.piotr@gmail.com
GitHub: https://github.com/nwg-piotr/nwg-panel
Project: https://github.com/nwg-piotr/nwg-shell
License: MIT
Usage:
0. Save this script as 'keyboard-layout' on your $PATH (e.g. '~/bin/keyboard-layout` or '~/.local/bin/keyboard-layout`).
1. Edit, to enter your `keyboard_id`, preferred `icon` and `sig_num`.
2. In nwg-shell-config create a new executor called "executor-keyboard".
3. Set "Script" to "keyboard-layout".
4. Set "On left click" to "keyboard-layout -s".
5. Set "Interval" to 0.
6. Set "Refresh on signal" to 37 (or whatever else you choose as the `sig_num` below); check the "use signal" box.
7. Add the executor to the panel.
Setting multiple keyboard layouts:
Nwg-shell users: in the config utility set comma-separated keyboard layouts, like e.g. "pl,us".
Others: do the same in your sway config file.
Dependency: `python-i3ipc`
"""
import argparse
import subprocess
import sys
from i3ipc import Connection
# Find your keyboard identifier with `swaymsg -t get_inputs`, paste here.
keyboard_id = "9610:42:SINO_WEALTH_Gaming_KB__Keyboard"
# Place your preferred icon name (or path) here. Leave empty ("") for no icon.
icon = "input-keyboard"
# The number of the signal to refresh the executor label, in range SIGTRMIN - SIGRTMAX (probably 34 - 64).
# You may check available range with `kill -l`.
sig_num = 37
i3 = Connection()
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-s",
"--switch",
action="store_true",
help="switches keyboard layout")
args = parser.parse_args()
if args.switch:
i3.command('input "{}" xkb_switch_layout next'.format(keyboard_id))
# Send refresh signal to nwg-panel
subprocess.Popen('pkill -{} nwg-panel'.format(sig_num), shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
sys.exit(0)
# Get keyboard layout name
layout_name = ""
inputs = i3.get_inputs()
for i in inputs:
if i.identifier == keyboard_id:
layout_name = i.xkb_active_layout_name
break
if icon:
# Print 2 lines: 1. icon name/path; 2. keyboard layout name.
print("{}\n{}".format(icon, layout_name))
else:
# Print the keyboard layout name.
print("{}".format(layout_name))
if __name__ == '__main__':
main()