Skip to content

Commit

Permalink
layout_center: refactor of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
fdev31 committed Nov 6, 2024
1 parent b312bf6 commit 10d5915
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions pyprland/plugins/layout_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""

from collections import defaultdict
from collections.abc import Callable
from functools import partial
from typing import Any, cast

from ..common import CastBoolMixin, is_rotated, state
Expand All @@ -19,6 +21,17 @@ class Extension(CastBoolMixin, Plugin):

workspace_info: dict[str, dict[str, Any]] = defaultdict(lambda: {"enabled": False, "addr": ""})
last_index = 0
command_handlers: dict[str, Callable]

async def init(self) -> None:
"""Initialize the plugin."""
self.command_handlers = {
"toggle": self._run_toggle,
"next": partial(self._run_changefocus, 1, default_override="next"),
"prev": partial(self._run_changefocus, -1, default_override="prev"),
"next2": partial(self._run_changefocus, 1, default_override="next2"),
"prev2": partial(self._run_changefocus, -1, default_override="prev2"),
}

# Events

Expand Down Expand Up @@ -80,16 +93,9 @@ async def event_closewindow(self, addr: str) -> None:

async def run_layout_center(self, what: str) -> None:
"""<toggle|next|prev> turn on/off or change the active window."""
if what == "toggle":
await self._run_toggle()
elif what == "next":
await self._run_changefocus(1, default_override="next")
elif what == "prev":
await self._run_changefocus(-1, default_override="prev")
elif what == "next2":
await self._run_changefocus(1, default_override="next2")
elif what == "prev2":
await self._run_changefocus(-1, default_override="prev2")
fn = self.command_handlers.get(what)
if fn:
await fn()
else:
await self.notify_error(f"unknown layout_center command: {what}")

Expand Down
2 changes: 1 addition & 1 deletion pyprland/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Package version."""

VERSION = "2.4.3-1"
VERSION = "2.4.3-4"

0 comments on commit 10d5915

Please sign in to comment.