Class: RosettAi::DBus::FocusAdapters::I3Adapter

Inherits:
Base
  • Object
show all
Defined in:
lib/rosett_ai/dbus/focus_adapters/i3_adapter.rb

Overview

Focus adapter for i3 and sway window managers.

Uses the i3ipc gem to subscribe to window::focus events via the i3/sway IPC socket.

Instance Method Summary collapse

Methods inherited from Base

#notify_focus_change, #on_focus_change, #running?

Constructor Details

#initializeI3Adapter

Returns a new instance of I3Adapter.



14
15
16
17
18
# File 'lib/rosett_ai/dbus/focus_adapters/i3_adapter.rb', line 14

def initialize
  super
  @connection = nil
  @thread = nil
end

Instance Method Details

#startObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rosett_ai/dbus/focus_adapters/i3_adapter.rb', line 20

def start
  return if @running

  require 'i3ipc'
  @connection = I3Ipc::Connection.new
  @running = true

  @thread = Thread.new { run_event_loop }
rescue LoadError
  RosettAi.logger.error('i3ipc gem not available')
  @running = false
rescue StandardError => e
  RosettAi.logger.error("Failed to connect to i3/sway IPC: #{e.message}")
  @running = false
end

#stopObject



36
37
38
39
40
# File 'lib/rosett_ai/dbus/focus_adapters/i3_adapter.rb', line 36

def stop
  super
  @thread&.kill
  @connection = nil
end