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 559797 - GrabMediaPlayerKeys does not respect "time" parameter
GrabMediaPlayerKeys does not respect "time" parameter
Status: RESOLVED FIXED
Product: gnome-settings-daemon
Classification: Core
Component: plugins
2.24.x
Other All
: Normal normal
: ---
Assigned To: gnome-settings-daemon-maint
gnome-settings-daemon-maint
Depends on:
Blocks:
 
 
Reported: 2008-11-07 20:17 UTC by Chow Loong Jin
Modified: 2008-11-20 21:39 UTC
See Also:
GNOME target: ---
GNOME version: 2.23/2.24


Attachments
Patch against 2.24.0 which fixes the issue (708 bytes, patch)
2008-11-07 20:19 UTC, Chow Loong Jin
none Details | Review
Updated one which works (893 bytes, patch)
2008-11-08 09:39 UTC, Chow Loong Jin
none Details | Review
handle GDK_CURRENT_TIME (1.39 KB, patch)
2008-11-20 19:02 UTC, Jens Granseuer
committed Details | Review

Description Chow Loong Jin 2008-11-07 20:17:01 UTC
Please describe the problem:
When an application calls GrabMediaPlayerKeys with a non-zero "time" parameter, it overrides applications which have called it with time=0. An example is Evince, which calls GrabMediaPlayerKeys with time=1, which overrides Banshee, which calls GrabMediaPlayerKeys with time=0.

Steps to reproduce:
1. Start Banshee
2. Press multimedia keys to confirm that it is working with Banshee
3. Start Evince
4. Press multimedia keys


Actual results:
Evince responds to the multimedia keys.

Expected results:
Banshee responds to the multimedia keys.

Does this happen every time?
Yes

Other information:
If I quit Banshee and start it again, Banshee has control of the multimedia keys again. Same happens when reloading "Multimedia Keys" extension of Banshee.
Comment 1 Chow Loong Jin 2008-11-07 20:19:39 UTC
Created attachment 122204 [details] [review]
Patch against 2.24.0 which fixes the issue
Comment 2 Jens Granseuer 2008-11-07 20:32:25 UTC
Hm. The code does look inconsistent, indeed. Bastien, what were the intended semantics here?
Comment 3 Chow Loong Jin 2008-11-08 07:08:05 UTC
Okay, I found that the patch I did earlier introduced a new issue where applications with time=0 end up being added to the bottom of the list if it makes the grab after another application with time>0, i.e. if Banshee starts after Evince, Evince retains the grab.

I'll upload an updated patch shortly.
Comment 4 Chow Loong Jin 2008-11-08 09:39:54 UTC
Created attachment 122224 [details] [review]
Updated one which works
Comment 5 Bastien Nocera 2008-11-18 18:34:37 UTC
The last app is supposed to get priority, 0 is supposed to mean "current time".

Something like that would probably do:

- media_player->time = time;
+ if (time == 0) {
+          media_player->time = GDK_CURRENT_TIME;
+ } else {
+           media_player->time = time;
+ }
Comment 6 Chow Loong Jin 2008-11-18 19:46:41 UTC
And what does "current time" mean?
Comment 7 Jens Granseuer 2008-11-18 20:17:31 UTC
What do you mean? "Current time" means now aka GDK_CURRENT_TIME, so that the last app to register gets highest priority (if it uses 0, that is). Does Bastien's proposed change fix your problem? It basically does the same thing your patch tried to do, only a bit simpler (and arguably more correct since it fixes the current timestamp instead of leaving it up in the air like before).
Comment 8 Chow Loong Jin 2008-11-19 05:07:18 UTC
I'm not sure exactly which lines he means. Is this patch supposed to be applied within the gsd_media_keys_manager_grab_media_player_keys function? Another thing I find weird is that GDK_CURRENT_TIME is defined as 0L, so wouldn't that be the same as media_player->time = time? (when time = 0 that is). Anyway I'll try modifying the function I mentioned above and see if that helps.
Comment 9 Chow Loong Jin 2008-11-19 05:56:37 UTC
Okay, I've just tested the patch by Bastien, and it has no effect whatsoever.
Comment 10 Jens Granseuer 2008-11-19 17:44:14 UTC
Hm, yeah, makes sense, I guess. We need to use g_get_current_time() or some such when GDK_CURRENT_TIME (ie. 0) is passed.
Comment 11 Chow Loong Jin 2008-11-19 17:53:32 UTC
Well, when I was coming up with the patch, I noticed that the original find_by_time function only returns 0, no matter what the input. I believe the flaw lies in find_by_time, not anywhere else.
Comment 12 Jens Granseuer 2008-11-19 18:12:23 UTC
That's just another angle on the same issue. If we set the time correctly in the first place, find_by_time becomes as simple as:

return ((MediaPlayer *)a)->time < ((MediaPlayer *)b)->time;
Comment 13 Chow Loong Jin 2008-11-19 18:20:25 UTC
In that case, the media-player list would be sorted in decreasing order of media_player->time, and so media_player->time has to be set to an extremely large value (MAX_INT?) if the D-Bus call was made with time=0, wouldn't it? 
Comment 14 Jens Granseuer 2008-11-19 18:34:20 UTC
No, it needs to be set to the current system time. That way any new app that registers with time=GDK_CURRENT_TIME automatically moves to the top of the stack.
Comment 15 Chow Loong Jin 2008-11-20 02:27:20 UTC
Then find_by_time would need to be modified accordingly wouldn't it? Something like..

if ((MediaPlayer*)a)->time == GDK_CURRENT_TIME)
        return 0;
return ((MediaPlayer*)a)->time < ((MediaPlayer*)b)->time;
Comment 16 Jens Granseuer 2008-11-20 19:02:43 UTC
Created attachment 123129 [details] [review]
handle GDK_CURRENT_TIME

Here's the proposed change.
Comment 17 Bastien Nocera 2008-11-20 20:06:05 UTC
Looks like it would do the trick.
Comment 18 Chow Loong Jin 2008-11-20 20:45:52 UTC
I have tested the patch, and can testify that it works.
Comment 19 Jens Granseuer 2008-11-20 21:39:05 UTC
Thanks for testing.

2008-11-20  Jens Granseuer  <...>

        * plugins/media-keys/gsd-media-keys-manager.c: (find_by_time),
        (gsd_media_keys_manager_grab_media_player_keys): fix handling of
        time = GDK_CURRENT_TIME. Previously, apps that registered with
        GDK_CURRENT_TIME would be trumped by any app that registered with
        time != 0 (bug #559797)