Struct layershellev::WindowStateUnit
source · pub struct WindowStateUnit<T: Debug> { /* private fields */ }
Expand description
This is the unit, binding to per screen. Because layer_shell is so unique, on surface bind to only one wl_output, only one buffer, only one output, so it will store includes the information of ZxdgOutput, size, and layer_shell
and it can set a binding, you to store the related data. like a cario_context, which is binding to the buffer on the wl_surface.
Implementations§
source§impl<T: Debug> WindowStateUnit<T>
impl<T: Debug> WindowStateUnit<T>
pub fn id(&self) -> Id
pub fn gen_wrapper(&self) -> WindowWrapper
source§impl<T: Debug> WindowStateUnit<T>
impl<T: Debug> WindowStateUnit<T>
pub fn raw_window_handle_rwh_06(&self) -> Result<RawWindowHandle, HandleError>
pub fn raw_display_handle_rwh_06(&self) -> Result<RawDisplayHandle, HandleError>
source§impl<T: Debug> WindowStateUnit<T>
impl<T: Debug> WindowStateUnit<T>
sourcepub fn get_wlsurface(&self) -> &WlSurface
pub fn get_wlsurface(&self) -> &WlSurface
get the wl surface from WindowState
sourcepub fn get_xdgoutput_info(&self) -> Option<&ZxdgOutputInfo>
pub fn get_xdgoutput_info(&self) -> Option<&ZxdgOutputInfo>
get the xdg_output info related to this unit
Examples found in repository?
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
fn main() {
let ev: WindowState<()> = WindowState::new("Hello")
.with_single(false)
.with_size((0, 400))
.with_layer(Layer::Top)
.with_margin((20, 20, 100, 20))
.with_anchor(Anchor::Bottom | Anchor::Left | Anchor::Right)
.with_keyboard_interacivity(KeyboardInteractivity::Exclusive)
.with_exclusize_zone(-1)
.build()
.unwrap();
let mut virtual_keyboard_manager = None;
ev.running(|event, ev, index| {
match event {
// NOTE: this will send when init, you can request bind extra object from here
LayerEvent::InitRequest => ReturnData::RequestBind,
LayerEvent::BindProvide(globals, qh) => {
// NOTE: you can get implied wayland object from here
virtual_keyboard_manager = Some(
globals
.bind::<zwp_virtual_keyboard_v1::ZwpVirtualKeyboardManagerV1, _, _>(
qh,
1..=1,
(),
)
.unwrap(),
);
println!("{:?}", virtual_keyboard_manager);
ReturnData::None
}
LayerEvent::XdgInfoChanged(_) => {
let index = index.unwrap();
let unit = ev.get_unit(index);
println!("{:?}", unit.get_xdgoutput_info());
ReturnData::None
}
LayerEvent::RequestBuffer(file, shm, qh, init_w, init_h) => {
draw(file, (init_w, init_h));
let pool = shm.create_pool(file.as_fd(), (init_w * init_h * 4) as i32, qh, ());
ReturnData::WlBuffer(pool.create_buffer(
0,
init_w as i32,
init_h as i32,
(init_w * 4) as i32,
wl_shm::Format::Argb8888,
qh,
(),
))
}
LayerEvent::RequestMessages(DispatchMessage::RequestRefresh { width, height }) => {
println!("{width}, {height}");
ReturnData::None
}
LayerEvent::RequestMessages(DispatchMessage::MouseButton { .. }) => ReturnData::None,
LayerEvent::RequestMessages(DispatchMessage::MouseEnter {
serial, pointer, ..
}) => ReturnData::RequestSetCursorShape((
"crosshair".to_owned(),
pointer.clone(),
*serial,
)),
LayerEvent::RequestMessages(DispatchMessage::MouseMotion {
time,
surface_x,
surface_y,
}) => {
println!("{time}, {surface_x}, {surface_y}");
ReturnData::None
}
LayerEvent::RequestMessages(DispatchMessage::KeyBoard { key, .. }) => {
match index {
Some(index) => {
let ev_unit = ev.get_unit(index);
match *key {
Q_KEY => ev_unit.set_anchor(Anchor::Top | Anchor::Left),
W_KEY => ev_unit.set_anchor(Anchor::Top),
E_KEY => ev_unit.set_anchor(Anchor::Top | Anchor::Right),
A_KEY => ev_unit.set_anchor(Anchor::Left),
S_KEY => ev_unit.set_anchor(
Anchor::Left | Anchor::Right | Anchor::Top | Anchor::Bottom,
),
D_KEY => ev_unit.set_anchor(Anchor::Right),
Z_KEY => ev_unit.set_anchor(Anchor::Left | Anchor::Bottom),
X_KEY => ev_unit.set_anchor(Anchor::Bottom),
C_KEY => ev_unit.set_anchor(Anchor::Bottom | Anchor::Right),
ESC_KEY => return ReturnData::RequestExist,
_ => {}
}
}
None => {
for ev_unit in ev.get_unit_iter() {
match *key {
Q_KEY => ev_unit.set_anchor(Anchor::Top | Anchor::Left),
W_KEY => ev_unit.set_anchor(Anchor::Top),
E_KEY => ev_unit.set_anchor(Anchor::Top | Anchor::Right),
A_KEY => ev_unit.set_anchor(Anchor::Left),
S_KEY => ev_unit.set_anchor(
Anchor::Left | Anchor::Right | Anchor::Top | Anchor::Bottom,
),
D_KEY => ev_unit.set_anchor(Anchor::Right),
Z_KEY => ev_unit.set_anchor(Anchor::Left | Anchor::Bottom),
X_KEY => ev_unit.set_anchor(Anchor::Bottom),
C_KEY => ev_unit.set_anchor(Anchor::Bottom | Anchor::Right),
ESC_KEY => return ReturnData::RequestExist,
_ => {}
}
}
}
};
ReturnData::None
}
_ => ReturnData::None,
}
})
.unwrap();
}
sourcepub fn set_anchor(&self, anchor: Anchor)
pub fn set_anchor(&self, anchor: Anchor)
set the anchor of the current unit. please take the simple.rs as refrence
Examples found in repository?
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
fn main() {
let ev: WindowState<()> = WindowState::new("Hello")
.with_single(false)
.with_size((0, 400))
.with_layer(Layer::Top)
.with_margin((20, 20, 100, 20))
.with_anchor(Anchor::Bottom | Anchor::Left | Anchor::Right)
.with_keyboard_interacivity(KeyboardInteractivity::Exclusive)
.with_exclusize_zone(-1)
.build()
.unwrap();
let mut virtual_keyboard_manager = None;
ev.running(|event, ev, index| {
match event {
// NOTE: this will send when init, you can request bind extra object from here
LayerEvent::InitRequest => ReturnData::RequestBind,
LayerEvent::BindProvide(globals, qh) => {
// NOTE: you can get implied wayland object from here
virtual_keyboard_manager = Some(
globals
.bind::<zwp_virtual_keyboard_v1::ZwpVirtualKeyboardManagerV1, _, _>(
qh,
1..=1,
(),
)
.unwrap(),
);
println!("{:?}", virtual_keyboard_manager);
ReturnData::None
}
LayerEvent::XdgInfoChanged(_) => {
let index = index.unwrap();
let unit = ev.get_unit(index);
println!("{:?}", unit.get_xdgoutput_info());
ReturnData::None
}
LayerEvent::RequestBuffer(file, shm, qh, init_w, init_h) => {
draw(file, (init_w, init_h));
let pool = shm.create_pool(file.as_fd(), (init_w * init_h * 4) as i32, qh, ());
ReturnData::WlBuffer(pool.create_buffer(
0,
init_w as i32,
init_h as i32,
(init_w * 4) as i32,
wl_shm::Format::Argb8888,
qh,
(),
))
}
LayerEvent::RequestMessages(DispatchMessage::RequestRefresh { width, height }) => {
println!("{width}, {height}");
ReturnData::None
}
LayerEvent::RequestMessages(DispatchMessage::MouseButton { .. }) => ReturnData::None,
LayerEvent::RequestMessages(DispatchMessage::MouseEnter {
serial, pointer, ..
}) => ReturnData::RequestSetCursorShape((
"crosshair".to_owned(),
pointer.clone(),
*serial,
)),
LayerEvent::RequestMessages(DispatchMessage::MouseMotion {
time,
surface_x,
surface_y,
}) => {
println!("{time}, {surface_x}, {surface_y}");
ReturnData::None
}
LayerEvent::RequestMessages(DispatchMessage::KeyBoard { key, .. }) => {
match index {
Some(index) => {
let ev_unit = ev.get_unit(index);
match *key {
Q_KEY => ev_unit.set_anchor(Anchor::Top | Anchor::Left),
W_KEY => ev_unit.set_anchor(Anchor::Top),
E_KEY => ev_unit.set_anchor(Anchor::Top | Anchor::Right),
A_KEY => ev_unit.set_anchor(Anchor::Left),
S_KEY => ev_unit.set_anchor(
Anchor::Left | Anchor::Right | Anchor::Top | Anchor::Bottom,
),
D_KEY => ev_unit.set_anchor(Anchor::Right),
Z_KEY => ev_unit.set_anchor(Anchor::Left | Anchor::Bottom),
X_KEY => ev_unit.set_anchor(Anchor::Bottom),
C_KEY => ev_unit.set_anchor(Anchor::Bottom | Anchor::Right),
ESC_KEY => return ReturnData::RequestExist,
_ => {}
}
}
None => {
for ev_unit in ev.get_unit_iter() {
match *key {
Q_KEY => ev_unit.set_anchor(Anchor::Top | Anchor::Left),
W_KEY => ev_unit.set_anchor(Anchor::Top),
E_KEY => ev_unit.set_anchor(Anchor::Top | Anchor::Right),
A_KEY => ev_unit.set_anchor(Anchor::Left),
S_KEY => ev_unit.set_anchor(
Anchor::Left | Anchor::Right | Anchor::Top | Anchor::Bottom,
),
D_KEY => ev_unit.set_anchor(Anchor::Right),
Z_KEY => ev_unit.set_anchor(Anchor::Left | Anchor::Bottom),
X_KEY => ev_unit.set_anchor(Anchor::Bottom),
C_KEY => ev_unit.set_anchor(Anchor::Bottom | Anchor::Right),
ESC_KEY => return ReturnData::RequestExist,
_ => {}
}
}
}
};
ReturnData::None
}
_ => ReturnData::None,
}
})
.unwrap();
}
sourcepub fn set_margin(&self, (top, right, bottom, left): (i32, i32, i32, i32))
pub fn set_margin(&self, (top, right, bottom, left): (i32, i32, i32, i32))
you can reset the margin which bind to the surface
pub fn set_layer(&self, layer: Layer)
sourcepub fn set_exclusive_zone(&self, zone: i32)
pub fn set_exclusive_zone(&self, zone: i32)
set current exclusive_zone
sourcepub fn set_binding(&mut self, binding: T)
pub fn set_binding(&mut self, binding: T)
you can use this function to set a binding data. the message passed back contain a index, you can use that to get the unit. It will be very useful, because you can use the binding data to operate the file binding to the buffer. you can take startcolorkeyboard as reference.
sourcepub fn get_binding_mut(&mut self) -> Option<&mut T>
pub fn get_binding_mut(&mut self) -> Option<&mut T>
return the binding data, with mut reference
sourcepub fn request_refresh(&self, (width, height): (i32, i32))
pub fn request_refresh(&self, (width, height): (i32, i32))
this function will refresh whole surface. it will reattach the buffer, and damage whole, and finall commit
Trait Implementations§
source§impl<T: Debug> HasDisplayHandle for WindowStateUnit<T>
impl<T: Debug> HasDisplayHandle for WindowStateUnit<T>
source§fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
source§impl<T: Debug> HasWindowHandle for WindowStateUnit<T>
impl<T: Debug> HasWindowHandle for WindowStateUnit<T>
source§fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>
Auto Trait Implementations§
impl<T> Freeze for WindowStateUnit<T>where
T: Freeze,
impl<T> !RefUnwindSafe for WindowStateUnit<T>
impl<T> Send for WindowStateUnit<T>where
T: Send,
impl<T> Sync for WindowStateUnit<T>where
T: Sync,
impl<T> Unpin for WindowStateUnit<T>where
T: Unpin,
impl<T> !UnwindSafe for WindowStateUnit<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
source§fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
HasDisplayHandle
insteadsource§impl<T> HasRawWindowHandle for Twhere
T: HasWindowHandle + ?Sized,
impl<T> HasRawWindowHandle for Twhere
T: HasWindowHandle + ?Sized,
source§fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
HasWindowHandle
instead