-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[update] Remove dependency on smithay
* 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
1 parent
0eea055
commit e621b94
Showing
5 changed files
with
62 additions
and
197 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.