fusuma-plugin-appmatcher 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +15 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/fusuma-appmatcher +33 -0
- data/fusuma-plugin-appmatcher.gemspec +31 -0
- data/lib/fusuma/plugin/appmatcher.rb +23 -0
- data/lib/fusuma/plugin/appmatcher/gnome.rb +113 -0
- data/lib/fusuma/plugin/appmatcher/user_switcher.rb +35 -0
- data/lib/fusuma/plugin/appmatcher/version.rb +9 -0
- data/lib/fusuma/plugin/appmatcher/x11.rb +98 -0
- data/lib/fusuma/plugin/buffers/appmatcher_buffer.rb +27 -0
- data/lib/fusuma/plugin/detectors/appmatcher_detector.rb +43 -0
- data/lib/fusuma/plugin/events/records/appmatcher_record.rb +19 -0
- data/lib/fusuma/plugin/inputs/appmatcher_input.rb +26 -0
- data/lib/fusuma/plugin/parsers/appmatcher_parser.rb +19 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aeb9cfe042862f7392b652a15b08b740642f825e1bc38b6bda069cd8656c6e90
|
4
|
+
data.tar.gz: a0edcc9bb643eec52dc29a2b47b7aac42d13ade082ac56125db2956d8a4120ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66486ba4e8dd2490181eb39b601be0e0240abc580536128f77e92e8644f9e0b1d0f9164635d616f15fa0418a9ca2507808309d703cef6dbeeb3f8f3faf4c2695
|
7
|
+
data.tar.gz: c4496554408febea8bcf250033594db3f7ebe65d85cd514a85f7ee85dfc0ea8edef0d632547c7b7c38f5fe5378f5bf31e7265d4dcebb8703f600e50f853f915e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at yhkyky@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in fusuma-plugin-appmatcher.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'bundler', '~> 2.0'
|
9
|
+
gem 'github_changelog_generator', '~> 1.14'
|
10
|
+
gem 'lefthook'
|
11
|
+
gem 'pry-byebug', '~> 3.4'
|
12
|
+
gem 'pry-doc'
|
13
|
+
gem 'pry-inline'
|
14
|
+
gem 'rake', '~> 13.0'
|
15
|
+
gem 'reek'
|
16
|
+
gem 'rspec', '~> 3.0'
|
17
|
+
gem 'rubocop'
|
18
|
+
gem 'yard'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 iberianpig
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# Fusuma::Plugin::Appmatcher [![Gem Version](https://badge.fury.io/rb/fusuma-plugin-appmatcher.svg)](https://badge.fury.io/rb/fusuma-plugin-appmatcher) [![Build Status](https://travis-ci.com/iberianpig/fusuma-plugin-appmatcher.svg?branch=master)](https://travis-ci.com/iberianpig/fusuma-plugin-appmatcher)
|
2
|
+
|
3
|
+
[Fusuma](https://github.com/iberianpig/fusuma) plugin configure per application
|
4
|
+
|
5
|
+
* Switch gesture mappings by detecting active application.
|
6
|
+
* Support X11, Ubuntu-Wayland
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Run the following code in your terminal.
|
12
|
+
|
13
|
+
### Install fusuma-plugin-appmatcher
|
14
|
+
|
15
|
+
```sh
|
16
|
+
$ sudo gem install fusuma-plugin-appmatcher
|
17
|
+
```
|
18
|
+
|
19
|
+
## List Running Application names
|
20
|
+
|
21
|
+
`$ fusuma-appmatcher -l` prints Running Application names.
|
22
|
+
|
23
|
+
```sh
|
24
|
+
$ fusuma-appmatcher -l
|
25
|
+
Slack
|
26
|
+
Google-chrome
|
27
|
+
Alacritty
|
28
|
+
```
|
29
|
+
|
30
|
+
You can use these applicatin name to under `application:` section in config.yml
|
31
|
+
|
32
|
+
## Add appmatcher properties and application names to config.yml
|
33
|
+
|
34
|
+
Add `appmatcher:` property in `~/.config/fusuma/config.yml`.
|
35
|
+
|
36
|
+
lines beginning from `#` are comments
|
37
|
+
|
38
|
+
### Add `application:` property
|
39
|
+
|
40
|
+
* Set the `application:` property in the root of config.yml.
|
41
|
+
|
42
|
+
* Under the `application:` property, you can set the `application name` as a property.
|
43
|
+
* For example, you can set `:Google-chrome`, `:Alacritty`, `Org.gnome.Nautilus`, and so on.
|
44
|
+
* You can find property name's hint, with `$ fusuma-appmatcher -l`
|
45
|
+
* If set `global:` as the `application name`, it is used as default configuration.
|
46
|
+
|
47
|
+
### Example
|
48
|
+
|
49
|
+
* Move the existing `swipe` or `pinch` sections in config.yml under `application:` > `Global:`.
|
50
|
+
|
51
|
+
```diff
|
52
|
+
- swipe:
|
53
|
+
- 4:
|
54
|
+
- up:
|
55
|
+
- sendkey: 'LEFTCTRL+LEFTALT+DOWN'
|
56
|
+
- keypress:
|
57
|
+
- LEFTSHIFT:
|
58
|
+
- sendkey: 'LEFTSHIFT+LEFTCTRL+LEFTALT+DOWN'
|
59
|
+
- down:
|
60
|
+
- sendkey: 'LEFTCTRL+LEFTALT+UP'
|
61
|
+
- LEFTSHIFT:
|
62
|
+
- sendkey: 'LEFTSHIFT+LEFTCTRL+LEFTALT+UP'
|
63
|
+
+ application:
|
64
|
+
+ Global:
|
65
|
+
+ swipe:
|
66
|
+
+ 4:
|
67
|
+
+ up:
|
68
|
+
+ sendkey: 'LEFTCTRL+LEFTALT+DOWN'
|
69
|
+
+ keypress:
|
70
|
+
+ LEFTSHIFT:
|
71
|
+
+ sendkey: 'LEFTSHIFT+LEFTCTRL+LEFTALT+DOWN'
|
72
|
+
+ down:
|
73
|
+
+ sendkey: 'LEFTCTRL+LEFTALT+UP'
|
74
|
+
+ LEFTSHIFT:
|
75
|
+
+ sendkey: 'LEFTSHIFT+LEFTCTRL+LEFTALT+UP'
|
76
|
+
+ Google-chrome:
|
77
|
+
+ swipe:
|
78
|
+
+ 3:
|
79
|
+
+ left:
|
80
|
+
+ sendkey: 'LEFTALT+RIGHT'
|
81
|
+
+ right:
|
82
|
+
+ sendkey: 'LEFTALT+LEFT'
|
83
|
+
+ up:
|
84
|
+
+ sendkey: 'LEFTCTRL+T'
|
85
|
+
+ down:
|
86
|
+
+ sendkey: 'LEFTCTRL+W'
|
87
|
+
+ Alacritty:
|
88
|
+
+ swipe:
|
89
|
+
+ 3:
|
90
|
+
+ up:
|
91
|
+
+ window: {fullscreen: 'add'}
|
92
|
+
+ down:
|
93
|
+
+ window: {fullscreen: 'remove'}
|
94
|
+
```
|
95
|
+
|
96
|
+
### TODO
|
97
|
+
|
98
|
+
* [ ] Support Threshold / Interval Settings
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/iberianpig/fusuma-plugin-appmatcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
103
|
+
|
104
|
+
## License
|
105
|
+
|
106
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
107
|
+
|
108
|
+
## Code of Conduct
|
109
|
+
|
110
|
+
Everyone interacting in the Fusuma::Plugin::Appmatcher project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/iberianpig/fusuma-plugin-appmatcher/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
task default: :spec
|
9
|
+
|
10
|
+
require 'github_changelog_generator/task'
|
11
|
+
|
12
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
13
|
+
config.user = 'iberianpig'
|
14
|
+
config.project = 'fusuma-plugin-appmatcher'
|
15
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'fusuma/plugin/appmatcher'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require_relative '../lib/fusuma/plugin/appmatcher.rb'
|
6
|
+
|
7
|
+
option = {}
|
8
|
+
opt = OptionParser.new
|
9
|
+
|
10
|
+
opt.on('-l', '--list-applications',
|
11
|
+
'List applications') do |v|
|
12
|
+
option[:list] = v
|
13
|
+
end
|
14
|
+
|
15
|
+
opt.on('--version', 'Show version') do |v|
|
16
|
+
option[:version] = v
|
17
|
+
end
|
18
|
+
|
19
|
+
opt.parse!(ARGV)
|
20
|
+
|
21
|
+
if option[:list]
|
22
|
+
matcher = Fusuma::Plugin::Appmatcher.backend_klass::Matcher.new
|
23
|
+
puts matcher.running_applications
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
if option[:version]
|
28
|
+
puts Fusuma::Plugin::Appmatcher::VERSION
|
29
|
+
return
|
30
|
+
end
|
31
|
+
|
32
|
+
matcher = Fusuma::Plugin::Appmatcher.backend_klass::Matcher.new
|
33
|
+
puts matcher.active_application
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'fusuma/plugin/appmatcher/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'fusuma-plugin-appmatcher'
|
9
|
+
spec.version = Fusuma::Plugin::Appmatcher::VERSION
|
10
|
+
spec.authors = ['iberianpig']
|
11
|
+
spec.email = ['yhkyky@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Fusuma plugin to assign gesture mapping per application'
|
14
|
+
spec.description = 'fusuma-plugin-appmatcher is Fusuma plugin for assigning gesture mapping per application.'
|
15
|
+
spec.homepage = 'https://github.com/iberianpig/fusuma-plugin-appmatcher'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'iniparse'
|
28
|
+
spec.add_runtime_dependency 'ruby-dbus'
|
29
|
+
|
30
|
+
spec.add_dependency 'fusuma', '~> 2.0.0.pre'
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fusuma/plugin/appmatcher/version'
|
4
|
+
|
5
|
+
require_relative 'appmatcher/x11.rb'
|
6
|
+
require_relative 'appmatcher/gnome.rb'
|
7
|
+
|
8
|
+
module Fusuma
|
9
|
+
module Plugin
|
10
|
+
module Appmatcher
|
11
|
+
module_function
|
12
|
+
|
13
|
+
# @return [Class]
|
14
|
+
def backend_klass
|
15
|
+
if ENV['DESKTOP_SESSION'] == 'ubuntu-wayland'
|
16
|
+
Fusuma::Plugin::Appmatcher::Gnome
|
17
|
+
else
|
18
|
+
Fusuma::Plugin::Appmatcher::X11
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'dbus'
|
5
|
+
require_relative './user_switcher.rb'
|
6
|
+
require 'posix/spawn'
|
7
|
+
|
8
|
+
module Fusuma
|
9
|
+
module Plugin
|
10
|
+
module Appmatcher
|
11
|
+
# Search Active Window's Name
|
12
|
+
class Gnome
|
13
|
+
attr_reader :matcher
|
14
|
+
attr_reader :reader
|
15
|
+
attr_reader :writer
|
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 = UserSwitcher.new.as_user 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
|
+
Process.detach(pid)
|
30
|
+
pid
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def register_on_application_changed(matcher)
|
37
|
+
matcher.on_active_application_changed do |name|
|
38
|
+
notify(name)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def notify(name)
|
43
|
+
@writer.puts(name)
|
44
|
+
rescue Errno::EPIPE
|
45
|
+
exit 0
|
46
|
+
rescue StandardError => e
|
47
|
+
MultiLogger.error e.message
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
|
51
|
+
# Look up application name using dbus
|
52
|
+
class Matcher
|
53
|
+
def initialize
|
54
|
+
session_bus = DBus.session_bus
|
55
|
+
service = session_bus.service('org.gnome.Shell')
|
56
|
+
@interface = service['/org/gnome/Shell']['org.gnome.Shell']
|
57
|
+
rescue DBus::Error => e
|
58
|
+
MultiLogger.error "DBus::Error: #{e.message}"
|
59
|
+
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Array<Application>]
|
64
|
+
def running_applications
|
65
|
+
gnome_shell_eval(
|
66
|
+
<<~GJS
|
67
|
+
global.get_window_actors().map(a => a.get_meta_window().get_wm_class());
|
68
|
+
GJS
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def active_application
|
73
|
+
# const index = global.get_window_actors()
|
74
|
+
# .findIndex(a=>a.meta_window.has_focus()===true);
|
75
|
+
# global.get_window_actors()[index].get_meta_window().get_wm_class();
|
76
|
+
gnome_shell_eval(
|
77
|
+
<<~GJS
|
78
|
+
const actor = global.get_window_actors().find(a=>a.meta_window.has_focus()===true)
|
79
|
+
actor && actor.get_meta_window().get_wm_class()
|
80
|
+
GJS
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def gnome_shell_eval(string)
|
85
|
+
success, body = @interface.Eval(string)
|
86
|
+
|
87
|
+
if success
|
88
|
+
response = begin
|
89
|
+
JSON.parse(body)
|
90
|
+
rescue StandardError
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
return response
|
94
|
+
end
|
95
|
+
|
96
|
+
raise body
|
97
|
+
end
|
98
|
+
|
99
|
+
def on_active_application_changed
|
100
|
+
loop do
|
101
|
+
sleep 0.5
|
102
|
+
new_application = active_application
|
103
|
+
next if @old_application == new_application
|
104
|
+
|
105
|
+
yield(new_application || 'NOT FOUND') if block_given?
|
106
|
+
@old_application = new_application
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'etc'
|
4
|
+
module Fusuma
|
5
|
+
module Plugin
|
6
|
+
module Appmatcher
|
7
|
+
class UserSwitcher
|
8
|
+
User = Struct.new(:username, :uid, :gid)
|
9
|
+
def initialize
|
10
|
+
username = ENV['SUDO_USER'] || Etc.getlogin
|
11
|
+
uid = `id -u #{username}`.chomp.to_i
|
12
|
+
gid = `id -g #{username}`.chomp.to_i
|
13
|
+
@login_user = User.new(username, uid, gid)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Drops privileges to that of the specified user
|
17
|
+
def drop_priv(user)
|
18
|
+
# Process.initgroups(user.username, user.gid)
|
19
|
+
Process::Sys.setegid(user.gid)
|
20
|
+
Process::Sys.setgid(user.gid)
|
21
|
+
Process::Sys.setuid(user.uid)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Execute the provided block in a child process as the specified user
|
25
|
+
# The parent blocks until the child finishes.
|
26
|
+
def as_user(user = @login_user)
|
27
|
+
fork do
|
28
|
+
drop_priv(user)
|
29
|
+
yield(user) if block_given?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './user_switcher.rb'
|
4
|
+
require 'posix/spawn'
|
5
|
+
|
6
|
+
module Fusuma
|
7
|
+
module Plugin
|
8
|
+
module Appmatcher
|
9
|
+
# Search Active Window's Name
|
10
|
+
class X11
|
11
|
+
attr_reader :matcher
|
12
|
+
attr_reader :reader
|
13
|
+
attr_reader :writer
|
14
|
+
def initialize
|
15
|
+
@reader, @writer = IO.pipe
|
16
|
+
end
|
17
|
+
|
18
|
+
# fork process and watch signal
|
19
|
+
# @return [Integer] Process id
|
20
|
+
def watch_start
|
21
|
+
@watch_start ||= begin
|
22
|
+
pid = UserSwitcher.new.as_user do |_user|
|
23
|
+
@reader.close
|
24
|
+
register_on_application_changed(Matcher.new)
|
25
|
+
end
|
26
|
+
Process.detach(pid)
|
27
|
+
pid
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def register_on_application_changed(matcher)
|
34
|
+
matcher.on_active_application_changed do |name|
|
35
|
+
notify(name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def notify(name)
|
40
|
+
@writer.puts(name)
|
41
|
+
rescue Errno::EPIPE
|
42
|
+
exit 0
|
43
|
+
rescue StandardError => e
|
44
|
+
MultiLogger.error e.message
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
# Look up application name using xprop
|
49
|
+
class Matcher
|
50
|
+
# @return [Array<String>]
|
51
|
+
def running_applications
|
52
|
+
`xprop -root _NET_CLIENT_LIST_STACKING`.split(', ')
|
53
|
+
.map { |id_str| id_str.match(/0x[\da-z]{2,}/).to_s }
|
54
|
+
.map { |id| active_application(id) }
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [String]
|
58
|
+
# @return [NilClass]
|
59
|
+
def active_application(id = active_window_id)
|
60
|
+
@cache ||= {}
|
61
|
+
@cache[id] ||= begin
|
62
|
+
return if id.nil?
|
63
|
+
|
64
|
+
`xprop -id #{id} WM_CLASS | cut -d "=" -f 2 | tr -d '"'`.strip.split(', ').last
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def on_active_application_changed
|
69
|
+
active_window_id(watch: true) do |id|
|
70
|
+
yield(active_application(id) || 'NOT FOUND')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def active_window_id(watch: false)
|
77
|
+
_p, i, o, _e = POSIX::Spawn.popen4(xprop_active_window_id(watch))
|
78
|
+
i.close
|
79
|
+
o.each do |line|
|
80
|
+
id = line.match(/0x[\da-z]{2,}/)&.to_s
|
81
|
+
|
82
|
+
return id unless block_given?
|
83
|
+
|
84
|
+
yield(id)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# @param spy [TrueClass, FalseClass]
|
89
|
+
# @return [String]
|
90
|
+
def xprop_active_window_id(spy)
|
91
|
+
spy_option = '-spy' if spy
|
92
|
+
"xprop #{spy_option} -root _NET_ACTIVE_WINDOW"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fusuma
|
4
|
+
module Plugin
|
5
|
+
module Buffers
|
6
|
+
# Buffer events having KeypressRecord
|
7
|
+
class AppmatcherBuffer < Buffer
|
8
|
+
DEFAULT_SOURCE = 'appmatcher_parser'
|
9
|
+
|
10
|
+
# @param event [Event]
|
11
|
+
def buffer(event)
|
12
|
+
return if event&.tag != source
|
13
|
+
|
14
|
+
@events.push(event)
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear_expired(*)
|
18
|
+
@events = [@events.last] if @events.size > 100
|
19
|
+
end
|
20
|
+
|
21
|
+
def empty?
|
22
|
+
@events.empty?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fusuma
|
4
|
+
module Plugin
|
5
|
+
module Detectors
|
6
|
+
# Detect KeypressEvent from KeypressBuffer
|
7
|
+
class AppmatcherDetector < Detector
|
8
|
+
BUFFER_TYPE = 'appmatcher'
|
9
|
+
|
10
|
+
DEFAULT_NAME = 'global'
|
11
|
+
|
12
|
+
# @param buffers [Array<Event>]
|
13
|
+
# @return [Event] if event is detected
|
14
|
+
# @return [NilClass] if event is NOT detected
|
15
|
+
def detect(buffers)
|
16
|
+
buffer = buffers.find { |b| b.type == BUFFER_TYPE }
|
17
|
+
|
18
|
+
return if buffer.empty?
|
19
|
+
|
20
|
+
record = buffer.events.last.record
|
21
|
+
|
22
|
+
index_record = Events::Records::IndexRecord.new(
|
23
|
+
index: create_index(record: record),
|
24
|
+
position: :prefix
|
25
|
+
)
|
26
|
+
|
27
|
+
create_event(record: index_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
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fusuma
|
4
|
+
module Plugin
|
5
|
+
module Events
|
6
|
+
module Records
|
7
|
+
# Record for Keypress event
|
8
|
+
class AppmatcherRecord < Record
|
9
|
+
attr_reader :name
|
10
|
+
|
11
|
+
# @param status [String]
|
12
|
+
def initialize(name:)
|
13
|
+
@name = name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../appmatcher.rb'
|
4
|
+
|
5
|
+
module Fusuma
|
6
|
+
module Plugin
|
7
|
+
module Inputs
|
8
|
+
# Get active application's name
|
9
|
+
class AppmatcherInput < Input
|
10
|
+
def io
|
11
|
+
@backend ||= Appmatcher.backend_klass.new
|
12
|
+
|
13
|
+
@pid ||= begin
|
14
|
+
pid = @backend.watch_start
|
15
|
+
# NOTE: Closing the parent process's pipe
|
16
|
+
@backend.writer.close
|
17
|
+
|
18
|
+
pid
|
19
|
+
end
|
20
|
+
|
21
|
+
@backend.reader
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fusuma
|
4
|
+
module Plugin
|
5
|
+
module Parsers
|
6
|
+
# Generate AppmatcherRecord from libinput_command_input
|
7
|
+
class AppmatcherParser < Parser
|
8
|
+
DEFAULT_SOURCE = 'appmatcher_input'
|
9
|
+
|
10
|
+
# @param record [String]
|
11
|
+
# @return [Records::Gesture, nil]
|
12
|
+
def parse_record(record)
|
13
|
+
line = record.to_s
|
14
|
+
Events::Records::AppmatcherRecord.new(name: line)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fusuma-plugin-appmatcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- iberianpig
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: iniparse
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-dbus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fusuma
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.0.pre
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.0.pre
|
55
|
+
description: fusuma-plugin-appmatcher is Fusuma plugin for assigning gesture mapping
|
56
|
+
per application.
|
57
|
+
email:
|
58
|
+
- yhkyky@gmail.com
|
59
|
+
executables:
|
60
|
+
- fusuma-appmatcher
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CODE_OF_CONDUCT.md
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- exe/fusuma-appmatcher
|
75
|
+
- fusuma-plugin-appmatcher.gemspec
|
76
|
+
- lib/fusuma/plugin/appmatcher.rb
|
77
|
+
- lib/fusuma/plugin/appmatcher/gnome.rb
|
78
|
+
- lib/fusuma/plugin/appmatcher/user_switcher.rb
|
79
|
+
- lib/fusuma/plugin/appmatcher/version.rb
|
80
|
+
- lib/fusuma/plugin/appmatcher/x11.rb
|
81
|
+
- lib/fusuma/plugin/buffers/appmatcher_buffer.rb
|
82
|
+
- lib/fusuma/plugin/detectors/appmatcher_detector.rb
|
83
|
+
- lib/fusuma/plugin/events/records/appmatcher_record.rb
|
84
|
+
- lib/fusuma/plugin/inputs/appmatcher_input.rb
|
85
|
+
- lib/fusuma/plugin/parsers/appmatcher_parser.rb
|
86
|
+
homepage: https://github.com/iberianpig/fusuma-plugin-appmatcher
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.3.1
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.1.4
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Fusuma plugin to assign gesture mapping per application
|
109
|
+
test_files: []
|