Class: Sh::MMKeys

Inherits:
Object show all
Defined in:
lib/sh_mmkeys.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ MMKeys

Returns a new instance of MMKeys.

Raises:

  • (ArgumentError)


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
      # MediaKeys are not supported after all
      @supported = false
    end
  end
  
  # Do we still think that MediaKeys are supported?
  if supported? and @mmkeys
    @mmkeys.connect!(:MediaPlayerKeyPressed) do |app, key|
      if app.downcase == 'shroom'
        block.call key
      end
    end
  end
end

Instance Method Details

#destroyObject



40
41
42
# File 'lib/sh_mmkeys.rb', line 40

def destroy
  @mmkeys.ReleaseMediaPlayerKeys('Shroom')
end

#supported?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/sh_mmkeys.rb', line 36

def supported?
  return @supported
end