Skip to content

Commit 897d6dd

Browse files
committed
Add window manager detection
1 parent 7bc3e74 commit 897d6dd

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

adafruit_shell.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
WINDOW_MANAGERS = {
5353
"x11": "W1",
54-
"wayland": "W2",
54+
"wayfire": "W2",
5555
"labwc": "W3",
5656
}
5757

@@ -175,6 +175,12 @@ def write_templated_file(self, output_path, template, **kwargs):
175175
# Render the template with the provided context
176176
rendered_content = self.load_template(template, **kwargs)
177177

178+
if rendered_content is None:
179+
self.error(
180+
f"Failed to load template '{template}'. Unable to write file '{output_path}'."
181+
)
182+
return False
183+
178184
with open(output_path, "w") as output_file:
179185
output_file.write(rendered_content)
180186

@@ -718,6 +724,32 @@ def set_window_manager(self, manager):
718724
):
719725
raise RuntimeError("Unable to change window manager")
720726

727+
def get_window_manager(self):
728+
"""
729+
Get the current window manager
730+
"""
731+
sessions = {"wayfire": "LXDE-pi-wayfire"}
732+
# Check for Raspbian Desktop sessions
733+
if self.exists("/usr/share/xsessions/rpd-x.desktop") or self.exists(
734+
"/usr/share/wayland-sessions/rpd-labwc.desktop"
735+
):
736+
sessions = {"x11": "rpd-x", "labwc": "rpd-labwc"}
737+
else:
738+
sessions = {
739+
"x11": "LXDE-pi-x",
740+
"labwc": "LXDE-pi-labwc",
741+
}
742+
743+
matches = self.pattern_search(
744+
"/etc/lightdm/lightdm.conf", "^(?!#.*?)user-session=(.+)", False, True
745+
)
746+
if matches:
747+
session_match = matches.group(1)
748+
for key, session in session_match.items():
749+
if session == sessions[key]:
750+
return key
751+
return None
752+
721753
def get_boot_config(self):
722754
"""
723755
Get the location of the boot config file

0 commit comments

Comments
 (0)