Merge lp:~djaler1/screenshot-tool/fix-1670010 into lp:~elementary-apps/screenshot-tool/trunk

Proposed by Kirill Romanov
Status: Merged
Approved by: Jeremy Wootten
Approved revision: 321
Merged at revision: 319
Proposed branch: lp:~djaler1/screenshot-tool/fix-1670010
Merge into: lp:~elementary-apps/screenshot-tool/trunk
Diff against target: 96 lines (+25/-10)
2 files modified
schemas/net.launchpad.screenshot.gschema.xml (+3/-2)
src/ScreenshotWindow.vala (+22/-8)
To merge this branch: bzr merge lp:~djaler1/screenshot-tool/fix-1670010
Reviewer Review Type Date Requested Status
Jeremy Wootten code, function Approve
Sergey Kislyakov (community) Approve
Review via email: mp+322256@code.launchpad.net

Commit message

Description of the change

To post a comment you must log in.
Revision history for this message
Sergey Kislyakov (defman21) wrote :

Works fine for me.

review: Approve
Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

I could not reproduce this bug in the current trunk.

@delay should not be allowed to be zero (or less) anyway. The SpinButton has a minimum value of 1, but the settings allow the user to change the delay to zero or less which, for negative delays, causes this branch to hang. It also hangs if you have a delay of zero with redaction.

As a quick fix you could check the value of delay on construction in order that it is consistent with the SpinButton range.

delay = int.max (1, settings.get_int ("delay"));

Ideally the settings schema should be also changed to not allow values less than 1.

review: Needs Fixing (code, function)
Revision history for this message
Kirill Romanov (djaler1) wrote :

I can set zero delay from command line, for example. And I need this functionality, I implement it. Cause 1 second delay is too long for me, when I use keybindings

Revision history for this message
Kirill Romanov (djaler1) wrote :

And negative values of delay is not problem of current branch, cause this branch is only for bug fix.

Revision history for this message
Sergey Kislyakov (defman21) wrote :

I don't see any reasons to make the delay always be >= 1. I don't want to wait for a second to make a screenshot. There shouldn't be a way to set it < 0 (it's not related to the fix though and it's a different bug), but there's nothing wrong with 0 delay.

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

If a 0 second delay is to be accepted then the SpinButton should also allow it and, more importantly, it should also work with redact == true. The value of timout must not be negative so I believe fixing is still required.

Revision history for this message
Kirill Romanov (djaler1) wrote :

Jeremy, all what you say is not about current bug fix.

Revision history for this message
Kirill Romanov (djaler1) wrote :

In my branch I just add 100ms if zero delay is set. And the correction of the old is a separate matter

Revision history for this message
Sergey Kislyakov (defman21) wrote :

I think it's better to send another merge request to address the issue you're talking about, Jeremy. I've filed a bug related to 0 delay which could happen even without the Kirill's patch.

320. By Kirill Romanov

Fix #1681254

Revision history for this message
Kirill Romanov (djaler1) wrote :

Jeremy, I added some fixes about negative timeout. Hope you'' like it

Revision history for this message
Sergey Kislyakov (defman21) wrote :

Looks fine for me.

review: Approve
Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

@Sergey: I agree it is in general better for merge to address a single issue. I would make an exception where the same, or closely linked, lines of code are affected and the issues are linked (in this case to do with delay).

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

@Kirill: I like the separate get_timeout function, however I find that with a delay setting of zero the screenshot is sometimes unsuccessful or corrupted, especially with redaction . I am not sure of the reason but you could try setting a non-zero minimum value returned from get_timeout () (although it would be better to understand the real reason). I think it would be more convenient for timeout to be consistently in milliseconds.

Alternatively, you could revert the minimum (reliable) delay to 1 second and address the problems with zero delay in another branch.

review: Needs Fixing (function)
321. By Kirill Romanov

get_timeout() now in millisecond, and return minimum 100ms

Revision history for this message
Kirill Romanov (djaler1) wrote :

@Jeremy: What about now?

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

Yes, that works fine now :-) Approving.

review: Approve (code, function)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'schemas/net.launchpad.screenshot.gschema.xml' (properties changed: -x to +x)
2--- schemas/net.launchpad.screenshot.gschema.xml 2016-03-24 04:14:18 +0000
3+++ schemas/net.launchpad.screenshot.gschema.xml 2017-04-10 18:08:41 +0000
4@@ -1,5 +1,5 @@
5 <schemalist>
6- <schema id="net.launchpad.screenshot" path="/net/launchpad/screenshot/" gettext-domain="screenshot">
7+ <schema id="net.launchpad.screenshot" path="/net/launchpad/screenshot/" gettext-domain="screenshot">
8 <key name="format" type="s">
9 <default>"png"</default>
10 </key>
11@@ -13,10 +13,11 @@
12 <default>false</default>
13 </key>
14 <key name="delay" type="i">
15+ <range min="0" max="15"/>
16 <default>1</default>
17 </key>
18 <key name="folder-dir" type="s">
19 <default>""</default>
20 </key>
21- </schema>
22+ </schema>
23 </schemalist>
24
25=== modified file 'src/ScreenshotWindow.vala'
26--- src/ScreenshotWindow.vala 2017-03-21 17:13:44 +0000
27+++ src/ScreenshotWindow.vala 2017-04-10 18:08:41 +0000
28@@ -100,7 +100,7 @@
29 var delay_label = new Gtk.Label (_("Delay in seconds:"));
30 delay_label.halign = Gtk.Align.END;
31
32- var delay_spin = new Gtk.SpinButton.with_range (1, 15, 1);
33+ var delay_spin = new Gtk.SpinButton.with_range (0, 15, 1);
34 settings.bind ("delay", delay_spin, "value", GLib.SettingsBindFlags.DEFAULT);
35
36 var grid = new Gtk.Grid ();
37@@ -172,7 +172,7 @@
38
39 public ScreenshotWindow.from_cmd (int? action, int? delay, bool? grab_pointer, bool? redact, bool? clipboard) {
40 if (delay != null) {
41- this.delay = delay;
42+ this.delay = int.max (0, delay);
43 }
44
45 if (grab_pointer != null) {
46@@ -405,10 +405,24 @@
47 }
48 }
49
50+ private int get_timeout(int delay, bool redact) {
51+ int timeout = delay * 1000;
52+
53+ if (redact) {
54+ timeout -= 1000;
55+ }
56+
57+ if (timeout < 100) {
58+ timeout = 100;
59+ }
60+
61+ return timeout;
62+ }
63+
64 private void capture_screen () {
65 this.hide ();
66
67- Timeout.add_seconds (delay - (redact ? 1 : 0), () => {
68+ Timeout.add (get_timeout (delay, redact), () => {
69 if (from_command == false) {
70 this.present ();
71 }
72@@ -424,7 +438,7 @@
73 screen = Gdk.Screen.get_default ();
74
75 this.hide ();
76- Timeout.add_seconds (delay - (redact ? 1 : 0), () => {
77+ Timeout.add (get_timeout (delay, redact), () => {
78 list = screen.get_window_stack ();
79 foreach (Gdk.Window item in list) {
80 if (screen.get_active_window () == item) {
81@@ -479,11 +493,11 @@
82 var win = selection_area.get_window ();
83
84 selection_area.captured.connect (() => {
85- if (delay == 0) {
86- selection_area.set_opacity (0);
87- }
88+ if (delay == 0) {
89+ selection_area.set_opacity (0);
90+ }
91 selection_area.close ();
92- Timeout.add_seconds (delay - (redact ? 1 : 0), () => {
93+ Timeout.add (get_timeout (delay, redact), () => {
94 if (from_command == false) {
95 this.present ();
96 }

Subscribers

People subscribed via source and target branches