Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an emit command (#4937) #8497

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Tert0
Copy link

@Tert0 Tert0 commented Dec 11, 2024

Closes #4937

Command Syntax: emit <press|release|press-release> <criteria> <keys>

Parameters

  • action: specifies whether to press, release the keys or do both
  • criteria: first window that matches the criteria will get the key input
  • keys: modifiers and keys separated by +

Examples

  • emit press-release [app_id=com.obsproject.Studio] ALT+F8
  • bindsym --no-repeat Ctrl+T emit press [app_id=wev] Ctrl+A
  • bindsym --no-repeat --release Ctrl+T emit release [app_id=wev] Ctrl+A

Test

  1. Open wev -f wl_keyboard with a terminal
  2. Move the wev window into another workspace
  3. Run
swaymsg 'bindsym --no-repeat Ctrl+T emit press [app_id=wev] Ctrl+A'
swaymsg 'bindsym --no-repeat --release Ctrl+T emit release [app_id=wev] Ctrl+A'
  1. Press and hold Ctrl+T
    -> The terminal running wev should show that Ctrl+A was pressed
  2. Release Ctrl+T
    -> The terminal running wev should show that Ctrl+A was released

Code Structure

I am not sure if I should move the code (for converting xkb keysym to key codes), that I copied from the sway/commands/bind.c, to common/utils.c or maybe somewhere else.

Command Syntax: emit <press|release|press-release> <criteria> <keys>
* action: specifies whether to press, release the keys or do both
* criteria: first window that matches the criteria will get the key input
* keys: modifiers and keys separated by +
Examples:
* emit press-release [app_id=com.obsproject.Studio] ALT+F8
* bindsym --no-repeat Ctrl+T emit press [app_id=wev] Ctrl+A
* bindsym --no-repeat --release Ctrl+T emit release [app_id=wev] Ctrl+A
@emersion
Copy link
Member

Now that we have Wayland protocols for this feature, I'm not sure adding IPC commands is really desirable…

@Tert0
Copy link
Author

Tert0 commented Dec 12, 2024

Which wayland protocols are you referring to?

@emersion
Copy link
Member

virtual-keyboard and virtual-pointer.

@Tert0
Copy link
Author

Tert0 commented Dec 12, 2024

As far as I understand the virtual-keyboard protocol, it does not allow sending keys to unfocused windows. This would be a useful feature to "emulate" global hotkeys for applications.
In #4937 are workarounds to do something like this with wtype but these solutions rely on switching to the window with swaymsg and to avoid infinite recursion you can not send the same keys that you bind the script to.

@kennylevinsen
Copy link
Member

As far as I understand the virtual-keyboard protocol, it does not allow sending keys to unfocused windows.

A Wayland surface must by definition have keyboard focus to receive key events. This is what enter/leave is.

The proposed command gives keyboard focus to the window matching the criteria (which is the bit "missing" from virtual-keyboard) and then issues a single synthetic key event. Unless all key events are sent at once, this would race with the keyboard state of the window the user currently focused and any keyboard inputs they are typing.

@Tert0
Copy link
Author

Tert0 commented Dec 12, 2024

A Wayland surface must by definition have keyboard focus to receive key events. This is what enter/leave is.

Using swaymg it additionally gives them visual focus (wl_surface::enter + shows them).

Unless all key events are sent at once, this would race with the keyboard state of the window the user currently focused and any keyboard inputs they are typing.

Is there a way with wlroots to send all key events at once?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Allow forwarding of key events
3 participants