Skip to content

Commit

Permalink
Fixed #19
Browse files Browse the repository at this point in the history
  • Loading branch information
marbetschar committed Feb 24, 2020
1 parent 347ac5e commit c7e70ef
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 11 deletions.
13 changes: 13 additions & 0 deletions data/com.github.marbetschar.time-limit.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
<provides>
<binary>com.github.marbetschar.time-limit</binary>
</provides>
<releases>
<release version="1.2.0" date="2020-02-24" urgency="medium">
<description>
<p><a href="https://github.com/marbetschar/time-limit/issues/19">Fixed #19</a>: "Grab arrow after first drag is sometimes difficult"</p>
<p><a href="https://github.com/marbetschar/time-limit/pull/23">Merged #23</a>: "Add French translations", thanks to Nathan Bonnemains 🎉️</p>
</description>
</release>
<release version="1.0.0" date="2020-02-06">
<description>
<p>Submitting the first version to elementary AppCenter! 🎉️</p>
</description>
</release>
</releases>
<content_rating type="oars-1.1">
<content_attribute id="violence-cartoon">none</content_attribute>
<content_attribute id="violence-fantasy">none</content_attribute>
Expand Down
17 changes: 16 additions & 1 deletion src/Widgets/Clock.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/Widgets/ProgressArrow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
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);
}

construct {
set_size_request (25, 25);
is_active = false;

add_events (Gdk.EventMask.BUTTON_PRESS_MASK
| Gdk.EventMask.BUTTON_RELEASE_MASK
Expand Down Expand Up @@ -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;

Expand Down
44 changes: 44 additions & 0 deletions src/Widgets/ProgressIndicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down

0 comments on commit c7e70ef

Please sign in to comment.