Created
August 29, 2016 00:21
-
-
Save BrettMayson/60480b41a2ee0e292220ee20afc61b3d to your computer and use it in GitHub Desktop.
CAUTION: USE XINPUT TO FIND YOUR DEVICE'S IDS
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
from gi.repository import Gtk | |
import os | |
KEYBOARD = 13 | |
MASTERKEY = 3 | |
TRACKPAD = 10 | |
MASTERTRACK = 2 | |
def disableKeyboard(): | |
os.system("xinput float "+str(KEYBOARD)) | |
os.system("xinput float "+str(TRACKPAD)) | |
def enableKeyboard(): | |
os.system("xinput reattach "+str(KEYBOARD)+" "+str(MASTERKEY)) | |
os.system("xinput reattach "+str(TRACKPAD)+" "+str(MASTERTRACK)) | |
DISPLAY = "eDP1" | |
def rotate(direction): | |
os.system("xrandr --output "+DISPLAY+" --rotate "+direction) | |
class IconoTray: | |
def __init__(self, iconname): | |
self.menu = Gtk.Menu() | |
APPIND_SUPPORT = 1 | |
try: from gi.repository import AppIndicator3 | |
except: APPIND_SUPPORT = 0 | |
if APPIND_SUPPORT == 1: | |
self.ind = AppIndicator3.Indicator.new("2in1", iconname, AppIndicator3.IndicatorCategory.APPLICATION_STATUS) | |
self.ind.set_status (AppIndicator3.IndicatorStatus.ACTIVE) | |
self.ind.set_menu(self.menu) | |
else: | |
self.myStatusIcon = Gtk.StatusIcon() | |
self.myStatusIcon.set_from_icon_name(iconname) | |
self.myStatusIcon.connect('popup-menu', self.right_click_event_statusicon) | |
def add_menu_item(self, command, title): | |
aMenuitem = Gtk.MenuItem() | |
aMenuitem.set_label(title) | |
aMenuitem.connect("activate", command) | |
self.menu.append(aMenuitem) | |
self.menu.show_all() | |
def add_seperator(self): | |
aMenuitem = Gtk.SeparatorMenuItem() | |
self.menu.append(aMenuitem) | |
self.menu.show_all() | |
def get_tray_menu(self): | |
return self.menu | |
#test/debug stuff below here | |
def main(): | |
app = IconoTray("input-keyboard") | |
app.add_menu_item(lambda x: disableKeyboard(), "Tablet Mode") | |
app.add_menu_item(lambda x: enableKeyboard(), "Laptop Mode") | |
app.add_seperator() | |
app.add_menu_item(lambda x: rotate("normal"),"Normal") | |
app.add_menu_item(lambda x: rotate("inverted"),"Inverted") | |
app.add_menu_item(lambda x: rotate("left"),"Left") | |
app.add_menu_item(lambda x: rotate("right"),"Right") | |
if __name__ == '__main__': | |
Gtk.main() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment