Class: I3Ipc::Connection
- Inherits:
-
Object
- Object
- I3Ipc::Connection
- Defined in:
- lib/i3ipc/connection.rb
Overview
Entry point for communication with i3-ipc. Able to send/receive messages and convert responses.
Instance Method Summary collapse
- #bar_config ⇒ Object
- #close ⇒ Object
- #command(cmds) ⇒ Object
-
#initialize(protocol = Protocol.new, autoconnect = true) ⇒ Connection
constructor
A new instance of Connection.
- #marks ⇒ Object
- #open ⇒ Object
- #outputs ⇒ Object
- #subscribe(event, block) ⇒ Object
- #tree ⇒ Object
- #version ⇒ Object
- #workspaces ⇒ Object
Constructor Details
#initialize(protocol = Protocol.new, autoconnect = true) ⇒ Connection
Returns a new instance of Connection.
30 31 32 33 |
# File 'lib/i3ipc/connection.rb', line 30 def initialize(protocol = Protocol.new, autoconnect = true) @protocol = protocol open if autoconnect end |
Instance Method Details
#bar_config ⇒ Object
82 83 84 |
# File 'lib/i3ipc/connection.rb', line 82 def reply_for(6) end |
#close ⇒ Object
39 40 41 |
# File 'lib/i3ipc/connection.rb', line 39 def close @protocol.disconnect end |
#command(cmds) ⇒ Object
43 44 45 |
# File 'lib/i3ipc/connection.rb', line 43 def command(cmds) reply_for(0, cmds) end |
#marks ⇒ Object
78 79 80 |
# File 'lib/i3ipc/connection.rb', line 78 def marks reply_for(5) end |
#open ⇒ Object
35 36 37 |
# File 'lib/i3ipc/connection.rb', line 35 def open @protocol.connect end |
#outputs ⇒ Object
70 71 72 |
# File 'lib/i3ipc/connection.rb', line 70 def outputs reply_for(3) end |
#subscribe(event, block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/i3ipc/connection.rb', line 51 def subscribe(event, block) event_number = event_number(event) # Send subscription request @protocol.send(2, [event]) reply = Reply.parse(@protocol.receive 2) raise WrongEvent.new(event) unless reply.success? pid = Thread.new do while true reply = Reply.parse(@protocol.receive_event event_number) block.call(reply) end end pid end |
#tree ⇒ Object
74 75 76 |
# File 'lib/i3ipc/connection.rb', line 74 def tree reply_for(4) end |
#version ⇒ Object
86 87 88 |
# File 'lib/i3ipc/connection.rb', line 86 def version reply_for(7) end |
#workspaces ⇒ Object
47 48 49 |
# File 'lib/i3ipc/connection.rb', line 47 def workspaces reply_for(1) end |