class Fusuma::Plugin::Appmatcher::Gnome

Search Active Window's Name

Attributes

matcher[R]
reader[R]
writer[R]

Public Class Methods

new() click to toggle source
# File lib/fusuma/plugin/appmatcher/gnome.rb, line 14
def initialize
  @reader, @writer = IO.pipe
end

Public Instance Methods

watch_start() click to toggle source

fork process and watch signal @return [Integer] Process id

# File lib/fusuma/plugin/appmatcher/gnome.rb, line 20
def watch_start
  @watch_start ||= begin
    pid = UserSwitcher.new.as_user do |user|
      @reader.close
      ENV['DBUS_SESSION_BUS_ADDRESS'] = "unix:path=/run/user/#{user.uid}/bus"
      register_on_application_changed(Matcher.new)
    end
    Process.detach(pid)
    pid
  end
end

Private Instance Methods

notify(name) click to toggle source
# File lib/fusuma/plugin/appmatcher/gnome.rb, line 40
def notify(name)
  @writer.puts(name)
rescue Errno::EPIPE
  exit 0
rescue StandardError => e
  MultiLogger.error e.message
  exit 1
end
register_on_application_changed(matcher) click to toggle source
# File lib/fusuma/plugin/appmatcher/gnome.rb, line 34
def register_on_application_changed(matcher)
  matcher.on_active_application_changed do |name|
    notify(name)
  end
end