From 5c446808aca7ccab7efafb3ca4c0b6b58d41eac4 Mon Sep 17 00:00:00 2001 From: jpike Date: Mon, 2 Jan 2012 18:56:19 +0000 Subject: [PATCH] Libnotify#close to close notification before timeout. --- README.rdoc | 4 +++- lib/libnotify.rb | 4 +++- lib/libnotify/api.rb | 5 +++++ lib/libnotify/ffi.rb | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.rdoc b/README.rdoc index b904e10..4c295e1 100644 --- a/README.rdoc +++ b/README.rdoc @@ -37,13 +37,15 @@ http://github.com/splattael/libnotify/raw/master/libnotify.png Libnotify.show(:icon_path => "emblem-default.png") Libnotify.show(:icon_path => :"emblem-default") - # Update pre-existing notification + # 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 == Installation diff --git a/lib/libnotify.rb b/lib/libnotify.rb index 3480ed7..cd4dab1 100644 --- a/lib/libnotify.rb +++ b/lib/libnotify.rb @@ -23,13 +23,15 @@ module Libnotify # @example Hash syntax # Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5) # - # @example Update pre-existing notification + # @example 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 # # @example Mixed syntax # Libnotify.new(options) do |n| diff --git a/lib/libnotify/api.rb b/lib/libnotify/api.rb index a21e405..554acbe 100644 --- a/lib/libnotify/api.rb +++ b/lib/libnotify/api.rb @@ -89,6 +89,11 @@ def update(options={}, &block) end end + # Close a previously shown notification. + def close + notify_notification_close(@notification, nil) if @notification + end + # @todo Simplify timeout= def timeout=(timeout) @timeout = case timeout diff --git a/lib/libnotify/ffi.rb b/lib/libnotify/ffi.rb index 25c5cc1..e38f450 100644 --- a/lib/libnotify/ffi.rb +++ b/lib/libnotify/ffi.rb @@ -29,6 +29,7 @@ def self.attach_functions! 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 + attach_function :notify_notification_close, [:pointer, :pointer], :bool end def lookup_urgency(urgency)