After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 688227 - idle-monitor: Reset the alarm so it can be triggered again
idle-monitor: Reset the alarm so it can be triggered again
Status: RESOLVED FIXED
Product: gnome-desktop
Classification: Core
Component: libgnome-desktop
unspecified
Other All
: Normal normal
: ---
Assigned To: Desktop Maintainers
Desktop Maintainers
: 693845 (view as bug list)
Depends on:
Blocks: 687791
 
 
Reported: 2012-11-13 10:00 UTC by Bastien Nocera
Modified: 2013-02-15 08:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
idle-monitor: Reset the alarm so it can be triggered again (1.79 KB, patch)
2012-11-13 10:00 UTC, Bastien Nocera
committed Details | Review
idle-monitor: Rename xalarm_reset to became_active_alarm (1.47 KB, patch)
2013-01-18 05:39 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
idle-monitor: Clarify code and comments about alarm rescheduling workaround (1.97 KB, patch)
2013-01-18 05:39 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
idle-monitor: Change the ::became-active API (5.26 KB, patch)
2013-01-18 05:39 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
idle-monitor: Clarify code and comments about alarm rescheduling workaround (1.97 KB, patch)
2013-01-23 19:16 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
idle-monitor: Fix documentation (1022 bytes, patch)
2013-01-23 19:16 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
idle-monitor: Make sure we publicly make watch intervals 64-bits wide (1.86 KB, patch)
2013-01-23 19:16 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
idle-monitor: Change the API to be function-based (14.43 KB, patch)
2013-01-23 19:16 UTC, Jasper St. Pierre (not reading bugmail)
accepted-commit_now Details | Review
gsm-presence: Update to new GnomeIdleMonitor API (4.50 KB, patch)
2013-01-23 22:19 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
power: Adapt to new GnomeIdleMonitor API (7.79 KB, patch)
2013-01-23 22:20 UTC, Jasper St. Pierre (not reading bugmail)
needs-work Details | Review
Update to new GnomeIdleMonitor API (5.04 KB, patch)
2013-01-23 22:20 UTC, Jasper St. Pierre (not reading bugmail)
needs-work Details | Review
idle-monitor: Change the API to be function-based (14.44 KB, patch)
2013-02-13 16:49 UTC, Bastien Nocera
none Details | Review
idle-monitor: Change the API to be function-based (14.79 KB, patch)
2013-02-13 17:02 UTC, Bastien Nocera
committed Details | Review
idle-monitor: Fix documentation (1.00 KB, patch)
2013-02-13 17:03 UTC, Bastien Nocera
committed Details | Review
gsm-presence: Update to new GnomeIdleMonitor API (3.49 KB, patch)
2013-02-13 17:04 UTC, Bastien Nocera
committed Details | Review
idle: add compat #define (3.26 KB, patch)
2013-02-14 19:19 UTC, Ray Strode [halfline]
committed Details | Review
Update to new GnomeIdleMonitor API (5.14 KB, patch)
2013-02-14 22:44 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
power: Adapt to new GnomeIdleMonitor API (7.07 KB, patch)
2013-02-14 22:47 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
cursor: Adapt to new GnomeIdleMonitor API (2.10 KB, patch)
2013-02-14 22:48 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review

Description Bastien Nocera 2012-11-13 10:00:24 UTC
.
Comment 1 Bastien Nocera 2012-11-13 10:00:26 UTC
Created attachment 228862 [details] [review]
idle-monitor: Reset the alarm so it can be triggered again

http://www.x.org/archive/X11R7.6/doc/xextproto/sync.txt says:

[... If] the delta is 0 and test-type is PositiveComparison
or NegativeComparison, no change is made to value and the alarm
state is changed to Inactive before the event is generated.

But we want to receive to receive events about the idleness/business
of the counter, so reset the alarm when the alarm is triggered.
Comment 2 Bastien Nocera 2012-12-14 16:31:04 UTC
Attachment 228862 [details] pushed as 7f9fba8 - idle-monitor: Reset the alarm so it can be triggered again
Comment 3 Giovanni Campagna 2012-12-14 18:12:21 UTC
Uhm... I didn't test this, so it probably solves the bug, but one comment: we use Negative/PositiveTransition, not Negative/PositiveComparison, so the above spec reference does not apply here.

