i3-ipc 0.1.2 → 0.1.3

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.
@@ -26,7 +26,7 @@ Use
26
26
 
27
27
  i3-ipc -t 1
28
28
  i3-ipc -t 1 -p
29
- i3-ipc -t 1 -j
29
+ i3-ipc -t 3 -j
30
30
  i3-ipc "exec xterm"
31
31
 
32
32
  Read the [man-page][man] for more information.
@@ -35,10 +35,14 @@ Subscribing
35
35
  -----------
36
36
 
37
37
  As of commit [3db4890][] i3 added events.
38
- For now there's only one event: `workspace`.
38
+ For now there's only two events: `workspace` and `focus`.
39
39
 
40
40
  According to the documentation:
41
- > This event is sent when the user switches to a different workspace, when a new workspace is initialized or when a workspace is removed (because the last client vanished).
41
+ > workspace
42
+ > Sent when the user switches to a different workspace, when a new workspace is initialized or when a workspace is removed (because the last client vanished).
43
+ > output
44
+ > Sent when RandR issues a change notification (of either screens, outputs, CRTCs or output properties).
45
+
42
46
 
43
47
  i3-ipc uses [EventMachine][em] to receive and handle these events.
44
48
 
@@ -55,9 +59,10 @@ To send data to the socket, you need to use `em.send_data`.
55
59
  * `type` is the received message type.
56
60
  This could be one of
57
61
  * MESSAGE_REPLY_COMMAND
58
- * MESSAGE_REPLY_COMMAND
59
- * MESSAGE_REPLY_COMMAND
60
- * EVENT_WORKSPACE #_
62
+ * MESSAGE_REPLY_GET_WORKSPACES
63
+ * MESSAGE_REPLY_SUBSCRIBE
64
+ * MESSAGE_REPLY_GET_OUTPUTS
65
+ * EVENT_WORKSPACE
61
66
  * `data` is the received data, already parsed.
62
67
 
63
68
  For example you can use the following code to get the actual focused screen:
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ begin
9
9
  task :publish => :gemcutter do
10
10
  require File.dirname(__FILE__) + '/lib/i3-ipc/version'
11
11
 
12
- system "git tag v#{I3::Version}"
12
+ sh "git tag v#{I3::Version}"
13
13
  sh "git push origin master --tags"
14
14
  sh "git clean -fd"
15
15
  exec "rake pages"
@@ -13,10 +13,12 @@ module I3
13
13
  MESSAGE_TYPE_COMMAND = 0
14
14
  MESSAGE_TYPE_GET_WORKSPACES = 1
15
15
  MESSAGE_TYPE_SUBSCRIBE = 2
16
+ MESSAGE_TYPE_GET_OUTPUTS = 3
16
17
 
17
18
  MESSAGE_REPLY_COMMAND = 0
18
19
  MESSAGE_REPLY_GET_WORKSPACES = 1
19
20
  MESSAGE_REPLY_SUBSCRIBE = 2
21
+ MESSAGE_REPLY_GET_OUTPUTS = 3
20
22
 
21
23
  EVENT_MASK = (1 << 31)
22
24
  EVENT_WORKSPACE = (EVENT_MASK | 0)
@@ -58,6 +60,15 @@ module I3
58
60
  handle_response MESSAGE_TYPE_GET_WORKSPACES
59
61
  end
60
62
 
63
+ # Gets the current outputs.
64
+ # The reply will be a JSON-encoded list
65
+ # of outputs
66
+ # (see the reply section of i3 docu).
67
+ def get_outputs
68
+ write format(MESSAGE_TYPE_GET_OUTPUTS)
69
+ handle_response MESSAGE_TYPE_GET_OUTPUTS
70
+ end
71
+
61
72
  # reads the reply from the socket
62
73
  # and parse the returned json into a ruby object
63
74
  #
@@ -1,9 +1,33 @@
1
1
  require 'optparse'
2
+ require 'pp'
2
3
 
3
4
  module I3
4
5
  module Runner
5
6
  extend self
6
7
 
