Skip to content

Commit

Permalink
Fixed detection (2 loops atleast has to be done because Asus WMI acce…
Browse files Browse the repository at this point in the history
…l tablet mode has priority)
  • Loading branch information
ldrahnik committed Jan 19, 2024
1 parent 909ee12 commit 9b0dd6f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions asus_fliplock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import importlib
import logging
import os
from time import sleep
import re
import sys
from typing import Optional
Expand Down Expand Up @@ -41,7 +42,7 @@ def search_devices():
with open('/proc/bus/input/devices', 'r') as f:
lines = f.readlines()
for line in lines:

# Look for the device switches
if re.search("switches", line):
switches_detected = 1
Expand Down Expand Up @@ -71,12 +72,13 @@ def search_devices():
if switches_detected == 2 and wmi_hotkeys_detected == 2:
break

if switches_detected != 2:
if switches_detected != 2 or wmi_hotkeys_detected != 2:
tries -= 1
if tries == 0:
if switches_detected != 2 and wmi_hotkeys_detected != 2:
log.error("Can't find neither switches or wmi hotkeys device")
sys.exit(1)
sleep(0.1)
else:
break

Expand Down Expand Up @@ -104,14 +106,14 @@ def execute_cmds_in_array(cmds):
execute_cmd(cmd)


def flip(intel_hid_switches_tablet_mode):
def flip(intel_hid_switches_tablet_mode):
if intel_hid_switches_tablet_mode:
execute_cmds_in_array(fliplock_layouts.tablet_mode_actions)
else:
execute_cmds_in_array(fliplock_layouts.laptop_mode_actions)


# If mode has been changed, do something
# If mode has been changed, do something
if switches is None and wmi_hotkeys is not None:

for e in d_t_wmi_hotkeys.events():
Expand All @@ -126,6 +128,7 @@ def flip(intel_hid_switches_tablet_mode):
flip(intel_hid_switches_tablet_mode)
intel_hid_switches_tablet_mode = not intel_hid_switches_tablet_mode

# TODO: first flip is ommited because device for swithes is added immediately when is flip_key (usually EV_KEY.KEY_PROG2) triggered
search_devices()


Expand Down

0 comments on commit 9b0dd6f

Please sign in to comment.