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

Add wlrlui -m to automatically match profiles #9

Merged
merged 4 commits into from
May 17, 2024
Merged
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
66 changes: 42 additions & 24 deletions src/wlr_layout_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@
pass


def apply_profile(profile):
load()
p_by_id = {p["uid"]: p for p in profile}
rects = [
(
Rect(-i["x"], i["y"], i["height"], i["width"])
if i.get("transform", 0) in (1, 3, 5, 7)
else Rect(-i["x"], i["y"], i["width"], i["height"])
)
for i in profile
]

for i, di in enumerate(displayInfo):
di.active = p_by_id[di.uid]["active"]
di.transform = p_by_id[di.uid].get("transform", 0)
di.scale = p_by_id[di.uid].get("scale", 1.0)
if di.transform in (1, 3, 5, 7):
rects[i].width, rects[i].height = rects[i].height, rects[i].width

cmd = make_command(displayInfo, rects, not LEGACY)
time.sleep(0.5)
if os.system(cmd):
print("Failed applying the layout")


def main():
if len(sys.argv) > 1:
from .profiles import load_profiles
Expand All @@ -26,46 +51,39 @@ def main():
print("")
for p in profiles:
print(f" - {p}")
elif sys.argv[1] == "-m":
load()
current_uids = set(di.uid for di in displayInfo)
for key in sorted(profiles):
prof_uids = {p["uid"] for p in profiles[key]}
# check that the two sets have the same elements
if prof_uids == current_uids:
print(f"Matched profile {key}. Applying it...")
apply_profile(profiles[key])
sys.exit(0)
levnikmyskin marked this conversation as resolved.
Show resolved Hide resolved
print(f"No profile found: {sys.argv[1]}")
sys.exit(1)

elif sys.argv[1][0] == "-":
load()
print(
"""With no options, launches the GUI
Options:
-l : list profiles
-m : find a profile that matches the currently plugged display set, and apply it.
No-op if not found; will apply first in alphabetical order if multiple found.
<profile name> : loads a profile
"""
)

else:
reload_pre_commands()
try:
profile = profiles[sys.argv[1]]
except KeyError:
print(f"No such profile: {sys.argv[1]}")
raise SystemExit(1)
load()
p_by_id = {p["uid"]: p for p in profile}
rects = [
(
Rect(-i["x"], i["y"], i["height"], i["width"])
if i.get("transform", 0) in (1, 3, 5, 7)
else Rect(-i["x"], i["y"], i["width"], i["height"])
)
for i in profile
]

for i, di in enumerate(displayInfo):
di.active = p_by_id[di.uid]["active"]
di.transform = p_by_id[di.uid].get("transform", 0)
di.scale = p_by_id[di.uid].get("scale", 1.0)
if di.transform in (1, 3, 5, 7):
rects[i].width, rects[i].height = rects[i].height, rects[i].width

cmd = make_command(displayInfo, rects, not LEGACY)
time.sleep(0.5)
if os.system(cmd):
print("Failed applying the layout")
sys.exit(0)
apply_profile(profile)
return
load()
max_width = int(sum(max(screen.available, key=lambda mode: mode.width).width for screen in displayInfo) // UI_RATIO)
max_height = int(sum(max(screen.available, key=lambda mode: mode.height).height for screen in displayInfo) // UI_RATIO)
Expand Down