8
+ def format_output(object, output)
9
+ if output == :pretty_print
10
+ pp object
11
+ elsif output == :json
12
+ require 'json'
13
+ puts object.to_json
14
+ else
15
+ p object
16
+ end
17
+ end
18
+
19
+ def subscribe(path, output)
20
+ trap('SIGINT') { EM.stop; puts }
21
+ I3::IPC.subscribe([:workspace], path) do |em, type, data|
22
+ case type
23
+ when I3::IPC::MESSAGE_REPLY_GET_WORKSPACES
24
+ format_output data, output
25
+ when I3::IPC::EVENT_WORKSPACE
26
+ em.send_data I3::IPC.format(I3::IPC::MESSAGE_TYPE_GET_WORKSPACES)
27
+ end
28
+ end
29
+ end
30
+
7
31
  def execute(*args)
8
32
  socket_file = '/tmp/i3-ipc.sock'
9
33
  type = 0
@@ -18,7 +42,7 @@ module I3
18
42
  socket_file = s
19
43
  end
20
44
 
21
- t_desc = 'Set type, 0 = command, 1 = workspace list, defaults to 0'
45
+ t_desc = 'Set type, 0 = command, 1 = workspace list, 2 = subscribe to workspace event, 3 = output list, default: 0'
22
46
  opts.on('-tTYPE', '--type TYPE', Integer, t_desc) do |t|
23
47
  type = t
24
48
  end
@@ -49,7 +73,8 @@ module I3
49
73
 
50
74
  s = I3::IPC.new(socket_file)
51
75
 
52
- if type == 0
76
+ case type
77
+ when 0
53
78
  if args.empty?
54
79
  abort "error: message type needs a message"
55
80
  end
@@ -57,17 +82,12 @@ module I3
57
82
  payload = args.shift
58
83
 
59
84
  puts s.command(payload) unless quiet
60
- elsif type == 1
61
- workspaces = s.get_workspaces
62
- if output == :pretty_print
63
- require 'pp'
64
- pp workspaces
65
- elsif output == :json
66
- require 'json'
67
- puts workspaces.to_json
68
- else
69
- p workspaces
70
- end
85
+ when I3::IPC::MESSAGE_TYPE_GET_WORKSPACES
86
+ format_output s.get_workspaces, output
87
+ when I3::IPC::MESSAGE_REPLY_SUBSCRIBE
88
+ subscribe socket_file, output
89
+ when I3::IPC::MESSAGE_TYPE_GET_OUTPUTS
90
+ format_output s.get_outputs, output
71
91
  else
72
92
  abort "error: type #{type} not yet implemented"
73
93
  end
@@ -34,7 +34,7 @@ preamble
34
34
  standalone = ''
35
35
  standalone << PREAMBLE
36
36
  file_dir = File.expand_path(File.dirname(__FILE__))
37
- exclude_files = %w(subscription.rb)
37
+ exclude_files = %w()
38
38
 
