From c7e70eff849a0cb91a8feaf2b9f3fb9d99809d5f Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Mon, 24 Feb 2020 09:35:30 +0100 Subject: [PATCH] Fixed #19 --- ...thub.marbetschar.time-limit.appdata.xml.in | 13 ++++++ src/Widgets/Clock.vala | 17 ++++++- src/Widgets/ProgressArrow.vala | 20 ++++----- src/Widgets/ProgressIndicator.vala | 44 +++++++++++++++++++ 4 files changed, 83 insertions(+), 11 deletions(-) diff --git a/data/com.github.marbetschar.time-limit.appdata.xml.in b/data/com.github.marbetschar.time-limit.appdata.xml.in index 5ba562a..30a1cf0 100644 --- a/data/com.github.marbetschar.time-limit.appdata.xml.in +++ b/data/com.github.marbetschar.time-limit.appdata.xml.in @@ -28,6 +28,19 @@ com.github.marbetschar.time-limit + + + +

Fixed #19: "Grab arrow after first drag is sometimes difficult"

+

Merged #23: "Add French translations", thanks to Nathan Bonnemains 🎉️

+
+
+ + +

Submitting the first version to elementary AppCenter! 🎉️

+
+
+
none none diff --git a/src/Widgets/Clock.vala b/src/Widgets/Clock.vala index b6a764f..ea87438 100644 --- a/src/Widgets/Clock.vala +++ b/src/Widgets/Clock.vala @@ -75,10 +75,12 @@ public class Timer.Widgets.Clock : Gtk.Overlay { bind_property ("progress", indicator, "progress", BindingFlags.BIDIRECTIONAL); add_events (Gdk.EventMask.BUTTON_PRESS_MASK - | Gdk.EventMask.BUTTON_RELEASE_MASK); + | Gdk.EventMask.BUTTON_RELEASE_MASK + | Gdk.EventMask.POINTER_MOTION_MASK); button_press_event.connect (on_button_press_event); button_release_event.connect (on_button_release_event); + motion_notify_event.connect (on_motion_notify_event); notify["progress"].connect (on_progress_changed); notify["seconds"].connect (on_seconds_changed); @@ -88,6 +90,9 @@ public class Timer.Widgets.Clock : Gtk.Overlay { } private bool on_button_press_event (Gdk.EventButton event) { + if (indicator.handles_event (event) && Gdk.EVENT_STOP == indicator.button_press_event (event)) { + return Gdk.EVENT_STOP; + } button_press_active = true; on_button_press_seconds = seconds; @@ -99,6 +104,9 @@ public class Timer.Widgets.Clock : Gtk.Overlay { } private bool on_button_release_event (Gdk.EventButton event) { + if (indicator.handles_event (event) && Gdk.EVENT_STOP == indicator.button_release_event (event)) { + return Gdk.EVENT_STOP; + } button_press_active = false; if (on_button_press_seconds == seconds && seconds > 0) { @@ -115,6 +123,13 @@ public class Timer.Widgets.Clock : Gtk.Overlay { return Gdk.EVENT_PROPAGATE; } + private bool on_motion_notify_event (Gdk.EventMotion event) { + if (indicator.handles_event (event) && Gdk.EVENT_STOP == indicator.motion_notify_event (event)) { + return Gdk.EVENT_STOP; + } + return Gdk.EVENT_PROPAGATE; + } + private void on_seconds_changed () { if (!pause) { launcher_entry.progress_visible = true; diff --git a/src/Widgets/ProgressArrow.vala b/src/Widgets/ProgressArrow.vala index 9ae4d0d..bf70ff5 100644 --- a/src/Widgets/ProgressArrow.vala +++ b/src/Widgets/ProgressArrow.vala @@ -22,6 +22,7 @@ public class Timer.Widgets.ProgressArrow : Gtk.DrawingArea { public double progress { get; construct set; } + public bool is_active { get; private set; } public ProgressArrow (double progress) { Object (progress: progress); @@ -29,6 +30,7 @@ public class Timer.Widgets.ProgressArrow : Gtk.DrawingArea { construct { set_size_request (25, 25); + is_active = false; add_events (Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK @@ -58,24 +60,22 @@ public class Timer.Widgets.ProgressArrow : Gtk.DrawingArea { return true; } - private bool drag_is_active = false; - - private bool on_button_press_event (Gdk.EventButton event) { - if (!drag_is_active) { - drag_is_active = true; + public bool on_button_press_event (Gdk.EventButton event) { + if (!is_active) { + is_active = true; } return Gdk.EVENT_PROPAGATE; } - private bool on_button_release_event (Gdk.EventButton event) { - if (drag_is_active) { - drag_is_active = false; + public bool on_button_release_event (Gdk.EventButton event) { + if (is_active) { + is_active = false; } return Gdk.EVENT_PROPAGATE; } - private bool on_motion_notify_event (Gdk.EventMotion event) { - if (drag_is_active) { + public bool on_motion_notify_event (Gdk.EventMotion event) { + if (is_active) { var parent_center_x = parent.get_allocated_width () / 2; var parent_center_y = parent.get_allocated_height () / 2; diff --git a/src/Widgets/ProgressIndicator.vala b/src/Widgets/ProgressIndicator.vala index cdecee3..a7f293b 100644 --- a/src/Widgets/ProgressIndicator.vala +++ b/src/Widgets/ProgressIndicator.vala @@ -23,9 +23,18 @@ public class Timer.Widgets.ProgressIndicator : Gtk.Fixed { public double progress { get; construct set; } + public bool is_active { + get { + return arrow.is_active; + } + } + private Timer.Widgets.ProgressArrow arrow; private Timer.Widgets.ProgressBar bar; + private int arrow_width; + private int arrow_height; + public ProgressIndicator (double progress) { Object (progress: progress); } @@ -44,6 +53,41 @@ public class Timer.Widgets.ProgressIndicator : Gtk.Fixed { notify["progress"].connect (() => { arrow_move (progress); }); + + arrow.size_allocate.connect (() => { + arrow_width = arrow.get_allocated_width (); + arrow_height = arrow.get_allocated_height (); + }); + + button_press_event.connect ((event) => { + return arrow.button_press_event (event); + }); + + button_release_event.connect ((event) => { + return arrow.button_release_event (event); + }); + + motion_notify_event.connect ((event) => { + return arrow.motion_notify_event (event); + }); + } + + public bool handles_event (Gdk.Event event) { + if (arrow.is_active) { + return true; + } + double event_x, event_y; + int arrow_min_x, arrow_min_y, arrow_max_x, arrow_max_y; + + event.get_coords (out event_x, out event_y); + + event_x += arrow_width / 2; + event_y += arrow_height / 2; + + arrow.translate_coordinates (base, 0, 0, out arrow_min_x, out arrow_min_y); + arrow.translate_coordinates (base, arrow_width, arrow_height, out arrow_max_x, out arrow_max_y); + + return event_x >= arrow_min_x && event_x <= arrow_max_x && event_y >= arrow_min_y && event_y <= arrow_max_y; } private void arrow_move (double progress) {