SafeEyes icon indicating copy to clipboard operation
SafeEyes copied to clipboard

Issue-213: Mediakey passthrough support for Ubuntu/Unity

Open stdedos opened this issue 5 years ago • 11 comments

Signed-off-by: Stavros Ntentos [email protected]

stdedos avatar Nov 15 '18 15:11 stdedos

I tried to implement the feature, by:

  • Reading the configuration (I assume event.detail and self.keycode_* is simply the scancode?)
  • http://paulsrandomcontent.blogspot.com/2013/10/for-project-i-wanted-to-send-key.html
  • and output from python3 -m keyboard for my keyboard
    {"time": 1542292736.643166, "is_keypad": false, "name": "f13", "scan_code": 113, "event_type": "up", "device": "/dev/input/event8"} # Mute
    {"time": 1542292738.179174, "is_keypad": false, "name": "f14", "scan_code": 114, "event_type": "up", "device": "/dev/input/event8"} # VolD
    {"time": 1542292738.819177, "is_keypad": false, "name": "help", "scan_code": 115, "event_type": "up", "device": "/dev/input/event8"} # VolU
    {"time": 1542292740.099214, "is_keypad": false, "name": "unknown", "scan_code": 166, "event_type": "up", "device": "/dev/input/event8"} # Stop
    {"time": 1542292740.995173, "is_keypad": false, "name": "unknown", "scan_code": 165, "event_type": "up", "device": "/dev/input/event8"} # Prev
    {"time": 1542292742.019193, "is_keypad": false, "name": "unknown", "scan_code": 164, "event_type": "up", "device": "/dev/input/event8"} # P/P
    {"time": 1542292742.787194, "is_keypad": false, "name": "unknown", "scan_code": 163, "event_type": "up", "device": "/dev/input/event8"} # Next
    

However, I get no log messages on the debug I added. Shortcuts work normally though. safeeyes.log

What am I doing wrong?

stdedos avatar Nov 15 '18 15:11 stdedos

Hi, Thank you very much for your contribution.

To get the debug output, please run Safe Eyes using the following command:

python3 -m safeeeyes --debug

I will test this feature in my system and let you know.

slgobinath avatar Nov 15 '18 16:11 slgobinath

I ran it differently (I now noticed that ~/safeeyes.log did not actually "write" anything):

