Skip to content

Commit 2c92e7a

Browse files
committed
wallpapers: do not change background if previously cleared
1 parent e334320 commit 2c92e7a

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

pyprland/plugins/wallpapers.py

+28-24
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Extension(CastBoolMixin, Plugin):
3939

4040
next_background_event = asyncio.Event()
4141
cur_image = ""
42+
_paused = False
4243

4344
async def on_reload(self) -> None:
4445
"""Re-build the image list."""
@@ -88,34 +89,35 @@ async def main_loop(self) -> None:
8889
variables = state.variables.copy()
8990

9091
while self.running:
91-
self.next_background_event.clear()
92-
93-
# Define the command template based on the 'unique' flag
94-
cmd_template = self.config.get(
95-
"command",
96-
('swaybg -o [output] -m fill -i "[file]"' if unique else 'swaybg -m fill -i "[file]"'),
97-
)
98-
99-
if unique:
100-
monitors = await self.hyprctl_json("monitors")
101-
old_filename = None
102-
for monitor in monitors:
103-
filename = prepare_for_quotes(self.select_next_image())
104-
while filename == old_filename:
92+
if not self._paused:
93+
self.next_background_event.clear()
94+
95+
# Define the command template based on the 'unique' flag
96+
cmd_template = self.config.get(
97+
"command",
98+
('swaybg -o [output] -m fill -i "[file]"' if unique else 'swaybg -m fill -i "[file]"'),
99+
)
100+
101+
if unique:
102+
monitors = await self.hyprctl_json("monitors")
103+
old_filename = None
104+
for monitor in monitors:
105105
filename = prepare_for_quotes(self.select_next_image())
106-
variables.update({"file": filename, "output": monitor["name"]})
106+
while filename == old_filename:
107+
filename = prepare_for_quotes(self.select_next_image())
108+
variables.update({"file": filename, "output": monitor["name"]})
109+
await self._run_one(cmd_template, variables)
110+
else:
111+
filename = self.select_next_image().replace('"', '\\"')
112+
variables.update({"file": filename})
107113
await self._run_one(cmd_template, variables)
108-
else:
109-
filename = self.select_next_image().replace('"', '\\"')
110-
variables.update({"file": filename})
111-
await self._run_one(cmd_template, variables)
112114

113-
await asyncio.sleep(1) # wait for the command(s) to start
115+
await asyncio.sleep(1) # wait for the command(s) to start
114116

115-
# check if the command failed
116-
for proc in self.proc:
117-
if proc.returncode:
118-
await self.notify_error("wallpaper command failed")
117+
# check if the command failed
118+
for proc in self.proc:
119+
if proc.returncode:
120+
await self.notify_error("wallpaper command failed")
119121

120122
interval = asyncio.sleep(60 * self.config.get("interval", 10) - 1)
121123
await asyncio.wait(
@@ -140,6 +142,7 @@ async def terminate(self) -> None:
140142
async def run_wall(self, arg: str) -> None:
141143
"""<next|clear> skip the current background image or stop displaying it."""
142144
if arg.startswith("n"):
145+
self._paused = False
143146
self.next_background_event.set()
144147
elif arg.startswith("c"):
145148
clear_command = self.config.get("clear_command")
@@ -149,4 +152,5 @@ async def run_wall(self, arg: str) -> None:
149152
# wait for it to finish
150153
await proc.wait()
151154
else:
155+
self._paused = True
152156
await self.terminate()

pyprland/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Package version."""
22

3-
VERSION = "2.3.1-2"
3+
VERSION = "2.3.1-3"

0 commit comments

Comments
 (0)