Also, last time I tried to debug a similar issue, I remember not seeing any AlarmNotify indicating that the alarm was inactive.
Comment 4 Bastien Nocera 2012-12-14 18:51:18 UTC
It fixed problems for me idle timeouts not getting triggered again unless I destroyed the monitor and created another one. Even with those fixes, the API is more than peculiar and too complicated for my taste.

Feel free to double-check my fixes with the idle test I added to gnome-desktop some time before that.
Comment 5 Jasper St. Pierre (not reading bugmail) 2013-01-18 04:41:49 UTC
From debugging a similar issue. For context, on whot's machine, the test case worked perfectly with the negative transition always triggering, and on my machine, it only triggered once.

<whot> Jasper: still here?
<Jasper> whot, sure
<whot> I think I found the issue
<whot> if you have a negative transition trigger, you get the event when idle falls below the value. but when you get the event, the server computes the value for the next transition. when it does that, the idle time in the server is 0, so the checks never register and the alarm isn't re-scheduled
<whot> because current_idle < alarm value. so nothing happens. I think this works sometimes because if anything else registers on the idle timer and triggers an alarm, it's recalculated again and then it may be rescheduled
<whot> alternatively, you can force that by changing the alarm, this will reschedule it too
<whot> makes sense?
<Jasper> so the reason it was working for you was because some other random client had an alarm scheduled
<Jasper> ?
<whot> that, or my computer was too slow :)
<Jasper> heh
<Jasper> so, would you consider this a server bug?
<whot> i think so, because the alarm is still considered active but it can never trigger
<Jasper> whot, wouldn't fixing this mean that clients that set a negative transition alarm on IDLETIME would get... a lot... of events?
<whot> not if we fix it properly, since the transition is defined as _transition_, not state. but I don't think we keep the state around properly
<Jasper> whot, well, IDLETIME is milliseconds
<Jasper> so if the user is moving his mouse, but every millisecond doesn't result in motion, there's a lot of traffic going on there
<Jasper> Unless there's already a base threshold in the server.
<whot> there isn't, at least I didn't see one
<whot> so if you set your threshold to 1, then yes, you'd see a lot of events
<Jasper> whot, any other threshold for a negative transition for IDLETIME makes no sense
<whot> for your use-case you can take the current value and use that
<whot> since idletime only goes backwards when not idle
<whot> you only need one trigger, right?
<Jasper> That's not the way our API works right now, but maybe it makes sense to do that.

Updating the alarm causes it to be rescheduled. Given that future X servers may actually send all of the negative transitions, I think it makes sense to restructure the GnomeIdleMonitor API to set a one-time alarm for became-active, rather than having it be always persistent. In gnome-shell's case, this would be set when we show a notification. In GPM's case, this would be set when we enter an idle state.

In both cases, we actually don't care about every single time we become active, we just want to say "please tell me the next time you become active".
Comment 6 Jasper St. Pierre (not reading bugmail) 2013-01-18 05:39:16 UTC
Created attachment 233719 [details] [review]
idle-monitor: Rename xalarm_reset to became_active_alarm

This name is a lot clearer about its purpose.
Comment 7 Jasper St. Pierre (not reading bugmail) 2013-01-18 05:39:19 UTC
Created attachment 233720 [details] [review]
idle-monitor: Clarify code and comments about alarm rescheduling workaround

Segment the code out in its own function, point out that this is an Xorg
bug, and don't actually set any attributes -- just call XSyncChangeAlarm.
Comment 8 Jasper St. Pierre (not reading bugmail) 2013-01-18 05:39:21 UTC
Created attachment 233721 [details] [review]
idle-monitor: Change the ::became-active API

