Skip to content

Commit

Permalink
monitors: add couple of options & remove "unknown"
Browse files Browse the repository at this point in the history
  • Loading branch information
fdev31 committed Feb 4, 2024
1 parent 550ba8f commit 576dc48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
40 changes: 18 additions & 22 deletions pyprland/plugins/monitors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
" The monitors plugin "
import asyncio
import subprocess
from collections import defaultdict
from copy import deepcopy
Expand Down Expand Up @@ -105,7 +104,8 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring

async def load_config(self, config) -> None:
await super().load_config(config)
await self.run_relayout()
if self.config.get("startup_relayout", True):
await self.run_relayout()

# Command

Expand All @@ -130,31 +130,27 @@ async def run_relayout(

# Event handlers

async def event_monitoradded(
self, monitor_name, no_default=False, monitors: list | None = None
) -> None:
async def event_monitoradded(self, monitor_name) -> None:
"Triggers when a monitor is plugged"

if not monitors:
monitors = cast(list, await self.hyprctlJSON("monitors"))

assert monitors

for mon in monitors:
if mon["name"].startswith(monitor_name):
mon_info = mon
break
if self.config.get("full_relayout", False):
await self.run_relayout()
else:
self.log.warning("Monitor %s not found", monitor_name)
return
if not monitors:
monitors = cast(list, await self.hyprctlJSON("monitors"))

assert monitors

if self._place_single_monitor(mon_info, monitors):
return
for mon in monitors:
if mon["name"].startswith(monitor_name):
mon_info = mon
break
else:
self.log.warning("Monitor %s not found", monitor_name)
return

if not no_default:
default_command = self.config.get("unknown")
if default_command:
await asyncio.create_subprocess_shell(default_command)
if self._place_single_monitor(mon_info, monitors):
return

# Utils

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self):
async def pypr(cmd):
"Simulates the pypr command"
assert pyprctrl_mock
return pyprctrl_mock.q.put(b"%s\n" % cmd.encode("utf-8"))
await pyprctrl_mock.q.put(b"%s\n" % cmd.encode("utf-8"))


async def my_mocked_unix_server(reader, *a):
Expand Down

0 comments on commit 576dc48

Please sign in to comment.