Class: RosettAi::DBus::FocusAdapters::Base

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

Overview

Base class for compositor-specific focus adapters.

Each adapter implements the same interface:

  • #start: Begin monitoring focus changes
  • #stop: Stop monitoring
  • #on_focus_change(&block): Register callback for focus changes

Callbacks receive (app_id, title) arguments.

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



18
19
20
21
# File 'lib/rosett_ai/dbus/focus_adapters/base.rb', line 18

def initialize
  @callbacks = []
  @running = false
end

Instance Method Details

#notify_focus_change(app_id, title) ⇒ Object (protected)

Notify all registered callbacks of a focus change

Parameters:

  • app_id (String)

    Application identifier

  • title (String)

    Window title



53
54
55
# File 'lib/rosett_ai/dbus/focus_adapters/base.rb', line 53

def notify_focus_change(app_id, title)
  @callbacks.each { |cb| cb.call(app_id.to_s, title.to_s) }
end

#on_focus_change {|app_id, title| ... } ⇒ Object

Register callback for focus changes

Yields:

  • (app_id, title)

    Called on focus change



26
27
28
# File 'lib/rosett_ai/dbus/focus_adapters/base.rb', line 26

def on_focus_change(&block)
  @callbacks << block
end

#running?Boolean

Check if monitoring is active

Returns:

  • (Boolean)


43
44
45
# File 'lib/rosett_ai/dbus/focus_adapters/base.rb', line 43

def running?
  @running
end

#startObject

Start monitoring focus changes

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/rosett_ai/dbus/focus_adapters/base.rb', line 31

def start
  raise NotImplementedError, "#{self.class}#start must be implemented"
end

#stopObject

Stop monitoring



36
37
38
# File 'lib/rosett_ai/dbus/focus_adapters/base.rb', line 36

def stop
  @running = false
end