Skip to content

Commit

Permalink
Merge pull request #1 from Lenbok/fix-stuck-modifiers
Browse files Browse the repository at this point in the history
Revert "Merge pull request mooz#71 from rbreaves/master"
  • Loading branch information
trueneu authored Oct 22, 2020
2 parents 51c3690 + 66ab9e6 commit c1d695a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
19 changes: 5 additions & 14 deletions xkeysnail/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
_pressed_modifier_keys = set()
_pressed_keys = set()

def output_modifier_key():
return _pressed_modifier_keys

def update_modifier_key_pressed(key, action):
if key in Modifier.get_all_keys():
if action.is_pressed():
Expand Down Expand Up @@ -60,17 +57,8 @@ def send_combo(combo):
missing_modifiers.remove(modifier)

for modifier_key in extra_modifier_keys:
# Do not release new modifier
# until original modifier is released
# unless no modifier is the new mapping
if len(combo.modifiers) > 0:
for modifier in combo.modifiers:
if modifier_key != str(modifier.get_key()):
send_key_action(modifier_key, Action.RELEASE)
released_modifiers_keys.append(modifier_key)
else:
send_key_action(modifier_key, Action.RELEASE)
released_modifiers_keys.append(modifier_key)
send_key_action(modifier_key, Action.RELEASE)
released_modifiers_keys.append(modifier_key)

pressed_modifier_keys = []
for modifier in missing_modifiers:
Expand All @@ -82,6 +70,9 @@ def send_combo(combo):

send_key_action(combo.key, Action.RELEASE)

for modifier in reversed(pressed_modifier_keys):
send_key_action(modifier, Action.RELEASE)

for modifier in reversed(released_modifiers_keys):
send_key_action(modifier, Action.PRESS)

Expand Down
20 changes: 1 addition & 19 deletions xkeysnail/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
from time import time
from inspect import signature
from .key import Action, Combo, Key, Modifier
from .output import send_combo, send_key_action, send_key, is_pressed, output_modifier_key
from .output import send_combo, send_key_action, send_key, is_pressed

__author__ = 'zh'

# ============================================================ #

import Xlib.display

_release_combo = False

def get_active_window_wm_class(display=Xlib.display.Display()):
"""Get active window's WM_CLASS"""
Expand Down Expand Up @@ -418,31 +417,14 @@ def on_event(event, device_name, quiet):


def on_key(key, action, wm_class=None, quiet=False):
global _release_combo
output_mods = output_modifier_key().copy()
if key in Modifier.get_all_keys():
update_pressed_modifier_keys(key, action)
send_key_action(key, action)
# Release mapped modifier only when physical mod
# is released
if str(key) != "Key.LEFT_SHIFT" and str(key) != "Key.RIGHT_SHIFT":
for output_key in output_mods:
update_pressed_modifier_keys(output_key, action)
send_key_action(output_key, action)
elif not action.is_pressed():
if is_pressed(key):
send_key_action(key, action)
# Unset modifiers used in nested mode_maps
elif _release_combo and len(output_mods) > 0:
_release_combo = False
for output_key in output_mods:
update_pressed_modifier_keys(output_key, action)
send_key_action(output_key, action)
else:
transform_key(key, action, wm_class=wm_class, quiet=quiet)
# Will unset mode maps modifiers on next combo
if _mode_maps != None:
_release_combo = True


def transform_key(key, action, wm_class=None, quiet=False):
Expand Down

0 comments on commit c1d695a

Please sign in to comment.