Added prev/next workspace commands

This commit is contained in:
Ezri 2025-02-12 13:15:26 -07:00
parent e99a57b074
commit c91f8da1a0
Signed by: ezri
GPG Key ID: 058A78E5680C6F24
2 changed files with 29 additions and 6 deletions

View File

@ -62,12 +62,14 @@ class ContextMngrInterface(
@dbus_method_async(input_signature="y", result_signature="b") @dbus_method_async(input_signature="y", result_signature="b")
async def move_container(self, user_index: int) -> bool: async def move_container(self, user_index: int) -> bool:
"""Move the focused container to a workspace by its 1-indexed ID in its group.""" """Move the focused container to a workspace by its 1-indexed ID in its group."""
print("Moving focused container to workspace", user_index) try:
print("Moving focused container to workspace", user_index, flush=True)
workspace, _ = self.workspace_tree.get_workspace(user_index) workspace, _ = self.workspace_tree.get_workspace(user_index)
if workspace is None: await workspace.move_container(self.connection)
return False
await workspace[0].move_container(self.connection)
return True return True
except Exception as e:
print(e, flush=True)
return False
@dbus_method_async(input_signature="", result_signature="b") @dbus_method_async(input_signature="", result_signature="b")
async def launch_default(self) -> bool: async def launch_default(self) -> bool:
@ -79,13 +81,29 @@ class ContextMngrInterface(
return True return True
@dbus_method_async(input_signature="y", result_signature="s") @dbus_method_async(input_signature="y", result_signature="s")
async def get_workspace(self, user_index: int) -> bool: async def get_workspace(self, user_index: int) -> str:
"""Get a workspace by its 1-indexed ID in its group.""" """Get a workspace by its 1-indexed ID in its group."""
workspace = self.workspace_tree.get_workspace(user_index) workspace = self.workspace_tree.get_workspace(user_index)
if workspace is None: if workspace is None:
return "" return ""
return json.dumps(workspace.__json__()) return json.dumps(workspace.__json__())
@dbus_method_async(input_signature="", result_signature="")
async def focus_next_workspace(self) -> None:
"""Switch to the next workspace on the focused output."""
try:
await self.workspace_tree.current_context.active_group.get_relative_workspace(1).focus(self.connection)
except Exception as e:
print(e, flush=True)
@dbus_method_async(input_signature="", result_signature="")
async def focus_previous_workspace(self) -> None:
"""Switch to the previous workspace on the focused output."""
try:
await self.workspace_tree.current_context.active_group.get_relative_workspace(-1).focus(self.connection)
except Exception as e:
print(e, flush=True)
async def __get_workspace_data(self) -> dict: async def __get_workspace_data(self) -> dict:
"""Get the workspace tree.""" """Get the workspace tree."""
try: try:

View File

@ -169,6 +169,11 @@ class WorkspaceGroup:
f"output {selector} position {self.position[0]} {self.position[1]} {mode} {transform} enable" f"output {selector} position {self.position[0]} {self.position[1]} {mode} {transform} enable"
) )
def get_relative_workspace(self, offset: int) -> Workspace:
"""Returns the workspace offset from the active workspace, looping around if necessary."""
active_index = self.workspaces.index(self.active_workspace)
return self.workspaces[(active_index + offset) % len(self.workspaces)]
async def validate(self, i3: Connection, workspaces: list[WorkspaceReply]): async def validate(self, i3: Connection, workspaces: list[WorkspaceReply]):
"""Validate that each workspace in the group is assigned to and present on the correct output.""" """Validate that each workspace in the group is assigned to and present on the correct output."""
ouput_name = self.get_output_name(i3) ouput_name = self.get_output_name(i3)