Created
September 17, 2015 03:16
-
-
Save msullivan/d3bca6ed2907ee5d8d16 to your computer and use it in GitHub Desktop.
Script to register a dummy panel so that multimedia keys work properly when using weirdo WMs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Michael J. Sullivan (http://www.msully.net/) | |
# Stupid little script to make gnome/unity media keys work when running | |
# weirdo window managers like xmonad and notion. | |
# Directions: | |
# With unity-settings-daemon running, run this script in the background. | |
# Tested on Ubuntu 15.04 using notion. | |
# unity-settings-daemon manages the keys (I think?), but only does it these | |
# days if there is a registered "Panel", which is, of course, done with | |
# a dbus call. So just do that, I guess. | |
# python dbus stuff cribbed from http://stackoverflow.com/questions/21793826/simple-but-specific-listener-and-sender-python-3-dbus-example | |
# The dance necessary to make this work was figured out from | |
# http://gnome-panel.sourcearchive.com/documentation/3.0.2-1/panel-shell_8c_source.html | |
import sys, signal | |
import dbus | |
def main(args): | |
try: | |
bus = dbus.SessionBus() | |
# Register ourselves as an org.gnome.Panel | |
proxy = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus") | |
iface = dbus.Interface(proxy, "org.freedesktop.DBus") | |
res = iface.RequestName("org.gnome.Panel", 1) | |
# 1 and 4 mean we succeeded | |
if res == 1 or res == 4: | |
pass | |
# 2 and 3 means there is already a panel running | |
elif res == 2 or res == 3: | |
sys.stderr.write("fake-panel: there is already a panel") | |
return 1 | |
# Anything else is ?? | |
else: | |
sys.stderr.write("fake-panel: unexpected reply: %s\n" % res) | |
return 1 | |
except dbus.DBusException as e: | |
sys.stderr.write("fake-panel: got dbus error: %s\n" % e) | |
return 1 | |
# Now just keep on idling forever so we hang onto the name. | |
while True: | |
signal.pause() | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment