uh-wm 0.0.9 → 0.0.10
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/README.md +15 -15
- data/lib/uh/wm/actions_handler.rb +39 -8
- data/lib/uh/wm/run_control.rb +71 -8
- data/lib/uh/wm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 304d345d72ebfed7045a3ac0cd0bdb58fe8fbd31
|
4
|
+
data.tar.gz: cb5379acb77ac283dbb0f28b27e4e93fe9e13b5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdc8985073e35f6d54f1d627e0233ab0ebdad4cfe25ce0baf8d7b1847083f942fc91fbf9e36ee4bac812f489df4bc190660d947bcdcf8e6f5454380376363897
|
7
|
+
data.tar.gz: a69f26be2e7bfd9781222840f0bec1508d962f7fc192e2b5908718dd496f7a996827cee6f6abc92b2639e173766b7a10164772cd8d6f221ba2966cc79a52bc09
|
data/README.md
CHANGED
@@ -17,13 +17,13 @@ specific messages, so it's easy to write your own layout.
|
|
17
17
|
Main features:
|
18
18
|
|
19
19
|
* Xinerama support;
|
20
|
-
*
|
21
|
-
with `select()`;
|
22
|
-
* configuration with a run control file
|
20
|
+
* different adapters for event handling: blocking, multiplexing
|
21
|
+
with `select()` or `kqueue()`;
|
22
|
+
* configuration with a run control file;
|
23
23
|
* key bindings with user defined code as callback;
|
24
24
|
* configurable modifier key;
|
25
25
|
* support user-defined layout strategies;
|
26
|
-
* program execution;
|
26
|
+
* external program execution;
|
27
27
|
* no re-parenting (therefore, no window decoration either);
|
28
28
|
* no grabbing of the modifier key alone;
|
29
29
|
* no mouse handling;
|
@@ -64,9 +64,9 @@ options:
|
|
64
64
|
Configuration
|
65
65
|
-------------
|
66
66
|
|
67
|
-
uhwm can be configured with a run control file
|
68
|
-
simple example is provided below, more details
|
69
|
-
|
67
|
+
uhwm can be configured with a run control file written in ruby. A
|
68
|
+
simple example is provided below, more details are available in the
|
69
|
+
[`RunControl` class documentation][run_control_doc].
|
70
70
|
|
71
71
|
``` ruby
|
72
72
|
DMENU = 'dmenu_run -b'.freeze
|
@@ -77,8 +77,8 @@ BROWSERS = %w[
|
|
77
77
|
].freeze
|
78
78
|
|
79
79
|
|
80
|
-
modifier :mod1 # This key
|
81
|
-
#
|
80
|
+
modifier :mod1 # This key is added to the modifier mask for *all*
|
81
|
+
# key bindings.
|
82
82
|
key(:p) { execute DMENU } # Execute given command in a shell when mod1+shift
|
83
83
|
# is pressed.
|
84
84
|
key(:Q) { quit } # Quit when mod1+shift+q is pressed (a capitalized
|
@@ -87,19 +87,19 @@ key(:enter) { execute VT } # Common key names (`enter') are translated to
|
|
87
87
|
# their X equivalent (`return').
|
88
88
|
|
89
89
|
rule BROWSERS do # Move windows to the `www' view when their app
|
90
|
-
layout_view_set 'www' # class
|
90
|
+
layout_view_set 'www' # class match either /\Aarora/, /\Achromium/… etc
|
91
91
|
end
|
92
92
|
|
93
93
|
launch do # Execute urxvt program twice, synchronously.
|
94
94
|
execute! VT # `execute!' is a variant of `execute' which
|
95
|
-
execute! VT #
|
95
|
+
execute! VT # return when a window is mapped.
|
96
96
|
layout_client_column_set :succ # Move last mapped window to next column.
|
97
97
|
end
|
98
98
|
```
|
99
99
|
|
100
100
|
Blocks given to `key`, `rule`, `launch` are executed in a special
|
101
101
|
context providing access to methods named "actions", which are
|
102
|
-
described in
|
102
|
+
described in the following section.
|
103
103
|
|
104
104
|
[run_control_doc]: http://www.rubydoc.info/gems/uh-wm/Uh/WM/RunControl
|
105
105
|
|
@@ -108,10 +108,10 @@ Actions
|
|
108
108
|
-------
|
109
109
|
|
110
110
|
The actions DSL implements a few built-in messages, but also acts as
|
111
|
-
a proxy to the layout. Any message prefixed with `layout_`
|
112
|
-
forwarded to the layout, with
|
111
|
+
a proxy to the layout. Any message prefixed with `layout_` is
|
112
|
+
forwarded to the layout, with its prefix stripped. That is, if
|
113
113
|
`layout_view_sel '2'` is evaluated, then the layout will receive the
|
114
|
-
`view_sel` message with `"2"` as argument.
|
114
|
+
`view_sel` message with `"2"` as argument. Accurate information is
|
115
115
|
available in the [`ActionsHandler` class documentation][actions_doc]
|
116
116
|
|
117
117
|
| Message | Arguments | Description
|
@@ -1,15 +1,29 @@
|
|
1
1
|
module Uh
|
2
2
|
module WM
|
3
|
+
# Provides a context with helper methods for key bindings
|
4
|
+
# ({RunControl#key}), client rules ({RunControl#rule}) and the {Launcher}
|
5
|
+
# ({RunControl#launch}).
|
3
6
|
class ActionsHandler
|
4
7
|
include EnvLogging
|
5
8
|
|
6
9
|
extend Forwardable
|
10
|
+
# @!method layout
|
11
|
+
# Returns the layout
|
12
|
+
# @return [Object] The layout
|
13
|
+
# @see Env#layout
|
7
14
|
def_delegator :@env, :layout
|
8
15
|
|
16
|
+
# @api private
|
17
|
+
# @param env [Env] An environment
|
18
|
+
# @param events [Dispatcher] A dispatcher
|
9
19
|
def initialize env, events
|
10
20
|
@env, @events = env, events
|
11
21
|
end
|
12
22
|
|
23
|
+
# Evaluates action code given as normal argument or block parameter
|
24
|
+
# @api private
|
25
|
+
# @param code [Proc] Action code
|
26
|
+
# @param block [Proc] Action code
|
13
27
|
def evaluate code = nil, &block
|
14
28
|
if code
|
15
29
|
instance_exec &code
|
@@ -18,11 +32,14 @@ module Uh
|
|
18
32
|
end
|
19
33
|
end
|
20
34
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
35
|
+
# Executes given command. Forks twice, creates a new session and makes
|
36
|
+
# the new process the session leader and process group leader of a new
|
37
|
+
# process group. The new process has no controlling terminal. Refer to
|
38
|
+
# `fork(2)` and `setsid(2)` for more detail.
|
39
|
+
#
|
40
|
+
# `command` argument is executed with `Kernel#exec`.
|
41
|
+
#
|
42
|
+
# @param command [String, Array] Command to execute
|
26
43
|
def execute command
|
27
44
|
log "Execute: #{command}"
|
28
45
|
pid = fork do
|
@@ -38,16 +55,22 @@ module Uh
|
|
38
55
|
Process.waitpid pid
|
39
56
|
end
|
40
57
|
|
58
|
+
# Kills layout current client (focused) with {Client#kill}
|
41
59
|
def kill_current
|
42
60
|
return unless layout.current_client
|
43
61
|
layout.current_client.kill
|
44
62
|
end
|
45
63
|
|
64
|
+
# Logs a separator string, can help during debug
|
46
65
|
def log_separator
|
47
66
|
log '- ' * 24
|
48
67
|
end
|
49
68
|
|
50
|
-
|
69
|
+
# Forwards unhandled messages prefixed with `layout_` to the layout,
|
70
|
+
# without the prefix
|
71
|
+
# @example
|
72
|
+
# layout_foo # delegates to `layout.foo'
|
73
|
+
def method_missing m, *args, &block
|
51
74
|
if respond_to? m
|
52
75
|
meth = layout_method m
|
53
76
|
log "#{layout.class.name}##{meth} #{args.inspect}"
|
@@ -61,14 +84,22 @@ module Uh
|
|
61
84
|
end
|
62
85
|
end
|
63
86
|
|
64
|
-
|
87
|
+
# Requests the window manager to terminate
|
88
|
+
def quit
|
89
|
+
log 'Quit requested'
|
90
|
+
@events.emit :quit
|
91
|
+
end
|
92
|
+
|
93
|
+
# Checks method existence in layout
|
94
|
+
# @api private
|
95
|
+
def respond_to_missing? m, _
|
65
96
|
m.to_s =~ /\Alayout_/ || super
|
66
97
|
end
|
67
98
|
|
68
99
|
|
69
100
|
private
|
70
101
|
|
71
|
-
def layout_method
|
102
|
+
def layout_method m
|
72
103
|
m.to_s.gsub(/\Alayout_/, 'handle_').to_sym
|
73
104
|
end
|
74
105
|
end
|
data/lib/uh/wm/run_control.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Uh
|
2
2
|
module WM
|
3
|
+
# Provides the context and behavior for run control file evaluation.
|
3
4
|
class RunControl
|
5
|
+
# Key sym translations for key bindings.
|
4
6
|
KEYSYM_TRANSLATIONS = {
|
5
7
|
backspace: :BackSpace,
|
6
8
|
enter: :Return,
|
@@ -9,6 +11,10 @@ module Uh
|
|
9
11
|
}.freeze
|
10
12
|
|
11
13
|
class << self
|
14
|
+
# Builds an instance and evaluates any run control file defined in
|
15
|
+
# the given {Env} instance
|
16
|
+
# @api private
|
17
|
+
# @param env [Env] An environment
|
12
18
|
def evaluate env
|
13
19
|
rc_path = File.expand_path(env.rc_path)
|
14
20
|
rc = new env
|
@@ -16,24 +22,59 @@ module Uh
|
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
25
|
+
# @api private
|
26
|
+
# @param env [Env] An environment
|
19
27
|
def initialize env
|
20
28
|
@env = env
|
21
29
|
end
|
22
30
|
|
31
|
+
# Evaluates run control code
|
32
|
+
# @api private
|
33
|
+
# @param code [String] The run control file content
|
34
|
+
# @param path [String] The run control file path
|
23
35
|
def evaluate code, path
|
24
36
|
instance_eval code, path
|
25
37
|
rescue ::StandardError, ::ScriptError => e
|
26
38
|
raise RunControlEvaluationError, e.message, e.backtrace
|
27
39
|
end
|
28
40
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
41
|
+
# Registers a key binding
|
42
|
+
# @example Output message on standard output when `modkey+f` is pressed
|
43
|
+
# key(:f) { puts 'hello world!' }
|
44
|
+
# @example Add `shift` key sym to the modifier mask
|
45
|
+
# key(:q, :shift) { quit }
|
46
|
+
# @example Convert capitalized key sym `Q` to `shift+q`
|
47
|
+
# key(:Q) { quit }
|
48
|
+
# @example Convert `enter` to `return` X key sym
|
49
|
+
# key(:enter) { execute 'xterm' }
|
50
|
+
# @param keysyms [Symbol] X key sym
|
51
|
+
# @param block Code to execute when the key binding is triggered, with
|
52
|
+
# `self` as an {ActionsHandler} instance
|
33
53
|
def key *keysyms, &block
|
34
54
|
@env.keybinds[translate_keysym *keysyms] = block
|
35
55
|
end
|
36
56
|
|
57
|
+
# Declares code to execute on window manager connection
|
58
|
+
# @example
|
59
|
+
# launch { execute 'xterm' }
|
60
|
+
# @param block Code to execute when the window manager has connected,
|
61
|
+
# with `self` as a {Launcher} instance
|
62
|
+
def launch &block
|
63
|
+
@env.launch = block
|
64
|
+
end
|
65
|
+
|
66
|
+
# Defines the layout with either a layout class or an instance with
|
67
|
+
# optional layout options. When given only a hash, configures options for
|
68
|
+
# the default layout and ignores the `options` parameter.
|
69
|
+
# @example
|
70
|
+
# layout MyLayout
|
71
|
+
# layout MyLayout, foo: :bar
|
72
|
+
# layout MyLayout.new
|
73
|
+
# layout MyLayout.new(foo: :bar)
|
74
|
+
# layout foo: :bar
|
75
|
+
# @param arg [Class, Object, Hash] A layout class, a layout instance, or
|
76
|
+
# options for the default layout
|
77
|
+
# @param options [Hash] Layout options
|
37
78
|
def layout arg, **options
|
38
79
|
case arg
|
39
80
|
when Class
|
@@ -49,16 +90,38 @@ module Uh
|
|
49
90
|
end
|
50
91
|
end
|
51
92
|
|
52
|
-
|
53
|
-
|
93
|
+
# Defines the modifier key to use for key bindings
|
94
|
+
# @example
|
95
|
+
# modifier :mod1 # Use `mod1' as modifier
|
96
|
+
# @param keysym [Symbol] X key sym
|
97
|
+
def modifier keysym
|
98
|
+
@env.modifier = keysym
|
54
99
|
end
|
55
100
|
|
101
|
+
# Declares a client rule
|
102
|
+
# @example
|
103
|
+
# rule %w[firefox chrome] do
|
104
|
+
# log 'moving client to `www\' view!'
|
105
|
+
# layout_view_set 'www'
|
106
|
+
# end
|
107
|
+
# @param selectors [String, Array<String>] Substring matched against the
|
108
|
+
# beginning of clients window application name
|
109
|
+
# @param block Code to execute when the client rule is matched
|
56
110
|
def rule selectors = '', &block
|
57
111
|
[*selectors].each { |selector| @env.rules[/\A#{selector}/i] = block }
|
58
112
|
end
|
59
113
|
|
60
|
-
|
61
|
-
|
114
|
+
# Configures the worker
|
115
|
+
# @example Use the blocking worker
|
116
|
+
# worker :block
|
117
|
+
# @example Use the kqueue worker with 1 second timeout
|
118
|
+
# worker :kqueue, timeout: 1
|
119
|
+
# @example Use the multiplexing (`select()`) worker with 1 second timeout
|
120
|
+
# worker :mux, timeout: 1
|
121
|
+
# @param type [Symbol] Worker type: `:block`, `:kqueue` or `:mux`
|
122
|
+
# @param options [Hash] Worker options
|
123
|
+
def worker type, **options
|
124
|
+
@env.worker = [type, options]
|
62
125
|
end
|
63
126
|
|
64
127
|
|
data/lib/uh/wm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uh-wm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibault Jouan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb-kqueue
|