As all current uses of the :;became-active signal are one-shot, it makes
sense for the test user to explicitly specify when they want that state
transition to happen, so we don't get a flood of events on all pointer
motion or key events that we won't do anything with.
Comment 9 Jasper St. Pierre (not reading bugmail) 2013-01-18 05:45:22 UTC
This is an experimental set of changes to the API. I have patches for the three major components (gnome-shell, gnome-settings-daemon, gnome-session) to adapt to the new API, but I'm not going to bother filing them until we OK the new API.

First, the name: gnome_idle_monitor_set_became_active_alarm is a bit too unwieldy in my opinion.

Also, I thought about dropping the signal in favor of a callback-based approach, given that the set_*_alarm would be tied to one function invocation.
Comment 10 Bastien Nocera 2013-01-18 11:07:09 UTC
(In reply to comment #5)
> In both cases, we actually don't care about every single time we become active,
> we just want to say "please tell me the next time you become active".

I don't want to have to request GnomeIdleMonitor to tell me it became active every single time.
For gnome-settings-daemon's power plugin, the use case is different, I already have positive transitions, and I'm interested in receiving became-active when I have negative transitions for _those timeouts_.
Comment 11 Jasper St. Pierre (not reading bugmail) 2013-01-18 16:28:41 UTC
(In reply to comment #10)
> I don't want to have to request GnomeIdleMonitor to tell me it became active
> every single time.
> For gnome-settings-daemon's power plugin, the use case is different, I already
> have positive transitions, and I'm interested in receiving became-active when I
> have negative transitions for _those timeouts_.

The API would still need to be changed anyway to respect that, otherwise we would get too many events if the user became-active when the state hadn't timed out yet.

The issue is "which timeout"? The minimum one is the only one that makes sense, in the g-s-d case. This means that we would need an API:

 1) If using watches, uses the minimum watch timeout as the became-active source.
 2) If not using watches, needs a special function to prime a one-fire no-threshold alarm.

Which sounds complicated. Suggestions?
Comment 12 Matthias Clasen 2013-01-19 20:10:12 UTC
This whole xsync api is a trainwreck.
Nobody can understand it, and even smart people get it wrong all the time.

That being said, I think it would make sense to have an api like:

guint
gnome_idle_monitor_add_nonidle_watch (GnomeIdleMonitor         *monitor,
                                      guint                     interval_msec,
                                      GnomeIdleMonitorWatchFunc callback,
                                      gpointer                  user_data,
                                      GDestroyNotify            notify);

to install a watch that gets triggered whenever idletime jumps from a value
>= interval_msec back to zero.

Might make sense to rename add_watch to add_idle_watch to match.
Comment 13 Jasper St. Pierre (not reading bugmail) 2013-01-23 04:47:56 UTC
That makes sense to me. Bastien, what do you feel about that?

