From 6211267e06e3581d942d39f8227cadb89eb3cf88 Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Fri, 29 Apr 2022 10:52:25 +0200 Subject: [PATCH] Add onclick to eventbox --- CHANGELOG.md | 1 + crates/eww/src/widgets/widget_definitions.rs | 32 +++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e002b28..c7d3967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add `search`, `captures`, `stringlength`, `arraylength` and `objectlength` functions for expressions (By: MartinJM, ElKowar) - Add `matches` function - Add transform widget (By: druskus20) +- Add `:onaccept` to input field, add `:onclick` to eventbox ### Notable Internal changes - Rework state management completely, now making local state and dynamic widget hierarchy changes possible. diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index 12ca517..4b98eff 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -302,7 +302,7 @@ fn build_gtk_checkbox(bargs: &mut BuilderArgs) -> Result { // @prop onunchecked - similar to onchecked but when the widget is unchecked prop(timeout: as_duration = Duration::from_millis(200), onchecked: as_string = "", onunchecked: as_string = "") { connect_signal_handler!(gtk_widget, gtk_widget.connect_toggled(move |gtk_widget| { - run_command(timeout, if gtk_widget.is_active() { &onchecked } else { &onunchecked }, &[""]); + run_command(timeout, if gtk_widget.is_active() { &onchecked } else { &onunchecked }, &[] as &[&str]); })); } }); @@ -437,9 +437,9 @@ fn build_gtk_button(bargs: &mut BuilderArgs) -> Result { gtk_widget.add_events(gdk::EventMask::BUTTON_PRESS_MASK); connect_signal_handler!(gtk_widget, gtk_widget.connect_button_press_event(move |_, evt| { match evt.button() { - 1 => run_command(timeout, &onclick, &[""]), - 2 => run_command(timeout, &onmiddleclick, &[""]), - 3 => run_command(timeout, &onrightclick, &[""]), + 1 => run_command(timeout, &onclick, &[] as &[&str]), + 2 => run_command(timeout, &onmiddleclick, &[] as &[&str]), + 3 => run_command(timeout, &onrightclick, &[] as &[&str]), _ => {}, } gtk::Inhibit(false) @@ -680,9 +680,33 @@ fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result { DragEntryType::Text => data.set_text(&dragvalue), }; })); + }, + // TODO the fact that we have the same code here as for button is ugly, as we want to keep consistency + + // @prop onclick - a command that get's run when the button is clicked + // @prop onmiddleclick - a command that get's run when the button is middleclicked + // @prop onrightclick - a command that get's run when the button is rightclicked + // @prop timeout - timeout of the command + prop( + timeout: as_duration = Duration::from_millis(200), + onclick: as_string = "", + onmiddleclick: as_string = "", + onrightclick: as_string = "" + ) { + gtk_widget.add_events(gdk::EventMask::BUTTON_PRESS_MASK); + connect_signal_handler!(gtk_widget, gtk_widget.connect_button_press_event(move |_, evt| { + match evt.button() { + 1 => run_command(timeout, &onclick, &[] as &[&str]), + 2 => run_command(timeout, &onmiddleclick, &[] as &[&str]), + 3 => run_command(timeout, &onrightclick, &[] as &[&str]), + _ => {}, + } + gtk::Inhibit(false) + })); } }); + Ok(gtk_widget) }