fusuma-plugin-appmatcher 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0ff585f50332d6d07f2a160b9d940ae58d5f2fd6fee54b25289df480d5a2c04
4
- data.tar.gz: 1421a3f34917a949932aadad5c2d3343b12bf133a7abe2c1eacc0e9a13ce46f0
3
+ metadata.gz: e05040ebda7865ab254ec65fdfecf9816b459e8cbbc4f2e5d8187e1d2a2f11e7
4
+ data.tar.gz: 96ed3b12d8af74d59903545312f3dbce677f0edd836f6f5b714d42d87635d44e
5
5
  SHA512:
6
- metadata.gz: d629c722c4caf82eba94e6ae3965bbb60c4df0b086277bfc3b1dd770fa73b07f27b23b7a1de5a9cc714d0c43ab3715788711f0e9903c2bb759c8c4c241816b51
7
- data.tar.gz: 6cf64e2d1ca08e64108db1735f002d15a4a8b29d77a1027b19e81a7ceb45505277629d819fe785acb07aced79655b40f185ca1666fe3f3439072880bfed6f28c
6
+ metadata.gz: f3f254bbe5151e53b5975dd1a16116834562769692c840f8406d182706a06e5235e876887e4aae3bf5e89f8259b0c377e55adda74a492f1e33fcb792ccf4e025
7
+ data.tar.gz: 5c3759120b876598eef36670a1caef96ca4e65a50616bdbd6b2d8ee0bf0d7570cc85c4476571e21f60cb350ee98f48f0cbdc5ad24645332af09c2a7d9d8638cc
data/README.md CHANGED
@@ -38,7 +38,7 @@ Google-chrome
38
38
  Alacritty
