Skip to content

Commit

Permalink
[update] Remove dependency on smithay
Browse files Browse the repository at this point in the history
* Use wl_output v4 to get output data now.

* Depend on only wayland-rs to reduce build times.

* Add build time optimizations to cargo.toml

Signed-off-by: Shinyzenith <[email protected]>
  • Loading branch information
Shinyzenith committed Jun 16, 2022
1 parent 0eea055 commit e621b94
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 197 deletions.
127 changes: 2 additions & 125 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub fn set_flags() -> Command<'static> {
arg!(--toggle <OUTPUT>)
.required(false)
.takes_value(true)
.conflicts_with("state")
.help("Toggle output state."),
);
app
Expand Down
85 changes: 41 additions & 44 deletions src/output.rs
Original file line number Diff line number Diff line change
@@ -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<OutputInfo> {
// 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<RefCell<Vec<OutputInfo>>> = 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::<WlOutput>(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<OutputInfo>) -> &'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);
}
Loading

0 comments on commit e621b94

Please sign in to comment.