summaryrefslogtreecommitdiff
path: root/src/river_protocols/control.rs
diff options
context:
space:
mode:
authorMax Verevkin <34583604+MaxVerevkin@users.noreply.github.com>2022-11-27 21:25:15 +0200
committerGitHub <noreply@github.com>2022-11-27 21:25:15 +0200
commitd28693c9d293ea7c348c0e9e1a4e89ccff6dcae4 (patch)
tree0794e56251e223388463a84d09616ef47a918bb4 /src/river_protocols/control.rs
parent9ddde2d2ee9833412e39afbd1ed907cdea22f08f (diff)
parentd45a4ef408c0f5a2071194d4c3285f0b7cb27dd0 (diff)
downloadi3bar-mango-d28693c9d293ea7c348c0e9e1a4e89ccff6dcae4.tar.gz
Merge pull request #1 from MaxVerevkin/next
Rewrite using latest walayd libs & implement HiDPI
Diffstat (limited to 'src/river_protocols/control.rs')
-rw-r--r--src/river_protocols/control.rs112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/river_protocols/control.rs b/src/river_protocols/control.rs
new file mode 100644
index 0000000..7cce23d
--- /dev/null
+++ b/src/river_protocols/control.rs
@@ -0,0 +1,112 @@
+use wayland_client::globals::{BindError, GlobalList};
+use wayland_client::{protocol::wl_seat, Connection, Dispatch, QueueHandle};
+
+use protocol::{zriver_command_callback_v1, zriver_control_v1};
+
+#[derive(Debug, Clone)]
+pub struct RiverControlState {
+ control: zriver_control_v1::ZriverControlV1,
+}
+
+impl RiverControlState {
+ pub fn new<D>(globals: &GlobalList, qh: &QueueHandle<D>) -> Result<Self, BindError>
+ where
+ D: Dispatch<zriver_control_v1::ZriverControlV1, (), D> + 'static,
+ {
+ let control = globals.bind(qh, 1..=1, ())?;
+ Ok(Self { control })
+ }
+
+ pub fn run_command<D, Args, Arg>(&self, qh: &QueueHandle<D>, seat: &wl_seat::WlSeat, args: Args)
+ where
+ D: Dispatch<zriver_command_callback_v1::ZriverCommandCallbackV1, RiverCommandCallbackData>
+ + 'static,
+ Args: IntoIterator<Item = Arg>,
+ Arg: Into<String>,
+ {
+ for arg in args {
+ self.control.add_argument(arg.into());
+ }
+ self.control
+ .run_command(seat, qh, RiverCommandCallbackData {});
+ }
+}
+
+pub trait RiverControlHandler: Sized {
+ fn river_control_state(&mut self) -> &mut RiverControlState;
+
+ fn command_failure(&mut self, conn: &Connection, qh: &QueueHandle<Self>, message: String);
+
+ fn command_success(&mut self, conn: &Connection, qh: &QueueHandle<Self>, message: String);
+}
+
+#[derive(Debug)]
+pub struct RiverCommandCallbackData {
+ // This is empty right now, but may be populated in the future.
+}
+
+#[macro_export]
+macro_rules! delegate_river_control {
+ ($ty: ty) => {
+ ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [
+ $crate::river_protocols::control::protocol::zriver_control_v1::ZriverControlV1: ()
+ ] => $crate::river_protocols::control::RiverControlState);
+ ::smithay_client_toolkit::reexports::client::delegate_dispatch!($ty: [
+ $crate::river_protocols::control::protocol::zriver_command_callback_v1::ZriverCommandCallbackV1: $crate::river_protocols::control::RiverCommandCallbackData
+ ] => $crate::river_protocols::control::RiverControlState);
+ };
+}
+
+impl<D> Dispatch<zriver_control_v1::ZriverControlV1, (), D> for RiverControlState
+where
+ D: Dispatch<zriver_control_v1::ZriverControlV1, ()> + RiverControlHandler + 'static,
+{
+ fn event(
+ _: &mut D,
+ _: &zriver_control_v1::ZriverControlV1,
+ _: zriver_control_v1::Event,
+ _: &(),
+ _: &Connection,
+ _: &QueueHandle<D>,
+ ) {
+ unreachable!("zriver_control_v1 has no events")
+ }
+}
+
+impl<D> Dispatch<zriver_command_callback_v1::ZriverCommandCallbackV1, RiverCommandCallbackData, D>
+ for RiverControlState
+where
+ D: Dispatch<zriver_command_callback_v1::ZriverCommandCallbackV1, RiverCommandCallbackData>
+ + RiverControlHandler
+ + 'static,
+{
+ fn event(
+ data: &mut D,
+ _callback: &zriver_command_callback_v1::ZriverCommandCallbackV1,
+ event: zriver_command_callback_v1::Event,
+ _udata: &RiverCommandCallbackData,
+ conn: &Connection,
+ qh: &QueueHandle<D>,
+ ) {
+ use zriver_command_callback_v1::Event;
+ match event {
+ Event::Success { output } => data.command_success(conn, qh, output),
+ Event::Failure { failure_message } => data.command_success(conn, qh, failure_message),
+ }
+ }
+}
+
+pub mod protocol {
+ #![allow(non_upper_case_globals)]
+
+ use smithay_client_toolkit::reexports::client as wayland_client;
+ use smithay_client_toolkit::reexports::client::protocol::*;
+
+ pub mod __interfaces {
+ use smithay_client_toolkit::reexports::client::protocol::__interfaces::*;
+ wayland_scanner::generate_interfaces!("protocols/river-control-unstable-v1.xml");
+ }
+ use self::__interfaces::*;
+
+ wayland_scanner::generate_client_code!("protocols/river-control-unstable-v1.xml");
+}