From 57128109ebb566d94e0eb933623df0a3773e360b Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Sat, 26 Dec 2020 23:19:33 +0100 Subject: [PATCH] improved compatibility --- DEBIAN/copyright | 3 + README.md | 3 +- bin/key-mapper-gtk-pkexec | 3 + data/key-mapper.desktop | 2 +- data/key-mapper.glade | 105 ++++++++++++++++------------ data/style.css | 6 ++ keymapper/dev/permissions.py | 6 +- setup.py | 1 + tests/testcases/test_permissions.py | 17 +++-- 9 files changed, 95 insertions(+), 51 deletions(-) create mode 100644 DEBIAN/copyright create mode 100755 bin/key-mapper-gtk-pkexec diff --git a/DEBIAN/copyright b/DEBIAN/copyright new file mode 100644 index 00000000..c44aa1c1 --- /dev/null +++ b/DEBIAN/copyright @@ -0,0 +1,3 @@ +Files: * +Copyright: 2020 sezanzeb +License: GPL-3+ \ No newline at end of file diff --git a/README.md b/README.md index 46274ed5..bb3a8d57 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,11 @@ Download a release .deb file from [/releases](https://github.com/sezanzeb/key-ma or install from source and dpkg using the following commands: ```bash +sudo apt install git python3-setuptools git clone https://github.com/sezanzeb/key-mapper.git cd key-mapper && ./scripts/build.sh sudo dpkg -i ./dist/key-mapper-0.4.0.deb -sudo apt-get -f install +sudo apt -f install ``` ##### pip diff --git a/bin/key-mapper-gtk-pkexec b/bin/key-mapper-gtk-pkexec new file mode 100755 index 00000000..e2460aad --- /dev/null +++ b/bin/key-mapper-gtk-pkexec @@ -0,0 +1,3 @@ +#!/bin/bash + +pkexec key-mapper-gtk diff --git a/data/key-mapper.desktop b/data/key-mapper.desktop index 2d50e354..011acdd4 100644 --- a/data/key-mapper.desktop +++ b/data/key-mapper.desktop @@ -2,7 +2,7 @@ Type=Application Name=key-mapper Icon=/usr/share/key-mapper/key-mapper.svg -Exec=pkexec key-mapper-gtk +Exec=key-mapper-gtk-pkexec Terminal=false Categories=Settings Comment=GUI for device specific key mappings diff --git a/data/key-mapper.glade b/data/key-mapper.glade index b2e67b91..0b8c4690 100644 --- a/data/key-mapper.glade +++ b/data/key-mapper.glade @@ -387,6 +387,7 @@ True False 10 + True Apply @@ -400,7 +401,7 @@ - False + True True 0 @@ -417,7 +418,7 @@ - False + True True 1 @@ -434,7 +435,7 @@ - False + True True 2 @@ -451,14 +452,14 @@ - False + True True 4 - False + True True 0 @@ -579,7 +580,7 @@ - True + False True 0 @@ -735,40 +736,11 @@ 2 - - - True - False - - - False - True - 4 - - True False - - - True - False - 10 - 10 - 10 - 10 - 6 - 6 - vertical - 2 - - - True - True - 0 - - + vertical True @@ -777,29 +749,74 @@ False True - 1 + 0 - + True False - This is the keycode you just pressed, and that you see in the mappings to the right. - 10 - 10 - 4 + + + True + False + 10 + 10 + 10 + 10 + 6 + 6 + vertical + 2 + + + + True + True + 0 + + + + + True + False + + + False + True + 1 + + + + + True + False + This is the keycode you just pressed, and that you see in the mappings to the right. + 10 + 10 + 4 + + + False + True + 2 + + False True - 2 + 1 False True - 5 + end + 4 diff --git a/data/style.css b/data/style.css index 87a8d977..3a3c676a 100644 --- a/data/style.css +++ b/data/style.css @@ -2,6 +2,11 @@ row { padding: 0; } +.status_bar frame { + /* the status bar is ugly in elementary os otherwise */ + border: 0px; +} + .table-header, .row-box { padding: 2px; } @@ -13,6 +18,7 @@ row { list entry { background-color: transparent; border-radius: 4px; + border: 0px; } list button:not(:focus) { diff --git a/keymapper/dev/permissions.py b/keymapper/dev/permissions.py index a2719c4d..d6744c32 100644 --- a/keymapper/dev/permissions.py +++ b/keymapper/dev/permissions.py @@ -30,6 +30,7 @@ import os from keymapper.logger import logger from keymapper.paths import USER +from keymapper.daemon import is_service_running def check_group(group): @@ -96,7 +97,10 @@ def can_read_devices(): plugdev_check = check_group('plugdev') # ubuntu. funnily, individual devices in /dev/input/ have write permitted. - can_write = check_injection_rights() + if not is_service_running(): + can_write = check_injection_rights() + else: + can_write = None ret = [ check for check diff --git a/setup.py b/setup.py index b6c7f030..3bdc7910 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,7 @@ setup( ('/etc/dbus-1/system.d/', ['data/keymapper.Control.conf']), ('/etc/xdg/autostart/', ['data/key-mapper-autoload.desktop']), ('/usr/bin/', ['bin/key-mapper-gtk']), + ('/usr/bin/', ['bin/key-mapper-gtk-pkexec']), ('/usr/bin/', ['bin/key-mapper-service']), ('/usr/bin/', ['bin/key-mapper-control']), ], diff --git a/tests/testcases/test_permissions.py b/tests/testcases/test_permissions.py index b799455b..ada40aeb 100644 --- a/tests/testcases/test_permissions.py +++ b/tests/testcases/test_permissions.py @@ -28,6 +28,7 @@ import unittest from keymapper.dev.permissions import check_injection_rights, check_group, \ can_read_devices from keymapper.paths import USER +from keymapper.daemon import is_service_running original_access = os.access @@ -37,7 +38,7 @@ original_stat = os.stat oringal_getuser = getpass.getuser -class TestCheckGroup(unittest.TestCase): +class TestPermissions(unittest.TestCase): def tearDown(self): # reset all fakes os.access = original_access @@ -97,12 +98,20 @@ class TestCheckGroup(unittest.TestCase): self.gr_mem = gr_mems[group][1] grp.getgrnam = getgrnam - # fake the `groups` output to act like the current session only - # has input and a_unused active - subprocess.check_output = lambda cmd: b'foo input a_unused bar' + + def fake_check_output(cmd): + # fake the `groups` output to act like the current session only + # has input and a_unused active + if cmd[0] == 'groups': + return b'foo input a_unused bar' + + return original_check_output(cmd) + + subprocess.check_output = fake_check_output def test_can_read_devices(self): self.fake_setup() + self.assertFalse(is_service_running()) # root user doesn't need this stuff getpass.getuser = lambda: 'root'