-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMediaKeys.vala
79 lines (70 loc) · 3.27 KB
/
MediaKeys.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*-
* Copyright (c) 2017-2017 Artem Anufrij <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The Noise authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Noise. This permission is above and beyond the permissions granted
* by the GPL license by which Noise is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Authored by: Artem Anufrij <[email protected]>
*/
namespace PlayMyVideos.Interfaces {
[DBus (name = "org.gnome.SettingsDaemon.MediaKeys")]
public interface GnomeMediaKeys : GLib.Object {
public abstract void GrabMediaPlayerKeys (string application, uint32 time) throws Error;
public abstract void ReleaseMediaPlayerKeys (string application) throws Error;
public signal void MediaPlayerKeyPressed (string application, string key);
}
public class MediaKeyListener : GLib.Object {
public static MediaKeyListener instance { get; private set; }
private GnomeMediaKeys? media_keys;
construct {
assert (media_keys == null);
try {
media_keys = Bus.get_proxy_sync (BusType.SESSION, "org.gnome.SettingsDaemon", "/org/gnome/SettingsDaemon/MediaKeys");
} catch (Error e) {
warning ("Mediakeys error: %s", e.message);
}
if (media_keys != null) {
media_keys.MediaPlayerKeyPressed.connect (pressed_key);
try {
media_keys.GrabMediaPlayerKeys (PlayMyVideos.PlayMyVideosApp.instance.application_id, (uint32)0);
}
catch (Error err) {
warning ("Could not grab media player keys: %s", err.message);
}
}
}
private MediaKeyListener (){}
public static void listen () {
instance = new MediaKeyListener ();
}
private void pressed_key (dynamic Object bus, string application, string key) {
if (application == (PlayMyVideos.PlayMyVideosApp.instance.application_id)) {
if (key == "Play") {
PlayMyVideos.PlayMyVideosApp.instance.mainwindow.toggle_playing ();
} else if (key == "Pause") {
PlayMyVideos.PlayMyVideosApp.instance.mainwindow.pause ();
} else if (key == "Next") {
PlayMyVideos.PlayMyVideosApp.instance.mainwindow.next ();
}
}
}
}
}