CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-i3ipc

Python library for controlling the i3 window manager and sway compositor through their IPC interface

Pending
Overview
Eval results
Files

workspaces.mddocs/

Workspace Operations

Complete workspace querying and management functionality for i3/sway workspaces. Provides detailed workspace information including visibility, focus state, dimensions, and output assignments.

Capabilities

Workspace Querying

def get_workspaces(self) -> List[WorkspaceReply]:
    """
    Get information about all workspaces.
    
    Returns:
    List[WorkspaceReply]: comprehensive workspace details for all workspaces
    """

Workspace Reply Structure

class WorkspaceReply:
    """Complete workspace information from GET_WORKSPACES response."""
    
    # Identification
    num: int  # Logical workspace number (-1 for named workspaces)
    name: str  # Workspace name (default: num+1, or custom name)
    
    # State properties
    visible: bool  # Whether workspace is currently visible on any output
    focused: bool  # Whether workspace currently has keyboard focus
    urgent: bool  # Whether workspace contains urgent windows
    
    # Layout and positioning
    rect: Rect  # Workspace rectangle (dimensions and position)
    output: str  # Name of output (monitor) displaying this workspace
    
    # Raw data access
    ipc_data: dict  # Complete raw IPC response data

Workspace Container Navigation

# From Con class - workspace-specific methods
def workspaces(self) -> List[Con]:
    """
    Get all workspace containers from the tree.
    
    Returns:
    List[Con]: all containers of type 'workspace'
    """

def workspace(self) -> Optional[Con]:
    """
    Get the workspace container that contains this container.
    
    Returns:
    Optional[Con]: parent workspace container or None if at root level
    """

Workspace Container Properties

# Workspace-specific properties available on Con objects of type 'workspace'
class Con:
    # When type == 'workspace':
    num: int  # Workspace number (matches WorkspaceReply.num)
    name: str  # Workspace name (matches WorkspaceReply.name)
    urgent: bool  # Urgent state
    focused: bool  # Focus state
    rect: Rect  # Workspace dimensions and position
    
    # Layout properties
    layout: str  # Workspace layout (splith, splitv, stacked, tabbed)
    orientation: str  # Primary split orientation
    
    # Child containers
    nodes: List[Con]  # Tiled child containers
    floating_nodes: List[Con]  # Floating child containers

Rectangle Geometry

class Rect:
    """Rectangle dimensions and positioning for workspaces."""
    x: int  # X coordinate of workspace area
    y: int  # Y coordinate of workspace area  
    width: int  # Workspace width in pixels
    height: int  # Workspace height in pixels

Workspace Examples

# Get all workspaces and display their status
workspaces = i3.get_workspaces()
for ws in workspaces:
    status = []
    if ws.focused:
        status.append("focused")
    if ws.visible:
        status.append("visible")  
    if ws.urgent:
        status.append("urgent")
    
    status_str = f" ({', '.join(status)})" if status else ""
    print(f"Workspace {ws.name} on {ws.output}{status_str}")
    print(f"  Dimensions: {ws.rect.width}x{ws.rect.height} at ({ws.rect.x}, {ws.rect.y})")

# Find the currently focused workspace
focused_ws = next((ws for ws in workspaces if ws.focused), None)
if focused_ws:
    print(f"Currently focused: {focused_ws.name}")

# Get workspace containers from tree
tree = i3.get_tree()
workspace_cons = tree.workspaces()
for ws_con in workspace_cons:
    print(f"Workspace {ws_con.name} has {len(ws_con.nodes)} tiled windows")
    print(f"  and {len(ws_con.floating_nodes)} floating windows")

# Find workspace containing a specific container
some_container = tree.find_focused()
if some_container:
    workspace = some_container.workspace()
    if workspace:
        print(f"Focused container is on workspace: {workspace.name}")

Install with Tessl CLI

npx tessl i tessl/pypi-i3ipc

docs

async.md

commands.md

connection.md

containers.md

events.md

index.md

outputs.md

workspaces.md

tile.json