$ (passthrough_media u=) safeeyes/__main__.py --debug
2018-11-15 18:56:41,398 [INFO]:[MainThread] Starting Safe Eyes
2018-11-15 18:56:41,398 [INFO]:[MainThread] Reading the session file
2018-11-15 18:56:41,421 [INFO]:[MainThread] Initialize the break screen
2018-11-15 18:56:41,421 [INFO]:[MainThread] Load all the plugins
2018-11-15 18:56:41,421 [INFO]:[MainThread] Initialize the core
2018-11-15 18:56:41,422 [INFO]:[MainThread] Successfully loaded <module 'donotdisturb.plugin' from '/usr/lib/python3/dist-packages/safeeyes/plugins/donotdisturb/plugin.py'>
2018-11-15 18:56:41,423 [INFO]:[MainThread] Successfully loaded <module 'notification.plugin' from '/usr/lib/python3/dist-packages/safeeyes/plugins/notification/plugin.py'>
2018-11-15 18:56:41,424 [INFO]:[MainThread] Successfully loaded <module 'audiblealert.plugin' from '/usr/lib/python3/dist-packages/safeeyes/plugins/audiblealert/plugin.py'>
2018-11-15 18:56:41,425 [INFO]:[MainThread] Successfully loaded <module 'trayicon.plugin' from '/usr/lib/python3/dist-packages/safeeyes/plugins/trayicon/plugin.py'>
2018-11-15 18:56:41,426 [INFO]:[MainThread] Successfully loaded <module 'smartpause.plugin' from '/usr/lib/python3/dist-packages/safeeyes/plugins/smartpause/plugin.py'>
2018-11-15 18:56:41,427 [INFO]:[MainThread] Successfully loaded <module 'screensaver.plugin' from '/usr/lib/python3/dist-packages/safeeyes/plugins/screensaver/plugin.py'>
2018-11-15 18:56:41,428 [INFO]:[MainThread] Successfully loaded <module 'healthstats.plugin' from '/usr/lib/python3/dist-packages/safeeyes/plugins/healthstats/plugin.py'>
2018-11-15 18:56:41,428 [DEBUG]:[MainThread] Initialize Skip Fullscreen plugin
2018-11-15 18:56:41,428 [DEBUG]:[MainThread] Initialize Notification plugin
2018-11-15 18:56:41,428 [DEBUG]:[MainThread] Initialize Audible Alert plugin
2018-11-15 18:56:41,428 [DEBUG]:[MainThread] Initialize Tray Icon plugin
2018-11-15 18:56:41,440 [DEBUG]:[MainThread] Initialize Smart Pause plugin
2018-11-15 18:56:41,440 [DEBUG]:[MainThread] Initialize Screensaver plugin
2018-11-15 18:56:41,440 [DEBUG]:[MainThread] Initialize Health Stats plugin
2018-11-15 18:56:41,440 [INFO]:[MainThread] Setting up an RPC server on port 7200
2018-11-15 18:56:41,441 [INFO]:[MainThread] Start the RPC server
2018-11-15 18:56:41,441 [DEBUG]:[MainThread] Start Smart Pause plugin
2018-11-15 18:56:41,441 [INFO]:[MainThread] Start Safe Eyes core
2018-11-15 18:56:41,442 [INFO]:[Thread-3] Waiting for 15 minutes until next break
2018-11-15 18:56:41,443 [INFO]:[MainThread] Update next break information
2018-11-15 18:56:44,801 [INFO]:[Thread-5] Take a break due to external request
2018-11-15 18:56:44,801 [INFO]:[Thread-5] Stop the scheduler
2018-11-15 18:56:44,801 [INFO]:[Thread-3] Pre-break waiting is over
2018-11-15 18:56:45,802 [INFO]:[MainThread] Searching for full-screen application
2018-11-15 18:56:45,815 [INFO]:[MainThread] Close pre-break notification
2018-11-15 18:56:45,818 [INFO]:[Thread-7] Lock the keyboard
2018-11-15 18:56:45,819 [INFO]:[MainThread] Show break screens in 3 display(s)
2018-11-15 18:56:45,867 [INFO]:[MainThread] Moved break screen to Display[0, 30]
2018-11-15 18:56:45,910 [INFO]:[MainThread] Moved break screen to Display[1680, 0]
2018-11-15 18:56:45,916 [INFO]:[MainThread] Moved break screen to Display[3600, 0]
2018-11-15 18:56:52,834 [INFO]:[Thread-7] User postponed the break
2018-11-15 18:56:52,835 [INFO]:[Thread-7] User postponed the break
2018-11-15 18:56:52,836 [INFO]:[Thread-7] Close the break screen(s)
2018-11-15 18:56:52,836 [INFO]:[Thread-7] Unlock the keyboard
2018-11-15 18:56:53,829 [INFO]:[Thread-8] Prepare for postponed break
2018-11-15 18:56:53,830 [INFO]:[Thread-8] Waiting for 5 minutes until next break
2018-11-15 18:56:53,830 [INFO]:[MainThread] Update next break information
2018-11-15 18:56:55,454 [INFO]:[MainThread] Quit Safe Eyes
2018-11-15 18:56:55,455 [INFO]:[MainThread] Disable Safe Eyes
2018-11-15 18:56:55,455 [DEBUG]:[MainThread] Stop Smart Pause plugin
2018-11-15 18:56:55,455 [INFO]:[MainThread] Stop Safe Eye core
2018-11-15 18:56:55,455 [DEBUG]:[MainThread] Stop Notification plugin
2018-11-15 18:56:55,455 [INFO]:[Thread-8] Pre-break waiting is over
2018-11-15 18:56:55,456 [INFO]:[MainThread] Stop the RPC server

Still nothing though :disappointed:

stdedos avatar Nov 15 '18 16:11 stdedos

Any progress?

stdedos avatar Nov 26 '18 14:11 stdedos

Hi, I got an output similar to this:

