mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-24 02:01:18 +07:00
Implement by-id workspace action addressing
It's not added to clap because there's no convenient mutually-exclusive argument enum derive yet (to have either the current <REFERENCE> or an --id <ID>). It's not added to config parsing because I don't see how it could be useful there. As such, it's only accessible through raw IPC.
This commit is contained in:
@@ -1233,6 +1233,7 @@ impl From<niri_ipc::Action> for Action {
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum WorkspaceReference {
|
pub enum WorkspaceReference {
|
||||||
|
Id(u64),
|
||||||
Index(u8),
|
Index(u8),
|
||||||
Name(String),
|
Name(String),
|
||||||
}
|
}
|
||||||
@@ -1240,6 +1241,7 @@ pub enum WorkspaceReference {
|
|||||||
impl From<WorkspaceReferenceArg> for WorkspaceReference {
|
impl From<WorkspaceReferenceArg> for WorkspaceReference {
|
||||||
fn from(reference: WorkspaceReferenceArg) -> WorkspaceReference {
|
fn from(reference: WorkspaceReferenceArg) -> WorkspaceReference {
|
||||||
match reference {
|
match reference {
|
||||||
|
WorkspaceReferenceArg::Id(id) => Self::Id(id),
|
||||||
WorkspaceReferenceArg::Index(i) => Self::Index(i),
|
WorkspaceReferenceArg::Index(i) => Self::Index(i),
|
||||||
WorkspaceReferenceArg::Name(n) => Self::Name(n),
|
WorkspaceReferenceArg::Name(n) => Self::Name(n),
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -308,10 +308,12 @@ pub enum SizeChange {
|
|||||||
AdjustProportion(f64),
|
AdjustProportion(f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Workspace reference (index or name) to operate on.
|
/// Workspace reference (id, index or name) to operate on.
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||||
pub enum WorkspaceReferenceArg {
|
pub enum WorkspaceReferenceArg {
|
||||||
|
/// Id of the workspace.
|
||||||
|
Id(u64),
|
||||||
/// Index of the workspace.
|
/// Index of the workspace.
|
||||||
Index(u8),
|
Index(u8),
|
||||||
/// Name of the workspace.
|
/// Name of the workspace.
|
||||||
|
|||||||
@@ -836,6 +836,32 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_workspace_by_id(&self, id: WorkspaceId) -> Option<(usize, &Workspace<W>)> {
|
||||||
|
match &self.monitor_set {
|
||||||
|
MonitorSet::Normal { ref monitors, .. } => {
|
||||||
|
for mon in monitors {
|
||||||
|
if let Some((index, workspace)) = mon
|
||||||
|
.workspaces
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|(_, w)| w.id() == id)
|
||||||
|
{
|
||||||
|
return Some((index, workspace));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MonitorSet::NoOutputs { workspaces } => {
|
||||||
|
if let Some((index, workspace)) =
|
||||||
|
workspaces.iter().enumerate().find(|(_, w)| w.id() == id)
|
||||||
|
{
|
||||||
|
return Some((index, workspace));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn find_workspace_by_name(&self, workspace_name: &str) -> Option<(usize, &Workspace<W>)> {
|
pub fn find_workspace_by_name(&self, workspace_name: &str) -> Option<(usize, &Workspace<W>)> {
|
||||||
match &self.monitor_set {
|
match &self.monitor_set {
|
||||||
MonitorSet::Normal { ref monitors, .. } => {
|
MonitorSet::Normal { ref monitors, .. } => {
|
||||||
|
|||||||
@@ -133,6 +133,10 @@ impl WorkspaceId {
|
|||||||
pub fn get(self) -> u64 {
|
pub fn get(self) -> u64 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn specific(id: u64) -> Self {
|
||||||
|
Self(id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
niri_render_elements! {
|
niri_render_elements! {
|
||||||
|
|||||||
+7
-5
@@ -115,6 +115,7 @@ use crate::input::{
|
|||||||
apply_libinput_settings, mods_with_finger_scroll_binds, mods_with_wheel_binds, TabletData,
|
apply_libinput_settings, mods_with_finger_scroll_binds, mods_with_wheel_binds, TabletData,
|
||||||
};
|
};
|
||||||
use crate::ipc::server::IpcServer;
|
use crate::ipc::server::IpcServer;
|
||||||
|
use crate::layout::workspace::WorkspaceId;
|
||||||
use crate::layout::{Layout, LayoutElement as _, MonitorRenderElement};
|
use crate::layout::{Layout, LayoutElement as _, MonitorRenderElement};
|
||||||
use crate::protocols::foreign_toplevel::{self, ForeignToplevelManagerState};
|
use crate::protocols::foreign_toplevel::{self, ForeignToplevelManagerState};
|
||||||
use crate::protocols::gamma_control::GammaControlManagerState;
|
use crate::protocols::gamma_control::GammaControlManagerState;
|
||||||
@@ -2422,16 +2423,17 @@ impl Niri {
|
|||||||
&self,
|
&self,
|
||||||
workspace_reference: WorkspaceReference,
|
workspace_reference: WorkspaceReference,
|
||||||
) -> Option<(Option<Output>, usize)> {
|
) -> Option<(Option<Output>, usize)> {
|
||||||
let workspace_name = match workspace_reference {
|
let (target_workspace_index, target_workspace) = match workspace_reference {
|
||||||
WorkspaceReference::Index(index) => {
|
WorkspaceReference::Index(index) => {
|
||||||
return Some((None, index.saturating_sub(1) as usize));
|
return Some((None, index.saturating_sub(1) as usize));
|
||||||
}
|
}
|
||||||
WorkspaceReference::Name(name) => name,
|
WorkspaceReference::Name(name) => self.layout.find_workspace_by_name(&name)?,
|
||||||
|
WorkspaceReference::Id(id) => {
|
||||||
|
let id = WorkspaceId::specific(id);
|
||||||
|
self.layout.find_workspace_by_id(id)?
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (target_workspace_index, target_workspace) =
|
|
||||||
self.layout.find_workspace_by_name(&workspace_name)?;
|
|
||||||
|
|
||||||
// FIXME: when we do fixes for no connected outputs, this will need fixing too.
|
// FIXME: when we do fixes for no connected outputs, this will need fixing too.
|
||||||
let active_workspace = self.layout.active_workspace()?;
|
let active_workspace = self.layout.active_workspace()?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user