Class: Fusuma::Plugin::Appmatcher::Gnome::Matcher
- Inherits:
-
Object
- Object
- Fusuma::Plugin::Appmatcher::Gnome::Matcher
- Defined in:
- lib/fusuma/plugin/appmatcher/gnome.rb
Overview
Look up application name using dbus
Instance Method Summary collapse
- #active_application ⇒ Object
-
#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.
-
#initialize ⇒ Matcher
constructor
A new instance of Matcher.
- #on_active_application_changed ⇒ Object
- #running_applications ⇒ Array<Application>
Constructor Details
#initialize ⇒ Matcher
Returns a new instance of Matcher.
52 53 54 55 56 57 58 59 60 |
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 52 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.}" exit 1 end |
Instance Method Details
#active_application ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 71 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( <<~GJS const actor = global.get_window_actors().find(a=>a.meta_window.has_focus()===true) actor && actor.get_meta_window().get_wm_class() GJS ) end |
#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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 99 def gnome_shell_eval(string) success, body = @interface.Eval(string) if success response = begin JSON.parse(body) rescue nil end return response end raise body end |
#on_active_application_changed ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 114 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_applications ⇒ Array<Application>
63 64 65 66 67 68 69 |
# File 'lib/fusuma/plugin/appmatcher/gnome.rb', line 63 def running_applications gnome_shell_eval( <<~GJS global.get_window_actors().map(a => a.get_meta_window().get_wm_class()); GJS ) end |