sway + input #40
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "addr2line"
|
name = "addr2line"
|
||||||
@ -620,8 +620,10 @@ dependencies = [
|
|||||||
"clap-verbosity-flag",
|
"clap-verbosity-flag",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures",
|
||||||
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"mpvipc-async",
|
"mpvipc-async",
|
||||||
|
"regex",
|
||||||
"sd-notify",
|
"sd-notify",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -988,6 +990,12 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.168"
|
version = "0.2.168"
|
||||||
|
@ -9,6 +9,8 @@ readme = "README.md"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
regex = "1.5.4"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
url = "2.2.2"
|
url = "2.2.2"
|
||||||
swayipc = "3.0"
|
swayipc = "3.0"
|
||||||
anyhow = "1.0.82"
|
anyhow = "1.0.82"
|
||||||
|
@ -14,6 +14,8 @@ in
|
|||||||
|
|
||||||
enableFirefox = lib.mkEnableOption "include fiorefox browser for external urls";
|
enableFirefox = lib.mkEnableOption "include fiorefox browser for external urls";
|
||||||
|
|
||||||
|
enableInput = lib.mkEnableOption "enable input maipulation with ydotool,";
|
||||||
|
|
||||||
enablePipewire = lib.mkEnableOption "pipewire" // { default = true; };
|
enablePipewire = lib.mkEnableOption "pipewire" // { default = true; };
|
||||||
|
|
||||||
logLevel = lib.mkOption {
|
logLevel = lib.mkOption {
|
||||||
@ -162,6 +164,11 @@ in
|
|||||||
pulse.enable = true;
|
pulse.enable = true;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
(lib.mkIf (cfg.enable && cfg.enableInput) {
|
||||||
|
programs.ydotool = {
|
||||||
|
enable = true;
|
||||||
|
};
|
||||||
|
})
|
||||||
(lib.mkIf (cfg.enable && cfg.enableSway) {
|
(lib.mkIf (cfg.enable && cfg.enableSway) {
|
||||||
programs.sway = {
|
programs.sway = {
|
||||||
enable = true;
|
enable = true;
|
||||||
@ -188,7 +195,7 @@ in
|
|||||||
users.greg = {
|
users.greg = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
group = "greg";
|
group = "greg";
|
||||||
extraGroups [ "audio" "video" "input" ];
|
extraGroups [ "audio" "video" "input" "ydotool" ];
|
||||||
uid = 2000;
|
uid = 2000;
|
||||||
description = "loud gym bro";
|
description = "loud gym bro";
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
mod base;
|
mod base;
|
||||||
mod rest_wrapper_v1;
|
// mod rest_wrapper_v1;
|
||||||
mod rest_wrapper_v2;
|
mod rest_wrapper_v2;
|
||||||
mod websocket_v1;
|
mod websocket_v1;
|
||||||
|
|
||||||
pub use rest_wrapper_v1::{rest_api_docs as rest_api_docs_v1, rest_api_routes as rest_api_routes_v1};
|
// pub use rest_wrapper_v1::{rest_api_docs as rest_api_docs_v1, rest_api_routes as rest_api_routes_v1};
|
||||||
pub use rest_wrapper_v2::{rest_api_docs as rest_api_docs_v2, rest_api_routes as rest_api_routes_v2};
|
pub use rest_wrapper_v2::{rest_api_docs as rest_api_docs_v2, rest_api_routes as rest_api_routes_v2};
|
||||||
pub use websocket_v1::websocket_api;
|
pub use websocket_v1::websocket_api;
|
||||||
|
174
src/api/base.rs
174
src/api/base.rs
@ -173,16 +173,15 @@ pub async fn playlist_set_looping(mpv: Mpv, r#loop: bool) -> anyhow::Result<()>
|
|||||||
|
|
||||||
use swayipc::{Connection, Fallible};
|
use swayipc::{Connection, Fallible};
|
||||||
|
|
||||||
pub async fn sway_run_command(command: String) -> Fallible<()> {
|
// pub async fn sway_run_command(command: String) -> Fallible<()> {
|
||||||
tokio::task::spawn_blocking(move || -> Fallible<()> {
|
// tokio::task::spawn_blocking(move || -> Fallible<()> {
|
||||||
let mut connection = Connection::new()?;
|
// let mut connection = Connection::new()?;
|
||||||
connection.run_command(&command)?;
|
// connection.run_command(&command)?;
|
||||||
Ok(())
|
// Ok(())
|
||||||
})
|
// })
|
||||||
.await
|
// .await
|
||||||
.map_err(|e| swayipc::Error::CommandFailed(e.to_string()))?
|
// .map_err(|e| swayipc::Error::CommandFailed(e.to_string()))?
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
//only to check if workspace exists.
|
//only to check if workspace exists.
|
||||||
fn get_workspace_names(connection: &mut Connection) -> Fallible<Vec<String>> {
|
fn get_workspace_names(connection: &mut Connection) -> Fallible<Vec<String>> {
|
||||||
@ -225,6 +224,7 @@ pub async fn sway_change_workspace(workspace: String) -> Fallible<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub async fn sway_launch_browser(url: &str) -> Fallible<()> {
|
pub async fn sway_launch_browser(url: &str) -> Fallible<()> {
|
||||||
// Validate URL
|
// Validate URL
|
||||||
let url = Url::parse(url)
|
let url = Url::parse(url)
|
||||||
@ -237,7 +237,19 @@ pub async fn sway_launch_browser(url: &str) -> Fallible<()> {
|
|||||||
|
|
||||||
tokio::task::spawn_blocking(move || -> Fallible<()> {
|
tokio::task::spawn_blocking(move || -> Fallible<()> {
|
||||||
let mut connection = Connection::new()?;
|
let mut connection = Connection::new()?;
|
||||||
connection.run_command(&format!("exec xdg-open {}", url))?;
|
// connection.run_command(&format!("exec xdg-open {}", url))?;
|
||||||
|
connection.run_command(&format!("exec firefox --kiosk {}", url))?; //moved to firefox to pin in kiosk mode. potentially add --new-window
|
||||||
|
|
||||||
|
// let browser_output = std::process::Command::new("xdg-settings")
|
||||||
|
// .arg("get")
|
||||||
|
// .arg("default-web-browser")
|
||||||
|
// .output()?;
|
||||||
|
// let default_browser = String::from_utf8(browser_output.stdout)?
|
||||||
|
// .trim()
|
||||||
|
// .trim_end_matches(".desktop")
|
||||||
|
// .to_string();
|
||||||
|
// connection.run_command(&format!("exec {} --kiosk {}", default_browser, url))?; // set default browser in kiosk mode
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
@ -255,6 +267,22 @@ pub async fn sway_close_workspace(workspace: String) -> Fallible<()> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // Get workspace tree and find all nodes in target workspace
|
||||||
|
// let tree = connection.get_tree()?;
|
||||||
|
// let workspace_nodes = tree
|
||||||
|
// .nodes
|
||||||
|
// .iter()
|
||||||
|
// .flat_map(|output| &output.nodes) // Get workspaces
|
||||||
|
// .find(|ws| ws.name.as_ref().map_or(false, |name| name == &workspace));
|
||||||
|
|
||||||
|
// // Kill all nodes in workspace if found
|
||||||
|
// if let Some(ws) = workspace_nodes {
|
||||||
|
// for container in ws.nodes.iter() {
|
||||||
|
// // Close each container in the workspace
|
||||||
|
// connection.run_command(&format!("[con_id={}] kill", container.id))?;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// Get workspace tree and find all nodes in target workspace
|
// Get workspace tree and find all nodes in target workspace
|
||||||
let tree = connection.get_tree()?;
|
let tree = connection.get_tree()?;
|
||||||
let workspace_nodes = tree
|
let workspace_nodes = tree
|
||||||
@ -263,13 +291,21 @@ pub async fn sway_close_workspace(workspace: String) -> Fallible<()> {
|
|||||||
.flat_map(|output| &output.nodes) // Get workspaces
|
.flat_map(|output| &output.nodes) // Get workspaces
|
||||||
.find(|ws| ws.name.as_ref().map_or(false, |name| name == &workspace));
|
.find(|ws| ws.name.as_ref().map_or(false, |name| name == &workspace));
|
||||||
|
|
||||||
// Kill all nodes in workspace if found
|
// Kill all non-MPV nodes in workspace if found
|
||||||
if let Some(ws) = workspace_nodes {
|
if let Some(ws) = workspace_nodes {
|
||||||
for container in ws.nodes.iter() {
|
for container in ws.nodes.iter() {
|
||||||
// Close each container in the workspace
|
// Check if window is MPV
|
||||||
|
let is_mpv = container.window_properties.as_ref()
|
||||||
|
.map(|props| props.class.as_ref()
|
||||||
|
.map_or(false, |class| class == "mpv"))
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
if !is_mpv {
|
||||||
|
// Close container only if not MPV
|
||||||
connection.run_command(&format!("[con_id={}] kill", container.id))?;
|
connection.run_command(&format!("[con_id={}] kill", container.id))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@ -277,3 +313,115 @@ pub async fn sway_close_workspace(workspace: String) -> Fallible<()> {
|
|||||||
.map_err(|e| swayipc::Error::CommandFailed(e.to_string()))?
|
.map_err(|e| swayipc::Error::CommandFailed(e.to_string()))?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
use regex::Regex;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref KEYPRESS_PATTERN: Regex = Regex::new(r"^(\d+:[01]\s*)+$").unwrap();
|
||||||
|
static ref CLEANUP_PATTERN: Regex = Regex::new(r"[^0-9: \t]").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate_keypress_string(input: &str) -> Fallible<String> {
|
||||||
|
let cleaned = CLEANUP_PATTERN.replace_all(input, "").to_string();
|
||||||
|
let cleaned = cleaned.trim();
|
||||||
|
|
||||||
|
if !KEYPRESS_PATTERN.is_match(cleaned) {
|
||||||
|
return Err(swayipc::Error::CommandFailed(
|
||||||
|
"Invalid keypress format. Expected 'number:1 number:0'".into()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(cleaned.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
//to simulate keypresses 42:1 38:1 38:0 24:1 24:0 38:1 38:0 42:0 -> LOL
|
||||||
|
pub async fn sway_input(keys: String) -> Fallible<()> {
|
||||||
|
let validated_input = validate_keypress_string(&keys)?;
|
||||||
|
|
||||||
|
tokio::task::spawn_blocking(move || -> Fallible<()> {
|
||||||
|
let mut connection = Connection::new()?;
|
||||||
|
connection.run_command(&format!("exec ydotool key {}", validated_input))?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|e| swayipc::Error::CommandFailed(e.to_string()))?
|
||||||
|
}
|
||||||
|
|
||||||
|
// simulate mouse movement
|
||||||
|
pub async fn sway_mouse_move(x: i32, y: i32) -> Fallible<()> {
|
||||||
|
tokio::task::spawn_blocking(move || -> Fallible<()> {
|
||||||
|
let mut connection = Connection::new()?;
|
||||||
|
connection.run_command(&format!("exec ydotool mousemove -x {} -y {}", x, y))?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|e| swayipc::Error::CommandFailed(e.to_string()))?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//simulate scroll
|
||||||
|
pub async fn sway_mouse_scroll(x: i32, y: i32) -> Fallible<()> {
|
||||||
|
tokio::task::spawn_blocking(move || -> Fallible<()> {
|
||||||
|
let mut connection = Connection::new()?;
|
||||||
|
connection.run_command(&format!("exec ydotool mousemove -w -x {} -y {}", x, y))?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|e| swayipc::Error::CommandFailed(e.to_string()))?
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum MouseButton {
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Middle,
|
||||||
|
Side,
|
||||||
|
Extra,
|
||||||
|
Forward,
|
||||||
|
Back,
|
||||||
|
Task,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MouseButton {
|
||||||
|
fn to_base_value(&self) -> u8 {
|
||||||
|
match self {
|
||||||
|
MouseButton::Left => 0x00,
|
||||||
|
MouseButton::Right => 0x01,
|
||||||
|
MouseButton::Middle => 0x02,
|
||||||
|
MouseButton::Side => 0x03,
|
||||||
|
MouseButton::Extra => 0x04,
|
||||||
|
MouseButton::Forward => 0x05,
|
||||||
|
MouseButton::Back => 0x06,
|
||||||
|
MouseButton::Task => 0x07,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Fallible<Self> {
|
||||||
|
match s.to_uppercase().as_str() {
|
||||||
|
"MIDDLE" => Ok(MouseButton::Middle),
|
||||||
|
"SIDE" => Ok(MouseButton::Side),
|
||||||
|
"EXTRA" => Ok(MouseButton::Extra),
|
||||||
|
"FORWARD" => Ok(MouseButton::Forward),
|
||||||
|
"BACK" => Ok(MouseButton::Back),
|
||||||
|
"TASK" => Ok(MouseButton::Task),
|
||||||
|
_ => Err(swayipc::Error::CommandFailed(format!("Invalid mouse button: {}", s))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn click_value(&self) -> u8 {
|
||||||
|
self.to_base_value() | 0xC0 // Combines DOWN (0x40) and UP (0x80)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn sway_mouse_click(button: String) -> Fallible<()> {
|
||||||
|
let mouse_button = MouseButton::from_str(&button)?;
|
||||||
|
let click_value = mouse_button.click_value();
|
||||||
|
|
||||||
|
tokio::task::spawn_blocking(move || -> Fallible<()> {
|
||||||
|
let mut connection = Connection::new()?;
|
||||||
|
connection.run_command(&format!("exec ydotool click {:#04x}", click_value))?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|e| swayipc::Error::CommandFailed(e.to_string()))?
|
||||||
|
}
|
@ -11,6 +11,7 @@ use serde_json::{json, Value};
|
|||||||
use utoipa::OpenApi;
|
use utoipa::OpenApi;
|
||||||
use utoipa_axum::{router::OpenApiRouter, routes};
|
use utoipa_axum::{router::OpenApiRouter, routes};
|
||||||
use utoipa_swagger_ui::SwaggerUi;
|
use utoipa_swagger_ui::SwaggerUi;
|
||||||
|
use futures::FutureExt;
|
||||||
|
|
||||||
use super::base;
|
use super::base;
|
||||||
|
|
||||||
@ -32,11 +33,14 @@ pub fn rest_api_routes(mpv: Mpv) -> Router {
|
|||||||
.route("/playlist/shuffle", post(shuffle))
|
.route("/playlist/shuffle", post(shuffle))
|
||||||
.route("/playlist/loop", get(playlist_get_looping))
|
.route("/playlist/loop", get(playlist_get_looping))
|
||||||
.route("/playlist/loop", post(playlist_set_looping))
|
.route("/playlist/loop", post(playlist_set_looping))
|
||||||
.route("/sway/command", post(sway_run_command))
|
// .route("/sway/command", post(sway_run_command))
|
||||||
.route("/sway/workspace/close", post(sway_close_workspace_handler))
|
.route("/sway/workspace/close", post(sway_close_workspace_handler))
|
||||||
.route("/sway/workspace/change", post(sway_change_workspace_handler))
|
.route("/sway/workspace/change", post(sway_change_workspace_handler))
|
||||||
.route("/sway/workspace/list", get(sway_get_workspace_names_handler))
|
.route("/sway/workspace/list", get(sway_get_workspace_names_handler))
|
||||||
.route("/sway/browser/launch", post(sway_launch_browser_handler))
|
.route("/sway/browser/launch", post(sway_launch_browser_handler))
|
||||||
|
.route("/sway/input/keys", post(sway_input_handler))
|
||||||
|
.route("/sway/input/mouse", post(sway_mouse_move_handler))
|
||||||
|
.route("/sway/input/scroll", post(sway_mouse_scroll_handler))
|
||||||
.with_state(mpv)
|
.with_state(mpv)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,72 +412,71 @@ async fn playlist_set_looping(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Execute a sway command TODO: restrict to switching workspace, etc instead of arbitrary commands
|
#[derive(serde::Deserialize, utoipa::ToSchema)]
|
||||||
#[derive(serde::Deserialize, utoipa::IntoParams)]
|
struct SwayCommandBody {
|
||||||
struct SwayCommandArgs {
|
|
||||||
command: String,
|
command: String,
|
||||||
}
|
}
|
||||||
#[utoipa::path(
|
|
||||||
post,
|
|
||||||
path = "/sway/command",
|
|
||||||
params(SwayCommandArgs),
|
|
||||||
responses(
|
|
||||||
(status = 200, description = "Success", body = EmptySuccessResponse),
|
|
||||||
(status = 500, description = "Internal server error", body = ErrorResponse),
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
async fn sway_run_command(Query(query): Query<SwayCommandArgs>) -> RestResponse {
|
|
||||||
base::sway_run_command(query.command).await.map_err(anyhow::Error::new).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// #[utoipa::path(
|
||||||
|
// post,
|
||||||
|
// path = "/sway/command",
|
||||||
|
// request_body = SwayCommandBody,
|
||||||
|
// responses(
|
||||||
|
// (status = 200, description = "Success", body = EmptySuccessResponse),
|
||||||
|
// (status = 500, description = "Internal server error", body = ErrorResponse),
|
||||||
|
// )
|
||||||
|
// )]
|
||||||
|
// async fn sway_run_command(Json(body): Json<SwayCommandBody>) -> RestResponse {
|
||||||
|
// base::sway_run_command(body.command).await.map_err(anyhow::Error::new).into()
|
||||||
|
// }
|
||||||
|
|
||||||
#[derive(serde::Deserialize, utoipa::IntoParams)]
|
#[derive(serde::Deserialize, utoipa::ToSchema)]
|
||||||
struct SwayBrowserArgs {
|
struct SwayBrowserBody {
|
||||||
url: String,
|
url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
post,
|
post,
|
||||||
path = "/sway/browser/launch",
|
path = "/sway/browser/launch",
|
||||||
params(SwayBrowserArgs),
|
request_body = SwayBrowserBody,
|
||||||
responses(
|
responses(
|
||||||
(status = 200, description = "Success", body = EmptySuccessResponse),
|
(status = 200, description = "Success", body = EmptySuccessResponse),
|
||||||
(status = 500, description = "Internal server error", body = ErrorResponse),
|
(status = 500, description = "Internal server error", body = ErrorResponse),
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
async fn sway_launch_browser_handler(Query(query): Query<SwayBrowserArgs>) -> RestResponse {
|
async fn sway_launch_browser_handler(Json(body): Json<SwayBrowserBody>) -> RestResponse {
|
||||||
base::sway_launch_browser(&query.url).await.map_err(anyhow::Error::new).into()
|
base::sway_launch_browser(&body.url).await.map_err(anyhow::Error::new).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, utoipa::IntoParams)]
|
#[derive(serde::Deserialize, utoipa::ToSchema)]
|
||||||
struct SwayWorkspaceArgs {
|
struct SwayWorkspaceBody {
|
||||||
workspace: String,
|
workspace: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
post,
|
post,
|
||||||
path = "/sway/workspace/close",
|
path = "/sway/workspace/close",
|
||||||
params(SwayWorkspaceArgs),
|
request_body = SwayWorkspaceBody,
|
||||||
responses(
|
responses(
|
||||||
(status = 200, description = "Success", body = EmptySuccessResponse),
|
(status = 200, description = "Success", body = EmptySuccessResponse),
|
||||||
(status = 500, description = "Internal server error", body = ErrorResponse),
|
(status = 500, description = "Internal server error", body = ErrorResponse),
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
async fn sway_close_workspace_handler(Query(query): Query<SwayWorkspaceArgs>) -> RestResponse {
|
async fn sway_close_workspace_handler(Json(body): Json<SwayWorkspaceBody>) -> RestResponse {
|
||||||
base::sway_close_workspace(query.workspace).await.map_err(anyhow::Error::new).into()
|
base::sway_close_workspace(body.workspace).await.map_err(anyhow::Error::new).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
post,
|
post,
|
||||||
path = "/sway/workspace/change",
|
path = "/sway/workspace/change",
|
||||||
params(SwayWorkspaceArgs),
|
request_body = SwayWorkspaceBody,
|
||||||
responses(
|
responses(
|
||||||
(status = 200, description = "Success", body = EmptySuccessResponse),
|
(status = 200, description = "Success", body = EmptySuccessResponse),
|
||||||
(status = 500, description = "Internal server error", body = ErrorResponse),
|
(status = 500, description = "Internal server error", body = ErrorResponse),
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
async fn sway_change_workspace_handler(Query(query): Query<SwayWorkspaceArgs>) -> RestResponse {
|
async fn sway_change_workspace_handler(Json(body): Json<SwayWorkspaceBody>) -> RestResponse {
|
||||||
base::sway_change_workspace(query.workspace).await.map_err(anyhow::Error::new).into()
|
base::sway_change_workspace(body.workspace).await.map_err(anyhow::Error::new).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
@ -491,3 +494,78 @@ async fn sway_get_workspace_names_handler() -> RestResponse {
|
|||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, utoipa::ToSchema)]
|
||||||
|
struct KeyboardInput {
|
||||||
|
keys: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/sway/input/keys",
|
||||||
|
request_body = KeyboardInput,
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Success", body = Vec<String>),
|
||||||
|
(status = 500, description = "Internal server error", body = ErrorResponse),
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
async fn sway_input_handler(
|
||||||
|
Json(payload): Json<KeyboardInput>
|
||||||
|
) -> RestResponse {
|
||||||
|
base::sway_input(payload.keys)
|
||||||
|
.await
|
||||||
|
.map(|_| json!({}))
|
||||||
|
.map_err(anyhow::Error::new)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/sway/input/mouse",
|
||||||
|
request_body = MouseMove,
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Success", body = Vec<String>),
|
||||||
|
(status = 500, description = "Internal server error", body = ErrorResponse),
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
async fn sway_mouse_move_handler(
|
||||||
|
Json(payload): Json<MouseMove>
|
||||||
|
) -> RestResponse {
|
||||||
|
base::sway_mouse_move(payload.x, payload.y)
|
||||||
|
.await
|
||||||
|
.map(|_| json!({}))
|
||||||
|
.map_err(anyhow::Error::new)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/sway/input/scroll",
|
||||||
|
request_body = MouseMove,
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Success", body = Vec<String>),
|
||||||
|
(status = 500, description = "Internal server error", body = ErrorResponse),
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
async fn sway_mouse_scroll_handler(
|
||||||
|
Json(payload): Json<MouseMove>
|
||||||
|
) -> RestResponse {
|
||||||
|
base::sway_mouse_scroll(payload.x, payload.y)
|
||||||
|
.await
|
||||||
|
.map(|_| json!({}))
|
||||||
|
.map_err(anyhow::Error::new)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, utoipa::ToSchema)]
|
||||||
|
struct MouseMove {
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
}
|
@ -357,7 +357,11 @@ pub enum WSCommand {
|
|||||||
Shuffle,
|
Shuffle,
|
||||||
SetSubtitleTrack { track: Option<usize> },
|
SetSubtitleTrack { track: Option<usize> },
|
||||||
SetLooping { value: bool },
|
SetLooping { value: bool },
|
||||||
SwayCommand { command: String },
|
// SwayCommand { command: String },
|
||||||
|
SwayLaunchBrowser { url: String },
|
||||||
|
SwayCloseWorkspace { workspace: String },
|
||||||
|
SwayChangeWorkspace { workspace: String },
|
||||||
|
SwayGetWorkspaces,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_message(
|
async fn handle_message(
|
||||||
@ -448,9 +452,25 @@ async fn handle_message(
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
WSCommand::SwayCommand { command } => {
|
// WSCommand::SwayCommand { command } => {
|
||||||
base::sway_run_command(command).await?;
|
// base::sway_run_command(command).await?;
|
||||||
|
// Ok(None)
|
||||||
|
// }
|
||||||
|
WSCommand::SwayLaunchBrowser { url } => {
|
||||||
|
base::sway_launch_browser(&url).await?;
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
WSCommand::SwayCloseWorkspace { workspace } => {
|
||||||
|
base::sway_close_workspace(workspace).await?;
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
WSCommand::SwayChangeWorkspace { workspace } => {
|
||||||
|
base::sway_change_workspace(workspace).await?;
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
WSCommand::SwayGetWorkspaces => {
|
||||||
|
let workspaces = base::sway_get_workspace_names().await?;
|
||||||
|
Ok(Some(json!(workspaces)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user