2018-12-01 07:58:51,428 [INFO]:[MainThread] Moved break screen to Display[0, 0]
<class 'Xlib.protocol.event.KeyPress'>(type = 2, detail = 133, sequence_number = 14, time = 3795319, root = <<class 'Xlib.display.Window'> 0x00000240>, window = <<class 'Xlib.display.Window'> 0x00000240>, child = <<class 'Xlib.display.Window'> 0x07e000b5>, root_x = 1698, root_y = 946, event_x = 1698, event_y = 946, state = 16, same_screen = 1)
2018-12-01 07:58:58,421 [DEBUG]:[Thread-7] event: None
133
2018-12-01 07:58:58,422 [DEBUG]:[Thread-7] event.detail: None
<class 'Xlib.protocol.event.KeyPress'>(type = 2, detail = 133, sequence_number = 15, time = 3795988, root = <<class 'Xlib.display.Window'> 0x00000240>, window = <<class 'Xlib.display.Window'> 0x00000240>, child = <<class 'Xlib.display.Window'> 0x07e000b5>, root_x = 1698, root_y = 946, event_x = 1698, event_y = 946, state = 16, same_screen = 1)
2018-12-01 07:58:59,424 [DEBUG]:[Thread-7] event: None
133
2018-12-01 07:58:59,424 [DEBUG]:[Thread-7] event.detail: None
<class 'Xlib.protocol.event.KeyPress'>(type = 2, detail = 133, sequence_number = 17, time = 3796991, root = <<class 'Xlib.display.Window'> 0x00000240>, window = <<class 'Xlib.display.Window'> 0x00000240>, child = <<class 'Xlib.display.Window'> 0x07e000b5>, root_x = 1698, root_y = 946, event_x = 1698, event_y = 946, state = 16, same_screen = 1)
2018-12-01 07:59:00,427 [DEBUG]:[Thread-7] event: None
133
2018-12-01 07:59:00,428 [DEBUG]:[Thread-7] event.detail: None
<class 'Xlib.protocol.event.KeyPress'>(type = 2, detail = 133, sequence_number = 19, time = 3797995, root = <<class 'Xlib.display.Window'> 0x00000240>, window = <<class 'Xlib.display.Window'> 0x00000240>, child = <<class 'Xlib.display.Window'> 0x07e000b5>, root_x = 1698, root_y = 946, event_x = 1698, event_y = 946, state = 16, same_screen = 1)
2018-12-01 07:59:01,431 [DEBUG]:[Thread-7] event: None
133
2018-12-01 07:59:01,431 [DEBUG]:[Thread-7] event.detail: None
<class 'Xlib.protocol.event.KeyPress'>(type = 2, detail = 133, sequence_number = 20, time = 3798018, root = <<class 'Xlib.display.Window'> 0x00000240>, window = <<class 'Xlib.display.Window'> 0x00000240>, child = <<class 'Xlib.display.Window'> 0x07e000b5>, root_x = 1698, root_y = 946, event_x = 1698, event_y = 946, state = 16, same_screen = 1)
2018-12-01 07:59:01,432 [DEBUG]:[Thread-7] event: None
133

To get this output, I ran Safe Eyes and took a break. Then I pressed some keys randomly.

slgobinath avatar Dec 01 '18 13:12 slgobinath

I assume your output is in-between

[INFO]:[Thread-7] Lock the keyboard
[...]
[INFO]:[Thread-7] Unlock the keyboard

these lines?

Weird. I couldn't replicate (or get the log output).

How did you "run" SafeEyes? I already have an installation of SafeEyes, so I would like to keep the main installation separate from whatever changes I do in the repository.

This is why I ran safeeyes/__main__.py --debug instead of python3 -m safeeeyes --debug. Is it possible that, even running it like so, code gets imported from the installation, instead of the local directory? Maybe I need to setup a venv to separate python environments

stdedos avatar Dec 01 '18 13:12 stdedos

these lines?

Yes

I already have an installation of SafeEyes, so I would like to keep the main installation separate from whatever changes I do in the repository.

I also have Safe Eyes installed from Ubuntu PPA. It does not affect running from source code. All you need is quite the currently running Safe Eyes instance and run from source code by executing python3 -m safeeyes from the Safe Eyes folder. No need to set any environment variables.

slgobinath avatar Dec 02 '18 14:12 slgobinath

It works on my system Ubuntu/Xenial.

Feel free check & verify it yourself too with other operating systems et. al.

stdedos avatar Dec 03 '18 14:12 stdedos

Hi, After fixing the comma issue, the code runs. However I have noticed two issues:

  1. To skip the screen, I need to pres Exc twice (or any key before Esc)
  2. Once I used a media key, the keyboard is unlocked. I can use Win key to open start menu and type anything there. At the same time, after using media key, the Exc shortcut for Skip doesn't work.

slgobinath avatar Dec 03 '18 17:12 slgobinath

I've seen the issue only with the mute key, once. However, I guessed that it was only the Unity/Notifications giving that result (and only on a corner case) instead of being a system/shortcut-wide issue, hence I ignored it 😒

Back to the drawing board I guess

stdedos avatar Dec 03 '18 21:12 stdedos

Hi, I think there is a way to send multimedia controls without using fake input. KDE Connect has such a feature (see this video: https://www.youtube.com/watch?v=AMiIRo0_Ros). I would recommend to check the code of GSConnect (https://github.com/andyholmes/gnome-shell-extension-gsconnect/blob/master/src/service/plugins/systemvolume.js) and see how they have implemented it.

slgobinath avatar Dec 03 '18 22:12 slgobinath