39
39
  exclude_file_list = exclude_files.map { |file|
40
40
  File.join(file_dir, file)
@@ -1,3 +1,3 @@
1
1
  module I3
2
- Version = '0.1.2'
2
+ Version = '0.1.3'
3
3
  end
@@ -0,0 +1,88 @@
1
+ .\" generated with Ronn/v0.4.1
2
+ .\" http://github.com/rtomayko/ronn/
3
+ .
4
+ .TH "I3\-IPC" "1" "March 2010" "badboy" "i3-ipc Manual"
5
+ .
6
+ .SH "NAME"
7
+ \fBi3\-ipc\fR \-\- inter\-process communication with i3
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBi3\-ipc\fR [\fB\-s\fR] [\fB\-t type\fR] [\fB\-p\fR] [\fB\-j\fR] [\fB\-q\fR] [\fBmessage\fR]
11
+ .
12
+ .SH "DESCRIPTION"
13
+ \fBi3\-ipc\fR can be used to communicate with i3, the improved tiling window manager, through the provided ipc socket. Useful for scripting the window manager.
14
+ .
15
+ .P
16
+ Currently implemented message types of i3 are the following:
17
+ .
18
+ .TP
19
+ \fB0 (COMMAND)\fR
20
+ The payload of the message is a command for i3
21
+ (like the commands you can bind to keys in the configuration file)
22
+ The command will be executed directly after receiving it.
23
+ The reply will be always {"succes":true} for now.
24
+ .
25
+ .TP
26
+ \fB1 (GET_WORKSPACES)\fR
27
+ Gets the current workspaces.
28
+ The reply will be a JSON\-encoded list of workspaces (see the reply section).
29
+ .
30
+ .SH "OPTIONS"
31
+ \fBi3\-ipc\fR's default mode of operation is to send the command (type 0) specified on the command line.
32
+ .
33
+ .P
34
+ These options can be used to change this behavior:
35
+ .
36
+ .TP
37
+ \fB\-s\fR, \fB\-\-socket\fR
38
+ Set the socket file, defaults to /tmp/i3\-ipc.sock
39
+ .
40
+ .TP
41
+ \fB\-t\fR, \fB\-\-type\fR
42
+ Set the type. Passing a type of 0 is the default and will send the specified command, type 1 gets the current workspace list.
43
+ .
44
+ .TP
45
+ \fB\-p\fR, \fB\-\-pretty\-print\fR
46
+ This will pretty print the received reply. Useful for the workspace list.
47
+ .
48
+ .TP
49
+ \fB\-j\fR, \fB\-\-json\fR
50
+ This will print the received reply as raw json\-encoded data. Useful to pass to another script.
51
+ .
52
+ .TP
53
+ \fB\-q\fR, \fB\-\-quiet\fR
54
+ Turn off the output. Useful for command mode.
55
+ .
56
+ .TP
57
+ \fBmessage\fR
58
+ This is the actual command to send as defined by i3
59
+ .
60
+ .P
61
+ You may additionally ask for help:
62
+ .
63
+ .TP
64
+ \fB\-h\fR, \fB\-\-help\fR
65
+ Print help.
66
+ .
67
+ .TP
68
+ \fB\-m\fR, \fB\-\-man\fR
69
+ Display this man page.
70
+ .
71
+ .SH "EXAMPLES"
72
+ .
73
+ .nf
74
+ $ i3\-ipc \-t 1
75
+ $ i3\-ipc \-t 1 \-p
76
+ $ i3\-ipc \-t 1 \-j
77
+ $ i3\-ipc "exec xterm"
78
+ .
79
+ .fi
80
+ .
81
+ .SH "BUGS"
82
+ \fIhttp://github.com/badboy/i3\-ipc/issues\fR
83
+ .
84
+ .SH "AUTHOR"
85
+ Jan\-Erik Rediger:: badboy@archlinux.us
86
+ .
87
+ .SH "SEE ALSO"
88
+ i3(1), i3\-msg(1), \fIhttp://i3.zekjur.net/\fR, \fIhttp://github.com/badboy/i3\-ipc\fR
@@ -0,0 +1,141 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
+ <meta name='generator' value='Ronn/v0.4.1'>
6
+ <title>i3-ipc(1) -- inter-process communication with i3</title>
7
+ <style type='text/css'>
8
+ body {margin:0}
9
+ #man, #man code, #man pre, #man tt, #man kbd, #man samp {
10
+ font-family:consolas,monospace;
11
+ font-size:16px;
12
+ line-height:1.3;
13
+ color:#343331;
14
+ background:#fff; }
15
+ #man { max-width:89ex; text-align:justify; margin:0 25px 25px 25px }
16
+ #man h1, #man h2, #man h3 { color:#232221;clear:left }
17
+ #man h1 { font-size:28px; margin:15px 0 30px 0; text-align:center }
18
+ #man h2 { font-size:18px; margin-bottom:0; margin-top:10px; line-height:1.3; }
19
+ #man h3 { font-size:16px; margin:0 0 0 4ex; }
20
+ #man p, #man ul, #man ol, #man dl, #man pre { margin:0 0 18px 0; }
21
+ #man pre {
22
+ color:#333231;
23
+ background:#edeceb;
24
+ padding:5px 7px;
25
+ margin:0px 0 20px 0;
26
+ border-left:2ex solid #ddd}
27
+ #man pre + h2, #man pre + h3 {
28
+ margin-top:22px;
29
+ }
30
+ #man h2 + pre, #man h3 + pre {
31
+ margin-top:5px;
32
+ }
33
+ #man > p, #man > ul, #man > ol, #man > dl, #man > pre { margin-left:8ex; }
34
+ #man dt { margin:0; clear:left }
35
+ #man dt.flush { float:left; width:8ex }
36
+ #man dd { margin:0 0 0 9ex }
37
+ #man code, #man strong, #man b { font-weight:bold; color:#131211; }
38
+ #man pre code { font-weight:normal; color:#232221; background:inherit }
39
+ #man em, var, u {
40
+ font-style:normal; color:#333231; border-bottom:1px solid #999; }
41
+ #man h1.man-title { display:none; }
42
+ #man ol.man, #man ol.man li { margin:2px 0 10px 0; padding:0;
43
+ float:left; width:33%; list-style-type:none;
44
+ text-transform:uppercase; font-size:18px; color:#999;
45
+ letter-spacing:1px;}
46
+ #man ol.man { width:100%; }
47
+ #man ol.man li.tl { text-align:left }
48
+ #man ol.man li.tc { text-align:center;letter-spacing:4px }
49
+ #man ol.man li.tr { text-align:right }
50
+ #man ol.man a { color:#999 }
51
+ #man ol.man a:hover { color:#333231 }
52
+ </style>
53
+ </head>
54
+ <body>
55
+ <div id='man'>
56
+
57
+ <h1 class='man-title'>i3-ipc(1)</h1>
58
+
59
+ <ol class='head man'>
60
+ <li class='tl'>i3-ipc(1)</li>
61
+ <li class='tc'>i3-ipc Manual</li>
62
+ <li class='tr'>i3-ipc(1)</li>
63
+ </ol>
64
+
65
+ <h2 id='NAME'>NAME</h2>
66
+ <p><code>i3-ipc</code> -- inter-process communication with i3</p>
67
+
68
+ <h2>SYNOPSIS</h2>
69
+
70
+ <p><code>i3-ipc</code> [<code>-s</code>] [<code>-t type</code>] [<code>-p</code>] [<code>-j</code>] [<code>-q</code>] [<code>message</code>]</p>
71
+
72
+ <h2>DESCRIPTION</h2>
73
+
74
+ <p><code>i3-ipc</code> can be used to communicate with i3, the improved tiling window manager, through the provided ipc socket. Useful for scripting the window manager.</p>
75
+
76
+ <p>Currently implemented message types of i3 are the following:</p>
77
+
78
+ <dl>
79
+ <dt><code>0 (COMMAND)</code></dt><dd> The payload of the message is a command for i3
80
+ (like the commands you can bind to keys in the configuration file)
81
+ The command will be executed directly after receiving it.
82
+ The reply will be always {"succes":true} for now.</dd>
83
+ <dt><code>1 (GET_WORKSPACES)</code></dt><dd> Gets the current workspaces.
84
+ The reply will be a JSON-encoded list of workspaces (see the reply section).</dd>
85
+ </dl>
86
+
87
+
88
+ <h2>OPTIONS</h2>
89
+
90
+ <p><code>i3-ipc</code>'s default mode of operation is to send the command (type 0) specified on the command line.</p>
91
+
92
+ <p>These options can be used to change this behavior:</p>
93
+
94
+ <dl>
95
+ <dt><code>-s</code>, <code>--socket</code></dt><dd><p>Set the socket file, defaults to /tmp/i3-ipc.sock</p></dd>
96
+ <dt><code>-t</code>, <code>--type</code></dt><dd><p>Set the type. Passing a type of 0 is the default and will send the specified command, type 1 gets the current workspace list.</p></dd>
97
+ <dt><code>-p</code>, <code>--pretty-print</code></dt><dd><p>This will pretty print the received reply. Useful for the workspace list.</p></dd>
98
+ <dt><code>-j</code>, <code>--json</code></dt><dd><p>This will print the received reply as raw json-encoded data. Useful to pass to another script.</p></dd>
99
+ <dt><code>-q</code>, <code>--quiet</code></dt><dd><p>Turn off the output. Useful for command mode.</p></dd>
100
+ <dt class="flush"><code>message</code></dt><dd><p>This is the actual command to send as defined by i3</p></dd>
101
+ </dl>
102
+
103
+
104
+ <p>You may additionally ask for help:</p>
105
+
106
+ <dl>
107
+ <dt><code>-h</code>, <code>--help</code></dt><dd><p>Print help.</p></dd>
108
+ <dt><code>-m</code>, <code>--man</code></dt><dd><p>Display this man page.</p></dd>
109
+ </dl>
110
+
111
+
112
+ <h2>EXAMPLES</h2>
113
+
114
+ <pre><code>$ i3-ipc -t 1
115
+ $ i3-ipc -t 1 -p
116
+ $ i3-ipc -t 1 -j
117
+ $ i3-ipc "exec xterm"
118
+ </code></pre>
119
+
120
+ <h2>BUGS</h2>
121
+
122
+ <p><a href="http://github.com/badboy/i3-ipc/issues">http://github.com/badboy/i3-ipc/issues</a></p>
123
+
124
+ <h2>AUTHOR</h2>
125
+
126
+ <p>Jan-Erik Rediger:: badboy@archlinux.us</p>
127
+
128
+ <h2>SEE ALSO</h2>
129
+
130
+ <p>i3(1), i3-msg(1), <a href="http://i3.zekjur.net/">http://i3.zekjur.net/</a>, <a href="http://github.com/badboy/i3-ipc">http://github.com/badboy/i3-ipc</a></p>
131
+
132
+
133
+ <ol class='foot man'>
134
+ <li class='tl'>badboy</li>
135
+ <li class='tc'>March 2010</li>
136
+ <li class='tr'>i3-ipc(1)</li>
137
+ </ol>
138
+
139
+ </div>
140
+ </body>
141
+ </html>
@@ -0,0 +1,73 @@
1
+ i3-ipc(1) -- inter-process communication with i3
2
+ ================================================
3
+
4
+ ## SYNOPSIS
5
+
6
+ `i3-ipc` [`-s`] [`-t type`] [`-p`] [`-j`] [`-q`] [`message`]
7
+
8
+ ## DESCRIPTION
9
+
10
+ `i3-ipc` can be used to communicate with i3, the improved tiling window manager, through the provided ipc socket. Useful for scripting the window manager.
11
+
12
+
13
+ Currently implemented message types of i3 are the following:
14
+
15
+ * `0 (COMMAND)`:
16
+ The payload of the message is a command for i3
17
+ (like the commands you can bind to keys in the configuration file)
18
+ The command will be executed directly after receiving it.
19
+ The reply will be always {"succes":true} for now.
20
+ * `1 (GET_WORKSPACES)`:
21
+ Gets the current workspaces.
22
+ The reply will be a JSON-encoded list of workspaces (see the reply section).
23
+
24
+ ## OPTIONS
25
+
26
+ `i3-ipc`'s default mode of operation is to send the command (type 0) specified on the command line.
27
+
28
+ These options can be used to change this behavior:
29
+
30
+ * `-s`, `--socket`:
31
+ Set the socket file, defaults to /tmp/i3-ipc.sock
32
+
33
+ * `-t`, `--type`:
34
+ Set the type. Passing a type of 0 is the default and will send the specified command, type 1 gets the current workspace list.
35
+
36
+ * `-p`, `--pretty-print`:
37
+ This will pretty print the received reply. Useful for the workspace list.
38
+
39
+ * `-j`, `--json`:
40
+ This will print the received reply as raw json-encoded data. Useful to pass to another script.
41
+
42
+ * `-q`, `--quiet`:
43
+ Turn off the output. Useful for command mode.
44
+
45
+ * `message`:
46
+ This is the actual command to send as defined by i3
47
+
48
+ You may additionally ask for help:
49
+
50
+ * `-h`, `--help`:
51
+ Print help.
52
+
53
+ * `-m`, `--man`:
54
+ Display this man page.
55
+
56
+ ## EXAMPLES
57
+
58
+ $ i3-ipc -t 1
59
+ $ i3-ipc -t 1 -p
60
+ $ i3-ipc -t 1 -j
61
+ $ i3-ipc "exec xterm"
62
+
63
+ ## BUGS
64
+
65
+ <http://github.com/badboy/i3-ipc/issues>
66
+
67
+ ## AUTHOR
68
+
69
+ Jan-Erik Rediger:: badboy@archlinux.us
70
+
71
+ ## SEE ALSO
72
+
73
+ i3(1), i3-msg(1), <http://i3.zekjur.net/>, <http://github.com/badboy/i3-ipc>
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan-Erik Rediger
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-14 00:00:00 +01:00
17
+ date: 2010-04-08 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -78,6 +78,9 @@ files:
78
78
  - lib/i3-ipc/runner.rb
79
79
  - lib/i3-ipc.rb
80
80
  - bin/i3-ipc
81
+ - man/i3-ipc.1.html
82
+ - man/i3-ipc.1
83
+ - man/i3-ipc.1.ronn
81
84
  has_rdoc: true
82
85
  homepage: http://github.com/badboy/i3-ipc
83
86
  licenses: []