cosmic-comp/src/utils/prelude.rs

60 lines
1.5 KiB
Rust
Raw Normal View History

2022-08-31 13:01:23 +02:00
use crate::input::{ActiveOutput, SeatId};
2022-07-04 15:27:08 +02:00
use smithay::{
2022-08-31 13:01:23 +02:00
input::Seat,
output::Output,
2022-07-04 16:00:29 +02:00
utils::{Logical, Rectangle, Transform},
2022-07-04 15:27:08 +02:00
};
2022-08-31 13:01:23 +02:00
pub use crate::shell::{Shell, Workspace};
pub use crate::state::{Common, State};
2022-07-05 18:46:38 +02:00
pub use crate::wayland::handlers::xdg_shell::popup::update_reactive_popups;
2022-07-04 15:27:08 +02:00
pub trait OutputExt {
fn geometry(&self) -> Rectangle<i32, Logical>;
}
impl OutputExt for Output {
fn geometry(&self) -> Rectangle<i32, Logical> {
2022-07-04 16:00:29 +02:00
Rectangle::from_loc_and_size(self.current_location(), {
Transform::from(self.current_transform())
.transform_size(
self.current_mode()
.map(|m| m.size)
.unwrap_or_else(|| (0, 0).into()),
)
.to_f64()
.to_logical(self.current_scale().fractional_scale())
.to_i32_round()
})
2022-07-04 15:27:08 +02:00
}
}
2022-07-08 14:00:13 +02:00
pub trait SeatExt {
fn id(&self) -> usize;
2022-09-28 12:01:29 +02:00
fn active_output(&self) -> Output;
fn set_active_output(&self, output: &Output);
2022-07-08 14:00:13 +02:00
}
impl SeatExt for Seat<State> {
fn id(&self) -> usize {
self.user_data().get::<SeatId>().unwrap().0
}
2022-09-28 12:01:29 +02:00
fn active_output(&self) -> Output {
self.user_data()
.get::<ActiveOutput>()
.map(|x| x.0.borrow().clone())
.unwrap()
}
2022-07-04 15:27:08 +02:00
2022-09-28 12:01:29 +02:00
fn set_active_output(&self, output: &Output) {
*self
2022-07-04 15:27:08 +02:00
.user_data()
.get::<ActiveOutput>()
.unwrap()
.0
.borrow_mut() = output.clone();
}
}