summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.elektranox.keyhandler.service3
-rwxr-xr-xtoggle-mouse-wheel-emulation29
-rwxr-xr-xtp-key-handler182
3 files changed, 152 insertions, 62 deletions
diff --git a/org.elektranox.keyhandler.service b/org.elektranox.keyhandler.service
new file mode 100644
index 0000000..dffdaef
--- /dev/null
+++ b/org.elektranox.keyhandler.service
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.elektranox.keyhandler
+Exec=/usr/local/bin/tp-key-handler
diff --git a/toggle-mouse-wheel-emulation b/toggle-mouse-wheel-emulation
index 88fffe9..ddd524f 100755
--- a/toggle-mouse-wheel-emulation
+++ b/toggle-mouse-wheel-emulation
@@ -1,12 +1,27 @@
#!/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}')
+swaymsg -q >/dev/null 2>&1
+SWAY=$?
-if [ $ENABLED = 1 ] ; then
- xinput set-prop $ID --type=int --format=8 "Evdev Wheel Emulation" 0
- echo "disabled"
+if [ $SWAY -ne 0 ] ; then
+ 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
else
- xinput set-prop $ID --type=int --format=8 "Evdev Wheel Emulation" 1
- echo "enabled"
+ status=$(swaymsg -rt get_inputs | jq -r '.[] | select(.identifier == "2:10:TPPS/2_IBM_TrackPoint") | .libinput.scroll_method')
+
+ if [ "$status" = 'on_button_down' ] ; then
+ swaymsg input "2:10:TPPS/2_IBM_TrackPoint" scroll_method none
+ echo "disabled"
+ else
+ swaymsg input "2:10:TPPS/2_IBM_TrackPoint" scroll_method on_button_down
+ echo "enabled"
+ fi
fi
diff --git a/tp-key-handler b/tp-key-handler
index 259210f..d7d2f4d 100755
--- a/tp-key-handler
+++ b/tp-key-handler
@@ -8,15 +8,24 @@ import subprocess
import time
from dbus.mainloop.glib import DBusGMainLoop
import notify2
+import sys
+from time import gmtime, strftime
class KeyhandlerDBUSService(dbus.service.Object):
def __init__(self):
- bus_name = dbus.service.BusName('org.elektranox.keyhandler', bus=dbus.SessionBus())
+ bus_name = dbus.service.BusName('org.elektranox.keyhandler', bus=dbus.SessionBus(), allow_replacement=True , replace_existing=True)
dbus.service.Object.__init__(self, bus_name, '/org/elektranox/keyhandler')
self.bnotice = notify2.Notification("Backlight", "", "display-brightness-symbolic")
self.vnotice = notify2.Notification("Volume", "", "")
self.wnotice = notify2.Notification("WLAN", "", "")
self.mnotice = notify2.Notification("Mouse", "", "")
+ self.timeout = 2000
+
+ def _check_sway(self):
+ # sway is not running in X
+ popen = subprocess.Popen(['/usr/bin/swaymsg', '-q'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ popen.wait()
+ return not popen.returncode
def _lid_status_open(self):
lidstatus = "state: unknown"
@@ -58,15 +67,25 @@ class KeyhandlerDBUSService(dbus.service.Object):
state = self._getBacklight() * 100 / self._getMaxBacklight()
self.bnotice.set_hint_int32("value", int(state))
self.bnotice.set_hint_string("synchronous", "brightness")
- self.bnotice.show()
+ self.bnotice.timeout = self.timeout
+ try:
+ self.bnotice.show()
+ except BaseException as e:
+ print(e)
+ Gtk.main_quit()
def _showVolumeState(self):
- popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'get', 'Master'], stdout = subprocess.PIPE)
+ muted = False
+ popen = subprocess.Popen(['/usr/bin/pulsemixer', '--get-mute'], stdout = subprocess.PIPE)
popen.wait()
(stdout,stderr) = popen.communicate(None)
- lines = stdout.decode("utf-8").split("\n")
- state = int(lines[-2].split()[3][1:-2])
- muted = lines[-2].split()[5][1:-1] == "off"
+ if "1" in stdout.decode("utf-8"):
+ muted = True
+ popen = subprocess.Popen(['/usr/bin/pulsemixer', '--get-volume'], stdout = subprocess.PIPE)
+ popen.wait()
+ (stdout,stderr) = popen.communicate(None)
+ channels = stdout.decode("utf-8").split("\n")[0].split(" ")
+ state = int((int(channels[0]) + int(channels[1])) / 2)
if muted:
self.vnotice.icon = "audio-volume-muted"
elif state < 20:
@@ -77,13 +96,19 @@ class KeyhandlerDBUSService(dbus.service.Object):
self.vnotice.icon = "audio-volume-high"
self.vnotice.set_hint_int32("value", state)
self.vnotice.set_hint_string("synchronous", "volume")
- self.vnotice.show()
+ self.vnotice.timeout = self.timeout
+ try:
+ self.vnotice.show()
+ except BaseException as e:
+ print(e)
+ Gtk.main_quit()
def _rfkill_get(self, rfid):
- popen = subprocess.Popen(['/usr/sbin/rfkill', 'list', rfid], stdout = subprocess.PIPE)
+ popen = subprocess.Popen(['/usr/sbin/rfkill', 'list', rfid, '-o', 'soft', '-rn'], stdout = subprocess.PIPE)
popen.wait()
(stdout,stderr) = popen.communicate()
- return stdout.decode("utf-8").split("\n")[1].split(" ")[2] == "no"
+ state = stdout.decode("utf-8").split("\n")[0].strip()
+ return state
def _showMicState(self):
popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'get', 'Capture'], stdout = subprocess.PIPE)
@@ -102,31 +127,34 @@ class KeyhandlerDBUSService(dbus.service.Object):
self.vnotice.icon = "microphone-sensitivity-high"
self.vnotice.set_hint_int32("value", state)
self.vnotice.set_hint_string("synchronous", "volume")
- self.vnotice.show()
+ self.vnotice.timeout = self.timeout
+ try:
+ self.vnotice.show()
+ except BaseException as e:
+ print(e)
+ Gtk.main_quit()
@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/pactl', 'set-sink-mute', 'alsa_output.pci-0000_00_1b.0.analog-stereo', 'toggle'])
+ popen = subprocess.Popen(['/usr/bin/pulsemixer', '--toggle-mute'])
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 = subprocess.Popen(['/usr/bin/pulsemixer', '--change-volume', '-2'], stdout=subprocess.DEVNULL)
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 = subprocess.Popen(['/usr/bin/pulsemixer', '--change-volume', '+2'], stdout=subprocess.DEVNULL)
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 = subprocess.Popen(['/usr/bin/amixer', 'set', 'Capture', 'toggle'], stdout=subprocess.DEVNULL)
popen.wait()
self._showMicState()
@@ -158,7 +186,6 @@ class KeyhandlerDBUSService(dbus.service.Object):
self._setBacklight(brightness)
self._showBacklightState()
-
@dbus.service.method('org.elektranox.keyhandler')
def backlightDec(self):
self._backlightChg(True)
@@ -171,38 +198,65 @@ class KeyhandlerDBUSService(dbus.service.Object):
def XF86Display(self):
lidopen = self._lid_status_open()
docked = self._dock_status_docked()
- if not docked:
- popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'eDP1', '--auto'])
- popen.wait()
- popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'DP2-1', '--off'])
- popen.wait()
- popen = subprocess.Popen(['/usr/bin/notify-send','Not docked'])
- popen.wait()
- elif lidopen:
- popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'eDP1', '--auto'])
- popen.wait()
- popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'DP2-1', '--right-of', 'eDP1', '--auto'])
- popen.wait()
- popen = subprocess.Popen(['/usr/bin/notify-send','Docked with open lid'])
- popen.wait()
+
+ if self._check_sway():
+ if not docked:
+ popen = subprocess.Popen(['/usr/bin/swaymsg','output', 'eDP-1', 'enable'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/notify-send','Not docked'])
+ popen.wait()
+ elif lidopen:
+ popen = subprocess.Popen(['/usr/bin/swaymsg','output', 'eDP-1', 'enable'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/swaymsg','output', 'DP-3', 'enable'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/swaymsg','output', 'eDP-1', 'pos', '0', '0'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/swaymsg','output', 'DP-3', 'pos', '1920', '0'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/notify-send','Docked with open lid'])
+ popen.wait()
+ else:
+ popen = subprocess.Popen(['/usr/bin/swaymsg','output', 'eDP-1', 'disable'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/notify-send','Docked with closed lid'])
+ popen.wait()
else:
- popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'DP2-1', '--right-of', 'eDP1', '--auto'])
- popen.wait()
- popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'eDP1', '--off'])
- popen.wait()
- popen = subprocess.Popen(['/usr/bin/notify-send','Docked with closed lid'])
- popen.wait()
+ if not docked:
+ popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'eDP1', '--auto'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'DP2-1', '--off'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/notify-send','Not docked'])
+ popen.wait()
+ elif lidopen:
+ popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'eDP1', '--auto'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'DP2-1', '--right-of', 'eDP1', '--auto'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/notify-send','Docked with open lid'])
+ popen.wait()
+ else:
+ popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'DP2-1', '--right-of', 'eDP1', '--auto'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/xrandr','--output', 'eDP1', '--off'])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/notify-send','Docked with closed lid'])
+ popen.wait()
@dbus.service.method('org.elektranox.keyhandler')
def WLAN(self):
# button itself is handled by systemd
state = self._rfkill_get("wlan")
- if state:
- self.wnotice.icon = "network-wireless-symbolic"
- self.wnotice.summary = "enabled"
- else:
+ if state == "blocked":
+ subprocess.call(['/usr/sbin/rfkill','block', 'wlan'])
self.wnotice.icon = "network-wireless-offline-symbolic"
- self.wnotice.summary = "disabled"
+ self.wnotice.summary = "WLAN disabled"
+ else:
+ subprocess.call(['/usr/sbin/rfkill','unblock', 'wlan'])
+ self.wnotice.icon = "network-wireless-symbolic"
+ self.wnotice.summary = "WLAN enabled"
+ self.wnotice.timeout = self.timeout
self.wnotice.show()
@dbus.service.method('org.elektranox.keyhandler')
@@ -211,12 +265,17 @@ class KeyhandlerDBUSService(dbus.service.Object):
popen.wait()
(stdout,stderr) = popen.communicate(None)
enabled = (stdout.decode("utf-8").find("enabled") != -1)
- self.mnotice.icon = "/usr/share/icons/mate/48x48/devices/input-mouse.png"
+ self.mnotice.icon = "/usr/share/icons/Adwaita/48x48/devices/input-mouse-symbolic.symbolic.png"
if enabled:
self.mnotice.summary = "Mouse Wheel Emulation enabled"
else:
self.mnotice.summary = "Mouse Wheel Emulation disabled"
- self.mnotice.show()
+ self.mnotice.timeout = self.timeout
+ try:
+ self.mnotice.show()
+ except BaseException as e:
+ print(e)
+ Gtk.main_quit()
@dbus.service.method('org.elektranox.keyhandler')
def XF86Search(self):
@@ -227,28 +286,41 @@ class KeyhandlerDBUSService(dbus.service.Object):
@dbus.service.method('org.elektranox.keyhandler')
def XF86LaunchA(self):
- popen = subprocess.Popen(['/usr/bin/notify-send','XF86LaunchA'])
+ timestamp = strftime("%Y-%m-%d_%H:%M:%S", gmtime())
+ filename = "screenshot-" + timestamp + ".png"
+ popen = subprocess.Popen(['/usr/bin/grim', filename])
+ popen.wait()
+ popen = subprocess.Popen(['/usr/bin/notify-send','Screenshot: ' + filename])
popen.wait()
- # TODO: add some fancy binding
pass
@dbus.service.method('org.elektranox.keyhandler')
def XF86Explorer(self):
state = self._rfkill_get("bluetooth")
- if state:
+ if state == "unblocked":
subprocess.call(['/usr/sbin/rfkill','block', 'bluetooth'])
- self.wnotice.icon = "/usr/share/icons/gnome/scalable/status/bluetooth-disabled-symbolic.svg"
+ self.wnotice.icon = "/usr/share/icons/Adwaita/48x48/status/bluetooth-disabled-symbolic.symbolic.png"
self.wnotice.summary = "Bluetooth blocked"
else:
subprocess.call(['/usr/sbin/rfkill','unblock', 'bluetooth'])
- self.wnotice.icon = "/usr/share/icons/gnome/scalable/status/bluetooth-active-symbolic.svg"
+ self.wnotice.icon = "/usr/share/icons/Adwaita/48x48/status/bluetooth-active-symbolic.symbolic.png"
self.wnotice.summary = "Bluetooth unblocked"
- self.wnotice.show()
- if not state:
+ self.wnotice.timeout = self.timeout
+ try:
+ self.wnotice.show()
+ except BaseException as e:
+ print(e)
+ Gtk.main_quit()
+ if not state == "unblocked":
time.sleep(1)
self._bluetooth_set_status(True)
-DBusGMainLoop(set_as_default=True)
-service = KeyhandlerDBUSService()
-notify2.init("TP Keyhandler")
-Gtk.main()
+def main():
+ notify2.init("TP Keyhandler", mainloop='glib')
+ service = KeyhandlerDBUSService()
+ Gtk.main()
+ service.remove_from_connection()
+
+if __name__ == '__main__':
+ while True:
+ main()