Skip to content

Conversation

@feng-yifan
Copy link

Summary

This PR introduces a new SwitchWorkspace action that switches to a workspace on its monitor without changing the currently focused monitor. This differs from the existing FocusWorkspace action, which moves keyboard focus to the target workspace's monitor.

Motivation

The current FocusWorkspace action is useful when you want to immediately start working on another workspace. However, there are valid workflows where you want to change a workspace on another monitor while keeping your current focus position:

  • Multi-monitor workflow with parallel tasks: On the primary work monitor, users often run multiple parallel tasks across different workspaces, each requiring auxiliary content from other workspaces on secondary displays. For example:

    • Workspace 1 (coding) + Reference documentation on Monitor 2
    • Workspace 2 (debugging) + Logs on Monitor 2
    • Workspace 3 (code review) + CI status on Monitor 2

    With SwitchWorkspace, the secondary monitor can automatically follow the primary monitor's workspace changes, keeping relevant auxiliary content in sync without requiring the user to manually switch and refocus.

  • Preparing a workspace on another monitor for an upcoming window move, such as organizing windows before a presentation or screen sharing session.

  • Previewing content on another monitor without interrupting current work, allowing quick glances at reference material or monitoring dashboards.

  • Setting up workspaces across multiple monitors before starting a complex task that requires specific window arrangements.

Usage

Via IPC socket:

# Connect to niri socket and send SwitchWorkspace action
socat STDIO "$NIRI_SOCKET"
{"Action":{"SwitchWorkspace":{"reference":{"Id":2}}}}

Via Rust:

let mut socket = Socket::connect()?;
socket.send(Request::Action(Action::SwitchWorkspace {
    reference: WorkspaceReferenceArg::Id(2),
}));

Implementation Details

  • niri-ipc: Added SwitchWorkspace variant to the Action enum with WorkspaceReferenceArg parameter
  • niri-config: Added SwitchWorkspace action variant and IPC conversion logic
  • src/input: Added handler in process_action that finds the output and workspace index, then delegates to the layout
  • src/layout: Added switch_workspace_on_output method that switches workspace on a specific output without changing focus

Testing

  • Compiled successfully with cargo build --release
  • Tested locally on my machine - runs well without any issues
  • Ran cargo clippy --all --all-targets - no warnings
  • Follows existing code patterns and conventions
  • Adds 30 lines across 4 files with focused, minimal changes

Backward Compatibility

This change is fully backward compatible. It adds a new optional action without modifying any existing behavior.

Related

Related to the discussion in #3351 about workspace switching behavior.

… monitor

Add a new SwitchWorkspace action that switches to a workspace on its
monitor without changing the focused monitor. This differs from
FocusWorkspace which moves keyboard focus to the target workspace's
monitor.

This enables workflows where users want to change workspace on
another monitor (e.g., preparing it for a window move) while keeping
their current focus position.

Changes:
- niri-ipc: Add SwitchWorkspace action to Action enum
- niri-config: Add SwitchWorkspace variant and IPC conversion
- src/input: Handle SwitchWorkspace action in process_action
- src/layout: Add switch_workspace_on_output method
@feng-yifan
Copy link
Author

I use a three-monitor setup. The allocation of tasks across the screens (from left to right) varies depending on my primary focus. Here’s how I typically organize them in different scenarios:

Scenario / Work Mode Left Monitor Center Monitor Right Monitor
Development Workflow Terminals (Debugging, Git, build tools) Primary Editor/IDE (Active coding) Documentation & Reference (API docs, specs)
Operations & Admin Monitoring Terminals (Logs, system dashboards) Configuration Editor (Scripts, config files) Procedural Documentation (Runbooks, wikis)
Learning & Research Nothing Note-taking (Ideas, summaries) Primary Content (eBooks, papers, course videos)

This dynamic arrangement allows me to optimize screen real estate for the specific task at hand, maintaining an efficient and focused workflow across different activities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant