From 1e2cfe481ff9b8c73e8e78024a691ee922276b78 Mon Sep 17 00:00:00 2001 From: Timidger Date: Fri, 6 Oct 2017 19:15:30 -0700 Subject: [PATCH 01/13] Added desktop-shell wayland protocol --- Cargo.lock | 25 +++++++ Cargo.toml | 4 +- build.rs | 36 ++++++++++ protocols/desktop-shell.xml | 138 ++++++++++++++++++++++++++++++++++++ src/main.rs | 3 +- 5 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 build.rs create mode 100644 protocols/desktop-shell.xml diff --git a/Cargo.lock b/Cargo.lock index de7f9c8..4b92612 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,7 @@ dependencies = [ "image 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-client 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -41,6 +42,11 @@ name = "bitflags" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bitflags" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byteorder" version = "0.5.3" @@ -487,6 +493,14 @@ dependencies = [ "xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wayland-scanner" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "xml-rs 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "wayland-sys" version = "0.6.0" @@ -514,12 +528,21 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "xml-rs" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" "checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159" "checksum bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "72cd7314bd4ee024071241147222c706e80385a1605ac7d4cd2fcc339da2ae46" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4" +"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum clap 2.23.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf1114886d7cde2d6448517161d7db8d681a9a1c09f7d210f0b0864e48195f6" @@ -578,7 +601,9 @@ dependencies = [ "checksum vec_map 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8cdc8b93bd0198ed872357fb2e667f7125646b1762f16d60b2c96350d361897" "checksum wayland-client 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "48a184bc501d82ba9fc02f3f352837e6aab86a6634f4f4e1e8c36a3cc4d8a951" "checksum wayland-scanner 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3307116809c500460a2d017534263b91045014b2df60598bc63bb32a6e0650fa" +"checksum wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6820262132b76ee4aa7893312fb9a24ce5434934a2b421669a30869fcd4a2769" "checksum wayland-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a6dd94a0fbbd2fa8fdcd95466d602284743adff37dde0250ad1c71f5b60eeeb" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7ec6c39eaa68382c8e31e35239402c0a9489d4141a8ceb0c716099a0b515b562" +"checksum xml-rs 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e1945e12e16b951721d7976520b0832496ef79c31602c7a29d950de79ba74621" diff --git a/Cargo.toml b/Cargo.toml index 0fdd7c2..01da38f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Timidger "] description = "Background program for Way Cooler" repository = "https://github.com/way-cooler/way-cooler-bg" license = "MIT" +build = "build.rs" [dependencies] wayland-sys = { version = "^0.6.0", features = ["client", "dlopen"] } @@ -15,4 +16,5 @@ image = "^0.10.3" dbus = "0.5.2" clap = "2.23.2" -# To make this work, gotta compile against the git version, because I'm grabbing gdk-sys not from git... +[build-dependencies] +wayland-scanner = { version = "0.9.1" } diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..6e0e3f1 --- /dev/null +++ b/build.rs @@ -0,0 +1,36 @@ +extern crate wayland_scanner; + +use wayland_scanner::{Side, generate_code, generate_interfaces}; +use std::env; +use std::fs; +use std::path::{Path, PathBuf}; + +fn main() { + generate_wayland_protocols(); +} + + +fn generate_wayland_protocols() { + let protocols = fs::read_dir("./protocols") + .expect("No /protocols/ directory"); + let out_dir = env::var("OUT_DIR").unwrap(); + let out_dir = Path::new(&out_dir); + + for protocol_path in protocols { + let protocol_path: fs::DirEntry = protocol_path.unwrap(); + let path: PathBuf = protocol_path.path().into(); + let mut file_name: String = protocol_path.file_name().into_string().unwrap(); + if let Some(extension) = file_name.find(".xml") { + file_name.truncate(extension); + } + generate_code( + path.clone(), + out_dir.join(file_name.clone() + "_api.rs"), + Side::Server + ); + generate_interfaces( + path, + out_dir.join(file_name + "_interface.rs") + ); + } +} diff --git a/protocols/desktop-shell.xml b/protocols/desktop-shell.xml new file mode 100644 index 0000000..581f0c5 --- /dev/null +++ b/protocols/desktop-shell.xml @@ -0,0 +1,138 @@ + + + + + Traditional user interfaces can rely on this interface to define the + foundations of typical desktops. Currently it's possible to set up + background, panels and locking surfaces. + + + + + + + + + + + + + + + + + + + + + The surface set by this request will receive a fake + pointer.enter event during grabs at position 0, 0 and is + expected to set an appropriate cursor image as described by + the grab_cursor event sent just before the enter event. + + + + + + + + + + + + + + + Tell the client we want it to create and set the lock surface, which is + a GUI asking the user to unlock the screen. The lock surface is + announced with 'set_lock_surface'. Whether or not the client actually + implements locking, it MUST send 'unlock' request to let the normal + desktop resume. + + + + + + This event will be sent immediately before a fake enter event on the + grab surface. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tell the server, that enough desktop elements have been drawn + to make the desktop look ready for use. During start-up, the + server can wait for this request with a black screen before + starting to fade in the desktop, for instance. If the client + parts of a desktop take a long time to initialize, we avoid + showing temporary garbage. + + + + + + + + + + + + + + + + + + + Tell the shell which side of the screen the panel is + located. This is so that new windows do not overlap the panel + and maximized windows maximize properly. + + + + + + + + + Only one client can bind this interface at a time. + + + + + A screensaver surface is normally hidden, and only visible after an + idle timeout. + + + + + + + + diff --git a/src/main.rs b/src/main.rs index d920192..b4fef16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,7 +171,7 @@ fn get_screen_resolution(con: Connection) -> (i32, i32) { let screen_r = &screen_r.get_items()[0]; let output_id = match screen_r { &MessageItem::Array(ref items, _) => { - match items[0] { + match items[1] { MessageItem::Str(ref string) => string.clone(), _ => panic!("Array didn't contain output id") } @@ -267,6 +267,7 @@ fn generate_image_background(path: &str, mode: BackgroundMode, color: Color, let dbus_con = Connection::get_private(BusType::Session).unwrap(); let resolution = get_screen_resolution(dbus_con); let (scr_width, scr_height) = (resolution.0 as u32, resolution.1 as u32); + println!("WIDTH: {}, HEIGHT: {}", scr_width, scr_height); let img_width = image.width(); let img_height = image.height(); From 6abecb07f210eeaa2870396c9ad6a3cb1aef1dd2 Mon Sep 17 00:00:00 2001 From: Timidger Date: Fri, 6 Oct 2017 19:42:29 -0700 Subject: [PATCH 02/13] Started rewrite --- Cargo.lock | 85 ++++++++++++++++++++--------- Cargo.toml | 6 ++- src/main.rs | 102 ++++++++++++++++++++++++++++------- src/window.rs | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 292 insertions(+), 48 deletions(-) create mode 100644 src/window.rs diff --git a/Cargo.lock b/Cargo.lock index de7f9c8..1885083 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,8 +7,9 @@ dependencies = [ "dbus 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-client 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-server 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -28,17 +29,17 @@ dependencies = [ [[package]] name = "bitflags" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitflags" -version = "0.7.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitflags" -version = "0.8.2" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -51,6 +52,11 @@ name = "byteorder" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cfg-if" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "clap" version = "2.23.2" @@ -187,11 +193,6 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "lazy_static" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "lazy_static" version = "0.2.8" @@ -237,6 +238,17 @@ dependencies = [ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "nix" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num-bigint" version = "0.1.37" @@ -468,32 +480,50 @@ name = "vec_map" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "wayland-client" -version = "0.6.2" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-scanner 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wayland-scanner" -version = "0.6.0" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-server" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wayland-sys" -version = "0.6.0" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dlib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -508,20 +538,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "xml-rs" -version = "0.3.6" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [metadata] "checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" "checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159" -"checksum bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "72cd7314bd4ee024071241147222c706e80385a1605ac7d4cd2fcc339da2ae46" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4" +"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" +"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum clap 2.23.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf1114886d7cde2d6448517161d7db8d681a9a1c09f7d210f0b0864e48195f6" "checksum color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a475fc4af42d83d28adf72968d9bcfaf035a1a9381642d8e85d8a04957767b0d" "checksum dbus 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "47f881971824401c27bc1ff9f641d54ac66e0f409631806fa7be8cad8e6be450" @@ -539,13 +570,13 @@ dependencies = [ "checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c" "checksum jpeg-decoder 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "919d49b634cde303392353c5dd51153ec005a1a981c6f4b8277692a51e9d260d" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" "checksum libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "88ee81885f9f04bff991e306fea7c1c60a5f0f9e409e99f6b40e3311a3363135" "checksum libloading 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0a020ac941774eb37e9d13d418c37b522e76899bfc4e7b1a600d529a53f83a66" "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" "checksum metadeps 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829fffe7ea1d747e23f64be972991bc516b2f1ac2ae4a3b33d8bea150c410151" "checksum miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "28eaee17666671fa872e567547e8428e83308ebe5808cdf6a0e28397dbe2c726" +"checksum nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "47e49f6982987135c5e9620ab317623e723bd06738fd85377e8d55f57c8b6487" "checksum num-bigint 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ba6d838b16e56da1b6c383d065ff1ec3c7d7797f65a3e8f6ba7092fd87820bac" "checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37" "checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e" @@ -576,9 +607,11 @@ dependencies = [ "checksum unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18127285758f0e2c6cf325bb3f3d138a12fee27de4f23e146cd6a179f26c2cf3" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum vec_map 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8cdc8b93bd0198ed872357fb2e667f7125646b1762f16d60b2c96350d361897" -"checksum wayland-client 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "48a184bc501d82ba9fc02f3f352837e6aab86a6634f4f4e1e8c36a3cc4d8a951" -"checksum wayland-scanner 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3307116809c500460a2d017534263b91045014b2df60598bc63bb32a6e0650fa" -"checksum wayland-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a6dd94a0fbbd2fa8fdcd95466d602284743adff37dde0250ad1c71f5b60eeeb" +"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +"checksum wayland-client 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "9b10f2880f3dedaa496609a0aa7117bc6824490a48309dfbbf26258e5acc5a9d" +"checksum wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6820262132b76ee4aa7893312fb9a24ce5434934a2b421669a30869fcd4a2769" +"checksum wayland-server 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "1bd54d473c5e1511b70b1feeddf02c351019561454552ef2c9491ce854ff2df1" +"checksum wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "b433ca9dbd9289a8ae8a5c49148d2a0e724b89432d7648727ca553027c247c47" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7ec6c39eaa68382c8e31e35239402c0a9489d4141a8ceb0c716099a0b515b562" +"checksum xml-rs 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e1945e12e16b951721d7976520b0832496ef79c31602c7a29d950de79ba74621" diff --git a/Cargo.toml b/Cargo.toml index 0fdd7c2..f9b7e31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,12 @@ authors = ["Timidger "] description = "Background program for Way Cooler" repository = "https://github.com/way-cooler/way-cooler-bg" license = "MIT" +build = "build.rs" [dependencies] -wayland-sys = { version = "^0.6.0", features = ["client", "dlopen"] } -wayland-client = { version = "^0.6.0", features = ["cursor", "dlopen"] } +wayland-sys = { version = "^0.9.0", features = ["client", "dlopen"] } +wayland-client = { version = "^0.9.0", features = ["cursor", "dlopen"] } +wayland-server = { version = "^0.9.0", features = ["dlopen"] } tempfile = "2.1" byteorder = ">= 0.3, < 0.6" image = "^0.10.3" diff --git a/src/main.rs b/src/main.rs index d920192..6a8db1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ -#[macro_use] -extern crate wayland_client; +#[macro_use] extern crate wayland_client; +extern crate wayland_server; +#[macro_use] extern crate wayland_sys; extern crate tempfile; @@ -9,6 +10,8 @@ extern crate dbus; extern crate clap; mod color; +mod window; +use window::Window; use color::Color; use std::mem::transmute; @@ -17,12 +20,13 @@ use std::io::Write; use std::str::FromStr; use std::cmp::{min, max}; -use wayland_client::wayland::get_display; -use wayland_client::wayland::compositor::{WlCompositor, WlSurface}; -use wayland_client::wayland::shell::WlShell; -use wayland_client::wayland::shm::{WlBuffer, WlShm, WlShmFormat}; -use wayland_client::wayland::seat::{WlSeat, WlPointerEvent}; -use wayland_client::{EventIterator, Proxy}; +use wayland_client::EnvHandler; +use wayland_client::protocol::{wl_compositor, wl_shell, wl_shm, wl_surface, + wl_seat, wl_keyboard, wl_buffer, + wl_output, wl_registry}; +use wl_surface::WlSurface; + +use wl_shm::Format as WlShmFormat; use byteorder::{NativeEndian, WriteBytesExt}; use clap::{Arg, App}; @@ -30,18 +34,46 @@ use image::{GenericImage, DynamicImage, Pixel, FilterType, load_from_memory, ope use dbus::{Connection, Message, MessageItem, BusType}; wayland_env!(WaylandEnv, - compositor: WlCompositor, - shell: WlShell, - shm: WlShm, - seat: WlSeat + compositor: wl_compositor::WlCompositor, + shell: wl_shell::WlShell, + shm: wl_shm::WlShm, + seat: wl_seat::WlSeat, + output: wl_output::WlOutput ); +mod generated { + // Generated code generally doesn't follow standards + #![allow(dead_code,non_camel_case_types,unused_unsafe,unused_variables)] + #![allow(non_upper_case_globals,non_snake_case,unused_imports)] + + pub mod interfaces { + #[doc(hidden)] + use wayland_server::protocol_interfaces::{wl_output_interface, wl_surface_interface}; + include!(concat!(env!("OUT_DIR"), "/desktop-shell_interface.rs")); + } + + pub mod client { + #[doc(hidden)] + use wayland_server::{Resource, Handler, + Client, Liveness, + EventLoopHandle, EventResult}; + #[doc(hidden)] + use wayland_server::protocol::{wl_output, wl_surface}; + #[doc(hidden)] + use super::interfaces; + include!(concat!(env!("OUT_DIR"), "/desktop-shell_api.rs")); + } +} + +use generated::client::desktop_shell::Handler as DesktopShellHandler; +impl DesktopShellHandler for Window {} + const CURSOR: &'static [u8; 656] = include_bytes!("../assets/arrow.png"); // DBus wait time const DBUS_WAIT_TIME: i32 = 2000; -type BufferResult = Result; +type BufferResult = Result; pub enum BackgroundMode { /// Scale image to make the shortest dimension (i.e. height or width) @@ -128,9 +160,18 @@ fn main() { ("".to_string(), BackgroundMode::Fill) }; - let (display, iter) = get_display() + let (display, mut event_queue) = wayland_client::default_connect() .expect("Unable to connect to a wayland compositor"); - let (env, evt_iter) = WaylandEnv::init(display, iter); + let env_id = event_queue.add_handler(EnvHandler::::new()); + let registry = display.get_registry(); + // a roundtrip sync will dispatch all event declaring globals to the handler + // This will make all the globals usable. + event_queue.sync_roundtrip().expect("Could not sync roundtrip"); + let output = get_output(env_id, registry, &mut event_queue); + + let window = Window::new(0, output, 0, event_queue.state()); + window.set_background(event_queue.state(),); + /*let (env, evt_iter) = WaylandEnv::init(display, iter); let compositor = env.compositor.as_ref().map(|o| &o.0).unwrap(); let shell = env.shell.as_ref().map(|o| &o.0).unwrap(); let mut background_surface = compositor.create_surface(); @@ -152,7 +193,8 @@ fn main() { background_surface.set_buffer_scale(1); let mut cursor_surface = compositor.create_surface(); let _cursor_buffer = self::cursor_surface(&mut cursor_surface, &env); - main_background_loop(background_surface, cursor_surface, evt_iter, &env); + */ + //main_background_loop(background_surface, cursor_surface, evt_iter, &env); } fn rgba_conversion(num: u8, third_num: u32) -> u8 { @@ -204,7 +246,8 @@ fn get_screen_resolution(con: Connection) -> (i32, i32) { /// Given a solid color, writes bytes associated with that color to /// a special Wayland surface which is then rendered as a background for Way Cooler. -fn generate_solid_background(color: Color, background_surface: &mut WlSurface, +/* +fn generate_solid_background(color: Color, background_surface: &mut wl_surface::WlSurface, env: &WaylandEnv) -> BufferResult { // Get shortcuts to the globals. let shm = env.shm.as_ref().map(|o| &o.0).unwrap(); @@ -255,7 +298,7 @@ fn fill_image_base_color(image: DynamicImage, color: Color) -> DynamicImage { /// Given the data from an image, writes it to a special Wayland surface /// which is then rendered as a background for Way Cooler. fn generate_image_background(path: &str, mode: BackgroundMode, color: Color, - background_surface: &mut WlSurface, env: &WaylandEnv) -> BufferResult { + background_surface: &mut wl_surface::WlSurface, env: &WaylandEnv) -> BufferResult { // TODO support more formats, split into separate function let image = open(path) .unwrap_or_else(|_| { @@ -387,7 +430,7 @@ fn generate_image_background(path: &str, mode: BackgroundMode, color: Color, Ok(background_buffer) } -fn cursor_surface(cursor_surface: &mut WlSurface, env: &WaylandEnv) -> BufferResult { +fn cursor_surface(cursor_surface: &mut wl_surface::WlSurface, env: &WaylandEnv) -> BufferResult { let shm = env.shm.as_ref().map(|o| &o.0).unwrap(); let image = load_from_memory(CURSOR) @@ -419,7 +462,9 @@ fn cursor_surface(cursor_surface: &mut WlSurface, env: &WaylandEnv) -> BufferRes cursor_surface.attach(Some(&cursor_buffer), 0, 0); Ok(cursor_buffer) } +*/ +/* /// Main loop for rendering backgrounds. /// Need to keep the surface alive, and update it if the /// user wants to change the background. @@ -457,7 +502,24 @@ fn main_background_loop(background_surface: WlSurface, cursor_surface: WlSurface event_iter.dispatch().expect("Connection with the compositor was lost."); } } - + */ + +fn get_output(env_id: usize, + registry: wl_registry::WlRegistry, + event_queue: &mut wayland_client::EventQueue) + -> wl_output::WlOutput { + let state = event_queue.state(); + let env = state.get_handler::>(env_id); + for &(name, ref interface, version) in env.globals() { + if interface == "wl_output" { + return registry.bind::(version, name) + } + } + for &(name, ref interface, version) in env.globals() { + println!("{:4} : {} (version {})", name, interface, version); + } + panic!("Could not find wl_output to bind to"); +} #[test] fn test_rgba_conversion() { diff --git a/src/window.rs b/src/window.rs new file mode 100644 index 0000000..e98bbbc --- /dev/null +++ b/src/window.rs @@ -0,0 +1,147 @@ +//! Module containing logic for writing to the screen. + +use std::io::{BufWriter, Seek, SeekFrom}; +use std::os::unix::io::AsRawFd; + +use wayland_client::{self, EventQueueHandle, EnvHandler, Proxy}; +use wayland_client::protocol::{wl_shm, wl_shell_surface, wl_buffer, wl_output, + wl_surface}; +use wayland_client::protocol::wl_shell_surface::FullscreenMethod; +use byteorder::{NativeEndian, WriteBytesExt}; +use tempfile; + +use ::WaylandEnv; +use ::color::Color; + +/// Used to know how big to make the surface. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct Resolution { + pub w: u32, + pub h: u32 +} + +impl Resolution { + pub fn new() -> Self { + Resolution { + w: 0, + h: 0 + } + } + + /// Gets the size of the resolution (width * height) + pub fn size(self) -> u32 { + self.w * self.h + } +} + +/// The main window struct, containing the buffer backing the wayland surface, +/// and the file descriptor to the shared memory. +pub struct Window { + buffer: wl_buffer::WlBuffer, + file: ::std::fs::File, + surface: wl_surface::WlSurface, + shell_surface: wl_shell_surface::WlShellSurface, +} + +impl Window { + // allocates a buffer to hold the surface data + pub fn new(resolution_id: usize, + output: wl_output::WlOutput, + env_id: usize, + state: wayland_client::StateGuard) -> Self { + let res: Resolution = *state.get_handler(resolution_id); + assert_ne!(res.size(), 0, "Resolution was not properly initialized"); + let env = state.get_handler::>(env_id); + // Create buffer, write bytes into buffer + let mut file = tempfile::tempfile().ok() + .expect("Unable to create buffer file"); + let mut buf = BufWriter::new(file); + let black: Color = 0x000000.into(); + for _ in 0..(res.size()) { + buf.write_u32::(black.to_u32()) + .expect("Could not write to temp file"); + } + file = buf.into_inner() + .expect("Could not get buffer file"); + // Create surface + let surface = env.compositor.create_surface(); + let shell_surface = env.shell.get_shell_surface(&surface); + let pool = env.shm + .create_pool(file.as_raw_fd(), (res.w * res.h * 4) as i32); + let buffer = pool.create_buffer(0, + res.w as i32, + res.h as i32, + (res.w * 4) as i32, + wl_shm::Format::Argb8888) + .expect("Pool is already dead"); + shell_surface.set_fullscreen(FullscreenMethod::Default, + 0, + Some(&output)); + surface.attach(Some(&buffer), 0, 0); + surface.commit(); + + Window { + buffer, + file, + surface, + shell_surface, + } + } + + pub fn shell_surface(&self) -> wl_shell_surface::WlShellSurface { + self.shell_surface.clone() + .expect("Shell surface was not initialized") + } + + /// Updates the buffer to have the given color. + pub fn update_color(&mut self, + color: Color, + res: Resolution) { + assert_ne!(res.size(), 0, "Resolution was not properly initialized"); + self.file.seek(SeekFrom::Start(0)) + .expect("Could not seek to beginning of file"); + let file_copy = self.file.try_clone() + .expect("Could not clone file handler"); + let mut buf = BufWriter::new(file_copy); + // Create buffer, write bytes into buffer + for _ in 0..(res.size()) { + buf.write_u32::(color.to_u32()) + .expect("Could not write to temp file"); + } + self.file = buf.into_inner() + .expect("Could not consume buffer writer"); + self.surface.damage(0, 0, res.w as i32, res.h as i32); + self.surface.attach(Some(&self.buffer), 0, 0); + self.surface.commit(); + } +} + +impl wl_shell_surface::Handler for Window { + fn ping(&mut self, _: &mut EventQueueHandle, + me: &wl_shell_surface::WlShellSurface, + serial: u32) { + me.pong(serial); + } + + // we ignore the other methods in this example, by default they do nothing +} + +declare_handler!(Window, + wl_shell_surface::Handler, + wl_shell_surface::WlShellSurface); + +impl wl_output::Handler for Resolution { + fn mode(&mut self, + _evqh: &mut EventQueueHandle, + _proxy: &wl_output::WlOutput, + _flags: wl_output::Mode, + width: i32, + height: i32, + _refresh: i32) { + self.w = width as u32; + self.h = height as u32; + println!("wxh: {}x{}", width, height); + } +} + +declare_handler!(Resolution, wl_output::Handler, wl_output::WlOutput); From ad62d2034793b643bbcab3cc54c9c2d62a1b1ca5 Mon Sep 17 00:00:00 2001 From: Timidger Date: Fri, 6 Oct 2017 20:44:35 -0700 Subject: [PATCH 03/13] Yay got it working, that was way too easy --- src/macros.rs | 24 +++++++++ src/main.rs | 117 +++++++++++++++++++++------------------- src/window.rs | 147 -------------------------------------------------- 3 files changed, 86 insertions(+), 202 deletions(-) create mode 100644 src/macros.rs delete mode 100644 src/window.rs diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..b90c67a --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,24 @@ + +#[macro_export] +macro_rules! get_wayland { + ($env_id: tt, $registry: expr, $event_queue: expr, $type: ty, $name: tt) => {{ + let state = $event_queue.state(); + let env = state.get_handler::>($env_id); + let mut value = None; + for &(name, ref interface, version) in env.globals() { + if interface == $name { + value = Some($registry.bind::<$type>(version, name)); + break; + } + } + match value { + Some(v) => v, + _ => { + for &(name, ref interface, version) in env.globals() { + println!("{:4} : {} (version {})", name, interface, version); + } + panic!(concat!("Could not find ", $name, " to bind to")); + } + } + }} +} diff --git a/src/main.rs b/src/main.rs index 49413b7..a15dc5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ #[macro_use] extern crate wayland_client; -extern crate wayland_server; #[macro_use] extern crate wayland_sys; extern crate tempfile; @@ -8,10 +7,9 @@ extern crate byteorder; extern crate image; extern crate dbus; extern crate clap; +#[macro_use] mod macros; mod color; -mod window; -use window::Window; use color::Color; use std::mem::transmute; @@ -22,9 +20,13 @@ use std::cmp::{min, max}; use wayland_client::EnvHandler; use wayland_client::protocol::{wl_compositor, wl_shell, wl_shm, wl_surface, - wl_seat, wl_keyboard, wl_buffer, - wl_output, wl_registry}; + wl_seat, wl_buffer, + wl_output}; use wl_surface::WlSurface; +use wl_output::WlOutput; +use wl_shell::WlShell; +use wl_seat::WlSeat; +use wl_compositor::WlCompositor; use wl_shm::Format as WlShmFormat; @@ -48,25 +50,23 @@ mod generated { pub mod interfaces { #[doc(hidden)] - use wayland_server::protocol_interfaces::{wl_output_interface, wl_surface_interface}; + use wayland_client::protocol_interfaces::{wl_output_interface, wl_surface_interface}; include!(concat!(env!("OUT_DIR"), "/desktop-shell_interface.rs")); } pub mod client { #[doc(hidden)] - use wayland_server::{Resource, Handler, - Client, Liveness, - EventLoopHandle, EventResult}; - #[doc(hidden)] - use wayland_server::protocol::{wl_output, wl_surface}; + use wayland_client::{Handler, Liveness, EventQueueHandle, Proxy, RequestResult}; #[doc(hidden)] + use wayland_client::protocol::{wl_compositor, wl_shell, wl_shm, wl_surface, + wl_seat, wl_keyboard, wl_buffer, + wl_output, wl_registry}; use super::interfaces; include!(concat!(env!("OUT_DIR"), "/desktop-shell_api.rs")); } } -use generated::client::desktop_shell::Handler as DesktopShellHandler; -impl DesktopShellHandler for Window {} +use generated::client::desktop_shell::DesktopShell; const CURSOR: &'static [u8; 656] = include_bytes!("../assets/arrow.png"); @@ -164,37 +164,46 @@ fn main() { .expect("Unable to connect to a wayland compositor"); let env_id = event_queue.add_handler(EnvHandler::::new()); let registry = display.get_registry(); + event_queue.register::<_, EnvHandler>(®istry, env_id); // a roundtrip sync will dispatch all event declaring globals to the handler // This will make all the globals usable. event_queue.sync_roundtrip().expect("Could not sync roundtrip"); - let output = get_output(env_id, registry, &mut event_queue); + let output = get_wayland!(env_id, ®istry, &mut event_queue, WlOutput, "wl_output"); - let window = Window::new(0, output, 0, event_queue.state()); - window.set_background(event_queue.state(),); - /*let (env, evt_iter) = WaylandEnv::init(display, iter); - let compositor = env.compositor.as_ref().map(|o| &o.0).unwrap(); - let shell = env.shell.as_ref().map(|o| &o.0).unwrap(); + let desktop_shell = get_wayland!(env_id, ®istry, &mut event_queue, DesktopShell, "desktop_shell"); + let shell = get_wayland!(env_id, ®istry, &mut event_queue, WlShell, "wl_shell"); + let compositor = get_wayland!(env_id, ®istry, &mut event_queue, WlCompositor, "wl_compositor"); + let seat = get_wayland!(env_id, ®istry, &mut event_queue, WlSeat, "wl_seat"); let mut background_surface = compositor.create_surface(); + desktop_shell.set_background(&output, &background_surface); + event_queue.dispatch() + .expect("Could not dispatch queue"); + let pointer = seat.get_pointer().expect("Could not get pointer from seat global"); let shell_surface = shell.get_shell_surface(&background_surface); shell_surface.set_class("Background".into()); - let _background_buffer = if image.is_empty() { shell_surface.set_title(format!("Background Color: {}", color.to_u32())); - generate_solid_background(color, &mut background_surface, &env) + generate_solid_background(color, &mut event_queue, &mut background_surface, env_id) } else { // TODO Actually give it the path or something idk shell_surface.set_title(format!("Background Image: {}", image)); - generate_image_background(image.as_ref(), mode, color, &mut background_surface, &env) + generate_image_background(image.as_ref(), &mut event_queue, mode, color, &mut background_surface, env_id) }.expect("could not generate image"); background_surface.commit(); background_surface.set_buffer_scale(1); let mut cursor_surface = compositor.create_surface(); - let _cursor_buffer = self::cursor_surface(&mut cursor_surface, &env); - */ - //main_background_loop(background_surface, cursor_surface, evt_iter, &env); + let _cursor_buffer = self::cursor_surface(&mut cursor_surface, &mut event_queue, env_id); + loop { + display.flush() + .expect("Could not flush display"); + event_queue.dispatch() + .expect("Could not dispatch queue"); + pointer.set_cursor(0, Some(&cursor_surface), 0, 0) + .expect("Could not set cursor"); + } } fn rgba_conversion(num: u8, third_num: u32) -> u8 { @@ -246,11 +255,14 @@ fn get_screen_resolution(con: Connection) -> (i32, i32) { /// Given a solid color, writes bytes associated with that color to /// a special Wayland surface which is then rendered as a background for Way Cooler. -/* -fn generate_solid_background(color: Color, background_surface: &mut wl_surface::WlSurface, - env: &WaylandEnv) -> BufferResult { +fn generate_solid_background(color: Color, + event_queue: &mut wayland_client::EventQueue, + background_surface: &mut wl_surface::WlSurface, + env_id: usize) -> BufferResult { // Get shortcuts to the globals. - let shm = env.shm.as_ref().map(|o| &o.0).unwrap(); + let state = event_queue.state(); + let env = state.get_handler::>(env_id); + let shm = &env.shm; // Create the surface we are going to write into let mut tmp = tempfile::tempfile().ok().expect("Unable to create a tempfile."); @@ -272,7 +284,8 @@ fn generate_solid_background(color: Color, background_surface: &mut wl_surface:: // Create the buffer that is mem-mapped to the temp file descriptor let pool = shm.create_pool(tmp.as_raw_fd(), size); - let background_buffer = pool.create_buffer(0, width, height, width, WlShmFormat::Argb8888); + let background_buffer = pool.create_buffer(0, width, height, width, WlShmFormat::Argb8888) + .expect("Could not create buffer"); // Tell Way Cooler not to set put this in the tree, treat as background // Attach the buffer to the surface @@ -297,9 +310,15 @@ fn fill_image_base_color(image: DynamicImage, color: Color) -> DynamicImage { /// Given the data from an image, writes it to a special Wayland surface /// which is then rendered as a background for Way Cooler. -fn generate_image_background(path: &str, mode: BackgroundMode, color: Color, - background_surface: &mut wl_surface::WlSurface, env: &WaylandEnv) -> BufferResult { +fn generate_image_background(path: &str, + event_queue: &mut wayland_client::EventQueue, + mode: BackgroundMode, + color: Color, + background_surface: &mut wl_surface::WlSurface, + env_id: usize) -> BufferResult { // TODO support more formats, split into separate function + let state = event_queue.state(); + let env = state.get_handler::>(env_id); let image = open(path) .unwrap_or_else(|_| { println!("Could not open image file \"{:?}\"", path); @@ -419,11 +438,12 @@ fn generate_image_background(path: &str, mode: BackgroundMode, color: Color, tmp.set_len(img_size as u64).expect("Could not truncate length of file"); tmp.write_all(&*vec).unwrap(); - let shm = env.shm.as_ref().map(|o| &o.0).unwrap(); + let shm = &env.shm; // Create the surface we are going to write into let pool = shm.create_pool(tmp.as_raw_fd(), img_size as i32); - let background_buffer = pool.create_buffer(0, scr_width as i32, scr_height as i32, img_stride as i32, WlShmFormat::Argb8888); + let background_buffer = pool.create_buffer(0, scr_width as i32, scr_height as i32, img_stride as i32, WlShmFormat::Argb8888) + .expect("Could not create buffer"); // Attach the buffer to the surface background_surface.attach(Some(&background_buffer), 0, 0); @@ -431,8 +451,12 @@ fn generate_image_background(path: &str, mode: BackgroundMode, color: Color, Ok(background_buffer) } -fn cursor_surface(cursor_surface: &mut wl_surface::WlSurface, env: &WaylandEnv) -> BufferResult { - let shm = env.shm.as_ref().map(|o| &o.0).unwrap(); +fn cursor_surface(cursor_surface: &mut wl_surface::WlSurface, + event_queue: &mut wayland_client::EventQueue, + env_id: usize) -> BufferResult { + let state = event_queue.state(); + let env = state.get_handler::>(env_id); + let shm = &env.shm; let image = load_from_memory(CURSOR) .expect("Could not read cursor data, report to maintainer!"); @@ -459,11 +483,11 @@ fn cursor_surface(cursor_surface: &mut wl_surface::WlSurface, env: &WaylandEnv) tmp.set_len(size as u64).expect("Could not truncate length of file"); tmp.write_all(&*vec).unwrap(); let pool = shm.create_pool(tmp.as_raw_fd(), size as i32); - let cursor_buffer = pool.create_buffer(0, width as i32, height as i32, stride as i32, WlShmFormat::Argb8888); + let cursor_buffer = pool.create_buffer(0, width as i32, height as i32, stride as i32, WlShmFormat::Argb8888) + .expect("Could not create buffer"); cursor_surface.attach(Some(&cursor_buffer), 0, 0); Ok(cursor_buffer) } -*/ /* /// Main loop for rendering backgrounds. @@ -505,23 +529,6 @@ fn main_background_loop(background_surface: WlSurface, cursor_surface: WlSurface } */ -fn get_output(env_id: usize, - registry: wl_registry::WlRegistry, - event_queue: &mut wayland_client::EventQueue) - -> wl_output::WlOutput { - let state = event_queue.state(); - let env = state.get_handler::>(env_id); - for &(name, ref interface, version) in env.globals() { - if interface == "wl_output" { - return registry.bind::(version, name) - } - } - for &(name, ref interface, version) in env.globals() { - println!("{:4} : {} (version {})", name, interface, version); - } - panic!("Could not find wl_output to bind to"); -} - #[test] fn test_rgba_conversion() { assert_eq!(rgba_conversion(10, 254), 9); diff --git a/src/window.rs b/src/window.rs deleted file mode 100644 index e98bbbc..0000000 --- a/src/window.rs +++ /dev/null @@ -1,147 +0,0 @@ -//! Module containing logic for writing to the screen. - -use std::io::{BufWriter, Seek, SeekFrom}; -use std::os::unix::io::AsRawFd; - -use wayland_client::{self, EventQueueHandle, EnvHandler, Proxy}; -use wayland_client::protocol::{wl_shm, wl_shell_surface, wl_buffer, wl_output, - wl_surface}; -use wayland_client::protocol::wl_shell_surface::FullscreenMethod; -use byteorder::{NativeEndian, WriteBytesExt}; -use tempfile; - -use ::WaylandEnv; -use ::color::Color; - -/// Used to know how big to make the surface. -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub struct Resolution { - pub w: u32, - pub h: u32 -} - -impl Resolution { - pub fn new() -> Self { - Resolution { - w: 0, - h: 0 - } - } - - /// Gets the size of the resolution (width * height) - pub fn size(self) -> u32 { - self.w * self.h - } -} - -/// The main window struct, containing the buffer backing the wayland surface, -/// and the file descriptor to the shared memory. -pub struct Window { - buffer: wl_buffer::WlBuffer, - file: ::std::fs::File, - surface: wl_surface::WlSurface, - shell_surface: wl_shell_surface::WlShellSurface, -} - -impl Window { - // allocates a buffer to hold the surface data - pub fn new(resolution_id: usize, - output: wl_output::WlOutput, - env_id: usize, - state: wayland_client::StateGuard) -> Self { - let res: Resolution = *state.get_handler(resolution_id); - assert_ne!(res.size(), 0, "Resolution was not properly initialized"); - let env = state.get_handler::>(env_id); - // Create buffer, write bytes into buffer - let mut file = tempfile::tempfile().ok() - .expect("Unable to create buffer file"); - let mut buf = BufWriter::new(file); - let black: Color = 0x000000.into(); - for _ in 0..(res.size()) { - buf.write_u32::(black.to_u32()) - .expect("Could not write to temp file"); - } - file = buf.into_inner() - .expect("Could not get buffer file"); - // Create surface - let surface = env.compositor.create_surface(); - let shell_surface = env.shell.get_shell_surface(&surface); - let pool = env.shm - .create_pool(file.as_raw_fd(), (res.w * res.h * 4) as i32); - let buffer = pool.create_buffer(0, - res.w as i32, - res.h as i32, - (res.w * 4) as i32, - wl_shm::Format::Argb8888) - .expect("Pool is already dead"); - shell_surface.set_fullscreen(FullscreenMethod::Default, - 0, - Some(&output)); - surface.attach(Some(&buffer), 0, 0); - surface.commit(); - - Window { - buffer, - file, - surface, - shell_surface, - } - } - - pub fn shell_surface(&self) -> wl_shell_surface::WlShellSurface { - self.shell_surface.clone() - .expect("Shell surface was not initialized") - } - - /// Updates the buffer to have the given color. - pub fn update_color(&mut self, - color: Color, - res: Resolution) { - assert_ne!(res.size(), 0, "Resolution was not properly initialized"); - self.file.seek(SeekFrom::Start(0)) - .expect("Could not seek to beginning of file"); - let file_copy = self.file.try_clone() - .expect("Could not clone file handler"); - let mut buf = BufWriter::new(file_copy); - // Create buffer, write bytes into buffer - for _ in 0..(res.size()) { - buf.write_u32::(color.to_u32()) - .expect("Could not write to temp file"); - } - self.file = buf.into_inner() - .expect("Could not consume buffer writer"); - self.surface.damage(0, 0, res.w as i32, res.h as i32); - self.surface.attach(Some(&self.buffer), 0, 0); - self.surface.commit(); - } -} - -impl wl_shell_surface::Handler for Window { - fn ping(&mut self, _: &mut EventQueueHandle, - me: &wl_shell_surface::WlShellSurface, - serial: u32) { - me.pong(serial); - } - - // we ignore the other methods in this example, by default they do nothing -} - -declare_handler!(Window, - wl_shell_surface::Handler, - wl_shell_surface::WlShellSurface); - -impl wl_output::Handler for Resolution { - fn mode(&mut self, - _evqh: &mut EventQueueHandle, - _proxy: &wl_output::WlOutput, - _flags: wl_output::Mode, - width: i32, - height: i32, - _refresh: i32) { - self.w = width as u32; - self.h = height as u32; - println!("wxh: {}x{}", width, height); - } -} - -declare_handler!(Resolution, wl_output::Handler, wl_output::WlOutput); From 92c0f6c78fb4e023d86014c8dfb6255c1c990435 Mon Sep 17 00:00:00 2001 From: Timidger Date: Fri, 6 Oct 2017 22:37:27 -0700 Subject: [PATCH 04/13] Updated to use the desktop-shell protocol --- Cargo.lock | 39 --------------------------------------- Cargo.toml | 1 - build.rs | 2 +- src/macros.rs | 11 ++++++----- src/main.rs | 18 ++++++++++++------ 5 files changed, 19 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a21fb47..581cfde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,7 +9,6 @@ dependencies = [ "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-client 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-server 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -54,11 +53,6 @@ name = "cc" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "cfg-if" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "clap" version = "2.26.2" @@ -270,17 +264,6 @@ dependencies = [ "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "nix" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "num-bigint" version = "0.1.40" @@ -533,11 +516,6 @@ name = "vec_map" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "wayland-client" version = "0.9.10" @@ -557,18 +535,6 @@ dependencies = [ "xml-rs 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "wayland-server" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "wayland-sys" version = "0.9.10" @@ -576,7 +542,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dlib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -605,7 +570,6 @@ dependencies = [ "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" "checksum cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7db2f146208d7e0fbee761b09cd65a7f51ccc38705d4e7262dad4d73b12a76b1" -"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3451e409013178663435d6f15fdb212f14ee4424a3d74f979d081d0a66b6f1f2" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" "checksum color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a475fc4af42d83d28adf72968d9bcfaf035a1a9381642d8e85d8a04957767b0d" @@ -633,7 +597,6 @@ dependencies = [ "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" "checksum metadeps 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b122901b3a675fac8cecf68dcb2f0d3036193bc861d1ac0e1c337f7d5254c2" "checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" -"checksum nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "47e49f6982987135c5e9620ab317623e723bd06738fd85377e8d55f57c8b6487" "checksum num-bigint 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "8fd0f8dbb4c0960998958a796281d88c16fbe68d87b1baa6f31e2979e81fd0bd" "checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba" "checksum num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "7485fcc84f85b4ecd0ea527b14189281cf27d60e583ae65ebc9c088b13dffe01" @@ -666,10 +629,8 @@ dependencies = [ "checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum wayland-client 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "9b10f2880f3dedaa496609a0aa7117bc6824490a48309dfbbf26258e5acc5a9d" "checksum wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6820262132b76ee4aa7893312fb9a24ce5434934a2b421669a30869fcd4a2769" -"checksum wayland-server 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "1bd54d473c5e1511b70b1feeddf02c351019561454552ef2c9491ce854ff2df1" "checksum wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "b433ca9dbd9289a8ae8a5c49148d2a0e724b89432d7648727ca553027c247c47" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/Cargo.toml b/Cargo.toml index 3ac358a..818ffd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ build = "build.rs" [dependencies] wayland-sys = { version = "^0.9.0", features = ["client", "dlopen"] } wayland-client = { version = "^0.9.0", features = ["cursor", "dlopen"] } -wayland-server = { version = "^0.9.0", features = ["dlopen"] } tempfile = "2.1" byteorder = ">= 0.3, < 0.6" image = "^0.10.3" diff --git a/build.rs b/build.rs index 6e0e3f1..1de6a47 100644 --- a/build.rs +++ b/build.rs @@ -26,7 +26,7 @@ fn generate_wayland_protocols() { generate_code( path.clone(), out_dir.join(file_name.clone() + "_api.rs"), - Side::Server + Side::Client ); generate_interfaces( path, diff --git a/src/macros.rs b/src/macros.rs index b90c67a..8da9649 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -12,13 +12,14 @@ macro_rules! get_wayland { } } match value { - Some(v) => v, - _ => { + None => { for &(name, ref interface, version) in env.globals() { - println!("{:4} : {} (version {})", name, interface, version); + eprintln!("{:4} : {} (version {})", name, interface, version); } - panic!(concat!("Could not find ", $name, " to bind to")); - } + eprintln!(concat!("Could not find the ", $name, " protocol!")); + None + }, + v => v } }} } diff --git a/src/main.rs b/src/main.rs index a15dc5c..014c228 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,6 @@ use wayland_client::EnvHandler; use wayland_client::protocol::{wl_compositor, wl_shell, wl_shm, wl_surface, wl_seat, wl_buffer, wl_output}; -use wl_surface::WlSurface; use wl_output::WlOutput; use wl_shell::WlShell; use wl_seat::WlSeat; @@ -168,12 +167,19 @@ fn main() { // a roundtrip sync will dispatch all event declaring globals to the handler // This will make all the globals usable. event_queue.sync_roundtrip().expect("Could not sync roundtrip"); - let output = get_wayland!(env_id, ®istry, &mut event_queue, WlOutput, "wl_output"); + let desktop_shell = match get_wayland!(env_id, ®istry, &mut event_queue, DesktopShell, "desktop_shell") { + Some(shell) => shell, + None => { + eprintln!("Please make sure you're running the correct version of Way Cooler"); + eprintln!("This program only supports versions >= 0.7"); + ::std::process::exit(1); + } + }; + let output = get_wayland!(env_id, ®istry, &mut event_queue, WlOutput, "wl_output").unwrap(); - let desktop_shell = get_wayland!(env_id, ®istry, &mut event_queue, DesktopShell, "desktop_shell"); - let shell = get_wayland!(env_id, ®istry, &mut event_queue, WlShell, "wl_shell"); - let compositor = get_wayland!(env_id, ®istry, &mut event_queue, WlCompositor, "wl_compositor"); - let seat = get_wayland!(env_id, ®istry, &mut event_queue, WlSeat, "wl_seat"); + let shell = get_wayland!(env_id, ®istry, &mut event_queue, WlShell, "wl_shell").unwrap(); + let compositor = get_wayland!(env_id, ®istry, &mut event_queue, WlCompositor, "wl_compositor").unwrap(); + let seat = get_wayland!(env_id, ®istry, &mut event_queue, WlSeat, "wl_seat").unwrap(); let mut background_surface = compositor.create_surface(); desktop_shell.set_background(&output, &background_surface); event_queue.dispatch() From 78a7368986330d9b39912a51785270b748b50f33 Mon Sep 17 00:00:00 2001 From: Timidger Date: Fri, 6 Oct 2017 22:49:56 -0700 Subject: [PATCH 05/13] Removed d-bus dependency yay! --- Cargo.lock | 49 ------------------- Cargo.toml | 1 - src/main.rs | 122 +++++++++------------------------------------- src/resolution.rs | 33 +++++++++++++ 4 files changed, 56 insertions(+), 149 deletions(-) create mode 100644 src/resolution.rs diff --git a/Cargo.lock b/Cargo.lock index 581cfde..272c0a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,6 @@ version = "0.2.1" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)", - "dbus 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-client 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -82,15 +81,6 @@ name = "color_quant" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "dbus" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", - "libdbus-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "dlib" version = "0.3.1" @@ -117,11 +107,6 @@ dependencies = [ "num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "error-chain" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "flate2" version = "0.2.20" @@ -221,14 +206,6 @@ name = "libc" version = "0.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "libdbus-sys" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "metadeps 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "libloading" version = "0.3.4" @@ -245,16 +222,6 @@ name = "lzw" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "metadeps" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "miniz-sys" version = "0.1.10" @@ -350,11 +317,6 @@ dependencies = [ "siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "pkg-config" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "png" version = "0.5.2" @@ -501,11 +463,6 @@ dependencies = [ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "toml" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "unicode-width" version = "0.1.4" @@ -573,12 +530,10 @@ dependencies = [ "checksum clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3451e409013178663435d6f15fdb212f14ee4424a3d74f979d081d0a66b6f1f2" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" "checksum color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a475fc4af42d83d28adf72968d9bcfaf035a1a9381642d8e85d8a04957767b0d" -"checksum dbus 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "acd824d45fad5ff0e178fcb3c040f13780e73f63a0a6d5cde59e7894f251ab0e" "checksum dlib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "148bce4ce1c36c4509f29cb54e62c2bd265551a9b00b38070fad551a851866ec" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" "checksum either 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbee135e9245416869bf52bd6ccc9b59e2482651510784e089b874272f02a252" "checksum enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180" -"checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8" "checksum flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "e6234dd4468ae5d1e2dbb06fe2b058696fdc50a339c68a393aefbf00bc81e423" "checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" "checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" @@ -592,10 +547,8 @@ dependencies = [ "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5" "checksum libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)" = "56cce3130fd040c28df6f495c8492e5ec5808fb4c9093c310df02b0c8f030148" -"checksum libdbus-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e764c95d2e469b780a35e0a7684857369912d99aa35eeb927f204eb63e6e5b6a" "checksum libloading 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0a020ac941774eb37e9d13d418c37b522e76899bfc4e7b1a600d529a53f83a66" "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" -"checksum metadeps 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b122901b3a675fac8cecf68dcb2f0d3036193bc861d1ac0e1c337f7d5254c2" "checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" "checksum num-bigint 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "8fd0f8dbb4c0960998958a796281d88c16fbe68d87b1baa6f31e2979e81fd0bd" "checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba" @@ -607,7 +560,6 @@ dependencies = [ "checksum phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d62594c0bb54c464f633175d502038177e90309daf2e0158be42ed5f023ce88f" "checksum phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6b07ffcc532ccc85e3afc45865469bf5d9e4ef5bfcf9622e3cfe80c2d275ec03" "checksum phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "07e24b0ca9643bdecd0632f2b3da6b1b89bbb0030e0b992afc1113b23a7bc2f2" -"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum png 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "06208e2ee243e3118a55dda9318f821f206d8563fb8d4df258767f8e62bb0997" "checksum rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "61efcbcd9fa8d8fbb07c84e34a8af18a1ff177b449689ad38a6e9457ecc7b2ae" "checksum rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b614fe08b6665cb9a231d07ac1364b0ef3cb3698f1239ee0c4c3a88a524f54c8" @@ -626,7 +578,6 @@ dependencies = [ "checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8e08afc40ae3459e4838f303e465aa50d823df8d7f83ca88108f6d3afe7edd" -"checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum wayland-client 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "9b10f2880f3dedaa496609a0aa7117bc6824490a48309dfbbf26258e5acc5a9d" diff --git a/Cargo.toml b/Cargo.toml index 818ffd9..f964061 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ wayland-client = { version = "^0.9.0", features = ["cursor", "dlopen"] } tempfile = "2.1" byteorder = ">= 0.3, < 0.6" image = "^0.10.3" -dbus = "0.5.2" clap = "2.23.2" [build-dependencies] diff --git a/src/main.rs b/src/main.rs index 014c228..25f8d94 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,11 +5,12 @@ extern crate tempfile; extern crate byteorder; extern crate image; -extern crate dbus; extern crate clap; #[macro_use] mod macros; mod color; +mod resolution; +use resolution::Resolution; use color::Color; use std::mem::transmute; @@ -32,7 +33,6 @@ use wl_shm::Format as WlShmFormat; use byteorder::{NativeEndian, WriteBytesExt}; use clap::{Arg, App}; use image::{GenericImage, DynamicImage, Pixel, FilterType, load_from_memory, open}; -use dbus::{Connection, Message, MessageItem, BusType}; wayland_env!(WaylandEnv, compositor: wl_compositor::WlCompositor, @@ -69,9 +69,6 @@ use generated::client::desktop_shell::DesktopShell; const CURSOR: &'static [u8; 656] = include_bytes!("../assets/arrow.png"); -// DBus wait time -const DBUS_WAIT_TIME: i32 = 2000; - type BufferResult = Result; pub enum BackgroundMode { @@ -177,6 +174,16 @@ fn main() { }; let output = get_wayland!(env_id, ®istry, &mut event_queue, WlOutput, "wl_output").unwrap(); + // Set up `Resolution`, which ensures the background is the same + // size as the output, even if it resizes. + let mut resolution = Resolution::new(); + let resolution_id = event_queue.add_handler(resolution); + event_queue.register::<_, Resolution>(&output, resolution_id); + // Dispatch so that the resolution is properly set in the handler. + event_queue.dispatch().expect("Could not dispatch resolution"); + + resolution = { *event_queue.state().get_handler(resolution_id) }; + let shell = get_wayland!(env_id, ®istry, &mut event_queue, WlShell, "wl_shell").unwrap(); let compositor = get_wayland!(env_id, ®istry, &mut event_queue, WlCompositor, "wl_compositor").unwrap(); let seat = get_wayland!(env_id, ®istry, &mut event_queue, WlSeat, "wl_seat").unwrap(); @@ -190,12 +197,11 @@ fn main() { let _background_buffer = if image.is_empty() { shell_surface.set_title(format!("Background Color: {}", color.to_u32())); - generate_solid_background(color, &mut event_queue, &mut background_surface, env_id) + generate_solid_background(color, resolution, &mut event_queue, &mut background_surface, env_id) } else { - // TODO Actually give it the path or something idk shell_surface.set_title(format!("Background Image: {}", image)); - generate_image_background(image.as_ref(), &mut event_queue, mode, color, &mut background_surface, env_id) + generate_image_background(image.as_ref(), resolution, &mut event_queue, mode, color, &mut background_surface, env_id) }.expect("could not generate image"); background_surface.commit(); @@ -217,51 +223,10 @@ fn rgba_conversion(num: u8, third_num: u32) -> u8 { ((big_num * third_num) / 255) as u8 } -fn get_screen_resolution(con: Connection) -> (i32, i32) { - let screens_msg = Message::new_method_call("org.way-cooler", - "/org/way_cooler/Screen", - "org.way_cooler.Screen", - "List") - .expect("Could not construct message -- is Way Cooler running?"); - let screen_r = con.send_with_reply_and_block(screens_msg, DBUS_WAIT_TIME) - .expect("Could not talk to Way Cooler -- is Way Cooler running?"); - let screen_r = &screen_r.get_items()[0]; - let output_id = match screen_r { - &MessageItem::Array(ref items, _) => { - match items[1] { - MessageItem::Str(ref string) => string.clone(), - _ => panic!("Array didn't contain output id") - } - } - _ => panic!("Wrong type from Screen") - }; - let res_msg = Message::new_method_call("org.way-cooler", - "/org/way_cooler/Screen", - "org.way_cooler.Screen", - "Resolution") - .expect("Could not construct message -- is Way Cooler running?") - .append(MessageItem::Str(output_id)); - let reply: MessageItem = con.send_with_reply_and_block(res_msg, DBUS_WAIT_TIME) - .expect("Could not talk to Way Cooler -- is Way Cooler running?") - .get1() - .expect("Way Cooler returned an unexpected value"); - match reply { - MessageItem::Struct(items) => { - let (width, height) = ( - (&items[0]).inner::() - .expect("Way Cooler returned an unexpected value"), - (&items[1]).inner::() - .expect("Way Cooler returned an unexpected value") - ); - (width as i32, height as i32) - }, - _ => panic!("Could not get resolution of screen") - } -} - /// Given a solid color, writes bytes associated with that color to /// a special Wayland surface which is then rendered as a background for Way Cooler. fn generate_solid_background(color: Color, + resolution: Resolution, event_queue: &mut wayland_client::EventQueue, background_surface: &mut wl_surface::WlSurface, env_id: usize) -> BufferResult { @@ -274,9 +239,7 @@ fn generate_solid_background(color: Color, let mut tmp = tempfile::tempfile().ok().expect("Unable to create a tempfile."); // Calculate how big the buffer needs to be from the output resolution - let dbus_con = Connection::get_private(BusType::Session).unwrap(); - let (width, height) = get_screen_resolution(dbus_con); - let size = (width * height) as i32; + let size = (resolution.w * resolution.h) as i32; // Write in the color coding to the surface for _ in 0..size { @@ -290,7 +253,11 @@ fn generate_solid_background(color: Color, // Create the buffer that is mem-mapped to the temp file descriptor let pool = shm.create_pool(tmp.as_raw_fd(), size); - let background_buffer = pool.create_buffer(0, width, height, width, WlShmFormat::Argb8888) + let background_buffer = pool.create_buffer(0, + resolution.w as i32, + resolution.h as i32, + resolution.w as i32, + WlShmFormat::Argb8888) .expect("Could not create buffer"); // Tell Way Cooler not to set put this in the tree, treat as background @@ -317,6 +284,7 @@ fn fill_image_base_color(image: DynamicImage, color: Color) -> DynamicImage { /// Given the data from an image, writes it to a special Wayland surface /// which is then rendered as a background for Way Cooler. fn generate_image_background(path: &str, + resolution: Resolution, event_queue: &mut wayland_client::EventQueue, mode: BackgroundMode, color: Color, @@ -330,12 +298,7 @@ fn generate_image_background(path: &str, println!("Could not open image file \"{:?}\"", path); ::std::process::exit(1); }); - /*let image = load_from_memory(CURSOR) - .expect("Could not read cursor data, report to maintainer!");*/ - let dbus_con = Connection::get_private(BusType::Session).unwrap(); - let resolution = get_screen_resolution(dbus_con); - let (scr_width, scr_height) = (resolution.0 as u32, resolution.1 as u32); - println!("WIDTH: {}, HEIGHT: {}", scr_width, scr_height); + let (scr_width, scr_height) = (resolution.w as u32, resolution.h as u32); let img_width = image.width(); let img_height = image.height(); @@ -495,45 +458,6 @@ fn cursor_surface(cursor_surface: &mut wl_surface::WlSurface, Ok(cursor_buffer) } -/* -/// Main loop for rendering backgrounds. -/// Need to keep the surface alive, and update it if the -/// user wants to change the background. -#[allow(unused_variables)] -fn main_background_loop(background_surface: WlSurface, cursor_surface: WlSurface, mut event_iter: EventIterator, env: &WaylandEnv) { - use wayland_client::wayland::WaylandProtocolEvent; - use wayland_client::Event; - let seat = env.seat.as_ref().map(|o| &o.0).unwrap(); - let mut pointer = seat.get_pointer(); - - pointer.set_event_iterator(&event_iter); - pointer.set_cursor(0, Some(&cursor_surface), 0, 0); - background_surface.commit(); - event_iter.sync_roundtrip().unwrap(); - loop { - for event in &mut event_iter { - match event { - Event::Wayland(wayland_event) => { - match wayland_event { - WaylandProtocolEvent::WlPointer(id, pointer_event) => { - match pointer_event { - WlPointerEvent::Enter(serial, background_surface, surface_x, surface_y) => { - pointer.set_cursor(0, Some(&cursor_surface), 0, 0); - }, - _ => { - } - } - }, - _ => {/* unhandled events */} - } - } - _ => { /* unhandled events */ } - } - } - event_iter.dispatch().expect("Connection with the compositor was lost."); - } -} - */ #[test] fn test_rgba_conversion() { diff --git a/src/resolution.rs b/src/resolution.rs new file mode 100644 index 0000000..4d08153 --- /dev/null +++ b/src/resolution.rs @@ -0,0 +1,33 @@ +use wayland_client::EventQueueHandle; +use wayland_client::protocol::wl_output; + +/// Used to know how big to make the surface. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct Resolution { + pub w: u32, + pub h: u32 +} + +impl Resolution { + pub fn new() -> Self { + Resolution { + w: 0, + h: 0 + } + } +} + +impl wl_output::Handler for Resolution { + fn mode(&mut self, + _evqh: &mut EventQueueHandle, + _proxy: &wl_output::WlOutput, + _flags: wl_output::Mode, + width: i32, + height: i32, + _refresh: i32) { + self.w = width as u32; + self.h = height as u32; + } +} + +declare_handler!(Resolution, wl_output::Handler, wl_output::WlOutput); From be8c62ed59e6f5f494decba0f949b690215a464c Mon Sep 17 00:00:00 2001 From: Timidger Date: Fri, 6 Oct 2017 23:34:26 -0700 Subject: [PATCH 06/13] Set the background for all of the screens --- src/macros.rs | 27 +++++++++++++++++- src/main.rs | 79 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 8da9649..78869d8 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,4 +1,3 @@ - #[macro_export] macro_rules! get_wayland { ($env_id: tt, $registry: expr, $event_queue: expr, $type: ty, $name: tt) => {{ @@ -23,3 +22,29 @@ macro_rules! get_wayland { } }} } + +#[macro_export] +macro_rules! get_all_wayland { + ($env_id: tt, $registry: expr, $event_queue: expr, $type: ty, $name: tt) => {{ + let state = $event_queue.state(); + let env = state.get_handler::>($env_id); + let mut value = None; + for &(name, ref interface, version) in env.globals() { + if interface == $name { + let mut list = value.take().unwrap_or_else(Vec::new); + list.push($registry.bind::<$type>(version, name)); + value = Some(list); + } + } + match value { + None => { + for &(name, ref interface, version) in env.globals() { + eprintln!("{:4} : {} (version {})", name, interface, version); + } + eprintln!(concat!("Could not find the ", $name, " protocol!")); + None + }, + v => v + } + }} +} diff --git a/src/main.rs b/src/main.rs index 25f8d94..58b5dcf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,9 +20,10 @@ use std::str::FromStr; use std::cmp::{min, max}; use wayland_client::EnvHandler; -use wayland_client::protocol::{wl_compositor, wl_shell, wl_shm, wl_surface, - wl_seat, wl_buffer, +use wayland_client::protocol::{wl_compositor, wl_shell, wl_shell_surface, + wl_shm, wl_surface, wl_seat, wl_buffer, wl_output}; +use wl_shell_surface::FullscreenMethod; use wl_output::WlOutput; use wl_shell::WlShell; use wl_seat::WlSeat; @@ -71,6 +72,7 @@ const CURSOR: &'static [u8; 656] = include_bytes!("../assets/arrow.png"); type BufferResult = Result; +#[derive(Debug, Clone, Copy)] pub enum BackgroundMode { /// Scale image to make the shortest dimension (i.e. height or width) /// fit it's container pertaining aspect ratio. @@ -172,42 +174,53 @@ fn main() { ::std::process::exit(1); } }; - let output = get_wayland!(env_id, ®istry, &mut event_queue, WlOutput, "wl_output").unwrap(); + let outputs = get_all_wayland!(env_id, ®istry, &mut event_queue, WlOutput, "wl_output").unwrap(); - // Set up `Resolution`, which ensures the background is the same - // size as the output, even if it resizes. - let mut resolution = Resolution::new(); - let resolution_id = event_queue.add_handler(resolution); - event_queue.register::<_, Resolution>(&output, resolution_id); - // Dispatch so that the resolution is properly set in the handler. - event_queue.dispatch().expect("Could not dispatch resolution"); - - resolution = { *event_queue.state().get_handler(resolution_id) }; - - let shell = get_wayland!(env_id, ®istry, &mut event_queue, WlShell, "wl_shell").unwrap(); - let compositor = get_wayland!(env_id, ®istry, &mut event_queue, WlCompositor, "wl_compositor").unwrap(); let seat = get_wayland!(env_id, ®istry, &mut event_queue, WlSeat, "wl_seat").unwrap(); - let mut background_surface = compositor.create_surface(); - desktop_shell.set_background(&output, &background_surface); - event_queue.dispatch() - .expect("Could not dispatch queue"); let pointer = seat.get_pointer().expect("Could not get pointer from seat global"); - let shell_surface = shell.get_shell_surface(&background_surface); - shell_surface.set_class("Background".into()); - let _background_buffer = if image.is_empty() { - shell_surface.set_title(format!("Background Color: {}", color.to_u32())); - - generate_solid_background(color, resolution, &mut event_queue, &mut background_surface, env_id) - } else { - shell_surface.set_title(format!("Background Image: {}", image)); - - generate_image_background(image.as_ref(), resolution, &mut event_queue, mode, color, &mut background_surface, env_id) - }.expect("could not generate image"); - - background_surface.commit(); - background_surface.set_buffer_scale(1); + let shell = get_wayland!(env_id, ®istry, &mut event_queue, WlShell, "wl_shell").unwrap(); + let compositor = get_wayland!(env_id, ®istry, &mut event_queue, WlCompositor, "wl_compositor").unwrap(); let mut cursor_surface = compositor.create_surface(); let _cursor_buffer = self::cursor_surface(&mut cursor_surface, &mut event_queue, env_id); + let resolutions: Vec = outputs.iter() + .map(|output| { + let res = Resolution::new(); + let resolution_id = event_queue.add_handler(res); + event_queue.register::<_, Resolution>(&output, resolution_id); + resolution_id + }).collect(); + for (output, resolution_id) in outputs.into_iter().zip(resolutions) { + + let mut background_surface = compositor.create_surface(); + desktop_shell.set_background(&output, &background_surface); + event_queue.dispatch() + .expect("Could not dispatch queue"); + + let resolution: Resolution = { *event_queue.state().get_handler(resolution_id) }; + assert!(resolution.w * resolution.h != 0); + let shell_surface = shell.get_shell_surface(&background_surface); + shell_surface.set_class("Background".into()); + shell_surface.set_fullscreen(FullscreenMethod::Default, 0, Some(&output)); + shell_surface.set_maximized(Some(&output)); + let _background_buffer = if image.is_empty() { + shell_surface.set_title(format!("Background Color: {}", color.to_u32())); + + generate_solid_background(color, resolution, &mut event_queue, &mut background_surface, env_id) + } else { + shell_surface.set_title(format!("Background Image: {}", image)); + + generate_image_background(image.as_ref(), + resolution, + &mut event_queue, + mode, + color, + &mut background_surface, + env_id) + }.expect("could not generate image"); + + background_surface.commit(); + background_surface.set_buffer_scale(1); + } loop { display.flush() .expect("Could not flush display"); From c7b6598df29ff52fe836428548c60f010caf643c Mon Sep 17 00:00:00 2001 From: Timidger Date: Fri, 6 Oct 2017 23:53:25 -0700 Subject: [PATCH 07/13] Only set resolution on current mode setting This means the background will always be the highest resolution --- src/resolution.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/resolution.rs b/src/resolution.rs index 4d08153..323487d 100644 --- a/src/resolution.rs +++ b/src/resolution.rs @@ -1,6 +1,10 @@ use wayland_client::EventQueueHandle; use wayland_client::protocol::wl_output; +/// The current mode that the monitor is set to. +/// That is the resolution we should use +const CURRENT_MODE: u32 = 0x1; + /// Used to know how big to make the surface. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct Resolution { @@ -21,12 +25,14 @@ impl wl_output::Handler for Resolution { fn mode(&mut self, _evqh: &mut EventQueueHandle, _proxy: &wl_output::WlOutput, - _flags: wl_output::Mode, + flags: wl_output::Mode, width: i32, height: i32, _refresh: i32) { - self.w = width as u32; - self.h = height as u32; + if flags.to_raw() & CURRENT_MODE != 0 { + self.w = width as u32; + self.h = height as u32; + } } } From 9984ce63a7688e5b21504ba44c52b5000f511762 Mon Sep 17 00:00:00 2001 From: Timidger Date: Sat, 7 Oct 2017 00:30:47 -0700 Subject: [PATCH 08/13] Added default background if no option specified --- assets/official-background.png | Bin 0 -> 29774 bytes src/main.rs | 88 ++++++++++++++++----------------- 2 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 assets/official-background.png diff --git a/assets/official-background.png b/assets/official-background.png new file mode 100644 index 0000000000000000000000000000000000000000..4cb60a9d831ff45869525ee7d92235bb96e491ea GIT binary patch literal 29774 zcmdsgc_5T)`~S4+w5d~3)=rW{BwLoD4Mjy{UrQ)^b_S!ce^tp)E8a(6o*5SAn7&z`zs*EHBFQpwt=Sn@fwGCMnXAF7yX=l*{^ zLOj^J^Teq~`zmQV|A-;cN>*5&E`c%JgCHm29 zivyn!68XPLhd*ctf`3(H z{NIaEfw&r$MM0ki!(d6j@z2G)y1(o@lBRJK;Px)mvvK*vXl(OQB*?rYC!D8z+KGMb z^Oqe!#X7wmqEkAWPWzy|<5F_Xdkvx>7V`1)xX2#`ts z@01Nms;w0A-ocfX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}dt|6_wMJ-Pwb+Rz4j3e*24`S2Zhe+LKLJHDadmDf#4 z`(Tj2Jj9I+=OF7AOxm67dv+-p5Bw5ce*?O|6EWcCTYBaIIP=tB(lvCu$t&)VgmO_RcV^b zi!9Z5X vtQ5@jt!%Ga=pjyBH@l{{|Gddn13h`YtJm#smFkH?bDfvCbQW`3=g() { - Ok(c) => c.into(), - Err(_) => { - let c = u32::from_str_radix(color, 16).unwrap(); - c.into() - } + let default_color = u32::from_str_radix("333333", 16).unwrap().into(); + let (color, mut image) = match (matches.value_of("color"), matches.value_of("image")) { + (None, None) => (default_color, Some(("".into(), BackgroundMode::Fill))), + (_, Some(image)) => { + let mode = matches.value_of("mode") + .map(|mode| mode.parse::().expect("Invalid background mode")) + .unwrap_or(BackgroundMode::Fill); + (default_color, Some((image.to_string(), mode))) + }, + (Some(color), None) => { + let color: Color = color.parse::() + .map(|c| c.into()) + .unwrap_or_else(|_| { + let c = u32::from_str_radix(color, 16).expect("Could not parse color"); + c.into() + }); + (color, None) } - } else { - let color = u32::from_str_radix("333333", 16).unwrap(); - color.into() - }; - - let (image, mode) = if let Some(image) = matches.value_of("image") { - let mode = if let Some(mode) = matches.value_of("mode") { - mode.parse::() - .expect("Invalid background mode") - } else { - BackgroundMode::Fill - }; - - (image.to_string(), mode) - } else { - ("".to_string(), BackgroundMode::Fill) }; let (display, mut event_queue) = wayland_client::default_connect() @@ -202,20 +193,27 @@ fn main() { shell_surface.set_class("Background".into()); shell_surface.set_fullscreen(FullscreenMethod::Default, 0, Some(&output)); shell_surface.set_maximized(Some(&output)); - let _background_buffer = if image.is_empty() { - shell_surface.set_title(format!("Background Color: {}", color.to_u32())); - - generate_solid_background(color, resolution, &mut event_queue, &mut background_surface, env_id) - } else { - shell_surface.set_title(format!("Background Image: {}", image)); - - generate_image_background(image.as_ref(), - resolution, - &mut event_queue, - mode, - color, - &mut background_surface, - env_id) + match image { + None => { + shell_surface.set_title(format!("Background Color: {}", color.to_u32())); + + generate_solid_background(color, resolution, &mut event_queue, &mut background_surface, env_id) + }, + Some((ref mut image, mode)) => { + if image.is_empty() { + shell_surface.set_title("Official background".into()); + } else { + shell_surface.set_title(format!("Background Image: {}", image)); + } + + generate_image_background(image.as_ref(), + resolution, + &mut event_queue, + mode, + color, + &mut background_surface, + env_id) + } }.expect("could not generate image"); background_surface.commit(); @@ -308,8 +306,10 @@ fn generate_image_background(path: &str, let env = state.get_handler::>(env_id); let image = open(path) .unwrap_or_else(|_| { - println!("Could not open image file \"{:?}\"", path); - ::std::process::exit(1); + load_from_memory(include_bytes!("../assets/official-background.png")) + .expect("Could not read in official background image") + //println!("Could not open image file \"{:?}\"", path); + //::std::process::exit(1); }); let (scr_width, scr_height) = (resolution.w as u32, resolution.h as u32); From 5387a6d2091398d47a10b07378b5af9e4f9a9396 Mon Sep 17 00:00:00 2001 From: Timidger Date: Sat, 7 Oct 2017 00:37:22 -0700 Subject: [PATCH 09/13] Made both bg pop in at same time, looks better --- src/main.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index eae3053..baabccb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,13 +180,14 @@ fn main() { event_queue.register::<_, Resolution>(&output, resolution_id); resolution_id }).collect(); - for (output, resolution_id) in outputs.into_iter().zip(resolutions) { - - let mut background_surface = compositor.create_surface(); - desktop_shell.set_background(&output, &background_surface); - event_queue.dispatch() - .expect("Could not dispatch queue"); - + let mut bg_metadata = outputs.iter().zip(resolutions).map(|(output, res_id)| { + let background_surface = compositor.create_surface(); + desktop_shell.set_background(output, &background_surface); + (output, res_id, background_surface) + }); + event_queue.dispatch() + .expect("Could not dispatch queue"); + for (output, resolution_id, mut background_surface) in &mut bg_metadata { let resolution: Resolution = { *event_queue.state().get_handler(resolution_id) }; assert!(resolution.w * resolution.h != 0); let shell_surface = shell.get_shell_surface(&background_surface); @@ -308,8 +309,6 @@ fn generate_image_background(path: &str, .unwrap_or_else(|_| { load_from_memory(include_bytes!("../assets/official-background.png")) .expect("Could not read in official background image") - //println!("Could not open image file \"{:?}\"", path); - //::std::process::exit(1); }); let (scr_width, scr_height) = (resolution.w as u32, resolution.h as u32); From f7e50558865c49de99ab6e6c64e762904b073a08 Mon Sep 17 00:00:00 2001 From: Timidger Date: Sat, 7 Oct 2017 00:42:47 -0700 Subject: [PATCH 10/13] Slightly improvements --- src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index baabccb..68545e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -414,16 +414,19 @@ fn generate_image_background(path: &str, } } - let vec = image_rgba.into_vec(); let mut tmp = tempfile::NamedTempFile::new().expect("Unable to create a tempfile."); tmp.set_len(img_size as u64).expect("Could not truncate length of file"); - tmp.write_all(&*vec).unwrap(); + tmp.write_all(&image_rgba).unwrap(); let shm = &env.shm; // Create the surface we are going to write into let pool = shm.create_pool(tmp.as_raw_fd(), img_size as i32); - let background_buffer = pool.create_buffer(0, scr_width as i32, scr_height as i32, img_stride as i32, WlShmFormat::Argb8888) + let background_buffer = pool.create_buffer(0, + scr_width as i32, + scr_height as i32, + img_stride as i32, + WlShmFormat::Argb8888) .expect("Could not create buffer"); // Attach the buffer to the surface From a5633496784d0ce48bc75fbfbc35d5a75141fc7e Mon Sep 17 00:00:00 2001 From: Timidger Date: Sat, 7 Oct 2017 23:22:55 -0700 Subject: [PATCH 11/13] Added helper library --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/color.rs | 50 ----------------------------------------------- src/macros.rs | 50 ----------------------------------------------- src/main.rs | 8 +++----- src/resolution.rs | 39 ------------------------------------ 6 files changed, 15 insertions(+), 144 deletions(-) delete mode 100644 src/color.rs delete mode 100644 src/macros.rs delete mode 100644 src/resolution.rs diff --git a/Cargo.lock b/Cargo.lock index 272c0a7..e35c12d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,6 +6,7 @@ dependencies = [ "clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "way-cooler-client-helpers 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-client 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -473,6 +474,15 @@ name = "vec_map" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "way-cooler-client-helpers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "wayland-client 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "wayland-client" version = "0.9.10" @@ -580,6 +590,7 @@ dependencies = [ "checksum textwrap 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8e08afc40ae3459e4838f303e465aa50d823df8d7f83ca88108f6d3afe7edd" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" +"checksum way-cooler-client-helpers 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f730f452618282eb633541b9b47847d7fab6347e04198feda5aeda9f598bc19d" "checksum wayland-client 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "9b10f2880f3dedaa496609a0aa7117bc6824490a48309dfbbf26258e5acc5a9d" "checksum wayland-scanner 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6820262132b76ee4aa7893312fb9a24ce5434934a2b421669a30869fcd4a2769" "checksum wayland-sys 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "b433ca9dbd9289a8ae8a5c49148d2a0e724b89432d7648727ca553027c247c47" diff --git a/Cargo.toml b/Cargo.toml index f964061..551fc69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ license = "MIT" build = "build.rs" [dependencies] +way-cooler-client-helpers = { version = "0.1" } wayland-sys = { version = "^0.9.0", features = ["client", "dlopen"] } wayland-client = { version = "^0.9.0", features = ["cursor", "dlopen"] } tempfile = "2.1" diff --git a/src/color.rs b/src/color.rs deleted file mode 100644 index 6c63dc7..0000000 --- a/src/color.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! Colors used for drawing to the screen -//! TODO This needs to be in a helper library - -use std::convert::From; - -/// Color to draw to the screen, including the alpha channel. -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] -pub struct Color { - red: u8, - green: u8, - blue: u8, - alpha: u8 -} - - -impl Color { - /// Makes a new solid color, with no transparency. - pub fn solid_color(red: u8, green: u8, blue: u8) -> Self { - Color { - red, - green, - blue, - alpha: 255 - } - } - - /// Gets the values of the colors, in this order: - /// (Red, Green, Blue, Alpha) - #[allow(dead_code)] - pub fn to_u8s(self) -> (u8, u8, u8, u8) { - (self.red, self.green, self.blue, self.alpha) - } - - /// To a u32, represented as in RGBA format - pub fn to_u32(self) -> u32 { - let values = [self.red, self.green, self.blue, self.alpha]; - unsafe { - ::std::mem::transmute(values) - } - } -} - -impl From for Color { - fn from(val: u32) -> Self { - let blue = ((val & 0xff0000) >> 16) as u8; - let green = ((val & 0x00ff00) >> 8) as u8; - let red = (val & 0x0000ff) as u8; - Color::solid_color(red, green, blue) - } -} diff --git a/src/macros.rs b/src/macros.rs deleted file mode 100644 index 78869d8..0000000 --- a/src/macros.rs +++ /dev/null @@ -1,50 +0,0 @@ -#[macro_export] -macro_rules! get_wayland { - ($env_id: tt, $registry: expr, $event_queue: expr, $type: ty, $name: tt) => {{ - let state = $event_queue.state(); - let env = state.get_handler::>($env_id); - let mut value = None; - for &(name, ref interface, version) in env.globals() { - if interface == $name { - value = Some($registry.bind::<$type>(version, name)); - break; - } - } - match value { - None => { - for &(name, ref interface, version) in env.globals() { - eprintln!("{:4} : {} (version {})", name, interface, version); - } - eprintln!(concat!("Could not find the ", $name, " protocol!")); - None - }, - v => v - } - }} -} - -#[macro_export] -macro_rules! get_all_wayland { - ($env_id: tt, $registry: expr, $event_queue: expr, $type: ty, $name: tt) => {{ - let state = $event_queue.state(); - let env = state.get_handler::>($env_id); - let mut value = None; - for &(name, ref interface, version) in env.globals() { - if interface == $name { - let mut list = value.take().unwrap_or_else(Vec::new); - list.push($registry.bind::<$type>(version, name)); - value = Some(list); - } - } - match value { - None => { - for &(name, ref interface, version) in env.globals() { - eprintln!("{:4} : {} (version {})", name, interface, version); - } - eprintln!(concat!("Could not find the ", $name, " protocol!")); - None - }, - v => v - } - }} -} diff --git a/src/main.rs b/src/main.rs index 68545e0..add737a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,10 @@ extern crate tempfile; extern crate byteorder; extern crate image; extern crate clap; -#[macro_use] mod macros; +#[macro_use] extern crate way_cooler_client_helpers; -mod color; -mod resolution; -use resolution::Resolution; -use color::Color; +use way_cooler_client_helpers::color::Color; +use way_cooler_client_helpers::wayland::Resolution; use std::mem::transmute; use std::os::unix::io::AsRawFd; diff --git a/src/resolution.rs b/src/resolution.rs deleted file mode 100644 index 323487d..0000000 --- a/src/resolution.rs +++ /dev/null @@ -1,39 +0,0 @@ -use wayland_client::EventQueueHandle; -use wayland_client::protocol::wl_output; - -/// The current mode that the monitor is set to. -/// That is the resolution we should use -const CURRENT_MODE: u32 = 0x1; - -/// Used to know how big to make the surface. -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub struct Resolution { - pub w: u32, - pub h: u32 -} - -impl Resolution { - pub fn new() -> Self { - Resolution { - w: 0, - h: 0 - } - } -} - -impl wl_output::Handler for Resolution { - fn mode(&mut self, - _evqh: &mut EventQueueHandle, - _proxy: &wl_output::WlOutput, - flags: wl_output::Mode, - width: i32, - height: i32, - _refresh: i32) { - if flags.to_raw() & CURRENT_MODE != 0 { - self.w = width as u32; - self.h = height as u32; - } - } -} - -declare_handler!(Resolution, wl_output::Handler, wl_output::WlOutput); From d12ab7f8268088419106b400ef923cb950b72ed3 Mon Sep 17 00:00:00 2001 From: Timidger Date: Sun, 8 Oct 2017 18:29:08 -0700 Subject: [PATCH 12/13] Changed way-cooler-bg name to wc-bg, v0.3.0 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 551fc69..48b4d87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "way-cooler-bg" -version = "0.2.1" +name = "wc-bg" +version = "0.3.0" authors = ["Timidger "] description = "Background program for Way Cooler" repository = "https://github.com/way-cooler/way-cooler-bg" From 7e44eba763289d9dc7d6ce194fec8ac73a39b7c4 Mon Sep 17 00:00:00 2001 From: Timidger Date: Sat, 14 Oct 2017 12:16:45 -0700 Subject: [PATCH 13/13] Updated cargo.lock --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e35c12d..45bc01c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] -name = "way-cooler-bg" -version = "0.2.1" +name = "wc-bg" +version = "0.3.0" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)",