Commit 288d66b8 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui
Browse files

bump dbus-rs

parent a08b67e4
Pipeline #154796 passed with stage
in 5 minutes and 51 seconds
This diff is collapsed.
......@@ -16,6 +16,6 @@ libhandy = "0.5"
pango = "0.8"
sass-rs = "0.2"
pretty_env_logger = "0.4"
dbus = "0.6"
dbus = "0.8"
rand = "0.7"
failure = "0.1"
use crate::application::Action;
use crate::colour;
use dbus::{BusType, Connection, Message};
use dbus::{
blocking::{BlockingSender, Connection},
message::Message,
};
use sass_rs::{compile_string, Options};
use std::collections::HashMap;
use std::thread;
use std::time::Duration;
macro_rules! get_widget {
($builder:expr, $wtype:ty, $name:ident) => {
......@@ -25,17 +29,20 @@ where
act
}
#[derive(Debug, Clone)]
pub struct ColorPickerError;
#[derive(Debug)]
pub enum ColorPickerError {
DBus(dbus::Error),
NoResponse,
}
impl From<dbus::Error> for ColorPickerError {
fn from(_s: dbus::Error) -> ColorPickerError {
ColorPickerError
fn from(s: dbus::Error) -> ColorPickerError {
ColorPickerError::DBus(s)
}
}
impl From<String> for ColorPickerError {
fn from(_s: String) -> ColorPickerError {
ColorPickerError
ColorPickerError::NoResponse
}
}
impl std::fmt::Display for ColorPickerError {
......@@ -51,16 +58,22 @@ impl std::error::Error for ColorPickerError {
}
pub fn pick_color() -> Result<gdk::RGBA, ColorPickerError> {
let connection = Connection::get_private(BusType::Session)?;
let connection = Connection::new_session()?;
let message = Message::new_method_call("org.gnome.Shell.Screenshot", "/org/gnome/Shell/Screenshot", "org.gnome.Shell.Screenshot", "PickColor")?;
let response = connection.send_with_reply_and_block(message, 60000)?;
let response = connection.send_with_reply_and_block(message, Duration::from_secs(60))?;
let result: HashMap<String, dbus::arg::Variant<Box<dyn dbus::arg::RefArg>>> = response.get1().ok_or_else(|| ColorPickerError::NoResponse)?;
let mut color = result
.get("color")
.ok_or_else(|| ColorPickerError::NoResponse)?
.0
.as_iter()
.ok_or_else(|| ColorPickerError::NoResponse)?;
let result: HashMap<String, dbus::arg::Variant<Box<dyn dbus::arg::RefArg>>, _> = response.get1().ok_or_else(|| ColorPickerError)?;
let mut color = result.get("color").ok_or_else(|| ColorPickerError)?.0.as_iter().ok_or_else(|| ColorPickerError)?;
let red = color.next().ok_or_else(|| ColorPickerError)?.as_f64().ok_or_else(|| ColorPickerError)?;
let green = color.next().ok_or_else(|| ColorPickerError)?.as_f64().ok_or_else(|| ColorPickerError)?;
let blue = color.next().ok_or_else(|| ColorPickerError)?.as_f64().ok_or_else(|| ColorPickerError)?;
let red = color.next().ok_or_else(|| ColorPickerError::NoResponse)?.as_f64().ok_or_else(|| ColorPickerError::NoResponse)?;
let green = color.next().ok_or_else(|| ColorPickerError::NoResponse)?.as_f64().ok_or_else(|| ColorPickerError::NoResponse)?;
let blue = color.next().ok_or_else(|| ColorPickerError::NoResponse)?.as_f64().ok_or_else(|| ColorPickerError::NoResponse)?;
let rgba = gdk::RGBA { red, green, blue, alpha: 1.0 };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment