Module: Libnotify

Defined in:
lib/libnotify.rb,
lib/libnotify/api.rb,
lib/libnotify/ffi.rb,
lib/libnotify/version.rb,
lib/libnotify/icon_finder.rb

Overview

Ruby bindings for libnotify using FFI.

See README.md for usage examples.

See Also:

Defined Under Namespace

Modules: FFI Classes: API, IconFinder

Constant Summary collapse

VERSION =
"0.9.4"

Class Method Summary collapse

Class Method Details

.icon_dirsObject

Exposes a list of icon directories to resolve ‘icon_path`.

Examples:

Libnotify.icon_dirs << "/usr/share/icons/gnome/*/"
Libnotify.show(:icon_path => "emblem-default.png")

See Also:



78
79
80
# File 'lib/libnotify.rb', line 78

def self.icon_dirs
  API.icon_dirs
end

.new(options = {}) {|notify| ... } ⇒ API

Creates a notification.

Examples:

Block syntax

n = Libnotify.new do |notify|
  notify.summary    = "hello"
  notify.body       = "world"
  notify.timeout    = 1.5         # 1.5 (s), 1000 (ms), "2", nil, false
  notify.urgency    = :critical   # :low, :normal, :critical
  notify.append     = false       # default true - append onto existing notification
  notify.transient  = true        # default false - keep the notifications around after display
  notify.icon_path  = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
end
n.show!

Hash syntax

Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)

Update pre-existing notification then close it

n = Libnotify.new(:summary => "hello", :body => "world")
n.update # identical to show! if not shown before
Kernel.sleep 1
n.update(:body => "my love") do |notify|
  notify.summary = "goodbye"
end
Kernel.sleep 1
n.close

Mixed syntax

Libnotify.new(options) do |n|
  n.timeout = 1.5     # overrides :timeout in options
  n.show!
end

Parameters:

  • options (Hash) (defaults to: {})

    options creating a notification

Options Hash (options):

  • :app_name (String) — default: 'Libnotify::API'

    name of the application

  • :summary (String) — default: ' '

    summary/title of the notification

  • :body (String) — default: ' '

    the body

  • :timeout (Fixnum, Float, nil, FalseClass, String) — default: nil

    display duration of the notification. Use false or nil for no timeout.

  • :urgency (Symbol) — default: :normal

    the urgency of the notification. Possible values are: :low, :normal and :critical

  • :icon_path (String)

    path the an icon displayed.

Yields:

  • (notify)

    passes the notification object

Yield Parameters:

  • notify (API)

    the notification object

Returns:

  • (API)

    the notification object



58
59
60
# File 'lib/libnotify.rb', line 58

def self.new(options = {}, &block)
  API.new(options, &block)
end

.show(options = {}, &block) ⇒ Object

Shows a notification. It takes the same options as Libnotify.new.

See Also:



65
66
67
# File 'lib/libnotify.rb', line 65

def self.show(options = {}, &block)
  API.show(options, &block)
end