Sha256: 7f5005a76b89b5d0804d99856f43a4a943d0fae7f1590b20d5b4ae3e82077ddc

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

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

    def self.included(base)
      # Workaround for "half-linked" libnotify.so. Does not work on rubinius (no ffi_lib_flags there)!
      # See: https://bugzilla.redhat.com/show_bug.cgi?id=626852
      ffi_lib_flags :lazy, :local, :global if respond_to?(:ffi_lib_flags)
      ffi_lib %w[libgtk-x11-2.0 libgtk-x11-2.0.so.0 libgtk-x11-2.0.so libgtk-3 libgtk-3.so.0 libgtk-3.so],
              %w[libgtkmm-2.4 libgtkmm-2.4.so.1 libgtkmm-2.4.so libgtkmm-3.0 libgtkmm-3.0.so.1 libgtkmm-3.0.so],
              %w[libnotify libnotify.so.4 libnotify.so.3 libnotify.so.2 libnotify.so.1 libnotify.so]
      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_set_hint_uint32, [:pointer, :string, :int],              :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

4 entries across 4 versions & 1 rubygems

Version Path
libnotify-0.6.0-universal-rubinius-1.2 lib/libnotify/ffi.rb
libnotify-0.6.0 lib/libnotify/ffi.rb
libnotify-0.5.9-universal-rubinius-1.2 lib/libnotify/ffi.rb
libnotify-0.5.9 lib/libnotify/ffi.rb