lib/fusuma/plugin/appmatcher/gnome.rb in fusuma-plugin-appmatcher-0.1.0.pre vs lib/fusuma/plugin/appmatcher/gnome.rb in fusuma-plugin-appmatcher-0.1.0.pre2
- old
+ new
@@ -1,36 +1,35 @@
# frozen_string_literal: true
require 'json'
require 'dbus'
-require_relative './user_switcher.rb'
+require_relative './user_switcher'
require 'posix/spawn'
module Fusuma
module Plugin
module Appmatcher
# Search Active Window's Name
class Gnome
- attr_reader :matcher
- attr_reader :reader
- attr_reader :writer
+ attr_reader :matcher, :reader, :writer
+
def initialize
@reader, @writer = IO.pipe
end
# fork process and watch signal
# @return [Integer] Process id
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
+ 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
def register_on_application_changed(matcher)
@@ -79,18 +78,34 @@
actor && actor.get_meta_window().get_wm_class()
GJS
)
end
+ # TODO
+ # def window_title
+ # # const index = global.get_window_actors()
+ # # .findIndex(a=>a.meta_window.has_focus()===true);
+ # # global.get_window_actors()[index].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
+
def gnome_shell_eval(string)
success, body = @interface.Eval(string)
if success
response = begin
- JSON.parse(body)
- rescue StandardError
- nil
- end
+ JSON.parse(body)
+ rescue StandardError
+ nil
+ end
return response
end
raise body
end