From 572447c6a4d19d2113a5203cdf410dbac66ef8f4 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Tue, 28 Jul 2026 14:55:45 -0400 Subject: [PATCH] more clean up of fusuma --- .../fusuma-plugin-niri-appmatcher.gemspec | 17 --- .../lib/fusuma/plugin/appmatcher/niri.rb | 137 ------------------ .../plugin/appmatcher/niri_backend_patch.rb | 29 ---- .../detectors/niri_appmatcher_loader.rb | 15 -- 4 files changed, 198 deletions(-) delete mode 100644 pkgs/fusuma-plugin-niri-appmatcher/fusuma-plugin-niri-appmatcher.gemspec delete mode 100644 pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/appmatcher/niri.rb delete mode 100644 pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/appmatcher/niri_backend_patch.rb delete mode 100644 pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/detectors/niri_appmatcher_loader.rb diff --git a/pkgs/fusuma-plugin-niri-appmatcher/fusuma-plugin-niri-appmatcher.gemspec b/pkgs/fusuma-plugin-niri-appmatcher/fusuma-plugin-niri-appmatcher.gemspec deleted file mode 100644 index 124ea09..0000000 --- a/pkgs/fusuma-plugin-niri-appmatcher/fusuma-plugin-niri-appmatcher.gemspec +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -Gem::Specification.new do |spec| - spec.name = "fusuma-plugin-niri-appmatcher" - spec.version = "0.1.0" - spec.authors = ["Ari Sosnovsky"] - spec.email = ["ari@sosnovsky.ca"] - spec.summary = "Niri appmatcher plugin for Fusuma" - spec.description = "Provides per-application gesture rules for the niri Wayland compositor by querying the focused window via niri IPC." - spec.homepage = "https://github.com/skykanin/nixos-setup" - spec.license = "MIT" - - spec.files = Dir["lib/**/*.rb"] - spec.require_paths = ["lib"] - - spec.add_dependency "fusuma", "~> 3.0" -end diff --git a/pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/appmatcher/niri.rb b/pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/appmatcher/niri.rb deleted file mode 100644 index dc3a269..0000000 --- a/pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/appmatcher/niri.rb +++ /dev/null @@ -1,137 +0,0 @@ -# frozen_string_literal: true - -require "json" -require "open3" -require "socket" -require "fusuma/plugin/appmatcher/user_switcher" -require "fusuma/multi_logger" -require "fusuma/custom_process" - -module Fusuma - module Plugin - module Appmatcher - # Search Active Window's Name for niri (scrollable-tiling Wayland compositor) - class Niri - include UserSwitcher - - attr_reader :reader, :writer - - # @return [Boolean] - def self.available? - return true if ENV["NIRI_SOCKET"] - - ENV.fetch("PATH", "").split(File::PATH_SEPARATOR).any? do |dir| - path = File.join(dir, "niri") - File.executable?(path) && !File.directory?(path) - end - end - - def initialize - @reader, @writer = IO.pipe - end - - # fork process and watch signal - # @return [Integer] Process id - def watch_start - as_user(proctitle: self.class.name.underscore) do |_user| - @reader.close - register_on_application_changed(Matcher.new) - end - end - - private - - def register_on_application_changed(matcher) - @writer.puts(matcher.active_application || "NOT FOUND") - - matcher.on_active_application_changed do |name| - notify(name) - end - end - - def notify(name) - @writer.puts(name) - rescue Errno::EPIPE - exit 0 - rescue => e - MultiLogger.error e.message - exit 1 - end - - # Look up application name using the niri IPC socket - class Matcher - # @return [Array] - def running_applications - request("Windows")["Ok"]["Windows"] - .map { |w| w["app_id"] } - .compact - .uniq - rescue => e - MultiLogger.error "Failed to get running applications: #{e.message}" - [] - end - - # @return [String, nil] - def active_application - request("FocusedWindow")["Ok"]["FocusedWindow"]&.dig("app_id") - rescue => e - MultiLogger.error "Failed to get active application: #{e.message}" - nil - end - - # Subscribe to niri's event stream and yield the app_id on focus change - def on_active_application_changed - unix_socket_request("EventStream") do |socket| - # The first line of an EventStream reply is the Ok confirmation; - # subsequent lines are JSON events. - socket.each_line do |line| - event = JSON.parse(line) - changed = event["WindowFocusChanged"] || - event.dig("WindowsChanged", "windows") && - event["WindowsChanged"]["windows"].find { |w| w["is_focused"] } - - app_id = - case changed - when Hash then changed["app_id"] - when NilClass then nil - else changed && active_application - end - - # WindowFocusChanged carries { id: ... } or null; on id-only - # events re-query the focused window for its app_id. - app_id ||= active_application if event["WindowFocusChanged"] - - yield(app_id || "NOT FOUND") if app_id || event["WindowFocusChanged"] - rescue JSON::ParserError - next - end - end - rescue => e - MultiLogger.error "Niri subscription error: #{e.message}" - sleep 1 - retry - end - - private - - # @return [String] - def socket_path - ENV["NIRI_SOCKET"] || raise("NIRI_SOCKET is not set") - end - - # Send a single request and return the parsed reply (one line of JSON). - def request(action) - unix_socket_request(action) { |s| JSON.parse(s.gets) } - end - - def unix_socket_request(action) - UNIXSocket.open(socket_path) do |socket| - socket.puts(JSON.generate(action)) - yield socket - end - end - end - end - end - end -end diff --git a/pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/appmatcher/niri_backend_patch.rb b/pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/appmatcher/niri_backend_patch.rb deleted file mode 100644 index 313f805..0000000 --- a/pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/appmatcher/niri_backend_patch.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# Registers the niri backend for fusuma-plugin-appmatcher. -# -# Upstream `Fusuma::Plugin::Appmatcher.backend_klass` selects a backend via a -# hardcoded case on XDG_SESSION_TYPE / XDG_CURRENT_DESKTOP and knows nothing -# about niri. We prepend a module that returns our Niri backend whenever it is -# available (i.e. NIRI_SOCKET is set), and otherwise defer to upstream. -# -# This file lives in a nested path on purpose: Fusuma's plugin manager -# auto-requires `fusuma/plugin/**/*.rb` from fusuma-plugin-* gems but -# explicitly excludes top-level files (fusuma/plugin/.rb). -require_relative "niri" - -module Fusuma - module Plugin - module Appmatcher - module NiriBackendSelection - def backend_klass - return Niri if Niri.available? - - super - end - end - - singleton_class.prepend(NiriBackendSelection) - end - end -end diff --git a/pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/detectors/niri_appmatcher_loader.rb b/pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/detectors/niri_appmatcher_loader.rb deleted file mode 100644 index e6a8ffd..0000000 --- a/pkgs/fusuma-plugin-niri-appmatcher/lib/fusuma/plugin/detectors/niri_appmatcher_loader.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -# Bootstrap for the niri appmatcher backend. -# -# fusuma-plugin-appmatcher hardcodes its backend list in -# `fusuma/plugin/appmatcher.rb` and offers no registry for third-party -# backends, so our Niri backend must be required explicitly. Fusuma only -# auto-requires `fusuma/plugin//*.rb` (detectors, inputs, -# buffers, ...) from `fusuma-plugin-*` gems on the load path; it never scans -# the `appmatcher/` backend directory. This file therefore lives in the -# `detectors` namespace purely so Fusuma auto-loads it at boot — it registers -# no detector, it just pulls in the backend and the `backend_klass` patch. -require "fusuma/plugin/appmatcher" -require "fusuma/plugin/appmatcher/niri" -require "fusuma/plugin/appmatcher/niri_backend_patch"