Skip to content

Commit

Permalink
feat: Suspend/Resume Support via Systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
mayanez committed Mar 23, 2024
1 parent 3487787 commit e0a5870
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ This tool is a daemon process that can be used to sync the two keyboard halves f

You may want to setup this tool to run at startup. Depending on your distribution `systemd` is a likely solution. See <https://github.com/arjun024/systemd-example-startup> for an example. If you installed via the AUR package this is setup automatically.

_NOTE:_ libusb does NOT raise a `HOTPLUG_EVENT_DEVICE_LEFT` event on suspend (at least on Linux). This means the sync script doesn't know the keyboard handles are invalid upon resuming. Two address this two `systemd` scripts can be used. See the `systemd/` directory in the repo. The AUR package takes this approach.

### Run

$ dumang-sync
Expand Down
9 changes: 9 additions & 0 deletions systemd/dumang-sync-python.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=DuMang DK6 Layer Sync (Python Invoke)

[Service]
Type=Simple
ExecStart=dumang-sync

[Install]
WantedBy=multi-user.target
13 changes: 10 additions & 3 deletions systemd/dumang-sync.service
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
[Unit]
Description=DuMang DK6 Layer Sync
# NOTE: Two systemd services are required since on suspend, libusb does NOT raise a HOTPLUG_EVENT_DEVICE_LEFT
# event. This means the sync script doesn't know the keyboard handles are invalid upon resuming.
# TODO: Is this expected behavior on part of libusb or a bug?
Before=sleep.target
StopWhenUnneeded=yes

[Service]
Type=Simple
ExecStart=dumang-sync
Type=oneshot
RemainAfterExit=yes
ExecStart=-/bin/systemctl stop dumang-sync-python.service
ExecStop=-/bin/systemctl start dumang-sync-python.service

[Install]
WantedBy=multi-user.target
WantedBy=sleep.target

0 comments on commit e0a5870

Please sign in to comment.