diff --git a/Cargo.lock b/Cargo.lock index 18db0a1..58184da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,16 +25,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "calloop" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf2eec61efe56aa1e813f5126959296933cf0700030e4314786c48779a66ab82" -dependencies = [ - "log", - "nix", -] - [[package]] name = "cc" version = "1.0.73" @@ -62,15 +52,6 @@ dependencies = [ "textwrap", ] -[[package]] -name = "dlib" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1b7517328c04c2aa68422fc60a41b92208182142ed04a25879c26c8f878794" -dependencies = [ - "libloading", -] - [[package]] name = "downcast-rs" version = "1.2.0" @@ -102,52 +83,18 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.118" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94" -[[package]] -name = "libloading" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" -dependencies = [ - "cfg-if", - "winapi", -] - -[[package]] -name = "log" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -dependencies = [ - "cfg-if", -] - [[package]] name = "memchr" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" -[[package]] -name = "memmap2" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b6c2ebff6180198788f5db08d7ce3bc1d0b617176678831a7510825973e357" -dependencies = [ - "libc", -] - [[package]] name = "memoffset" version = "0.6.5" @@ -157,12 +104,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "nix" version = "0.22.3" @@ -176,17 +117,6 @@ dependencies = [ "memoffset", ] -[[package]] -name = "nom" -version = "7.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" -dependencies = [ - "memchr", - "minimal-lexical", - "version_check", -] - [[package]] name = "once_cell" version = "1.9.0" @@ -226,37 +156,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - [[package]] name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" -[[package]] -name = "smithay-client-toolkit" -version = "0.15.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1325f292209cee78d5035530932422a30aa4c8fda1a16593ac083c1de211e68a" -dependencies = [ - "bitflags", - "calloop", - "dlib", - "lazy_static", - "log", - "memmap2", - "nix", - "pkg-config", - "wayland-client", - "wayland-cursor", - "wayland-protocols", -] - [[package]] name = "strsim" version = "0.10.0" @@ -284,12 +189,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wayland-client" version = "0.29.4" @@ -300,7 +199,6 @@ dependencies = [ "downcast-rs", "libc", "nix", - "scoped-tls", "wayland-commons", "wayland-scanner", "wayland-sys", @@ -318,17 +216,6 @@ dependencies = [ "wayland-sys", ] -[[package]] -name = "wayland-cursor" -version = "0.29.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52758f13d5e7861fc83d942d3d99bf270c83269575e52ac29e5b73cb956a6bd" -dependencies = [ - "nix", - "wayland-client", - "xcursor", -] - [[package]] name = "wayland-protocols" version = "0.29.4" @@ -358,8 +245,6 @@ version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9341df79a8975679188e37dab3889bfa57c44ac2cb6da166f519a81cbe452d4" dependencies = [ - "dlib", - "lazy_static", "pkg-config", ] @@ -368,7 +253,8 @@ name = "wayout" version = "1.0.0" dependencies = [ "clap", - "smithay-client-toolkit", + "wayland-client", + "wayland-protocols", ] [[package]] @@ -402,15 +288,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "xcursor" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" -dependencies = [ - "nom", -] - [[package]] name = "xml-rs" version = "0.8.4" diff --git a/Cargo.toml b/Cargo.toml index a10c657..16b1e70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,13 @@ version = "1.0.0" [dependencies] clap = "3.1.2" -smithay-client-toolkit = "0.15.3" +wayland-client = "0.29.4" +wayland-protocols = { version = "0.29.4", features=["unstable_protocols", "client"] } [[bin]] name = "wayout" path = "src/wayout.rs" + +[profile.release] +opt-level = 'z' # Optimize for size. +strip = true # Strip symbols from bina diff --git a/src/flags.rs b/src/flags.rs index 1dc847e..b89a669 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -21,7 +21,6 @@ pub fn set_flags() -> Command<'static> { arg!(--toggle ) .required(false) .takes_value(true) - .conflicts_with("state") .help("Toggle output state."), ); app diff --git a/src/output.rs b/src/output.rs index 0258d38..e97cf1b 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,54 +1,51 @@ -use smithay_client_toolkit::{ - environment, - environment::Environment, - output::{with_output_info, OutputHandler, OutputInfo, XdgOutputHandler}, - reexports::{ - client::{protocol::wl_output::WlOutput, Display}, - protocols::unstable::xdg_output::v1::client::zxdg_output_manager_v1::ZxdgOutputManagerV1, - }, -}; +use std::{cell::RefCell, process::exit, rc::Rc}; +use wayland_client::{protocol::wl_output, protocol::wl_output::WlOutput, Display, GlobalManager}; -struct Env { - outputs: OutputHandler, - xdg_output: XdgOutputHandler, +#[derive(Debug, Clone)] +pub struct OutputInfo { + pub wl_output: *mut WlOutput, + pub name: String, } -environment! {Env, - singles = [ - ZxdgOutputManagerV1 => xdg_output, - ], - multis = [ - WlOutput => outputs, - ] -} - -pub fn get_valid_outputs(display: Display) -> Vec<(WlOutput, OutputInfo)> { - let mut queue = display.create_event_queue(); - let attached_display = display.attach(queue.token()); - - let (outputs, xdg_output) = XdgOutputHandler::new_output_handlers(); - let mut valid_outputs: Vec<(WlOutput, OutputInfo)> = Vec::new(); +pub fn get_all_outputs(display: Display) -> Vec { + // Connecting to wayland environment. + let mut event_queue = display.create_event_queue(); + let attached_display = (*display).clone().attach(event_queue.token()); - let env = Environment::new( - &attached_display, - &mut queue, - Env { - outputs, - xdg_output, - }, - ) - .unwrap(); + let outputs: Rc>> = Rc::new(RefCell::new(Vec::new())); - queue.sync_roundtrip(&mut (), |_, _, _| {}).unwrap(); + // Instantiating the global manager. + let globals = GlobalManager::new(&attached_display); + event_queue.sync_roundtrip(&mut (), |_, _, _| {}).unwrap(); - for output in env.get_all_outputs() { - with_output_info(&output, |info| { - if !info.obsolete { - valid_outputs.push((output.clone(), info.clone())); - } else { - output.release(); + globals + .instantiate_exact::(4) + .expect("Failed to bind to wl_output global.") + .quick_assign({ + let outputs = outputs.clone(); + move |output, event, _| { + if let wl_output::Event::Name { name } = event { + outputs.borrow_mut().push(OutputInfo { + wl_output: &mut output.detach(), + name, + }); + } } }); + event_queue.sync_roundtrip(&mut (), |_, _, _| {}).unwrap(); + let x = outputs.borrow().to_vec(); + x +} + +/// Get a wl_output object from the output name. +pub fn get_wloutput(name: String, outputs: Vec) -> &'static WlOutput { + for output in outputs { + if output.name == name { + unsafe { + return &*output.wl_output; + } + } } - valid_outputs + println!("Error: No output of name \"{}\" was found", name); + exit(1); } diff --git a/src/wayout.rs b/src/wayout.rs index c2c9a33..da90db9 100644 --- a/src/wayout.rs +++ b/src/wayout.rs @@ -1,12 +1,7 @@ -use smithay_client_toolkit::{ - output::OutputInfo, - reexports::{ - client::{protocol::wl_output::WlOutput, Display, GlobalManager}, - protocols::wlr::unstable::output_power_management::v1::client::{ - zwlr_output_power_manager_v1::ZwlrOutputPowerManagerV1, zwlr_output_power_v1, - zwlr_output_power_v1::Mode, - }, - }, +use wayland_client::{protocol::wl_output::WlOutput, Display, GlobalManager}; +use wayland_protocols::wlr::unstable::output_power_management::v1::client::{ + zwlr_output_power_manager_v1::ZwlrOutputPowerManagerV1, zwlr_output_power_v1, + zwlr_output_power_v1::Mode, }; use std::{cell::RefCell, process::exit, rc::Rc}; @@ -68,11 +63,11 @@ pub fn set_head_state(output_name: String, mode: Mode) { let globals = GlobalManager::new(&attached_display); event_queue.sync_roundtrip(&mut (), |_, _, _| {}).unwrap(); - let valid_outputs = output::get_valid_outputs(display); + let valid_outputs = output::get_all_outputs(display); let output_power_manager = globals.instantiate_exact::(1); event_queue.sync_roundtrip(&mut (), |_, _, _| {}).unwrap(); - let output_choice = get_wloutput(output_name, valid_outputs); + let output_choice = output::get_wloutput(output_name, valid_outputs); output_power_manager .as_ref() .unwrap() @@ -88,17 +83,20 @@ pub fn get_head_states() -> Vec { event_queue .dispatch(&mut (), |_, _, _| unreachable!()) .unwrap(); - let valid_outputs = output::get_valid_outputs(display); + let valid_outputs = output::get_all_outputs(display); let output_power_manager = globals.instantiate_exact::(1); let head_states: Rc>> = Rc::new(RefCell::new(Vec::new())); for output in valid_outputs { - let (output, output_info) = output; - let output_name = output_info.name; + let output_name = output.name; + let output_ptr: &WlOutput; + unsafe { + output_ptr = &*output.wl_output as &WlOutput; + } output_power_manager .as_ref() .unwrap() - .get_output_power(&output) + .get_output_power(output_ptr) .quick_assign({ let head_states = head_states.clone(); let output_name = output_name.clone(); @@ -130,14 +128,3 @@ pub fn get_head_states() -> Vec { let head_states = head_states.borrow_mut().to_vec(); head_states } - -fn get_wloutput(name: String, valid_outputs: Vec<(WlOutput, OutputInfo)>) -> WlOutput { - for device in valid_outputs { - let (output_device, info) = device; - if info.name == name { - return output_device; - } - } - println!("Error: No output of name \"{}\" was found", name); - exit(1); -}