diff --git a/CHANGELOG.md b/CHANGELOG.md index 072640e6..c1ba7f95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index 8284d0fa..7982ad1e 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -817,6 +817,22 @@ fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result { 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); @@ -864,6 +880,30 @@ fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result { 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);