aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDemonKingSwarn <rockingswarn@gmail.com>2025-01-28 17:36:48 +0530
committerDemonKingSwarn <rockingswarn@gmail.com>2025-02-03 20:21:07 +0530
commit3405b97815100248400df158dcede0ee21f20250 (patch)
tree36f9ba94949cbc98c707d40be8c5edd340bb634e
parent6f9d0ed99402ba0e277103901ef2a5a9381e1ba1 (diff)
downloadhypr-wellbeing-3405b97815100248400df158dcede0ee21f20250.zip
hypr-wellbeing-3405b97815100248400df158dcede0ee21f20250.tar.gz
chore: working on hyprland ipc communication
-rw-r--r--src/GetWindowsv2.cs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/GetWindowsv2.cs b/src/GetWindowsv2.cs
new file mode 100644
index 0000000..7185776
--- /dev/null
+++ b/src/GetWindowsv2.cs
@@ -0,0 +1,62 @@
+namespace hyprwatch.Window
+{
+ using System;
+ using System.Net.Sockets;
+ using System.Text;
+ using System.IO;
+ using System.Text.RegularExpressions;
+
+ public partial class GetWindowsv2
+ {
+ public static string ActiveWindow()
+ {
+ string xdgRuntimeDir = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR");
+ string hyprlandInstanceSig = Environment.GetEnvironmentVariable("HYPRLAND_INSTANCE_SIGNATURE");
+
+ string socketPath = Path.Combine(xdgRuntimeDir, "hypr", hyprlandInstanceSig, ".socket2.sock");
+
+ string activeWindow = "Home-Screen";
+
+ var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
+
+ try
+ {
+ socket.Connect(new UnixDomainSocketEndPoint(socketPath));
+
+ using (var stream = new NetworkStream(socket))
+ using (var reader = new StreamReader(stream))
+ {
+ while (true)
+ {
+ string line = reader.ReadLine();
+
+ if (line == null)
+ {
+ break;
+ }
+
+ var classMatch = ClassRegex().Match(line);
+ if(classMatch.Success)
+ {
+ activeWindow = classMatch.Groups[1].Value.Trim();
+ break;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ }
+ finally
+ {
+ socket.Close();
+ }
+
+ return activeWindow;
+ }
+
+ [GeneratedRegex(@"activewindow>>([^,]+)")]
+ public static partial Regex ClassRegex();
+ }
+}