Created
April 28, 2019 19:42
-
-
Save ximon18/dd5263bd220192dfcebeae5ebc784cf7 to your computer and use it in GitHub Desktop.
Linux tray applet for autorandr
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/python | |
# For: https://github.com/phillipberndt/autorandr | |
# Based on: https://fosspost.org/tutorials/custom-system-tray-icon-indicator-linux | |
import os | |
from gi import require_version | |
require_version('Gtk', '3.0') | |
require_version('AppIndicator3', '0.1') | |
from gi.repository import Gtk as gtk, AppIndicator3 as appindicator | |
from subprocess import Popen, PIPE | |
def main(): | |
indicator = appindicator.Indicator.new("autorandrtray", "semi-starred-symbolic", appindicator.IndicatorCategory.APPLICATION_STATUS) | |
indicator.set_status(appindicator.IndicatorStatus.ACTIVE) | |
indicator.set_menu(menu()) | |
gtk.main() | |
def menu(): | |
menu = gtk.Menu() | |
profiles = ['common (virtual)', 'clone-largest (virtual)', 'horizontal (virtual)', 'vertical (virtual)'] | |
pipe = Popen('autorandr', shell=True, stdout=PIPE) | |
for line in pipe.stdout: | |
profiles.append(line.strip()) | |
auto = gtk.MenuItem('autodetect') | |
auto.connect('activate', change_profile, '') | |
menu.append(auto) | |
menu.append(gtk.SeparatorMenuItem()) | |
for profile in profiles: | |
command = gtk.MenuItem(profile) | |
command.connect('activate', change_profile, profile.split(' ')[0]) | |
menu.append(command) | |
menu.append(gtk.SeparatorMenuItem()) | |
exittray = gtk.MenuItem('Exit Tray') | |
exittray.connect('activate', quit) | |
menu.append(exittray) | |
menu.show_all() | |
return menu | |
def change_profile(_, profile): | |
os.system("autorandr --change " + profile) | |
def quit(_): | |
gtk.main_quit() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment