Skip to content

Commit

Permalink
layout/monitor: Add next monitor to focus/move to
Browse files Browse the repository at this point in the history
  • Loading branch information
julianschuler committed Dec 15, 2024
1 parent 82e3024 commit 19c07bb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions niri-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,14 +1225,17 @@ pub enum Action {
FocusMonitorRight,
FocusMonitorDown,
FocusMonitorUp,
FocusMonitorNext,
MoveWindowToMonitorLeft,
MoveWindowToMonitorRight,
MoveWindowToMonitorDown,
MoveWindowToMonitorUp,
MoveWindowToMonitorNext,
MoveColumnToMonitorLeft,
MoveColumnToMonitorRight,
MoveColumnToMonitorDown,
MoveColumnToMonitorUp,
MoveColumnToMonitorNext,
SetWindowHeight(#[knuffel(argument, str)] SizeChange),
#[knuffel(skip)]
SetWindowHeightById {
Expand All @@ -1254,6 +1257,7 @@ pub enum Action {
MoveWorkspaceToMonitorRight,
MoveWorkspaceToMonitorDown,
MoveWorkspaceToMonitorUp,
MoveWorkspaceToMonitorNext,
}

impl From<niri_ipc::Action> for Action {
Expand Down Expand Up @@ -1353,14 +1357,17 @@ impl From<niri_ipc::Action> for Action {
niri_ipc::Action::FocusMonitorRight {} => Self::FocusMonitorRight,
niri_ipc::Action::FocusMonitorDown {} => Self::FocusMonitorDown,
niri_ipc::Action::FocusMonitorUp {} => Self::FocusMonitorUp,
niri_ipc::Action::FocusMonitorNext {} => Self::FocusMonitorNext,
niri_ipc::Action::MoveWindowToMonitorLeft {} => Self::MoveWindowToMonitorLeft,
niri_ipc::Action::MoveWindowToMonitorRight {} => Self::MoveWindowToMonitorRight,
niri_ipc::Action::MoveWindowToMonitorDown {} => Self::MoveWindowToMonitorDown,
niri_ipc::Action::MoveWindowToMonitorUp {} => Self::MoveWindowToMonitorUp,
niri_ipc::Action::MoveWindowToMonitorNext {} => Self::MoveWindowToMonitorNext,
niri_ipc::Action::MoveColumnToMonitorLeft {} => Self::MoveColumnToMonitorLeft,
niri_ipc::Action::MoveColumnToMonitorRight {} => Self::MoveColumnToMonitorRight,
niri_ipc::Action::MoveColumnToMonitorDown {} => Self::MoveColumnToMonitorDown,
niri_ipc::Action::MoveColumnToMonitorUp {} => Self::MoveColumnToMonitorUp,
niri_ipc::Action::MoveColumnToMonitorNext {} => Self::MoveColumnToMonitorNext,
niri_ipc::Action::SetWindowHeight { id: None, change } => Self::SetWindowHeight(change),
niri_ipc::Action::SetWindowHeight {
id: Some(id),
Expand All @@ -1383,6 +1390,7 @@ impl From<niri_ipc::Action> for Action {
niri_ipc::Action::MoveWorkspaceToMonitorRight {} => Self::MoveWorkspaceToMonitorRight,
niri_ipc::Action::MoveWorkspaceToMonitorDown {} => Self::MoveWorkspaceToMonitorDown,
niri_ipc::Action::MoveWorkspaceToMonitorUp {} => Self::MoveWorkspaceToMonitorUp,
niri_ipc::Action::MoveWorkspaceToMonitorNext {} => Self::MoveWorkspaceToMonitorNext,
niri_ipc::Action::ToggleDebugTint {} => Self::ToggleDebugTint,
niri_ipc::Action::DebugToggleOpaqueRegions {} => Self::DebugToggleOpaqueRegions,
niri_ipc::Action::DebugToggleDamage {} => Self::DebugToggleDamage,
Expand Down
8 changes: 8 additions & 0 deletions niri-ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ pub enum Action {
FocusMonitorDown {},
/// Focus the monitor above.
FocusMonitorUp {},
/// Focus the next monitor.
FocusMonitorNext {},
/// Move the focused window to the monitor to the left.
MoveWindowToMonitorLeft {},
/// Move the focused window to the monitor to the right.
Expand All @@ -354,6 +356,8 @@ pub enum Action {
MoveWindowToMonitorDown {},
/// Move the focused window to the monitor above.
MoveWindowToMonitorUp {},
/// Move the focused window to the next monitor.
MoveWindowToMonitorNext {},
/// Move the focused column to the monitor to the left.
MoveColumnToMonitorLeft {},
/// Move the focused column to the monitor to the right.
Expand All @@ -362,6 +366,8 @@ pub enum Action {
MoveColumnToMonitorDown {},
/// Move the focused column to the monitor above.
MoveColumnToMonitorUp {},
/// Move the focused column to the next monitor.
MoveColumnToMonitorNext {},
/// Change the height of a window.
#[cfg_attr(
feature = "clap",
Expand Down Expand Up @@ -424,6 +430,8 @@ pub enum Action {
MoveWorkspaceToMonitorDown {},
/// Move the focused workspace to the monitor above.
MoveWorkspaceToMonitorUp {},
/// Move the focused workspace to the next monitor.
MoveWorkspaceToMonitorNext {},
/// Toggle a debug tint on windows.
ToggleDebugTint {},
/// Toggle visualization of render element opaque regions.
Expand Down
34 changes: 34 additions & 0 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,14 @@ impl State {
}
}
}
Action::FocusMonitorNext => {
if let Some(output) = self.niri.output_next() {
self.niri.layout.focus_output(&output);
if !self.maybe_warp_cursor_to_focus_centered() {
self.move_cursor_to_output(&output);
}
}
}
Action::MoveWindowToMonitorLeft => {
if let Some(output) = self.niri.output_left() {
self.niri.layout.move_to_output(None, &output, None);
Expand Down Expand Up @@ -1198,6 +1206,15 @@ impl State {
}
}
}
Action::MoveWindowToMonitorNext => {
if let Some(output) = self.niri.output_next() {
self.niri.layout.move_to_output(None, &output, None);
self.niri.layout.focus_output(&output);
if !self.maybe_warp_cursor_to_focus_centered() {
self.move_cursor_to_output(&output);
}
}
}
Action::MoveColumnToMonitorLeft => {
if let Some(output) = self.niri.output_left() {
self.niri.layout.move_column_to_output(&output);
Expand Down Expand Up @@ -1234,6 +1251,15 @@ impl State {
}
}
}
Action::MoveColumnToMonitorNext => {
if let Some(output) = self.niri.output_next() {
self.niri.layout.move_column_to_output(&output);
self.niri.layout.focus_output(&output);
if !self.maybe_warp_cursor_to_focus_centered() {
self.move_cursor_to_output(&output);
}
}
}
Action::SetColumnWidth(change) => {
self.niri.layout.set_column_width(change);
}
Expand Down Expand Up @@ -1294,6 +1320,14 @@ impl State {
}
}
}
Action::MoveWorkspaceToMonitorNext => {
if let Some(output) = self.niri.output_next() {
self.niri.layout.move_workspace_to_output(&output);
if !self.maybe_warp_cursor_to_focus_centered() {
self.move_cursor_to_output(&output);
}
}
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,17 @@ impl Niri {
.cloned()
}

pub fn output_next(&self) -> Option<Output> {
let active = self.layout.active_output()?;

self.global_space
.outputs()
.skip_while(|&output| output != active)
.nth(1)
.or(self.global_space.outputs().next())
.cloned()
}

pub fn find_output_and_workspace_index(
&self,
workspace_reference: WorkspaceReference,
Expand Down

0 comments on commit 19c07bb

Please sign in to comment.