Sha256: 143bc7f35f20835a0aa050119ba9212d5fb3054859fdae12f261242c9ae4fe78

Contents?: true

Size: 1.39 KB

Versions: 14

Compression:

Stored size: 1.39 KB

Contents

module Libnotify
  # Raw FFI bindings.
  module FFI
    require 'ffi'
    extend ::FFI::Library

    def self.included(base)
      ffi_lib %w[libnotify libnotify.so libnotify.so.1]
      attach_functions!
    rescue LoadError => e
      warn e.message
    end

    URGENCY = [ :low, :normal, :critical ]

    def self.attach_functions!
      attach_function :notify_init,                         [:string],                              :bool
      attach_function :notify_uninit,                       [],                                     :void
      attach_function :notify_notification_new,             [:string, :string, :string, :pointer],  :pointer
      attach_function :notify_notification_set_urgency,     [:pointer, :int],                       :void
      attach_function :notify_notification_set_timeout,     [:pointer, :long],                      :void
      attach_function :notify_notification_set_hint_string, [:pointer, :string, :string],           :void
      attach_function :notify_notification_clear_hints,     [:pointer],                             :void
      attach_function :notify_notification_show,            [:pointer, :pointer],                   :bool
    end

    def lookup_urgency(urgency)
      URGENCY.index(urgency)
    end

    def method_missing(method, *args, &block)
      if method.to_s =~ /^notify_/
        warn "libnotify.so not found!"
      end

      super
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
libnotify-0.5.5-universal-rubinius-1.2 lib/libnotify/ffi.rb
libnotify-0.5.5 lib/libnotify/ffi.rb
libnotify-0.5.4-universal-rubinius-1.2 lib/libnotify/ffi.rb
libnotify-0.5.4-java lib/libnotify/ffi.rb
libnotify-0.5.4 lib/libnotify/ffi.rb
libnotify-0.5.3-universal-rubinius-1.2 lib/libnotify/ffi.rb
libnotify-0.5.3-universal-java-1.6 lib/libnotify/ffi.rb
libnotify-0.5.3-x86-linux lib/libnotify/ffi.rb
libnotify-0.5.2-universal-rubinius-1.2 lib/libnotify/ffi.rb
libnotify-0.5.2-universal-java-1.6 lib/libnotify/ffi.rb
libnotify-0.5.2-x86-linux lib/libnotify/ffi.rb
libnotify-0.5.1-x86-linux lib/libnotify/ffi.rb
libnotify-0.5.1-universal-rubinius-1.2 lib/libnotify/ffi.rb
libnotify-0.5.1-universal-java-1.6 lib/libnotify/ffi.rb