Skip to content

Commit

Permalink
Merge pull request #10 from acro5piano/feature/multi-keyboards
Browse files Browse the repository at this point in the history
enable to wait sway startup
  • Loading branch information
acro5piano authored Feb 19, 2022
2 parents 01755ef + 8327df7 commit 251f0d0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Simply write your own service and run it as a python script:
```python
# /etc/wayremap.config.py

from wayremap import ecodes as e, run, WayremapConfig, Binding
from wayremap import ecodes as e, run, WayremapConfig, Binding, wait_sway
import uinput as k

wayremap_config = WayremapConfig(
Expand Down Expand Up @@ -89,6 +89,10 @@ wayremap_config = WayremapConfig(
Binding([e.KEY_LEFTALT, e.KEY_X], [[k.KEY_LEFTCTRL, k.KEY_K]]),
])


# Required if you want to use wayremap as a startup service.
wait_sway()

# Finally, run wayremap.
run(wayremap_config)

Expand Down
33 changes: 32 additions & 1 deletion example/multiple-keyboards.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
import uinput as k
from wayremap import ecodes as e, WayremapConfig, Binding, run
from wayremap import ecodes as e, WayremapConfig, Binding, run, wait_sway

applications = [
'Brave-browser',
]

bindings = [
# Emacs-like key binding
Binding([e.KEY_LEFTCTRL, e.KEY_LEFTALT, e.KEY_A],
[[k.KEY_LEFTCTRL, k.KEY_HOME]]),
Binding([e.KEY_LEFTCTRL, e.KEY_LEFTALT, e.KEY_E],
[[k.KEY_LEFTCTRL, k.KEY_END]]),
Binding([e.KEY_LEFTCTRL, e.KEY_LEFTALT, e.KEY_H],
[[k.KEY_LEFTCTRL, k.KEY_BACKSPACE]]),
Binding([e.KEY_LEFTCTRL, e.KEY_F], [[k.KEY_RIGHT]]),
Binding([e.KEY_LEFTCTRL, e.KEY_B], [[k.KEY_LEFT]]),
Binding([e.KEY_LEFTCTRL, e.KEY_P], [[k.KEY_UP]]),
Binding([e.KEY_LEFTCTRL, e.KEY_N], [[k.KEY_DOWN]]),
Binding([e.KEY_LEFTCTRL, e.KEY_K],
[[k.KEY_LEFTSHIFT, k.KEY_END], [k.KEY_LEFTCTRL, k.KEY_X]]),
Binding([e.KEY_LEFTCTRL, e.KEY_A], [[k.KEY_HOME]]),
Binding([e.KEY_LEFTCTRL, e.KEY_E], [[k.KEY_END]]),
Binding([e.KEY_LEFTCTRL, e.KEY_Y], [[k.KEY_LEFTCTRL, k.KEY_V]]),
Binding([e.KEY_LEFTALT, e.KEY_F], [[k.KEY_LEFTCTRL, k.KEY_RIGHT]]),
Binding([e.KEY_LEFTALT, e.KEY_B], [[k.KEY_LEFTCTRL, k.KEY_LEFT]]),
Binding([e.KEY_LEFTALT, e.KEY_D], [[k.KEY_LEFTCTRL, k.KEY_DELETE]]),
Binding([e.KEY_LEFTCTRL, e.KEY_H], [[k.KEY_BACKSPACE]]),
Binding([e.KEY_LEFTCTRL, e.KEY_D], [[k.KEY_DELETE]]),
Binding([e.KEY_LEFTCTRL, e.KEY_S], [[k.KEY_LEFTCTRL, k.KEY_F]]),

# OSX-like key binding
Binding([e.KEY_LEFTALT, e.KEY_A], [[k.KEY_LEFTCTRL, k.KEY_A]]),
Binding([e.KEY_LEFTALT, e.KEY_C], [[k.KEY_LEFTCTRL, k.KEY_C]]),
Binding([e.KEY_LEFTALT, e.KEY_V], [[k.KEY_LEFTCTRL, k.KEY_V]]),

# Slack helm!
Binding([e.KEY_LEFTALT, e.KEY_X], [[k.KEY_LEFTCTRL, k.KEY_K]]),
]

wait_sway()

run(
WayremapConfig(input_identifier=
'Lenovo TrackPoint Keyboard II usb-0000:00:14.0-1/input0',
Expand Down
14 changes: 14 additions & 0 deletions wayremap/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ def find_sway_ipc_path() -> str:
raise Exception('Cannot find sway socket under /run/user/')


def wait_sway(tried=0):
try:
find_sway_ipc_path()
except:
if tried > 30:
raise Exception(
'Cannot find sway socket under `/run/user/`, tried 30 seconds.'
)
else:
print(f"Waiting for sway... {tried}")
time.sleep(1)
wait_sway(tried + 1)


def subscribe_sway(apps: list[str]):
if apps is None or len(apps) == 0:
print(
Expand Down

0 comments on commit 251f0d0

Please sign in to comment.