| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Fenrir TTY screen reader |
| 5 |
# By Chrys, Storm Dragon, and contributors. |
| 6 |
|
| 7 |
|
| 8 |
from fenrirscreenreader.core.i18n import _ |
| 9 |
|
| 10 |
|
| 11 |
class command: |
| 12 |
def __init__(self): |
| 13 |
pass |
| 14 |
|
| 15 |
def initialize(self, environment): |
| 16 |
self.env = environment |
| 17 |
|
| 18 |
def shutdown(self): |
| 19 |
pass |
| 20 |
|
| 21 |
def get_description(self): |
| 22 |
return "No description found" |
| 23 |
|
| 24 |
def run(self): |
| 25 |
if self.env["input"]["old_num_lock"] == self.env["input"]["new_num_lock"]: |
| 26 |
return |
| 27 |
|
| 28 |
# Only announce numlock changes if an actual numlock key was pressed |
| 29 |
# AND the LED state actually changed (some numpads send spurious NUMLOCK events) |
| 30 |
current_input = self.env["input"]["curr_input"] |
| 31 |
previous_input = self.env["input"]["prev_input"] |
| 32 |
relevant_input = current_input or previous_input |
| 33 |
|
| 34 |
# Check if this is a genuine numlock key press by verifying: |
| 35 |
# 1. KEY_NUMLOCK is in the current input sequence |
| 36 |
# 2. The LED state has actually changed |
| 37 |
# 3. This isn't just a side effect from a KP_ key (which some buggy numpads do) |
| 38 |
is_genuine_numlock = ( |
| 39 |
relevant_input and |
| 40 |
"KEY_NUMLOCK" in relevant_input and |
| 41 |
not any( |
| 42 |
key.startswith("KEY_KP") |
| 43 |
for key in relevant_input |
| 44 |
if isinstance(key, str) |
| 45 |
) |
| 46 |
) |
| 47 |
|
| 48 |
if is_genuine_numlock: |
| 49 |
if self.env["input"]["new_num_lock"]: |
| 50 |
self.env["runtime"]["OutputManager"].present_text( |
| 51 |
_("Numlock on"), interrupt=True |
| 52 |
) |
| 53 |
else: |
| 54 |
self.env["runtime"]["OutputManager"].present_text( |
| 55 |
_("Numlock off"), interrupt=True |
| 56 |
) |
| 57 |
|
| 58 |
def set_callback(self, callback): |
| 59 |
pass |