Class: Fusuma::Plugin::Appmatcher::Gnome::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/plugin/appmatcher/gnome.rb

Overview

Look up application name using dbus

Instance Method Summary collapse

Constructor Details

#initializeMatcher

Returns a new instance of Matcher.



51
52
53
54
55
56
57
58
59
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 51

def initialize
  session_bus = DBus.session_bus
  service = session_bus.service("org.gnome.Shell")
  @interface = service["/org/gnome/Shell"]["org.gnome.Shell"]
rescue DBus::Error => e
  MultiLogger.error "DBus::Error: #{e.message}"

  exit 1
end

Instance Method Details

#active_applicationObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 70

def active_application
  # const index = global.get_window_actors()
  #                   .findIndex(a=>a.meta_window.has_focus()===true);
  # global.get_window_actors()[index].get_meta_window().get_wm_class();
  gnome_shell_eval(
    "      const actor = global.get_window_actors().find(a=>a.meta_window.has_focus()===true)\n      actor && actor.get_meta_window().get_wm_class()\n    GJS\n  )\nend\n"

#gnome_shell_eval(string) ⇒ Object

TODO def window_title # const index = global.get_window_actors() # .findIndex(a=>a.meta_window.has_focus()===true); # global.get_window_actors().get_meta_window().get_title();

gnome_shell_eval(
  # <<~GJS
  #   global.get_window_actors().map((current) => {
  #     const wm_class = current.get_meta_window().get_wm_class();
  #     const title = current.get_meta_window().get_title();
  #     return { application: wm_class, window_title: title }
  #   })
  # GJS
)

end



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 98

def gnome_shell_eval(string)
  success, body = @interface.Eval(string)

  if success
    response = begin
      JSON.parse(body)
    rescue StandardError
      nil
    end
    return response
  end

  raise body
end

#on_active_application_changedObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 113

def on_active_application_changed
  loop do
    sleep 0.5
    new_application = active_application
    next if @old_application == new_application

    yield(new_application || "NOT FOUND") if block_given?
    @old_application = new_application
  end
end

#running_applicationsArray<Application>

Returns:

  • (Array<Application>)


62
63
64
65
66
67
68
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 62

def running_applications
  gnome_shell_eval(
    "      global.get_window_actors().map(a => a.get_meta_window().get_wm_class());\n    GJS\n  )\nend\n"