Added DBUS support
Added Plasma handler
This commit is contained in:
parent
368ac08449
commit
ae708d4f87
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"rust-analyzer.linkedProjects": [
|
||||
"./Cargo.toml",
|
||||
"./Cargo.toml"
|
||||
]
|
||||
}
|
||||
49
Cargo.lock
generated
49
Cargo.lock
generated
@ -23,6 +23,17 @@ version = "3.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ec6d3da8e550377a85339063af6e3735f4b1d9392108da4e083a1b3b9820288"
|
||||
|
||||
[[package]]
|
||||
name = "dbus"
|
||||
version = "0.9.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"libdbus-sys",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.12"
|
||||
@ -46,6 +57,15 @@ version = "0.2.153"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||
|
||||
[[package]]
|
||||
name = "libdbus-sys"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72"
|
||||
dependencies = [
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.1"
|
||||
@ -57,11 +77,18 @@ name = "mycelium"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"configparser",
|
||||
"dbus",
|
||||
"glob",
|
||||
"rand",
|
||||
"untildify",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
@ -139,3 +166,25 @@ name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
@ -5,6 +5,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
configparser = "3.0.4"
|
||||
dbus = "0.9.7"
|
||||
glob = "0.3.1"
|
||||
rand = "0.8.5"
|
||||
untildify = { path = "../untildify" }
|
||||
|
||||
@ -6,7 +6,7 @@ use untildify;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Monitors {
|
||||
monitors: Vec<MonitorType>,
|
||||
pub monitors: Vec<MonitorType>,
|
||||
}
|
||||
|
||||
impl Monitors {
|
||||
|
||||
33
src/files.rs
33
src/files.rs
@ -2,8 +2,6 @@ use core::fmt;
|
||||
use glob::glob;
|
||||
use rand::seq::SliceRandom;
|
||||
use std::fmt::Write as _;
|
||||
use std::io::Write as _;
|
||||
use std::process::exit;
|
||||
|
||||
use crate::config::*;
|
||||
use crate::enums::*;
|
||||
@ -44,31 +42,16 @@ impl Wallpapers {
|
||||
),
|
||||
}
|
||||
}
|
||||
// Todo implement a random selector for a given key, like `wallpapers.random_selection(MonitorType::Ultrawide)`
|
||||
pub fn random_selection(&self, monitor_type: MonitorType) {
|
||||
|
||||
pub fn random_selection(&self, monitor_type: &MonitorType) -> &Wallpaper {
|
||||
match monitor_type {
|
||||
MonitorType::Ultrawide => {
|
||||
println!(
|
||||
"{:?}",
|
||||
self.ultrawide.choose(&mut rand::thread_rng()).unwrap()
|
||||
);
|
||||
}
|
||||
MonitorType::Horizontal => {
|
||||
println!(
|
||||
"{:?}",
|
||||
self.horizontal.choose(&mut rand::thread_rng()).unwrap()
|
||||
);
|
||||
}
|
||||
MonitorType::Vertical => {
|
||||
println!(
|
||||
"{:?}",
|
||||
self.vertical.choose(&mut rand::thread_rng()).unwrap()
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
MonitorType::Ultrawide => self.ultrawide.choose(&mut rand::thread_rng()).unwrap(),
|
||||
MonitorType::Horizontal => self.horizontal.choose(&mut rand::thread_rng()).unwrap(),
|
||||
MonitorType::Vertical => self.vertical.choose(&mut rand::thread_rng()).unwrap(),
|
||||
_ => self.horizontal.choose(&mut rand::thread_rng()).unwrap(),
|
||||
}
|
||||
}
|
||||
// Todo implement a function to load all files of particular filetypes into the Vec<Wallpaper>
|
||||
|
||||
pub fn load_images(&mut self, monitor_type: MonitorType) {
|
||||
let path = self
|
||||
.config
|
||||
@ -99,7 +82,7 @@ impl Wallpapers {
|
||||
MonitorType::Ultrawide => self.ultrawide.push(Wallpaper { path: filepath }),
|
||||
MonitorType::Horizontal => self.horizontal.push(Wallpaper { path: filepath }),
|
||||
MonitorType::Vertical => self.vertical.push(Wallpaper { path: filepath }),
|
||||
_ => {}
|
||||
MonitorType::Error => self.horizontal.push(Wallpaper { path: filepath }),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
43
src/handlers/dbus.rs
Normal file
43
src/handlers/dbus.rs
Normal file
@ -0,0 +1,43 @@
|
||||
use dbus::blocking::Connection;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn test() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// First open up a connection to the session bus
|
||||
let conn = Connection::new_session()?;
|
||||
|
||||
// Second, create a wrapper struct around the connection that makes it easy
|
||||
// to send method calls to a specific destination and path.
|
||||
let proxy = conn.with_proxy(
|
||||
"org.kde.plasmashell",
|
||||
"/PlasmaShell",
|
||||
Duration::from_millis(5000),
|
||||
);
|
||||
|
||||
use dbus_s::OrgKdePlasmaShell;
|
||||
// Now make the method call. The ListNames method call takes zero input parameters and
|
||||
// one output parameter which is an array of strings
|
||||
// Therefore the input is a zero tuple "()", and the output is a single tuple "(names, )"
|
||||
|
||||
let test = "
|
||||
var allDesktops = desktops();
|
||||
allDesktops[0].wallpaperPlugin = 'org.kde.image';
|
||||
allDesktops[0].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
|
||||
allDesktops[0].writeConfig('Image', 'file:///home/ben/Pictures/wallpaper-ultra/wallhaven-pkj7gm.png');w
|
||||
allDesktops[1].wallpaperPlugin = 'org.kde.image';
|
||||
allDesktops[1].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
|
||||
allDesktops[1].writeConfig('Image', 'file:///home/ben/Pictures/wallpaper-hor/papes/1490136858978.jpg');
|
||||
";
|
||||
|
||||
proxy.evaluate_script(test);
|
||||
|
||||
// let (_, error): (String, dbus::Error) = proxy
|
||||
// .method_call("org.kde.PlasmaShell", "evaluateScript", (test,))
|
||||
// .unwrap();
|
||||
|
||||
// Let's print all the names to stdout
|
||||
// for name in names {
|
||||
// println!("{}", name);
|
||||
// }
|
||||
|
||||
Ok(())
|
||||
}
|
||||
276
src/handlers/dbus_s.rs
Normal file
276
src/handlers/dbus_s.rs
Normal file
@ -0,0 +1,276 @@
|
||||
// This code was autogenerated with `dbus-codegen-rust -g -m None -d org.kde.plasmashell -p /PlasmaShell`, see https://github.com/diwic/dbus-rs
|
||||
use dbus;
|
||||
#[allow(unused_imports)]
|
||||
use dbus::arg;
|
||||
use dbus::blocking;
|
||||
|
||||
pub trait OrgKdePlasmaShell {
|
||||
fn toggle_dashboard(&self) -> Result<(), dbus::Error>;
|
||||
fn toggle_activity_manager(&self) -> Result<(), dbus::Error>;
|
||||
fn toggle_widget_explorer(&self) -> Result<(), dbus::Error>;
|
||||
fn set_dashboard_shown(&self, show: bool) -> Result<(), dbus::Error>;
|
||||
fn evaluate_script(&self, script: &str) -> Result<String, dbus::Error>;
|
||||
fn color(&self) -> Result<u32, dbus::Error>;
|
||||
fn dump_current_layout_js(&self) -> Result<Vec<u8>, dbus::Error>;
|
||||
fn load_look_and_feel_default_layout(&self, layout: &str) -> Result<(), dbus::Error>;
|
||||
fn activate_launcher_menu(&self) -> Result<(), dbus::Error>;
|
||||
fn refresh_current_shell(&self) -> Result<(), dbus::Error>;
|
||||
fn wallpaper(&self, screen_num: u32) -> Result<arg::PropMap, dbus::Error>;
|
||||
fn set_wallpaper(
|
||||
&self,
|
||||
wallpaper_plugin: &str,
|
||||
parameters: &str,
|
||||
screen_num: u32,
|
||||
) -> Result<(), dbus::Error>;
|
||||
fn edit_mode(&self) -> Result<bool, dbus::Error>;
|
||||
fn setedit_mode(&self, value: bool) -> Result<(), dbus::Error>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OrgKdePlasmaShellWallpaperChanged {
|
||||
pub screen_num: u32,
|
||||
}
|
||||
|
||||
impl arg::AppendAll for OrgKdePlasmaShellWallpaperChanged {
|
||||
fn append(&self, i: &mut arg::IterAppend) {
|
||||
arg::RefArg::append(&self.screen_num, i);
|
||||
}
|
||||
}
|
||||
|
||||
impl arg::ReadAll for OrgKdePlasmaShellWallpaperChanged {
|
||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
||||
Ok(OrgKdePlasmaShellWallpaperChanged {
|
||||
screen_num: i.read()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl dbus::message::SignalArgs for OrgKdePlasmaShellWallpaperChanged {
|
||||
const NAME: &'static str = "wallpaperChanged";
|
||||
const INTERFACE: &'static str = "org.kde.PlasmaShell";
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OrgKdePlasmaShellColorChanged {
|
||||
pub changed_color: String,
|
||||
}
|
||||
|
||||
impl arg::AppendAll for OrgKdePlasmaShellColorChanged {
|
||||
fn append(&self, i: &mut arg::IterAppend) {
|
||||
arg::RefArg::append(&self.changed_color, i);
|
||||
}
|
||||
}
|
||||
|
||||
impl arg::ReadAll for OrgKdePlasmaShellColorChanged {
|
||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
||||
Ok(OrgKdePlasmaShellColorChanged {
|
||||
changed_color: i.read()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl dbus::message::SignalArgs for OrgKdePlasmaShellColorChanged {
|
||||
const NAME: &'static str = "colorChanged";
|
||||
const INTERFACE: &'static str = "org.kde.PlasmaShell";
|
||||
}
|
||||
|
||||
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target = T>> OrgKdePlasmaShell
|
||||
for blocking::Proxy<'a, C>
|
||||
{
|
||||
fn toggle_dashboard(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "toggleDashboard", ())
|
||||
}
|
||||
|
||||
fn toggle_activity_manager(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "toggleActivityManager", ())
|
||||
}
|
||||
|
||||
fn toggle_widget_explorer(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "toggleWidgetExplorer", ())
|
||||
}
|
||||
|
||||
fn set_dashboard_shown(&self, show: bool) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "setDashboardShown", (show,))
|
||||
}
|
||||
|
||||
fn evaluate_script(&self, script: &str) -> Result<String, dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "evaluateScript", (script,))
|
||||
.and_then(|r: (String,)| Ok(r.0))
|
||||
}
|
||||
|
||||
fn color(&self) -> Result<u32, dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "color", ())
|
||||
.and_then(|r: (u32,)| Ok(r.0))
|
||||
}
|
||||
|
||||
fn dump_current_layout_js(&self) -> Result<Vec<u8>, dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "dumpCurrentLayoutJS", ())
|
||||
.and_then(|r: (Vec<u8>,)| Ok(r.0))
|
||||
}
|
||||
|
||||
fn load_look_and_feel_default_layout(&self, layout: &str) -> Result<(), dbus::Error> {
|
||||
self.method_call(
|
||||
"org.kde.PlasmaShell",
|
||||
"loadLookAndFeelDefaultLayout",
|
||||
(layout,),
|
||||
)
|
||||
}
|
||||
|
||||
fn activate_launcher_menu(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "activateLauncherMenu", ())
|
||||
}
|
||||
|
||||
fn refresh_current_shell(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "refreshCurrentShell", ())
|
||||
}
|
||||
|
||||
fn wallpaper(&self, screen_num: u32) -> Result<arg::PropMap, dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "wallpaper", (screen_num,))
|
||||
.and_then(|r: (arg::PropMap,)| Ok(r.0))
|
||||
}
|
||||
|
||||
fn set_wallpaper(
|
||||
&self,
|
||||
wallpaper_plugin: &str,
|
||||
parameters: &str,
|
||||
screen_num: u32,
|
||||
) -> Result<(), dbus::Error> {
|
||||
self.method_call(
|
||||
"org.kde.PlasmaShell",
|
||||
"setWallpaper",
|
||||
(wallpaper_plugin, parameters, screen_num),
|
||||
)
|
||||
}
|
||||
|
||||
fn edit_mode(&self) -> Result<bool, dbus::Error> {
|
||||
<Self as blocking::stdintf::org_freedesktop_dbus::Properties>::get(
|
||||
self,
|
||||
"org.kde.PlasmaShell",
|
||||
"editMode",
|
||||
)
|
||||
}
|
||||
|
||||
fn setedit_mode(&self, value: bool) -> Result<(), dbus::Error> {
|
||||
<Self as blocking::stdintf::org_freedesktop_dbus::Properties>::set(
|
||||
self,
|
||||
"org.kde.PlasmaShell",
|
||||
"editMode",
|
||||
value,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OrgFreedesktopDBusProperties {
|
||||
fn get<R0: for<'b> arg::Get<'b> + 'static>(
|
||||
&self,
|
||||
interface_name: &str,
|
||||
property_name: &str,
|
||||
) -> Result<R0, dbus::Error>;
|
||||
fn set<I2: arg::Arg + arg::Append>(
|
||||
&self,
|
||||
interface_name: &str,
|
||||
property_name: &str,
|
||||
value: I2,
|
||||
) -> Result<(), dbus::Error>;
|
||||
fn get_all(&self, interface_name: &str) -> Result<arg::PropMap, dbus::Error>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
pub interface_name: String,
|
||||
pub changed_properties: arg::PropMap,
|
||||
pub invalidated_properties: Vec<String>,
|
||||
}
|
||||
|
||||
impl arg::AppendAll for OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
fn append(&self, i: &mut arg::IterAppend) {
|
||||
arg::RefArg::append(&self.interface_name, i);
|
||||
arg::RefArg::append(&self.changed_properties, i);
|
||||
arg::RefArg::append(&self.invalidated_properties, i);
|
||||
}
|
||||
}
|
||||
|
||||
impl arg::ReadAll for OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
||||
Ok(OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
interface_name: i.read()?,
|
||||
changed_properties: i.read()?,
|
||||
invalidated_properties: i.read()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl dbus::message::SignalArgs for OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
const NAME: &'static str = "PropertiesChanged";
|
||||
const INTERFACE: &'static str = "org.freedesktop.DBus.Properties";
|
||||
}
|
||||
|
||||
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target = T>> OrgFreedesktopDBusProperties
|
||||
for blocking::Proxy<'a, C>
|
||||
{
|
||||
fn get<R0: for<'b> arg::Get<'b> + 'static>(
|
||||
&self,
|
||||
interface_name: &str,
|
||||
property_name: &str,
|
||||
) -> Result<R0, dbus::Error> {
|
||||
self.method_call(
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Get",
|
||||
(interface_name, property_name),
|
||||
)
|
||||
.and_then(|r: (arg::Variant<R0>,)| Ok((r.0).0))
|
||||
}
|
||||
|
||||
fn set<I2: arg::Arg + arg::Append>(
|
||||
&self,
|
||||
interface_name: &str,
|
||||
property_name: &str,
|
||||
value: I2,
|
||||
) -> Result<(), dbus::Error> {
|
||||
self.method_call(
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Set",
|
||||
(interface_name, property_name, arg::Variant(value)),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_all(&self, interface_name: &str) -> Result<arg::PropMap, dbus::Error> {
|
||||
self.method_call(
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"GetAll",
|
||||
(interface_name,),
|
||||
)
|
||||
.and_then(|r: (arg::PropMap,)| Ok(r.0))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OrgFreedesktopDBusIntrospectable {
|
||||
fn introspect(&self) -> Result<String, dbus::Error>;
|
||||
}
|
||||
|
||||
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target = T>>
|
||||
OrgFreedesktopDBusIntrospectable for blocking::Proxy<'a, C>
|
||||
{
|
||||
fn introspect(&self) -> Result<String, dbus::Error> {
|
||||
self.method_call("org.freedesktop.DBus.Introspectable", "Introspect", ())
|
||||
.and_then(|r: (String,)| Ok(r.0))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OrgFreedesktopDBusPeer {
|
||||
fn ping(&self) -> Result<(), dbus::Error>;
|
||||
fn get_machine_id(&self) -> Result<String, dbus::Error>;
|
||||
}
|
||||
|
||||
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target = T>> OrgFreedesktopDBusPeer
|
||||
for blocking::Proxy<'a, C>
|
||||
{
|
||||
fn ping(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.freedesktop.DBus.Peer", "Ping", ())
|
||||
}
|
||||
|
||||
fn get_machine_id(&self) -> Result<String, dbus::Error> {
|
||||
self.method_call("org.freedesktop.DBus.Peer", "GetMachineId", ())
|
||||
.and_then(|r: (String,)| Ok(r.0))
|
||||
}
|
||||
}
|
||||
4
src/handlers/mod.rs
Normal file
4
src/handlers/mod.rs
Normal file
@ -0,0 +1,4 @@
|
||||
pub mod dbus_s;
|
||||
use dbus_s::*;
|
||||
pub mod plasma;
|
||||
use plasma::*;
|
||||
57
src/handlers/plasma.rs
Normal file
57
src/handlers/plasma.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use crate::config::Monitors;
|
||||
use crate::handlers::dbus_s;
|
||||
use crate::Wallpapers;
|
||||
|
||||
use dbus::blocking::Connection;
|
||||
use std::fmt::Write as _;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn change_wallpapers(wallpapers: &Wallpapers) {
|
||||
// First open up a connection to the session bus
|
||||
let conn = Connection::new_session().unwrap();
|
||||
|
||||
// Second, create a wrapper struct around the connection that makes it easy
|
||||
// to send method calls to a specific destination and path.
|
||||
let proxy = conn.with_proxy(
|
||||
"org.kde.plasmashell",
|
||||
"/PlasmaShell",
|
||||
Duration::from_millis(5000),
|
||||
);
|
||||
|
||||
use dbus_s::OrgKdePlasmaShell;
|
||||
|
||||
let javascript = generate_js(wallpapers);
|
||||
let resp = proxy.evaluate_script(javascript.as_ref());
|
||||
match resp {
|
||||
Ok(str) => {}
|
||||
Err(e) => println!("{}", e),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_js(wallpapers: &Wallpapers) -> String {
|
||||
let mut javascript = String::new();
|
||||
javascript.push_str("var allDesktops = desktops();\n");
|
||||
let mut count = 0;
|
||||
for monitor in wallpapers.config.monitors.monitors.iter() {
|
||||
let mut file_buff = String::new();
|
||||
let _ = write!(
|
||||
&mut file_buff,
|
||||
"file://{}",
|
||||
wallpapers.random_selection(monitor)
|
||||
);
|
||||
let mut boilerplate = String::new();
|
||||
// let boilerplate_formatter = ;
|
||||
let _ = write!(
|
||||
&mut boilerplate,
|
||||
"
|
||||
allDesktops[{0}].wallpaperPlugin = 'org.kde.image';
|
||||
allDesktops[{0}].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
|
||||
allDesktops[{0}].writeConfig('Image', '{1}');
|
||||
",
|
||||
count, file_buff
|
||||
);
|
||||
javascript.push_str(&boilerplate);
|
||||
count += 1;
|
||||
}
|
||||
javascript
|
||||
}
|
||||
@ -3,11 +3,15 @@ mod enums;
|
||||
use enums::*;
|
||||
mod files;
|
||||
use files::*;
|
||||
mod handlers;
|
||||
|
||||
fn main() {
|
||||
let mut wallpapers = Wallpapers::new();
|
||||
|
||||
wallpapers.load_all();
|
||||
wallpapers.random_selection(MonitorType::Ultrawide);
|
||||
println!("{}", "");
|
||||
wallpapers.random_selection(&MonitorType::Ultrawide);
|
||||
wallpapers.random_selection(&MonitorType::Horizontal);
|
||||
wallpapers.random_selection(&MonitorType::Vertical);
|
||||
let resp = handlers::plasma::change_wallpapers(&wallpapers);
|
||||
// println!("{}", resp);
|
||||
}
|
||||
|
||||
215
test.rs
Normal file
215
test.rs
Normal file
@ -0,0 +1,215 @@
|
||||
// This code was autogenerated with `dbus-codegen-rust -g -m None -d org.kde.plasmashell -p /PlasmaShell`, see https://github.com/diwic/dbus-rs
|
||||
use dbus as dbus;
|
||||
#[allow(unused_imports)]
|
||||
use dbus::arg;
|
||||
use dbus::blocking;
|
||||
|
||||
pub trait OrgKdePlasmaShell {
|
||||
fn toggle_dashboard(&self) -> Result<(), dbus::Error>;
|
||||
fn toggle_activity_manager(&self) -> Result<(), dbus::Error>;
|
||||
fn toggle_widget_explorer(&self) -> Result<(), dbus::Error>;
|
||||
fn set_dashboard_shown(&self, show: bool) -> Result<(), dbus::Error>;
|
||||
fn evaluate_script(&self, script: &str) -> Result<String, dbus::Error>;
|
||||
fn color(&self) -> Result<u32, dbus::Error>;
|
||||
fn dump_current_layout_js(&self) -> Result<Vec<u8>, dbus::Error>;
|
||||
fn load_look_and_feel_default_layout(&self, layout: &str) -> Result<(), dbus::Error>;
|
||||
fn activate_launcher_menu(&self) -> Result<(), dbus::Error>;
|
||||
fn refresh_current_shell(&self) -> Result<(), dbus::Error>;
|
||||
fn wallpaper(&self, screen_num: u32) -> Result<arg::PropMap, dbus::Error>;
|
||||
fn set_wallpaper(&self, wallpaper_plugin: &str, parameters: arg::PropMap, screen_num: u32) -> Result<(), dbus::Error>;
|
||||
fn edit_mode(&self) -> Result<bool, dbus::Error>;
|
||||
fn setedit_mode(&self, value: bool) -> Result<(), dbus::Error>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OrgKdePlasmaShellWallpaperChanged {
|
||||
pub screen_num: u32,
|
||||
}
|
||||
|
||||
impl arg::AppendAll for OrgKdePlasmaShellWallpaperChanged {
|
||||
fn append(&self, i: &mut arg::IterAppend) {
|
||||
arg::RefArg::append(&self.screen_num, i);
|
||||
}
|
||||
}
|
||||
|
||||
impl arg::ReadAll for OrgKdePlasmaShellWallpaperChanged {
|
||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
||||
Ok(OrgKdePlasmaShellWallpaperChanged {
|
||||
screen_num: i.read()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl dbus::message::SignalArgs for OrgKdePlasmaShellWallpaperChanged {
|
||||
const NAME: &'static str = "wallpaperChanged";
|
||||
const INTERFACE: &'static str = "org.kde.PlasmaShell";
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OrgKdePlasmaShellColorChanged {
|
||||
pub changed_color: String,
|
||||
}
|
||||
|
||||
impl arg::AppendAll for OrgKdePlasmaShellColorChanged {
|
||||
fn append(&self, i: &mut arg::IterAppend) {
|
||||
arg::RefArg::append(&self.changed_color, i);
|
||||
}
|
||||
}
|
||||
|
||||
impl arg::ReadAll for OrgKdePlasmaShellColorChanged {
|
||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
||||
Ok(OrgKdePlasmaShellColorChanged {
|
||||
changed_color: i.read()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl dbus::message::SignalArgs for OrgKdePlasmaShellColorChanged {
|
||||
const NAME: &'static str = "colorChanged";
|
||||
const INTERFACE: &'static str = "org.kde.PlasmaShell";
|
||||
}
|
||||
|
||||
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgKdePlasmaShell for blocking::Proxy<'a, C> {
|
||||
|
||||
fn toggle_dashboard(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "toggleDashboard", ())
|
||||
}
|
||||
|
||||
fn toggle_activity_manager(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "toggleActivityManager", ())
|
||||
}
|
||||
|
||||
fn toggle_widget_explorer(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "toggleWidgetExplorer", ())
|
||||
}
|
||||
|
||||
fn set_dashboard_shown(&self, show: bool) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "setDashboardShown", (show, ))
|
||||
}
|
||||
|
||||
fn evaluate_script(&self, script: &str) -> Result<String, dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "evaluateScript", (script, ))
|
||||
.and_then(|r: (String, )| Ok(r.0, ))
|
||||
}
|
||||
|
||||
fn color(&self) -> Result<u32, dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "color", ())
|
||||
.and_then(|r: (u32, )| Ok(r.0, ))
|
||||
}
|
||||
|
||||
fn dump_current_layout_js(&self) -> Result<Vec<u8>, dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "dumpCurrentLayoutJS", ())
|
||||
.and_then(|r: (Vec<u8>, )| Ok(r.0, ))
|
||||
}
|
||||
|
||||
fn load_look_and_feel_default_layout(&self, layout: &str) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "loadLookAndFeelDefaultLayout", (layout, ))
|
||||
}
|
||||
|
||||
fn activate_launcher_menu(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "activateLauncherMenu", ())
|
||||
}
|
||||
|
||||
fn refresh_current_shell(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "refreshCurrentShell", ())
|
||||
}
|
||||
|
||||
fn wallpaper(&self, screen_num: u32) -> Result<arg::PropMap, dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "wallpaper", (screen_num, ))
|
||||
.and_then(|r: (arg::PropMap, )| Ok(r.0, ))
|
||||
}
|
||||
|
||||
fn set_wallpaper(&self, wallpaper_plugin: &str, parameters: arg::PropMap, screen_num: u32) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.kde.PlasmaShell", "setWallpaper", (wallpaper_plugin, parameters, screen_num, ))
|
||||
}
|
||||
|
||||
fn edit_mode(&self) -> Result<bool, dbus::Error> {
|
||||
<Self as blocking::stdintf::org_freedesktop_dbus::Properties>::get(self, "org.kde.PlasmaShell", "editMode")
|
||||
}
|
||||
|
||||
fn setedit_mode(&self, value: bool) -> Result<(), dbus::Error> {
|
||||
<Self as blocking::stdintf::org_freedesktop_dbus::Properties>::set(self, "org.kde.PlasmaShell", "editMode", value)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OrgFreedesktopDBusProperties {
|
||||
fn get<R0: for<'b> arg::Get<'b> + 'static>(&self, interface_name: &str, property_name: &str) -> Result<R0, dbus::Error>;
|
||||
fn set<I2: arg::Arg + arg::Append>(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), dbus::Error>;
|
||||
fn get_all(&self, interface_name: &str) -> Result<arg::PropMap, dbus::Error>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
pub interface_name: String,
|
||||
pub changed_properties: arg::PropMap,
|
||||
pub invalidated_properties: Vec<String>,
|
||||
}
|
||||
|
||||
impl arg::AppendAll for OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
fn append(&self, i: &mut arg::IterAppend) {
|
||||
arg::RefArg::append(&self.interface_name, i);
|
||||
arg::RefArg::append(&self.changed_properties, i);
|
||||
arg::RefArg::append(&self.invalidated_properties, i);
|
||||
}
|
||||
}
|
||||
|
||||
impl arg::ReadAll for OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
||||
Ok(OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
interface_name: i.read()?,
|
||||
changed_properties: i.read()?,
|
||||
invalidated_properties: i.read()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl dbus::message::SignalArgs for OrgFreedesktopDBusPropertiesPropertiesChanged {
|
||||
const NAME: &'static str = "PropertiesChanged";
|
||||
const INTERFACE: &'static str = "org.freedesktop.DBus.Properties";
|
||||
}
|
||||
|
||||
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgFreedesktopDBusProperties for blocking::Proxy<'a, C> {
|
||||
|
||||
fn get<R0: for<'b> arg::Get<'b> + 'static>(&self, interface_name: &str, property_name: &str) -> Result<R0, dbus::Error> {
|
||||
self.method_call("org.freedesktop.DBus.Properties", "Get", (interface_name, property_name, ))
|
||||
.and_then(|r: (arg::Variant<R0>, )| Ok((r.0).0, ))
|
||||
}
|
||||
|
||||
fn set<I2: arg::Arg + arg::Append>(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.freedesktop.DBus.Properties", "Set", (interface_name, property_name, arg::Variant(value), ))
|
||||
}
|
||||
|
||||
fn get_all(&self, interface_name: &str) -> Result<arg::PropMap, dbus::Error> {
|
||||
self.method_call("org.freedesktop.DBus.Properties", "GetAll", (interface_name, ))
|
||||
.and_then(|r: (arg::PropMap, )| Ok(r.0, ))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OrgFreedesktopDBusIntrospectable {
|
||||
fn introspect(&self) -> Result<String, dbus::Error>;
|
||||
}
|
||||
|
||||
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgFreedesktopDBusIntrospectable for blocking::Proxy<'a, C> {
|
||||
|
||||
fn introspect(&self) -> Result<String, dbus::Error> {
|
||||
self.method_call("org.freedesktop.DBus.Introspectable", "Introspect", ())
|
||||
.and_then(|r: (String, )| Ok(r.0, ))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OrgFreedesktopDBusPeer {
|
||||
fn ping(&self) -> Result<(), dbus::Error>;
|
||||
fn get_machine_id(&self) -> Result<String, dbus::Error>;
|
||||
}
|
||||
|
||||
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgFreedesktopDBusPeer for blocking::Proxy<'a, C> {
|
||||
|
||||
fn ping(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.freedesktop.DBus.Peer", "Ping", ())
|
||||
}
|
||||
|
||||
fn get_machine_id(&self) -> Result<String, dbus::Error> {
|
||||
self.method_call("org.freedesktop.DBus.Peer", "GetMachineId", ())
|
||||
.and_then(|r: (String, )| Ok(r.0, ))
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user