mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
Implement IPC for the overview state (#1526)
* Implement IPC for the overview state * Update Overview IPC to maintain naming consistency, renamed OverviewToggled to be more clear, simplify overview state request on the server, consolidate ipc refresh * Fix Overview is_open in IPC client * Change opened to is_open * Update niri-ipc/src/lib.rs Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com> * Update niri-ipc/src/state.rs Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com> * Update src/ipc/client.rs Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com> * Update src/ipc/client.rs Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com> * Add overview state to EventStreamStatePart replicate and apply * Fix formatting * Rename Overview to OverviewState --------- Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
This commit is contained in:
@@ -97,6 +97,8 @@ pub enum Request {
|
||||
EventStream,
|
||||
/// Respond with an error (for testing error handling).
|
||||
ReturnError,
|
||||
/// Request information about the overview.
|
||||
OverviewState,
|
||||
}
|
||||
|
||||
/// Reply from niri to client.
|
||||
@@ -139,6 +141,16 @@ pub enum Response {
|
||||
PickedColor(Option<PickedColor>),
|
||||
/// Output configuration change result.
|
||||
OutputConfigChanged(OutputConfigChanged),
|
||||
/// Information about the overview.
|
||||
OverviewState(Overview),
|
||||
}
|
||||
|
||||
/// Overview information.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct Overview {
|
||||
/// Whether the overview is currently open.
|
||||
pub is_open: bool,
|
||||
}
|
||||
|
||||
/// Color picked from the screen.
|
||||
@@ -1269,6 +1281,11 @@ pub enum Event {
|
||||
/// Index of the newly active layout.
|
||||
idx: u8,
|
||||
},
|
||||
/// The overview was opened or closed.
|
||||
OverviewOpenedOrClosed {
|
||||
/// The new state of the overview.
|
||||
is_open: bool,
|
||||
},
|
||||
}
|
||||
|
||||
impl FromStr for WorkspaceReferenceArg {
|
||||
|
||||
@@ -40,6 +40,9 @@ pub struct EventStreamState {
|
||||
|
||||
/// State of the keyboard layouts.
|
||||
pub keyboard_layouts: KeyboardLayoutsState,
|
||||
|
||||
/// State of the overview.
|
||||
pub overview: OverviewState,
|
||||
}
|
||||
|
||||
/// The workspaces state communicated over the event stream.
|
||||
@@ -63,12 +66,20 @@ pub struct KeyboardLayoutsState {
|
||||
pub keyboard_layouts: Option<KeyboardLayouts>,
|
||||
}
|
||||
|
||||
/// The overview state communicated over the event stream.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct OverviewState {
|
||||
/// Whether the overview is currently open.
|
||||
pub is_open: bool,
|
||||
}
|
||||
|
||||
impl EventStreamStatePart for EventStreamState {
|
||||
fn replicate(&self) -> Vec<Event> {
|
||||
let mut events = Vec::new();
|
||||
events.extend(self.workspaces.replicate());
|
||||
events.extend(self.windows.replicate());
|
||||
events.extend(self.keyboard_layouts.replicate());
|
||||
events.extend(self.overview.replicate());
|
||||
events
|
||||
}
|
||||
|
||||
@@ -76,6 +87,7 @@ impl EventStreamStatePart for EventStreamState {
|
||||
let event = self.workspaces.apply(event)?;
|
||||
let event = self.windows.apply(event)?;
|
||||
let event = self.keyboard_layouts.apply(event)?;
|
||||
let event = self.overview.apply(event)?;
|
||||
Some(event)
|
||||
}
|
||||
}
|
||||
@@ -192,3 +204,21 @@ impl EventStreamStatePart for KeyboardLayoutsState {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl EventStreamStatePart for OverviewState {
|
||||
fn replicate(&self) -> Vec<Event> {
|
||||
vec![Event::OverviewOpenedOrClosed {
|
||||
is_open: self.is_open,
|
||||
}]
|
||||
}
|
||||
|
||||
fn apply(&mut self, event: Event) -> Option<Event> {
|
||||
match event {
|
||||
Event::OverviewOpenedOrClosed { is_open } => {
|
||||
self.is_open = is_open;
|
||||
}
|
||||
event => return Some(event),
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user