From 08eef05ae8534d47845c50ae5e1c237c3fe18bf1 Mon Sep 17 00:00:00 2001 From: Pedro Burgos <43417195+druskus20@users.noreply.github.com> Date: Mon, 25 Oct 2021 01:03:21 +0200 Subject: [PATCH] Add support for :hover css selectors for eventbox (#323) --- crates/eww/src/widgets/widget_definitions.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index cd89a53..be187e9 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -528,7 +528,7 @@ fn build_center_box(bargs: &mut BuilderArgs) -> Result { } /// @widget eventbox extends container -/// @desc a container which can receive events and must contain exactly one child +/// @desc a container which can receive events and must contain exactly one child. Supports `:hover` css selectors. fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result { let gtk_widget = gtk::EventBox::new(); @@ -538,6 +538,21 @@ fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result { let cursor_hover_enter_handler_id: EventHandlerId = Rc::new(RefCell::new(None)); let cursor_hover_leave_handler_id: EventHandlerId = Rc::new(RefCell::new(None)); + // Support :hover selector + gtk_widget.connect_enter_notify_event(|gtk_widget, evt| { + if evt.detail() != NotifyType::Inferior { + gtk_widget.clone().set_state_flags(gtk::StateFlags::PRELIGHT, false); + } + gtk::Inhibit(false) + }); + + gtk_widget.connect_leave_notify_event(|gtk_widget, evt| { + if evt.detail() != NotifyType::Inferior { + gtk_widget.clone().unset_state_flags(gtk::StateFlags::PRELIGHT); + } + gtk::Inhibit(false) + }); + resolve_block!(bargs, gtk_widget, { // @prop timeout - timeout of the command // @prop onscroll - event to execute when the user scrolls with the mouse over the widget. The placeholder `{}` used in the command will be replaced with either `up` or `down`.