Note that the original bug is going to get fixed upstream, so this means that we'll get a bunch of events if we don't get smart soon: https://bugs.freedesktop.org/show_bug.cgi?id=59644
Comment 14 Bastien Nocera 2013-01-23 12:53:47 UTC
(In reply to comment #13)
> That makes sense to me. Bastien, what do you feel about that?

Fine by me, as long as we remove the became-active signal too and the counterpart signal to "triggered-idle".

It provides a nice symmetry to the API, infinitely cleaner than what we have now.
Comment 15 Jasper St. Pierre (not reading bugmail) 2013-01-23 19:16:43 UTC
Created attachment 234244 [details] [review]
idle-monitor: Clarify code and comments about alarm rescheduling workaround

Segment the code out in its own function, point out that this is an Xorg
bug, and don't actually set any attributes -- just call XSyncChangeAlarm.
Comment 16 Jasper St. Pierre (not reading bugmail) 2013-01-23 19:16:46 UTC
Created attachment 234245 [details] [review]
idle-monitor: Fix documentation
Comment 17 Jasper St. Pierre (not reading bugmail) 2013-01-23 19:16:50 UTC
Created attachment 234246 [details] [review]
idle-monitor: Make sure we publicly make watch intervals 64-bits wide
Comment 18 Jasper St. Pierre (not reading bugmail) 2013-01-23 19:16:53 UTC
Created attachment 234247 [details] [review]
idle-monitor: Change the API to be function-based

As the current API design has been unknowingly relying on an Xorg server
bug that may be fixed in the future, we need to modify the API so that
became-active is explicitly asked for by the user so that we won't get
flooded with a large number of events for almost every input event.
Comment 19 Jasper St. Pierre (not reading bugmail) 2013-01-23 22:19:56 UTC
Created attachment 234257 [details] [review]
gsm-presence: Update to new GnomeIdleMonitor API
Comment 20 Jasper St. Pierre (not reading bugmail) 2013-01-23 22:20:08 UTC
Created attachment 234258 [details] [review]
power: Adapt to new GnomeIdleMonitor API
Comment 21 Jasper St. Pierre (not reading bugmail) 2013-01-23 22:20:18 UTC
Created attachment 234259 [details] [review]
Update to new GnomeIdleMonitor API
Comment 22 Giovanni Campagna 2013-01-23 22:24:29 UTC
Review of attachment 234246 [details] [review]:

You should flag the commit somehow, so that we don't forget to bump the soname at the next release.
Comment 23 Bastien Nocera 2013-01-30 16:35:43 UTC
Review of attachment 234244 [details] [review]:

::: libgnome-desktop/gnome-idle-monitor.c
@@ +127,3 @@
+	XSyncAlarmAttributes attr;
+
+	/* Some versions of Xorg have an issue where alarms aren't

citation needed (or bugzilla link, upstream ML thread).
Comment 24 Bastien Nocera 2013-01-30 16:37:12 UTC
Review of attachment 234245 [details] [review]:

::: libgnome-desktop/gnome-idle-monitor.c
@@ +447,3 @@
  * @interval_msec: The idletime interval, in milliseconds
  * @callback: (allow-none): The callback to call when the user has
+ *     accumulated @interval_msec seconds of idle time.

s/seconds/milliseconds/ I would think.
Comment 25 Bastien Nocera 2013-01-30 16:37:58 UTC
Review of attachment 234246 [details] [review]:

Looks good.
Comment 26 Bastien Nocera 2013-01-30 16:43:33 UTC
Review of attachment 234247 [details] [review]:

::: libgnome-desktop/gnome-idle-monitor.c
@@ -72,3 @@
-{
-	BECAME_ACTIVE,
-	TRIGGERED_IDLE,

What was wrong with sending signals?
The callbacks are nice, but sending a signal is nicer to bindings, especially when, in some programs, they might all be handled by the same function.

@@ +482,3 @@
  */
 guint
+gnome_idle_monitor_add_user_active_watch (GnomeIdleMonitor          *monitor,

If I were to add such a function, I would make the prototype match that of add_idle_watch(), and remove the automatically created "active" watch.

With the code below, you'd receive xalarms even if you didn't call gnome_idle_monitor_add_user_active_watch().
Comment 27 Bastien Nocera 2013-01-30 16:44:59 UTC
I'll leave the other 3 patches to be reviewed when the API changes are settled.
Comment 28 Bastien Nocera 2013-01-30 17:21:13 UTC
Review of attachment 234247 [details] [review]:

I'd be happy with the signals removal if I had assurance that this code is usable from gobject-introspection based bindings without additional C code.

::: libgnome-desktop/gnome-idle-monitor.c
@@ +482,3 @@
  */
 guint
+gnome_idle_monitor_add_user_active_watch (GnomeIdleMonitor          *monitor,

That last bit about receiving xalarms for the user became active aren't correct.
Comment 29 Bastien Nocera 2013-01-30 18:01:01 UTC
(In reply to comment #28)
> Review of attachment 234247 [details] [review]:
> 
> I'd be happy with the signals removal if I had assurance that this code is
> usable from gobject-introspection based bindings without additional C code.

As the gnome-shell patch shows, it should be usable from bindings. Even if I prefer signals, Jasper doesn't, so fine to commit.
Comment 30 Bastien Nocera 2013-01-30 18:04:51 UTC
Review of attachment 234257 [details] [review]:

Looks fine.
Comment 31 Bastien Nocera 2013-01-30 18:09:13 UTC
Review of attachment 234258 [details] [review]:

Please split off the cursor patch from the power patch, and bump the gnome-desktop dep.

::: plugins/power/gsd-power-manager.c
@@ +2425,3 @@
 
+        /* if we're moving to an idle mode, make sure
+         * we add a watch to take us back to normal */

You can't do that here, there's nothing saying that GSD_POWER_IDLE_MODE_NORMAL has to happen when the idle isn't idle (that's not the case when plugging in the AC for example).
This should be done in idle_triggered_idle_cb().

You can double-check that this works properly by running the test suite ("make check" in plugins/power/, make sure that the latest python-dbusmock is installed).
Comment 32 Bastien Nocera 2013-02-13 16:49:57 UTC
Created attachment 235910 [details] [review]
idle-monitor: Change the API to be function-based

As the current API design has been unknowingly relying on an Xorg server
bug that may be fixed in the future, we need to modify the API so that
became-active is explicitly asked for by the user so that we won't get
flooded with a large number of events for almost every input event.
Comment 33 Jasper St. Pierre (not reading bugmail) 2013-02-13 16:57:42 UTC
Review of attachment 235910 [details] [review]:

The one thing I'm not sure about is "add_user_active_watch" and "add_idle_watch". "add_active_watch" sounded wrong, and "add_user_idle_watch" sounds a bit unnecessary. Opinions?
Comment 34 Bastien Nocera 2013-02-13 17:02:37 UTC
Created attachment 235913 [details] [review]
idle-monitor: Change the API to be function-based

As the current API design has been unknowingly relying on an Xorg server
bug that may be fixed in the future, we need to modify the API so that
became-active is explicitly asked for by the user so that we won't get
flooded with a large number of events for almost every input event.
Comment 35 Bastien Nocera 2013-02-13 17:03:42 UTC
Created attachment 235914 [details] [review]
idle-monitor: Fix documentation
Comment 36 Bastien Nocera 2013-02-13 17:04:19 UTC
Created attachment 235915 [details] [review]
gsm-presence: Update to new GnomeIdleMonitor API
Comment 37 Bastien Nocera 2013-02-13 17:24:56 UTC
(In reply to comment #33)
> Review of attachment 235910 [details] [review]:
> 
> The one thing I'm not sure about is "add_user_active_watch" and
> "add_idle_watch". "add_active_watch" sounded wrong, and "add_user_idle_watch"
> sounds a bit unnecessary. Opinions?

Really not fussed.
Comment 38 Ray Strode [halfline] 2013-02-13 17:37:03 UTC
could solve the naming inconsistency by adding a

enum GnomeIdleMonitorWatchMode
{
 GNOME_IDLE_MONITOR_WATCH_USER_ACTIVITY,
 GNOME_IDLE_MONITOR_WATCH_USER_INACTIVITY
};

and then just having one function.  but doesn't really matter. api cleanliness is already a lost cause for gnome-desktop
Comment 39 Ray Strode [halfline] 2013-02-13 17:44:28 UTC
since these are one-shot functions I think it would probably be better if they followed the _async (..., GCancellable, GAsyncReadyCallback, ...) idiom but doesn't really matter.
Comment 40 Bastien Nocera 2013-02-14 10:49:22 UTC
(In reply to comment #38)
> could solve the naming inconsistency by adding a
> 
> enum GnomeIdleMonitorWatchMode
> {
>  GNOME_IDLE_MONITOR_WATCH_USER_ACTIVITY,
>  GNOME_IDLE_MONITOR_WATCH_USER_INACTIVITY
> };
> 
> and then just having one function.  but doesn't really matter. api cleanliness
> is already a lost cause for gnome-desktop

"inactivity" isn't 1-1 with "became idle" though.
Comment 41 Bastien Nocera 2013-02-14 10:51:05 UTC
(In reply to comment #39)
> since these are one-shot functions I think it would probably be better if they
> followed the _async (..., GCancellable, GAsyncReadyCallback, ...) idiom but
> doesn't really matter.

I wouldn't use GIO style async functions for something which might, or might not be called, depending on user interaction. I would have preferred a signal, but the API is already mushy enough.

I'll commit this as-is.
Comment 42 Ray Strode [halfline] 2013-02-14 15:16:02 UTC
Hi,

> I'll commit this as-is.

sounds good.
Comment 43 Bastien Nocera 2013-02-14 15:38:55 UTC
Attachment 234244 [details] pushed as 626de2a - idle-monitor: Clarify code and comments about alarm rescheduling workaround
Attachment 234246 [details] pushed as 36c472b - idle-monitor: Make sure we publicly make watch intervals 64-bits wide
Attachment 235913 [details] pushed as 1fc10e6 - idle-monitor: Change the API to be function-based
Attachment 235914 [details] pushed as 21348a1 - idle-monitor: Fix documentation
Comment 44 Bastien Nocera 2013-02-14 15:41:51 UTC
Comment on attachment 235915 [details] [review]
gsm-presence: Update to new GnomeIdleMonitor API

Attachment 235915 [details] pushed as 377e024 - gsm-presence: Update to new GnomeIdleMonitor API
Comment 45 Bastien Nocera 2013-02-14 17:08:55 UTC
Comment on attachment 234259 [details] [review]
Update to new GnomeIdleMonitor API

This patch doesn't apply anymore.
Comment 46 Ray Strode [halfline] 2013-02-14 19:19:08 UTC
Created attachment 236130 [details] [review]
idle: add compat #define

This commit is just temporary until g-s-d is updated.
Comment 47 Ray Strode [halfline] 2013-02-14 19:19:57 UTC
Comment on attachment 236130 [details] [review]
idle: add compat #define

pushing since the build is apparently broken atm.
Comment 48 Florian Müllner 2013-02-14 22:31:30 UTC
(In reply to comment #43)
> Attachment 235913 [details] pushed as 1fc10e6 - idle-monitor: Change the API to be
> function-based

Is someone already working on unbreaking gnome-shell or should I do it?
Comment 49 Jasper St. Pierre (not reading bugmail) 2013-02-14 22:44:26 UTC
Created attachment 236180 [details] [review]
Update to new GnomeIdleMonitor API
Comment 50 Jasper St. Pierre (not reading bugmail) 2013-02-14 22:45:25 UTC
*** Bug 693845 has been marked as a duplicate of this bug. ***
Comment 51 Jasper St. Pierre (not reading bugmail) 2013-02-14 22:47:35 UTC
Created attachment 236182 [details] [review]
power: Adapt to new GnomeIdleMonitor API
Comment 52 Jasper St. Pierre (not reading bugmail) 2013-02-14 22:48:33 UTC
Created attachment 236183 [details] [review]
cursor: Adapt to new GnomeIdleMonitor API

OK, here are my patches for gnome-settings-daemon. Note that these are not even
close to tested, because I can't run the power test suite for some reason, even
with an unpatched everything.
Comment 53 Giovanni Campagna 2013-02-14 23:19:05 UTC
Review of attachment 236182 [details] [review]:

::: plugins/power/gsd-power-manager.c
@@ +2722,3 @@
+                        manager->priv->idle_logout_warning_id = gnome_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
+                                                                                                   timeout_logout_warning * 1000,
+                                                                                                   idle_triggered_idle_cb, manager, NULL);

These should be sleep_warning, I think
Comment 54 Bastien Nocera 2013-02-15 08:10:09 UTC
Comment on attachment 236182 [details] [review]
power: Adapt to new GnomeIdleMonitor API

Attachment 236182 [details] pushed as e8bc8e8 - power: Adapt to new GnomeIdleMonitor API
Comment 55 Bastien Nocera 2013-02-15 08:11:35 UTC
Comment on attachment 236183 [details] [review]
cursor: Adapt to new GnomeIdleMonitor API

Got committed as part of the power plugin port...
Comment 56 Bastien Nocera 2013-02-15 08:13:33 UTC
Attachment 236180 [details] pushed as 261fbef - Update to new GnomeIdleMonitor API

And we'll handle bugs separately, if any.