use derive_more::{Constructor, Display as MDisplay};
use std::fmt::Display as FDisplay;
use strum::{Display as SDisplay, EnumProperty};
use crate::shared::*;
pub mod reload {
use super::*;
pub fn call() -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(Empty, "reload"),
)?;
Ok(())
}
pub async fn call_async() -> crate::Result<()> {
write_to_socket(
get_socket_path(SocketType::Command),
command!(Empty, "reload"),
)
.await?;
Ok(())
}
}
pub mod kill {
use super::*;
pub fn call() -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(Empty, "kill"),
)?;
Ok(())
}
pub async fn call_async() -> crate::Result<()> {
write_to_socket(
get_socket_path(SocketType::Command),
command!(Empty, "kill"),
)
.await?;
Ok(())
}
}
pub mod set_cursor {
use super::*;
pub fn call<Str: FDisplay>(theme: Str, size: u16) -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(Empty, "setcursor {theme} {size}"),
)?;
Ok(())
}
pub async fn call_async<Str: FDisplay>(theme: Str, size: u16) -> crate::Result<()> {
write_to_socket(
get_socket_path(SocketType::Command),
command!(Empty, "setcursor {theme} {size}"),
)
.await?;
Ok(())
}
}
pub mod output {
use super::*;
#[derive(SDisplay)]
pub enum OutputBackends {
#[strum(serialize = "wayland")]
Wayland,
#[strum(serialize = "x11")]
X11,
#[strum(serialize = "headless")]
Headless,
#[strum(serialize = "auto")]
Auto,
}
pub fn create(backend: OutputBackends) -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(Empty, "output create {backend}"),
)?;
Ok(())
}
pub fn remove<Str: FDisplay>(name: Str) -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(Empty, "output remove {name}"),
)?;
Ok(())
}
}
pub mod switch_xkb_layout {
use super::*;
#[derive(MDisplay)]
pub enum SwitchXKBLayoutCmdTypes {
#[display(fmt = "next")]
Next,
#[display(fmt = "prev")]
Previous,
#[display(fmt = "{}", "_0")]
Id(u8),
}
pub fn call<Str: FDisplay>(device: Str, cmd: SwitchXKBLayoutCmdTypes) -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(Empty, "switchxkblayout {device} {cmd}"),
)?;
Ok(())
}
pub async fn call_async<Str: FDisplay>(
device: Str,
cmd: SwitchXKBLayoutCmdTypes,
) -> crate::Result<()> {
write_to_socket(
get_socket_path(SocketType::Command),
command!(Empty, "switchxkblayout {device} {cmd}"),
)
.await?;
Ok(())
}
}
pub mod set_error {
use super::*;
pub fn call(color: Color, msg: String) -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(Empty, "seterror {color} {msg}"),
)?;
Ok(())
}
pub async fn call_async(color: Color, msg: String) -> crate::Result<()> {
write_to_socket(
get_socket_path(SocketType::Command),
command!(Empty, "seterror {color} {msg}"),
)
.await?;
Ok(())
}
}
pub mod notify {
use super::*;
use std::time::Duration;
#[allow(missing_docs)]
#[derive(Copy, Clone)]
#[repr(i8)]
pub enum Icon {
NoIcon = -1,
Warning = 0,
Info = 1,
Hint = 2,
Error = 3,
Confused = 4,
Ok = 5,
}
pub fn call(icon: Icon, time: Duration, color: Color, msg: String) -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(
Empty,
"notify {} {} {color} {msg}",
icon as i8,
time.as_millis()
),
)?;
Ok(())
}
pub async fn call_async(
icon: Icon,
time: Duration,
color: Color,
msg: String,
) -> crate::Result<()> {
write_to_socket(
get_socket_path(SocketType::Command),
command!(
Empty,
"notify {} {} {color} {msg}",
icon as i8,
time.as_millis()
),
)
.await?;
Ok(())
}
}
#[derive(Copy, Clone, MDisplay, Constructor)]
#[display(fmt = "rgba({:02x}{:02x}{:02x}{:02x})", "_0", "_1", "_2", "_3")]
pub struct Color(u8, u8, u8, u8);
pub mod set_prop {
use super::*;
fn l(b: bool) -> &'static str {
if b {
"lock"
} else {
""
}
}
#[derive(EnumProperty, MDisplay)]
pub enum PropType {
#[display(fmt = "animationstyle {}", "_0")]
AnimationStyle(String),
#[display(fmt = "rounding {} {}", "_0", "l(*_1)")]
Rounding(
i64,
bool,
),
#[display(fmt = "forcenoblur {} {}", "*_0 as u8", "l(*_1)")]
ForceNoBlur(
bool,
bool,
),
#[display(fmt = "forceopaque {} {}", "*_0 as u8", "l(*_1)")]
ForceOpaque(
bool,
bool,
),
#[display(fmt = "forceopaqueoverriden {} {}", "*_0 as u8", "l(*_1)")]
ForceOpaqueOverriden(
bool,
bool,
),
#[display(fmt = "forceallowsinput {} {}", "*_0 as u8", "l(*_1)")]
ForceAllowsInput(
bool,
bool,
),
#[display(fmt = "forcenoanims {} {}", "*_0 as u8", "l(*_1)")]
ForceNoAnims(
bool,
bool,
),
#[display(fmt = "forcenoborder {} {}", "*_0 as u8", "l(*_1)")]
ForceNoBorder(
bool,
bool,
),
#[display(fmt = "forcenoshadow {} {}", "*_0 as u8", "l(*_1)")]
ForceNoShadow(
bool,
bool,
),
#[display(fmt = "windowdancecompat {} {}", "*_0 as u8", "l(*_1)")]
WindowDanceCompat(
bool,
bool,
),
#[display(fmt = "nomaxsize {} {}", "*_0 as u8", "l(*_1)")]
NoMaxSize(
bool,
bool,
),
#[display(fmt = "dimaround {} {}", "*_0 as u8", "l(*_1)")]
DimAround(
bool,
bool,
),
#[display(fmt = "alphaoverride {} {}", "*_0 as u8", "l(*_1)")]
AlphaOverride(
bool,
bool,
),
#[display(fmt = "alpha {} {}", "_0", "l(*_1)")]
Alpha(
f32,
bool,
),
#[display(fmt = "alphainactiveoverride {} {}", "*_0 as u8", "l(*_1)")]
AlphaInactiveOverride(
bool,
bool,
),
#[display(fmt = "alphainactive {} {}", "_0", "l(*_1)")]
AlphaInactive(
f32,
bool,
),
#[display(fmt = "alphabordercolor {} {}", "_0", "l(*_1)")]
ActiveBorderColor(
Color,
bool,
),
#[display(fmt = "inalphabordercolor {} {}", "_0", "l(*_1)")]
InactiveBorderColor(
Color,
bool,
),
}
pub fn call(ident: String, prop: PropType, lock: bool) -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(
Empty,
"setprop {ident} {prop} {}",
if lock { "lock" } else { "" }
),
)?;
Ok(())
}
pub async fn call_async(ident: String, prop: PropType, lock: bool) -> crate::Result<()> {
write_to_socket(
get_socket_path(SocketType::Command),
command!(
Empty,
"setprop {ident} {prop} {}",
if lock { "lock" } else { "" }
),
)
.await?;
Ok(())
}
}
pub mod plugin {
use super::*;
use std::path::Path;
pub fn load(path: &Path) -> crate::Result<()> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(Empty, "plugin load {}", path.display()),
)?;
Ok(())
}
pub async fn load_async(path: &Path) -> crate::Result<()> {
write_to_socket(
get_socket_path(SocketType::Command),
command!(Empty, "plugin load {}", path.display()),
)
.await?;
Ok(())
}
pub fn list() -> crate::Result<String> {
write_to_socket_sync(
get_socket_path(SocketType::Command),
command!(Empty, "plugin list"),
)
}
pub async fn list_async() -> crate::Result<String> {
write_to_socket(
get_socket_path(SocketType::Command),
command!(Empty, "plugin list"),
)
.await
}
}