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

#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

#startvoid

This method returns an undefined value.

Start the adapter or service.



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

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

#stopvoid

This method returns an undefined value.

Stop the adapter or service.



40
41
42
43
44
# File 'lib/rosett_ai/dbus/focus_adapters/i3_adapter.rb', line 40

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