Class: Fusuma::Plugin::Appmatcher::Hyprland::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/plugin/appmatcher/hyprland.rb

Overview

Look up application name using hyprctl

Constant Summary collapse

ACTIVEWINDOW_EVENT =
"activewindow"

Instance Method Summary collapse

Instance Method Details

#active_applicationString?

Returns:

  • (String, nil)


64
65
66
67
68
69
70
# File 'lib/fusuma/plugin/appmatcher/hyprland.rb', line 64

def active_application
  output = `hyprctl -j activewindow 2>/dev/null`
  return nil if output.empty? || output.strip == "{}"
  JSON.parse(output)["class"]
rescue JSON::ParserError
  nil
end

#on_active_application_changedObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/fusuma/plugin/appmatcher/hyprland.rb', line 72

def on_active_application_changed
  socket = connect_to_socket2
  return unless socket

  loop do
    line = socket.gets
    break unless line

    event, data = line.chomp.split(">>", 2)
    next unless event == ACTIVEWINDOW_EVENT

    window_class, _window_title = data.split(",", 2)
    yield(window_class.to_s.empty? ? "NOT FOUND" : window_class)
  end
rescue Errno::ECONNRESET, Errno::EPIPE, IOError
  # socket disconnected
ensure
  socket&.close
end

#running_applicationsArray<String>

Returns:

  • (Array<String>)


55
56
57
58
59
60
61
# File 'lib/fusuma/plugin/appmatcher/hyprland.rb', line 55

def running_applications
  output = `hyprctl clients -j 2>/dev/null`
  return [] if output.empty?
  JSON.parse(output).map { |c| c["class"] }.compact.uniq
rescue JSON::ParserError
  []
end