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

Add support for :keypress property to eventbox #1272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexandrePicavet
Copy link

@AlexandrePicavet AlexandrePicavet commented Jan 15, 2025

Description

I wanted to be able to close my window by pressing the Escape key, but I couldn't figure out how to do that, so I added a way to handle keypress events on the eventbox widget to execute a command.

Usage

The keypress property is structured in the following way:

Enter |> echo 'You pressed the Enter key'

Enter : The key to press
|> : The separator
echo 'You pressed the Enter key' : The command

Here's an example of how to use it:

(defwindow my-window
	:monitor 0
	:stacking "fg"
	:exclusive false
	:focusable true
	:geometry (geometry
		:anchor "top left"
		:x 0
		:y 0
		:width "100%"
		:height "100%"
	)
	(eventbox
		:keypress "Escape |> eww close my-window"
		(label :text "Press the Escape key to close the window")
	)
)

Showcase

eww-keypress.mp4

Additional Notes

  • I wasn't sure which syntax would be best for this feature, so if you have a different suggestion, I can change that.
  • It is my first rust contribution, so I may have done some things not quite up to the standards, if so, I'll happily fix them.
  • As shown on the video above, I added a debug log on keypress indicating which key has been pressed and which widget caught this event. Do you find this useful, or would you prefer that I remove it ?

Checklist

  • All widgets I've added are correctly documented.
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes.
  • I used cargo fmt to automatically format all code before committing.

@AlexandrePicavet AlexandrePicavet changed the title feat(eventbox-keypress-command): First implementation Add support for :keypress property to eventbox Jan 15, 2025
@AlexandrePicavet AlexandrePicavet force-pushed the feat/eventbox-keypress-command branch from 3199825 to ffc38fe Compare January 30, 2025 18:49
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.

1 participant