Class: DockDriver::I3
- Inherits:
-
Object
- Object
- DockDriver::I3
- Extended by:
- Loggability
- Defined in:
- lib/dock_driver/i3.rb
Overview
A class to provide IPC communication with i3wm.
Constant Summary collapse
- COMMAND =
:nodoc:
0- GET_WORKSPACES =
:nodoc:
1- SUBSCRIBE =
:nodoc:
2- GET_OUTPUTS =
:nodoc:
3- MAGIC =
:nodoc:
'i3-ipc'- EVENT_MASK =
:nodoc:
(1 << 31)
- EVENT_WORKSPACE =
:nodoc:
(EVENT_MASK | 0)
Instance Attribute Summary collapse
-
#ipc ⇒ Object
The IPC socket object.
-
#path ⇒ Object
The IPC socket path.
Instance Method Summary collapse
-
#command(cmd) ⇒ Object
Send a command to i3.
-
#get_workspaces ⇒ Object
Return an array of current workspace state.
-
#initialize(socket = '~/.i3/ipc.sock') ⇒ I3
constructor
A constructor OF DOOM!.
-
#subscribe_workspaces ⇒ Object
Register interest in workspace change events.
-
#wait_for_event(type, timeout = nil) {|msg| ... } ⇒ Object
Do a blocking select, yielding an event when one is seen.
Constructor Details
#initialize(socket = '~/.i3/ipc.sock') ⇒ I3
A constructor OF DOOM!
30 31 32 33 |
# File 'lib/dock_driver/i3.rb', line 30 def initialize( socket = '~/.i3/ipc.sock' ) @path = Pathname( socket )..to_s @ipc = UNIXSocket.open( @path ) end |
Instance Attribute Details
#ipc ⇒ Object
The IPC socket object.
24 25 26 |
# File 'lib/dock_driver/i3.rb', line 24 def ipc @ipc end |
#path ⇒ Object
The IPC socket path.
27 28 29 |
# File 'lib/dock_driver/i3.rb', line 27 def path @path end |
Instance Method Details
#command(cmd) ⇒ Object
Send a command to i3.
36 37 38 |
# File 'lib/dock_driver/i3.rb', line 36 def command( cmd ) self.send_data( COMMAND, cmd ) end |
#get_workspaces ⇒ Object
Return an array of current workspace state.
41 42 43 44 |
# File 'lib/dock_driver/i3.rb', line 41 def get_workspaces self.send_data( GET_WORKSPACES ) return self.read_data( GET_WORKSPACES ) end |
#subscribe_workspaces ⇒ Object
Register interest in workspace change events.
47 48 49 50 51 |
# File 'lib/dock_driver/i3.rb', line 47 def subscribe_workspaces self.send_data( SUBSCRIBE, JSON.generate(['workspace'])) result = self.read_data( SUBSCRIBE ) return result[ 'success' ] end |
#wait_for_event(type, timeout = nil) {|msg| ... } ⇒ Object
Do a blocking select, yielding an event when one is seen.
54 55 56 57 58 59 |
# File 'lib/dock_driver/i3.rb', line 54 def wait_for_event( type, timeout=nil ) sock = select( [self.ipc], nil, nil, timeout ) return nil unless sock and type and msg = self.read_data( type ) yield msg if block_given? return msg end |