39
39
  ```
40
40
 
41
- You can use these applicatin name to under `application:` context in config.yml
41
+ You can use these application name to under `application:` context in config.yml
42
42
 
43
43
  ## Add appmatcher properties and application names to config.yml
44
44
 
@@ -20,13 +20,10 @@ module Fusuma
20
20
  # fork process and watch signal
21
21
  # @return [Integer] Process id
22
22
  def watch_start
23
- @watch_start ||= begin
24
- pid = as_user(proctitle: self.class.name.underscore) do |user|
25
- @reader.close
26
- ENV["DBUS_SESSION_BUS_ADDRESS"] = "unix:path=/run/user/#{user.uid}/bus"
27
- register_on_application_changed(Matcher.new)
28
- end
29
- pid
23
+ as_user(proctitle: self.class.name.underscore) do |user|
24
+ @reader.close
25
+ ENV["DBUS_SESSION_BUS_ADDRESS"] = "unix:path=/run/user/#{user.uid}/bus"
26
+ register_on_application_changed(Matcher.new)
30
27
  end
31
28
  end
32
29
 
@@ -11,24 +11,6 @@ module Fusuma
11
11
  class Installer
12
12
  include UserSwitcher
13
13
 
14
- EXTENSION = "./appmatcher@iberianpig.dev"
15
-
16
- def gnome_shell_extension_path
17
- output = `gnome-shell --version`
18
- version = output.match(/GNOME Shell (\d+\.\d+)/)
19
-
20
- if version
21
- version_number = version[1].to_f
22
- if version_number >= 45.0
23
- "./appmatcher45@iberianpig.dev"
24
- else
25
- "./appmatcher@iberianpig.dev"
26
- end
27
- else
28
- "./appmatcher@iberianpig.dev"
29
- end
30
- end
31
-
32
14
  def install
33
15
  pid = as_user(proctitle: self.class.name.underscore) do |user|
34
16
  FileUtils.cp_r(source_path, install_path(user.username))
@@ -52,18 +34,41 @@ module Fusuma
52
34
  File.exist?(install_path)
53
35
  end
54
36
 
37
+ def enabled?
38
+ enabled_extensions = YAML.load(`gsettings get org.gnome.shell enabled-extensions`)
39
+ enabled_extensions&.include?(EXTENSION)
40
+ end
41
+
55
42
  private
56
43
 
57
44
  def user_extension_dir(username = login_username)
58
45
  File.expand_path("#{Dir.home(username)}/.local/share/gnome-shell/extensions/")
59
46
  end
60
47
 
48
+ EXTENSION = "appmatcher@iberianpig.dev"
49
+ EXTENSION45 = "appmatcher45@iberianpig.dev"
61
50
  def install_path(username = login_username)
62
51
  File.expand_path("#{Dir.home(username)}/.local/share/gnome-shell/extensions/#{EXTENSION}")
63
52
  end
64
53
 
65
54
  def source_path
66
- File.expand_path(gnome_shell_extension_path, __dir__)
55
+ File.expand_path(gnome_shell_extension_filename, __dir__)
56
+ end
57
+
58
+ def gnome_shell_extension_filename
59
+ output = `gnome-shell --version`
60
+ version = output.match(/GNOME Shell (\d+\.\d+)/)
61
+
62
+ if version
63
+ version_number = version[1].to_f
64
+ if version_number >= 45.0
65
+ EXTENSION45
66
+ else
67
+ EXTENSION
68
+ end
69
+ else
70
+ EXTENSION
71
+ end
67
72
  end
68
73
 
69
74
  def login_username
@@ -22,19 +22,13 @@ module Fusuma
22
22
  # fork process and watch signal
23
23
  # @return [Integer] Process id
24
24
  def watch_start
25
- @watch_start ||= begin
26
- pid = as_user(proctitle: self.class.name.underscore) do
27
- @reader.close
28
- sleep # stop indefinitely without using CPU
29
- end
30
- pid
25
+ as_user(proctitle: self.class.name.underscore) do
26
+ @reader.close
27
+ sleep # stop indefinitely without using CPU
31
28
  end
32
29
  end
33
30
 
34
31
  class Matcher
35
- def initialize
36
- end
37
-
38
32
  def running_applications
39
33
  warn
40
34
  nil
@@ -3,7 +3,7 @@
3
3
  module Fusuma
4
4
  module Plugin
5
5
  module Appmatcher
6
- VERSION = "0.7.1"
6
+ VERSION = "0.8.0"
7
7
  end
8
8
  end
9
9
  end
@@ -21,12 +21,9 @@ module Fusuma
21
21
  # fork process and watch signal
22
22
  # @return [Integer] Process id
23
23
  def watch_start
24
- @watch_start ||= begin
25
- pid = as_user(proctitle: self.class.name.underscore) do |_user|
26
- @reader.close
27
- register_on_application_changed(Matcher.new)
28
- end
29
- pid
24
+ as_user(proctitle: self.class.name.underscore) do |_user|
25
+ @reader.close
26
+ register_on_application_changed(Matcher.new)
30
27
  end
31
28
  end
32
29
 
@@ -3,7 +3,6 @@
3
3
  require "fusuma/plugin/appmatcher/version"
4
4
 
5
5
  require "fusuma/plugin/appmatcher/x11"
6
- require "fusuma/plugin/appmatcher/gnome"
7
6
  require "fusuma/plugin/appmatcher/gnome_extension"
8
7
  require "fusuma/plugin/appmatcher/gnome_extensions/installer"
9
8
  require "fusuma/plugin/appmatcher/unsupported_backend"
@@ -22,12 +21,19 @@ module Fusuma
22
21
  when /wayland/
23
22
  case xdg_current_desktop
24
23
  when /GNOME/
25
- return GnomeExtension if GnomeExtensions::Installer.new.installed?
26
-
27
- return Gnome
24
+ if GnomeExtensions::Installer.new.enabled?
25
+ return GnomeExtension
26
+ else
27
+ MultiLogger.warn "Appmatcher Gnome Shell Extension is NOT enabled"
28
+ MultiLogger.warn "Please enable it by running the following command:"
29
+ MultiLogger.warn ""
30
+ MultiLogger.warn "$ fusuma-appmatcher --install-gnome-extension"
31
+ MultiLogger.warn ""
32
+ end
28
33
  end
29
34
  end
30
35
 
36
+ MultiLogger.warn "appmatcher doesn't support"
31
37
  UnsupportedBackend
32
38
  end
33
39
 
@@ -7,20 +7,16 @@ module Fusuma
7
7
  module Inputs
8
8
  # Get active application's name
9
9
  class AppmatcherInput < Input
10
- attr_reader :pid
11
-
12
10
  def io
13
- @backend ||= Appmatcher.backend_klass.new
11
+ return @io if instance_variable_defined?(:@io)
14
12
 
15
- @pid ||= begin
16
- pid = @backend.watch_start
17
- # NOTE: Closing the parent process's pipe
18
- @backend.writer.close
13
+ @backend = Appmatcher.backend_klass.new
19
14
 
20
- pid
21
- end
15
+ @backend.watch_start
16
+ # NOTE: Closing the parent process's pipe
17
+ @backend.writer.close
22
18
 
23
- @backend.reader
19
+ @io = @backend.reader
24
20
  end
25
21
 
26
22
  def shutdown
@@ -28,6 +24,7 @@ module Fusuma
28
24
  @backend.shutdown
29
25
  end
30
26
 
27
+ # TODO: use read_from_io
31
28
  # @param record [String] application name
32
29
  # @return [Event]
33
30
  def create_event(record:)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma-plugin-appmatcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-03 00:00:00.000000000 Z
11
+ date: 2025-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rexml
@@ -68,7 +68,6 @@ files:
68
68
  - exe/fusuma-appmatcher
69
69
  - fusuma-plugin-appmatcher.gemspec
70
70
  - lib/fusuma/plugin/appmatcher.rb
71
- - lib/fusuma/plugin/appmatcher/gnome.rb
72
71
  - lib/fusuma/plugin/appmatcher/gnome_extension.rb
73
72
  - lib/fusuma/plugin/appmatcher/gnome_extensions/appmatcher45@iberianpig.dev/extension.js
74
73
  - lib/fusuma/plugin/appmatcher/gnome_extensions/appmatcher45@iberianpig.dev/metadata.json
@@ -88,7 +87,7 @@ licenses:
88
87
  - MIT
89
88
  metadata:
90
89
  rubygems_mfa_required: 'true'
91
- post_install_message:
90
+ post_install_message:
92
91
  rdoc_options: []
93
92
  require_paths:
94
93
  - lib
@@ -103,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
102
  - !ruby/object:Gem::Version
104
103
  version: '0'
105
104
  requirements: []
106
- rubygems_version: 3.4.10
107
- signing_key:
105
+ rubygems_version: 3.4.19
106
+ signing_key:
108
107
  specification_version: 4
109
108
  summary: Fusuma plugin to assign gesture mapping per application
110
109
  test_files: []
@@ -1,128 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "json"
4
- require "dbus"
5
- require_relative "user_switcher"
6
-
7
- module Fusuma
8
- module Plugin
9
- module Appmatcher
10
- # Search Active Window's Name
11
- class Gnome
12
- include UserSwitcher
13
-
14
- attr_reader :reader, :writer
15
-
16
- def initialize
17
- @reader, @writer = IO.pipe
18
- end
19
-
20
- # fork process and watch signal
21
- # @return [Integer] Process id
22
- def watch_start
23
- @watch_start ||= begin
24
- pid = as_user(proctitle: self.class.name.underscore) do |user|
25
- @reader.close
26
- ENV["DBUS_SESSION_BUS_ADDRESS"] = "unix:path=/run/user/#{user.uid}/bus"
27
- register_on_application_changed(Matcher.new)
28
- end
29
- pid
30
- end
31
- end
32
-
33
- private
34
-
35
- def register_on_application_changed(matcher)
36
- matcher.on_active_application_changed do |name|
37
- notify(name)
38
- end
39
- end
40
-
41
- def notify(name)
42
- @writer.puts(name)
43
- rescue Errno::EPIPE
44
- exit 0
45
- rescue => e
46
- MultiLogger.error e.message
47
- exit 1
48
- end
49
-
50
- # Look up application name using dbus
51
- class Matcher
52
- def initialize
53
- session_bus = DBus.session_bus
54
- service = session_bus.service("org.gnome.Shell")
55
- @interface = service["/org/gnome/Shell"]["org.gnome.Shell"]
56
- rescue DBus::Error => e
57
- MultiLogger.error "DBus::Error: #{e.message}"
58
-
59
- exit 1
60
- end
61
-
62
- # @return [Array<Application>]
63
- def running_applications
64
- gnome_shell_eval(
65
- <<~GJS
66
- global.get_window_actors().map(a => a.get_meta_window().get_wm_class());
67
- GJS
68
- )
69
- end
70
-
71
- def active_application
72
- # const index = global.get_window_actors()
73
- # .findIndex(a=>a.meta_window.has_focus()===true);
74
- # global.get_window_actors()[index].get_meta_window().get_wm_class();
75
- gnome_shell_eval(
76
- <<~GJS
77
- const actor = global.get_window_actors().find(a=>a.meta_window.has_focus()===true)
78
- actor && actor.get_meta_window().get_wm_class()
79
- GJS
80
- )
81
- end
82
-
83
- # TODO
84
- # def window_title
85
- # # const index = global.get_window_actors()
86
- # # .findIndex(a=>a.meta_window.has_focus()===true);
87
- # # global.get_window_actors()[index].get_meta_window().get_title();
88
- # gnome_shell_eval(
89
- # # <<~GJS
90
- # # global.get_window_actors().map((current) => {
91
- # # const wm_class = current.get_meta_window().get_wm_class();
92
- # # const title = current.get_meta_window().get_title();
93
- # # return { application: wm_class, window_title: title }
94
- # # })
95
- # # GJS
96
- # )
97
- # end
98
-
99
- def gnome_shell_eval(string)
100
- success, body = @interface.Eval(string)
101
-
102
- if success
103
- response = begin
104
- JSON.parse(body)
105
- rescue
106
- nil
107
- end
108
- return response
109
- end
110
-
111
- raise body
112
- end
113
-
114
- def on_active_application_changed
115
- loop do
116
- sleep 0.5
117
- new_application = active_application
118
- next if @old_application == new_application
119
-
120
- yield(new_application || "NOT FOUND") if block_given?
121
- @old_application = new_application
122
- end
123
- end
124
- end
125
- end
126
- end
127
- end
128
- end