Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveWindow Entity Hyprland Support #116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
working window title and extraAttributes
  • Loading branch information
Jonas Fenchel committed Jul 8, 2024
commit 554ef5ec201620174e0356c7be5ca4426044eb9f
48 changes: 44 additions & 4 deletions IoTuring/Entity/Deployments/ActiveWindow/ActiveWindow.py
Original file line number Diff line number Diff line change
@@ -30,16 +30,35 @@ def Initialize(self):
UpdateFunction = {
OsD.LINUX: self.GetActiveWindow_Linux,
OsD.WINDOWS: self.GetActiveWindow_Windows,
OsD.MACOS: self.GetActiveWindow_macOS
OsD.MACOS: self.GetActiveWindow_macOS,
'hyprland': self.GetActiveWindow_Hyprland, # each Wayland compositor need its own implementation since they have their own apis
}

self.UpdateSpecificFunction = UpdateFunction[OsD.GetOs()]

self.RegisterEntitySensor(EntitySensor(self, KEY))
if De.GetDesktopEnvironment() == 'hyprland':
self.UpdateSpecificFunction = UpdateFunction['hyprland']
self.hyprland_regex_patterns = {
'workspace': r'workspace:\s*(\d+)',
'floating': r'floating:\s*(\d+)',
'monitor': r'monitor:\s*(\d+)',
'class': r'class:\s*(\S+)',
'title': r'title:\s*(.*)',
'initialTitle': r'initialTitle:\s*"(.+?)"',
'pid': r'pid:\s*(\d+)',
'xwayland': r'xwayland:\s*(\d+)',
'fullscreen': r'fullscreen:\s*(\d+)',
'pinned': r'pinned:\s*(\d+)'
}
self.RegisterEntitySensor(EntitySensor(self, KEY, supportsExtraAttributes=True))

self.extraAttributes = {}

def Update(self):
if self.UpdateSpecificFunction:
self.SetEntitySensorValue(KEY, str(self.UpdateSpecificFunction()))
if self.extraAttributes:
for extraAttributeKey, extraAttributeValue in self.extraAttributes.items():
self.SetEntitySensorExtraAttribute(KEY, extraAttributeKey, extraAttributeValue)

def GetActiveWindow_macOS(self):
try:
@@ -77,11 +96,32 @@ def GetActiveWindow_Linux(self) -> str:

return 'Inactive'

def GetActiveWindow_Hyprland(self):
title = None
p = self.RunCommand('hyprctl activewindow')
# if the command was successful, assign all lines to respective variables
if p.stdout:
# Use regular expressions to search for each variable in the output
for key, pattern in self.hyprland_regex_patterns.items():
match = re.search(pattern, p.stdout)
if match:
if key == 'title':
title = match.group(1)
self.extraAttributes[key] = match.group(1)


return title


@classmethod
def CheckSystemSupport(cls):
if OsD.IsLinux():
if De.IsWayland():
raise Exception("Wayland is not supported")
if De.GetDesktopEnvironment() == 'hyprland':
if not OsD.CommandExists("hyprctl"):
raise Exception("No hyprctl command found!")
else:
raise Exception("Wayland is not supported")
elif not OsD.CommandExists("xprop"):
raise Exception("No xprop command found!")

Loading