Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ All notable changes to eww will be listed here, starting at changes since versio
- Add `value-pos` to scale widget (By: ipsvn)
- Add `floor` and `ceil` function calls to simplexpr (By: wsbankenstein)
- Add `formatbytes` function calls to simplexpr (By: topongo)
- Add `onfocus` and `onfocuslost` properties to eventbox (By: RelativeAlbatros)

## [0.6.0] (21.04.2024)

Expand Down
40 changes: 40 additions & 0 deletions crates/eww/src/widgets/widget_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,22 @@ fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result<gtk::EventBox> {
glib::Propagation::Proceed
});

gtk_widget.connect_focus_in_event(|gtk_widget, evt| {
// method not found in &EventFocus
if evt.is_focus_in() {
gtk_widget.set_state_flags(gtk::StateFlags::FOCUSED, true);
}
glib::Propagation::Proceed
});

gtk_widget.connect_focus_out_event(|gtk_widget, evt| {
// method not found in &EventFocus
if evt.is_focus_out() {
gtk_widget.unset_state_flags(gtk::StateFlags::FOCUSED);
}
glib::Propagation::Proceed
});

// Support :active selector
gtk_widget.connect_button_press_event(|gtk_widget, _| {
gtk_widget.set_state_flags(gtk::StateFlags::ACTIVE, false);
Expand Down Expand Up @@ -864,6 +880,30 @@ fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result<gtk::EventBox> {
glib::Propagation::Proceed
}));
},
// @prop timeout - timeout of the command. Default: "200ms"
// @prop onfocus - event to execute when the keyboard focus enters the widget
prop(timeout: as_duration = Duration::from_millis(200), onfocus: as_string) {
gtk_widget.add_events(gdk::EventMask::FOCUS_CHANGE_MASK);
connect_signal_handler!(gtk_widget, gtk_widget.connect_focus_in_event(move |_, evt| {
// method not found in &EventFocus
if evt.is_focus_in() {
run_command(timeout, &onfocus, &[evt.position().0, evt.position().1]);
}
glib::Propagation::Proceed
}));
},
// @prop timeout - timeout of the command. Default: "200ms"
// @prop onfocuslost - event to execute when the widget loses focus
prop(timeout: as_duration = Duration::from_millis(200), onfocuslost: as_string) {
gtk_widget.add_events(gdk::EventMask::FOCUS_CHANGE_MASK);
connect_signal_handler!(gtk_widget, gtk_widget.connect_focus_out_event(move |_, evt| {
// method not found in &EventFocus
if evt.is_focus_out() {
run_command(timeout, &onfocuslost, &[evt.position().0, evt.position().1]);
}
glib::Propagation::Proceed
}));
},
// @prop cursor - Cursor to show while hovering (see [gtk3-cursors](https://docs.gtk.org/gdk3/ctor.Cursor.new_from_name.html) for possible names)
prop(cursor: as_string) {
gtk_widget.add_events(gdk::EventMask::ENTER_NOTIFY_MASK);
Expand Down