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
|
# File 'lib/sh_mmkeys.rb', line 3
def initialize &block
raise(ArgumentError, "No callback block provided") unless block
@supported = try_require('rubygems') and try_require('rbus')
if supported?
begin
bus = RBus.session_bus
begin
@mmkeys = bus.get_object('org.gnome.SettingsDaemon', '/org/gnome/SettingsDaemon/MediaKeys')
@mmkeys.interface!('org.gnome.SettingsDaemon.MediaKeys')
@mmkeys.GrabMediaPlayerKeys('Shroom', 0)
rescue
@mmkeys = bus.get_object('org.gnome.SettingsDaemon', '/org/gnome/SettingsDaemon/MediaKeys')
@mmkeys.interface!('org.gnome.SettingsDaemon.MediaKeys')
@mmkeys.GrabMediaPlayerKeys('Shroom', 0)
end
rescue
@supported = false
end
end
if supported? and @mmkeys
@mmkeys.connect!(:MediaPlayerKeyPressed) do |app, key|
if app.downcase == 'shroom'
block.call key
end
end
end
end
|