Added prev/next workspace commands
This commit is contained in:
parent
e99a57b074
commit
c91f8da1a0
@ -62,12 +62,14 @@ class ContextMngrInterface(
|
||||
@dbus_method_async(input_signature="y", result_signature="b")
|
||||
async def move_container(self, user_index: int) -> bool:
|
||||
"""Move the focused container to a workspace by its 1-indexed ID in its group."""
|
||||
print("Moving focused container to workspace", user_index)
|
||||
workspace, _ = self.workspace_tree.get_workspace(user_index)
|
||||
if workspace is None:
|
||||
try:
|
||||
print("Moving focused container to workspace", user_index, flush=True)
|
||||
workspace, _ = self.workspace_tree.get_workspace(user_index)
|
||||
await workspace.move_container(self.connection)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(e, flush=True)
|
||||
return False
|
||||
await workspace[0].move_container(self.connection)
|
||||
return True
|
||||
|
||||
@dbus_method_async(input_signature="", result_signature="b")
|
||||
async def launch_default(self) -> bool:
|
||||
@ -79,13 +81,29 @@ class ContextMngrInterface(
|
||||
return True
|
||||
|
||||
@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."""
|
||||
workspace = self.workspace_tree.get_workspace(user_index)
|
||||
if workspace is None:
|
||||
return ""
|
||||
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:
|
||||
"""Get the workspace tree."""
|
||||
try:
|
||||
|
||||
@ -169,6 +169,11 @@ class WorkspaceGroup:
|
||||
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]):
|
||||
"""Validate that each workspace in the group is assigned to and present on the correct output."""
|
||||
ouput_name = self.get_output_name(i3)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user