aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs6
-rw-r--r--src/input.rs11
-rw-r--r--src/ipc/client.rs12
-rw-r--r--src/ipc/server.rs9
-rw-r--r--src/layout/mod.rs3
-rw-r--r--src/layout/monitor.rs2
-rw-r--r--src/layout/workspace.rs3
7 files changed, 39 insertions, 7 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 8dd8927d..2632f1ec 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -2,6 +2,7 @@ use std::ffi::OsString;
use std::path::PathBuf;
use clap::{Parser, Subcommand};
+use niri_ipc::Action;
use crate::utils::version;
@@ -46,4 +47,9 @@ pub enum Sub {
pub enum Msg {
/// List connected outputs.
Outputs,
+ /// Perform an action.
+ Action {
+ #[command(subcommand)]
+ action: Action,
+ },
}
diff --git a/src/input.rs b/src/input.rs
index 507e4479..0f586aba 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -1,7 +1,8 @@
use std::any::Any;
use std::collections::HashSet;
-use niri_config::{Action, Binds, LayoutAction, Modifiers};
+use niri_config::{Action, Binds, Modifiers};
+use niri_ipc::LayoutSwitchTarget;
use smithay::backend::input::{
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _,
@@ -273,6 +274,10 @@ impl State {
return;
}
+ self.do_action(action);
+ }
+
+ pub fn do_action(&mut self, action: Action) {
if self.niri.is_locked() && !allowed_when_locked(&action) {
return;
}
@@ -377,8 +382,8 @@ impl State {
self.niri.seat.get_keyboard().unwrap().with_xkb_state(
self,
|mut state| match action {
- LayoutAction::Next => state.cycle_next_layout(),
- LayoutAction::Prev => state.cycle_prev_layout(),
+ LayoutSwitchTarget::Next => state.cycle_next_layout(),
+ LayoutSwitchTarget::Prev => state.cycle_prev_layout(),
},
);
}
diff --git a/src/ipc/client.rs b/src/ipc/client.rs
index 7754187a..b2004a7b 100644
--- a/src/ipc/client.rs
+++ b/src/ipc/client.rs
@@ -19,8 +19,9 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
let mut stream =
UnixStream::connect(socket_path).context("error connecting to {socket_path}")?;
- let request = match msg {
+ let request = match &msg {
Msg::Outputs => Request::Outputs,
+ Msg::Action { action } => Request::Action(action.clone()),
};
let mut buf = serde_json::to_vec(&request).unwrap();
stream
@@ -35,6 +36,14 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
.read_to_end(&mut buf)
.context("error reading IPC response")?;
+ if matches!(msg, Msg::Action { .. }) {
+ if buf.is_empty() {
+ return Ok(());
+ } else {
+ bail!("unexpected response: expected no response, got {buf:?}");
+ }
+ }
+
let response = serde_json::from_slice(&buf).context("error parsing IPC response")?;
match msg {
Msg::Outputs => {
@@ -100,6 +109,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
println!();
}
}
+ Msg::Action { .. } => unreachable!(),
}
Ok(())
diff --git a/src/ipc/server.rs b/src/ipc/server.rs
index d493e861..bedfe48f 100644
--- a/src/ipc/server.rs
+++ b/src/ipc/server.rs
@@ -22,6 +22,7 @@ pub struct IpcServer {
}
struct ClientCtx {
+ event_loop: LoopHandle<'static, State>,
ipc_outputs: Rc<RefCell<HashMap<String, niri_ipc::Output>>>,
}
@@ -85,6 +86,7 @@ fn on_new_ipc_client(state: &mut State, stream: UnixStream) {
};
let ctx = ClientCtx {
+ event_loop: state.niri.event_loop.clone(),
ipc_outputs: state.backend.ipc_outputs(),
};
@@ -115,6 +117,13 @@ async fn handle_client(ctx: ClientCtx, stream: Async<'_, UnixStream>) -> anyhow:
let ipc_outputs = ctx.ipc_outputs.borrow().clone();
Response::Outputs(ipc_outputs)
}
+ Request::Action(action) => {
+ let action = niri_config::Action::from(action);
+ ctx.event_loop.insert_idle(move |state| {
+ state.do_action(action);
+ });
+ return Ok(());
+ }
};
let buf = serde_json::to_vec(&response).context("error formatting response")?;
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index c4bcc61f..93b1fe13 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -34,7 +34,8 @@ use std::mem;
use std::rc::Rc;
use std::time::Duration;
-use niri_config::{self, CenterFocusedColumn, Config, SizeChange, Struts};
+use niri_config::{self, CenterFocusedColumn, Config, Struts};
+use niri_ipc::SizeChange;
use smithay::backend::renderer::element::solid::SolidColorRenderElement;
use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
use smithay::backend::renderer::element::{AsRenderElements, Id};
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index e67f5bf2..cb99279a 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -2,7 +2,7 @@ use std::cmp::min;
use std::rc::Rc;
use std::time::Duration;
-use niri_config::SizeChange;
+use niri_ipc::SizeChange;
use smithay::backend::renderer::element::utils::{
CropRenderElement, Relocate, RelocateRenderElement,
};
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 0e576b7a..64bc4bc7 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -3,7 +3,8 @@ use std::iter::{self, zip};
use std::rc::Rc;
use std::time::Duration;
-use niri_config::{CenterFocusedColumn, PresetWidth, SizeChange, Struts};
+use niri_config::{CenterFocusedColumn, PresetWidth, Struts};
+use niri_ipc::SizeChange;
use smithay::desktop::space::SpaceElement;
use smithay::desktop::{layer_map_for_output, Window};
use smithay::output::Output;