From 7186dcad089c4d2d931c45a4e7b99a6fb9ff3ce0 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Sun, 6 Dec 2015 11:19:56 +0100 Subject: initial commit --- toggle-mouse-wheel-emulation | 12 ++++ tp-key-handler | 162 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100755 toggle-mouse-wheel-emulation create mode 100755 tp-key-handler diff --git a/toggle-mouse-wheel-emulation b/toggle-mouse-wheel-emulation new file mode 100755 index 0000000..88fffe9 --- /dev/null +++ b/toggle-mouse-wheel-emulation @@ -0,0 +1,12 @@ +#!/bin/sh + +ID=$(xinput --list --id-only "PS/2 Synaptics TouchPad") +ENABLED=$(xinput list-props $ID | grep -E "Evdev Wheel Emulation \([0-9]*\):" | awk '{print $5}') + +if [ $ENABLED = 1 ] ; then + xinput set-prop $ID --type=int --format=8 "Evdev Wheel Emulation" 0 + echo "disabled" +else + xinput set-prop $ID --type=int --format=8 "Evdev Wheel Emulation" 1 + echo "enabled" +fi diff --git a/tp-key-handler b/tp-key-handler new file mode 100755 index 0000000..ec17cf2 --- /dev/null +++ b/tp-key-handler @@ -0,0 +1,162 @@ +#!/usr/bin/python +import gtk +import dbus +import dbus.service +import subprocess +from dbus.mainloop.glib import DBusGMainLoop +import pynotify + +class KeyhandlerDBUSService(dbus.service.Object): + def __init__(self): + bus_name = dbus.service.BusName('org.elektranox.keyhandler', bus=dbus.SessionBus()) + dbus.service.Object.__init__(self, bus_name, '/org/elektranox/keyhandler') + self.bnotice = pynotify.Notification("Backlight", "", "display-brightness-symbolic") + self.vnotice = pynotify.Notification("Volume", "", "") + self.wnotice = pynotify.Notification("WLAN", "", "") + self.mnotice = pynotify.Notification("Mouse", "", "") + + def _showBacklightState(self): + popen = subprocess.Popen(['/usr/bin/xbacklight'], stdout = subprocess.PIPE) + popen.wait() + (stdout,stderr) = popen.communicate(None) + state = int(float((stdout))) + self.bnotice.set_hint_int32("value", state) + self.bnotice.set_hint_string("synchronous", "brightness") + self.bnotice.show() + + def _showVolumeState(self): + popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'get', 'Master'], stdout = subprocess.PIPE) + popen.wait() + (stdout,stderr) = popen.communicate(None) + lines = stdout.split("\n") + state = int(lines[-2].split()[3][1:-2]) + muted = lines[-2].split()[5][1:-1] == "off" + if muted: + self.vnotice.set_property("icon-name", "audio-volume-muted") + elif state < 20: + self.vnotice.set_property("icon-name", "audio-volume-low") + elif state < 60: + self.vnotice.set_property("icon-name", "audio-volume-medium") + else: + self.vnotice.set_property("icon-name", "audio-volume-high") + self.vnotice.set_hint_int32("value", state) + self.vnotice.set_hint_string("synchronous", "volume") + self.vnotice.show() + + def _showMicState(self): + popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'get', 'Capture'], stdout = subprocess.PIPE) + popen.wait() + (stdout,stderr) = popen.communicate(None) + lines = stdout.split("\n") + state = int(lines[-2].split()[4][1:-2]) + muted = lines[-2].split()[6][1:-1] == "off" + if muted: + self.vnotice.set_property("icon-name", "microphone-sensitivity-muted") + elif state < 20: + self.vnotice.set_property("icon-name", "microphone-sensitivity-low") + elif state < 60: + self.vnotice.set_property("icon-name", "microphone-sensitivity-medium") + else: + self.vnotice.set_property("icon-name", "microphone-sensitivity-high") + self.vnotice.set_hint_int32("value", state) + self.vnotice.set_hint_string("synchronous", "volume") + self.vnotice.show() + + @dbus.service.method('org.elektranox.keyhandler') + def volumeMute(self): + #popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'set', 'Master', 'toggle']) + popen = subprocess.Popen(['/usr/bin/amixer', 'set', 'Master', 'toggle']) + popen.wait() + self._showVolumeState() + + @dbus.service.method('org.elektranox.keyhandler') + def volumeDec(self): + popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'set', 'Master', '2%-']) + popen.wait() + self._showVolumeState() + + @dbus.service.method('org.elektranox.keyhandler') + def volumeInc(self): + popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'set', 'Master', '2%+']) + popen.wait() + self._showVolumeState() + + @dbus.service.method('org.elektranox.keyhandler') + def micMute(self): + #popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'set', 'Master', 'toggle']) + popen = subprocess.Popen(['/usr/bin/amixer', 'set', 'Capture', 'toggle']) + popen.wait() + self._showMicState() + + @dbus.service.method('org.elektranox.keyhandler') + def backlightDec(self): + popen = subprocess.Popen(['/usr/bin/xbacklight','-dec', '5']) + popen.wait() + self._showBacklightState() + + @dbus.service.method('org.elektranox.keyhandler') + def backlightInc(self): + popen = subprocess.Popen(['/usr/bin/xbacklight','-inc', '5']) + popen.wait() + self._showBacklightState() + + @dbus.service.method('org.elektranox.keyhandler') + def XF86Display(self): + popen = subprocess.Popen(['/usr/bin/notify-send','XF86Display']) + popen.wait() + # TODO: add some fancy binding + pass + + @dbus.service.method('org.elektranox.keyhandler') + def WLAN(self): + # button itself is handled by systemd + popen = subprocess.Popen(['/usr/sbin/rfkill', 'list', 'wlan'], stdout = subprocess.PIPE) + popen.wait() + (stdout,stderr) = popen.communicate(None) + state = stdout.split("\n")[1].split(" ")[2] == "no" + if state: + self.wnotice.set_property("icon-name", "network-wireless-symbolic") + self.wnotice.set_property("summary", "enabled") + else: + self.wnotice.set_property("icon-name", "network-wireless-offline-symbolic") + self.wnotice.set_property("summary", "disabled") + self.wnotice.show() + + @dbus.service.method('org.elektranox.keyhandler') + def XF86Tools(self): + popen = subprocess.Popen(['/usr/local/bin/toggle-mouse-wheel-emulation'], stdout = subprocess.PIPE) + popen.wait() + (stdout,stderr) = popen.communicate(None) + enabled = (stdout.find("enabled") != -1) + self.mnotice.set_property("icon-name", "/usr/share/icons/mate/48x48/devices/input-mouse.png") + if enabled: + self.mnotice.set_property("summary", "Mouse Wheel Emulation enabled") + else: + self.mnotice.set_property("summary", "Mouse Wheel Emulation disabled") + self.mnotice.show() + + @dbus.service.method('org.elektranox.keyhandler') + def XF86Search(self): + popen = subprocess.Popen(['/usr/bin/notify-send','XF86Search']) + popen.wait() + # TODO: add some fancy binding + pass + + @dbus.service.method('org.elektranox.keyhandler') + def XF86LaunchA(self): + popen = subprocess.Popen(['/usr/bin/notify-send','XF86LaunchA']) + popen.wait() + # TODO: add some fancy binding + pass + + @dbus.service.method('org.elektranox.keyhandler') + def XF86Explorer(self): + popen = subprocess.Popen(['/usr/bin/notify-send','XF86Explorer']) + popen.wait() + # TODO: add some fancy binding + pass + +DBusGMainLoop(set_as_default=True) +service = KeyhandlerDBUSService() +pynotify.init("TP Keyhandler") +gtk.main() -- cgit v1.2.3