Skip to content

input: emit Lua signal for switch toggle events#624

Merged
JimmyCozza merged 3 commits into
trip-zip:mainfrom
jx853:switch
Jul 5, 2026
Merged

input: emit Lua signal for switch toggle events#624
JimmyCozza merged 3 commits into
trip-zip:mainfrom
jx853:switch

Conversation

@jx853

@jx853 jx853 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description

This adds support for libinput switch devices, including laptop lid switches, tablet mode switches, and keypad slide switches.

When wlroots reports a switch toggle event, somewm now emits the global Lua signal switch::toggle with a table payload:

  • device_name: the switch device name
  • type: "lid", "tablet_mode", or "unknown" (WLR_SWITCH_TYPE_KEYPAD_SLIDE can be added if wlr 0.19.x version is increased)
  • state: "on" or "off"

Closes #519

Test Plan

I tested with the following code and my laptop lid switch. It would be difficult to write a unit test as I don't see an easy way to spoof switch inputs.

awesome.connect_signal("switch::toggle", function(ev)
    naughty.notification {
        urgency = "critical",
        title = "Switch Input",
        text = "device name: " .. ev.device_name
            .. " switch type: " .. ev.type
            .. " state: " .. ev.state,
    }
end)

Checklist

  • Lua libraries (lua/awful/, lua/gears/, lua/wibox/, lua/naughty/) are not modified — if a bug surfaces in Lua, the fix belongs in C
  • Tests pass (make test-unit && make test-integration)

@jx853 jx853 marked this pull request as ready for review July 2, 2026 05:12
@sicelo

sicelo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Oh this is great! Will test later today or tomorrow hopefully.

@sicelo

sicelo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Tested. Works for me as advertised. Thank you so much!

Code looks clean (within the limits of my ability to review it 😄 )

I'm a bit sad we can't support WLR_SWITCH_TYPE_KEYPAD_SLIDE yet due to wlroots 0.19. My device with that switch is the main reason I opened #519, having added support for it to libinput a while before that

@jx853

jx853 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

It compiles locally for me supporting WLR_SWITCH_TYPE_KEYPAD_SLIDE on wlroots 0.19.3 its just that the CI uses an older version so I had to remove that branch for it to pass. If you use the code from before the force push with the latest version of wlroots it should support that device. See here.

@jx853

jx853 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

If you compile the current PR with newer wlroots it should register that device as "unknown" so it could still work.

@sicelo

sicelo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Oh yeah! I wasn't aware they backported it to 0.19.x! I only followed it up to the time it was accepted in 0.20. I guess we shall bump the version in CI then @trip-zip to the latest 0.19.x release so we can have all libinput supported switches 😄

@jx853

jx853 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

this commit should pass once they update the CI.

@sicelo

sicelo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

#625

@JimmyCozza JimmyCozza merged commit e865143 into trip-zip:main Jul 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: input/libinput: support switch devices

3 participants