From 333f7d1f4757855cbdb84e51ac64f52be226e753 Mon Sep 17 00:00:00 2001 From: DemonKingSwarn Date: Sat, 14 Jun 2025 23:21:56 +0530 Subject: chore: added niri support --- src/GetWindows.cs | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/GetWindows.cs b/src/GetWindows.cs index e110760..ee72c39 100644 --- a/src/GetWindows.cs +++ b/src/GetWindows.cs @@ -1,4 +1,4 @@ -namespace hyprwatch.Window +namespace hyprwatch.Window { using System; using System.Diagnostics; @@ -8,20 +8,28 @@ namespace hyprwatch.Window { public static string ActiveWindow() { + string desktopEnv = Environment.GetEnvironmentVariable("XDG_CURRENT_DESKTOP"); string? activeWindow = null; try { - Process process = new Process + Process process = new Process(); + process.StartInfo = new ProcessStartInfo(); + + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.CreateNoWindow = true; + + + if(desktopEnv == "Hyprland") { - StartInfo = new ProcessStartInfo - { - FileName = "hyprctl", - Arguments = "activewindow", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - } - }; + process.StartInfo.FileName = "hyprctl"; + process.StartInfo.Arguments = "activewindow"; + } + else if(desktopEnv == "niri") + { + process.StartInfo.FileName = "niri"; + process.StartInfo.Arguments = "msg focused-window"; + } process.Start(); @@ -30,10 +38,25 @@ namespace hyprwatch.Window var classMatch = ClassRegex().Match(output); - if(classMatch.Success) + if(desktopEnv == "niri") + { + var match = Regex.Match(output, "App ID:\\s+\"([^\"]+)\""); + if(match.Success) + { + activeWindow = match.Groups[1].Value.Trim(); + } + } + + + if(desktopEnv == "Hyprland") { - activeWindow = classMatch.Groups[1].Value.Trim(); + if(classMatch.Success) + { + activeWindow = classMatch.Groups[1].Value.Trim(); + } } + + } catch(Exception ex) { -- cgit v1.1