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:

Author:

  • Peter Suschlik

Defined Under Namespace

Modules: FFI Classes: API, IconFinder

Constant Summary

VERSION =
"0.8.4"

Class Method Summary (collapse)

Class Method Details

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

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

Options Hash (options):

  • :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



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

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

+ (Object) show(options = {}, &block)

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