fusuma-plugin-appmatcher 0.1.0.pre → 0.1.0.pre2
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 +4 -4
- data/fusuma-plugin-appmatcher.gemspec +1 -1
- data/lib/fusuma/plugin/appmatcher.rb +4 -4
- data/lib/fusuma/plugin/appmatcher/gnome.rb +31 -16
- data/lib/fusuma/plugin/appmatcher/user_switcher.rb +3 -0
- data/lib/fusuma/plugin/appmatcher/version.rb +1 -1
- data/lib/fusuma/plugin/appmatcher/x11.rb +26 -16
- data/lib/fusuma/plugin/detectors/appmatcher_detector.rb +10 -16
- data/lib/fusuma/plugin/inputs/appmatcher_input.rb +2 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c82fbaea367e1b416873bfda4fd07e6c33ca726403a7d1200dfd6351a1f92f70
|
4
|
+
data.tar.gz: e22437189f3f762f636507fc5eeba5304f28e8e59168a81fb12ec6e18da82589
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4f83d6928f08ecd382a6beda34478e83912e4fe964e9578fc3f531595c175c90ae116b087e5288ecf65bbdab805faee6b938830a29d4f6555df903098a44639
|
7
|
+
data.tar.gz: c518fabd2584b692448225179ed2808eb9b91b989b8bf937902f6c4a80ebb1deeaf56ce51c88b48799910656a8f6644b61a577cc9e58ee50538fe75689521c36
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'fusuma/plugin/appmatcher/version'
|
4
4
|
|
5
|
-
require_relative 'appmatcher/x11
|
6
|
-
require_relative 'appmatcher/gnome
|
5
|
+
require_relative 'appmatcher/x11'
|
6
|
+
require_relative 'appmatcher/gnome'
|
7
7
|
|
8
8
|
module Fusuma
|
9
9
|
module Plugin
|
@@ -13,9 +13,9 @@ module Fusuma
|
|
13
13
|
# @return [Class]
|
14
14
|
def backend_klass
|
15
15
|
if ENV['DESKTOP_SESSION'] == 'ubuntu-wayland'
|
16
|
-
|
16
|
+
Gnome
|
17
17
|
else
|
18
|
-
|
18
|
+
X11
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'dbus'
|
5
|
-
require_relative './user_switcher
|
5
|
+
require_relative './user_switcher'
|
6
6
|
require 'posix/spawn'
|
7
7
|
|
8
8
|
module Fusuma
|
@@ -10,9 +10,8 @@ module Fusuma
|
|
10
10
|
module Appmatcher
|
11
11
|
# Search Active Window's Name
|
12
12
|
class Gnome
|
13
|
-
attr_reader :matcher
|
14
|
-
|
15
|
-
attr_reader :writer
|
13
|
+
attr_reader :matcher, :reader, :writer
|
14
|
+
|
16
15
|
def initialize
|
17
16
|
@reader, @writer = IO.pipe
|
18
17
|
end
|
@@ -21,14 +20,14 @@ module Fusuma
|
|
21
20
|
# @return [Integer] Process id
|
22
21
|
def watch_start
|
23
22
|
@watch_start ||= begin
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
pid = UserSwitcher.new.as_user 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)
|
27
|
+
end
|
28
|
+
Process.detach(pid)
|
29
|
+
pid
|
30
|
+
end
|
32
31
|
end
|
33
32
|
|
34
33
|
private
|
@@ -81,15 +80,31 @@ module Fusuma
|
|
81
80
|
)
|
82
81
|
end
|
83
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
|
+
|
84
99
|
def gnome_shell_eval(string)
|
85
100
|
success, body = @interface.Eval(string)
|
86
101
|
|
87
102
|
if success
|
88
103
|
response = begin
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
104
|
+
JSON.parse(body)
|
105
|
+
rescue StandardError
|
106
|
+
nil
|
107
|
+
end
|
93
108
|
return response
|
94
109
|
end
|
95
110
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'fusuma/custom_process'
|
3
4
|
require 'etc'
|
5
|
+
|
4
6
|
module Fusuma
|
5
7
|
module Plugin
|
6
8
|
module Appmatcher
|
7
9
|
class UserSwitcher
|
10
|
+
include CustomProcess
|
8
11
|
User = Struct.new(:username, :uid, :gid)
|
9
12
|
def initialize
|
10
13
|
username = ENV['SUDO_USER'] || Etc.getlogin
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative './user_switcher
|
3
|
+
require_relative './user_switcher'
|
4
|
+
require 'fusuma/multi_logger'
|
5
|
+
require 'fusuma/custom_process'
|
4
6
|
require 'posix/spawn'
|
5
7
|
|
6
8
|
module Fusuma
|
@@ -8,9 +10,8 @@ module Fusuma
|
|
8
10
|
module Appmatcher
|
9
11
|
# Search Active Window's Name
|
10
12
|
class X11
|
11
|
-
attr_reader :matcher
|
12
|
-
|
13
|
-
attr_reader :writer
|
13
|
+
attr_reader :matcher, :reader, :writer
|
14
|
+
|
14
15
|
def initialize
|
15
16
|
@reader, @writer = IO.pipe
|
16
17
|
end
|
@@ -19,13 +20,13 @@ module Fusuma
|
|
19
20
|
# @return [Integer] Process id
|
20
21
|
def watch_start
|
21
22
|
@watch_start ||= begin
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
pid = UserSwitcher.new.as_user do |_user|
|
24
|
+
@reader.close
|
25
|
+
register_on_application_changed(Matcher.new)
|
26
|
+
end
|
27
|
+
Process.detach(pid)
|
28
|
+
pid
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
32
|
private
|
@@ -59,10 +60,10 @@ module Fusuma
|
|
59
60
|
def active_application(id = active_window_id)
|
60
61
|
@cache ||= {}
|
61
62
|
@cache[id] ||= begin
|
62
|
-
|
63
|
+
return if id.nil?
|
63
64
|
|
64
|
-
|
65
|
-
|
65
|
+
`xprop -id #{id} WM_CLASS | cut -d "=" -f 2 | tr -d '"'`.strip.split(', ').last
|
66
|
+
end
|
66
67
|
end
|
67
68
|
|
68
69
|
def on_active_application_changed
|
@@ -73,8 +74,8 @@ module Fusuma
|
|
73
74
|
|
74
75
|
private
|
75
76
|
|
76
|
-
def active_window_id(watch: false)
|
77
|
-
_p, i, o,
|
77
|
+
def active_window_id(watch: false, &block)
|
78
|
+
_p, i, o, e = POSIX::Spawn.popen4(xprop_active_window_id(watch))
|
78
79
|
i.close
|
79
80
|
o.each do |line|
|
80
81
|
id = line.match(/0x[\da-z]{2,}/)&.to_s
|
@@ -83,6 +84,15 @@ module Fusuma
|
|
83
84
|
|
84
85
|
yield(id)
|
85
86
|
end
|
87
|
+
MultiLogger.error e.read if o.eof?
|
88
|
+
e.close
|
89
|
+
o.close
|
90
|
+
|
91
|
+
return nil unless block_given?
|
92
|
+
sleep 1
|
93
|
+
active_window_id(watch: watch, &block)
|
94
|
+
rescue StandardError => e
|
95
|
+
MultiLogger.error e.message
|
86
96
|
end
|
87
97
|
|
88
98
|
# @param spy [TrueClass, FalseClass]
|
@@ -5,10 +5,15 @@ module Fusuma
|
|
5
5
|
module Detectors
|
6
6
|
# Detect KeypressEvent from KeypressBuffer
|
7
7
|
class AppmatcherDetector < Detector
|
8
|
+
SOURCES = ['appmatcher']
|
8
9
|
BUFFER_TYPE = 'appmatcher'
|
9
|
-
|
10
10
|
DEFAULT_NAME = 'global'
|
11
11
|
|
12
|
+
# Always watch buffers and detect them.
|
13
|
+
def watch?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
12
17
|
# @param buffers [Array<Event>]
|
13
18
|
# @return [Event] if event is detected
|
14
19
|
# @return [NilClass] if event is NOT detected
|
@@ -19,23 +24,12 @@ module Fusuma
|
|
19
24
|
|
20
25
|
record = buffer.events.last.record
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
context_record = Events::Records::ContextRecord.new(
|
28
|
+
name: 'application',
|
29
|
+
value: record.name
|
25
30
|
)
|
26
31
|
|
27
|
-
create_event(record:
|
28
|
-
end
|
29
|
-
|
30
|
-
# @param record [Events::Records::KeypressRecord]
|
31
|
-
# @return [Config::Index]
|
32
|
-
def create_index(record:)
|
33
|
-
Config::Index.new(
|
34
|
-
[
|
35
|
-
Config::Index::Key.new('application'),
|
36
|
-
Config::Index::Key.new(record.name, fallback: DEFAULT_NAME)
|
37
|
-
]
|
38
|
-
)
|
32
|
+
create_event(record: context_record)
|
39
33
|
end
|
40
34
|
end
|
41
35
|
end
|
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.1.0.
|
4
|
+
version: 0.1.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iberianpig
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iniparse
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.0.0.
|
47
|
+
version: 2.0.0.pre2
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.0.0.
|
54
|
+
version: 2.0.0.pre2
|
55
55
|
description: fusuma-plugin-appmatcher is Fusuma plugin for assigning gesture mapping
|
56
56
|
per application.
|
57
57
|
email:
|