Struct WindowStateUnit

Source
pub struct WindowStateUnit<T> { /* private fields */ }

Implementations§

Source§

impl<T> WindowStateUnit<T>

Source

pub fn id(&self) -> Id

get the WindowState id

Source

pub fn try_set_viewport_destination( &self, width: i32, height: i32, ) -> Option<()>

Source

pub fn try_set_viewport_source( &self, x: f64, y: f64, width: f64, height: f64, ) -> Option<()>

Source

pub fn gen_wrapper(&self) -> WindowWrapper

gen the WindowState WindowWrapper

Source§

impl<T> WindowStateUnit<T>

Source§

impl<T> WindowStateUnit<T>

Source

pub fn get_wlsurface(&self) -> &WlSurface

get the wl surface from WindowState

Examples found in repository?
examples/simplelayer.rs (line 46)
8fn main() {
9    let ev: WindowState<()> = WindowState::new("Hello")
10        .with_allscreens()
11        .with_size((0, 400))
12        .with_layer(Layer::Top)
13        .with_margin((20, 20, 100, 20))
14        .with_anchor(Anchor::Bottom | Anchor::Left | Anchor::Right)
15        .with_keyboard_interacivity(KeyboardInteractivity::Exclusive)
16        .with_exclusize_zone(-1)
17        .build()
18        .unwrap();
19
20    let mut virtual_keyboard_manager = None;
21    ev.running(|event, ev, index| {
22        match event {
23            // NOTE: this will send when init, you can request bind extra object from here
24            LayerEvent::InitRequest => ReturnData::RequestBind,
25            LayerEvent::BindProvide(globals, qh) => {
26                // NOTE: you can get implied wayland object from here
27                virtual_keyboard_manager = Some(
28                    globals
29                        .bind::<zwp_virtual_keyboard_v1::ZwpVirtualKeyboardManagerV1, _, _>(
30                            qh,
31                            1..=1,
32                            (),
33                        )
34                        .unwrap(),
35                );
36                println!("{:?}", virtual_keyboard_manager);
37                ReturnData::RequestCompositor
38            }
39            LayerEvent::CompositorProvide(compositor, qh) => {
40                // NOTE: you can set input region to limit area which gets input events
41                // surface outside region becomes transparent for input events
42                // To ignore all input events use region with (0,0) size
43                for x in ev.get_unit_iter() {
44                    let region = compositor.create_region(qh, ());
45                    region.add(0, 0, 0, 0);
46                    x.get_wlsurface().set_input_region(Some(&region));
47                }
48                ReturnData::None
49            }
50            LayerEvent::XdgInfoChanged(_) => {
51                let index = index.unwrap();
52                let unit = ev.get_unit_with_id(index).unwrap();
53                println!("{:?}", unit.get_xdgoutput_info());
54                ReturnData::None
55            }
56            LayerEvent::RequestBuffer(file, shm, qh, init_w, init_h) => {
57                draw(file, (init_w, init_h));
58                let pool = shm.create_pool(file.as_fd(), (init_w * init_h * 4) as i32, qh, ());
59                ReturnData::WlBuffer(pool.create_buffer(
60                    0,
61                    init_w as i32,
62                    init_h as i32,
63                    (init_w * 4) as i32,
64                    wl_shm::Format::Argb8888,
65                    qh,
66                    (),
67                ))
68            }
69            LayerEvent::RequestMessages(DispatchMessage::RequestRefresh {
70                width, height, ..
71            }) => {
72                println!("{width}, {height}");
73                ReturnData::None
74            }
75            LayerEvent::RequestMessages(DispatchMessage::MouseButton { .. }) => ReturnData::None,
76            LayerEvent::RequestMessages(DispatchMessage::MouseEnter {
77                serial, pointer, ..
78            }) => ReturnData::RequestSetCursorShape((
79                "crosshair".to_owned(),
80                pointer.clone(),
81                *serial,
82            )),
83            LayerEvent::RequestMessages(DispatchMessage::MouseMotion {
84                time,
85                surface_x,
86                surface_y,
87            }) => {
88                println!("{time}, {surface_x}, {surface_y}");
89                ReturnData::None
90            }
91            LayerEvent::RequestMessages(DispatchMessage::KeyboardInput { event, .. }) => {
92                if let PhysicalKey::Code(KeyCode::Escape) = event.physical_key {
93                    ReturnData::RequestExit
94                } else {
95                    ReturnData::None
96                }
97            }
98            _ => ReturnData::None,
99        }
100    })
101    .unwrap();
102}
Source

pub fn get_xdgoutput_info(&self) -> Option<&ZxdgOutputInfo>

get the xdg_output info related to this unit

Examples found in repository?
examples/simplelayer.rs (line 53)
8fn main() {
9    let ev: WindowState<()> = WindowState::new("Hello")
10        .with_allscreens()
11        .with_size((0, 400))
12        .with_layer(Layer::Top)
13        .with_margin((20, 20, 100, 20))
14        .with_anchor(Anchor::Bottom | Anchor::Left | Anchor::Right)
15        .with_keyboard_interacivity(KeyboardInteractivity::Exclusive)
16        .with_exclusize_zone(-1)
17        .build()
18        .unwrap();
19
20    let mut virtual_keyboard_manager = None;
21    ev.running(|event, ev, index| {
22        match event {
23            // NOTE: this will send when init, you can request bind extra object from here
24            LayerEvent::InitRequest => ReturnData::RequestBind,
25            LayerEvent::BindProvide(globals, qh) => {
26                // NOTE: you can get implied wayland object from here
27                virtual_keyboard_manager = Some(
28                    globals
29                        .bind::<zwp_virtual_keyboard_v1::ZwpVirtualKeyboardManagerV1, _, _>(
30                            qh,
31                            1..=1,
32                            (),
33                        )
34                        .unwrap(),
35                );
36                println!("{:?}", virtual_keyboard_manager);
37                ReturnData::RequestCompositor
38            }
39            LayerEvent::CompositorProvide(compositor, qh) => {
40                // NOTE: you can set input region to limit area which gets input events
41                // surface outside region becomes transparent for input events
42                // To ignore all input events use region with (0,0) size
43                for x in ev.get_unit_iter() {
44                    let region = compositor.create_region(qh, ());
45                    region.add(0, 0, 0, 0);
46                    x.get_wlsurface().set_input_region(Some(&region));
47                }
48                ReturnData::None
49            }
50            LayerEvent::XdgInfoChanged(_) => {
51                let index = index.unwrap();
52                let unit = ev.get_unit_with_id(index).unwrap();
53                println!("{:?}", unit.get_xdgoutput_info());
54                ReturnData::None
55            }
56            LayerEvent::RequestBuffer(file, shm, qh, init_w, init_h) => {
57                draw(file, (init_w, init_h));
58                let pool = shm.create_pool(file.as_fd(), (init_w * init_h * 4) as i32, qh, ());
59                ReturnData::WlBuffer(pool.create_buffer(
60                    0,
61                    init_w as i32,
62                    init_h as i32,
63                    (init_w * 4) as i32,
64                    wl_shm::Format::Argb8888,
65                    qh,
66                    (),
67                ))
68            }
69            LayerEvent::RequestMessages(DispatchMessage::RequestRefresh {
70                width, height, ..
71            }) => {
72                println!("{width}, {height}");
73                ReturnData::None
74            }
75            LayerEvent::RequestMessages(DispatchMessage::MouseButton { .. }) => ReturnData::None,
76            LayerEvent::RequestMessages(DispatchMessage::MouseEnter {
77                serial, pointer, ..
78            }) => ReturnData::RequestSetCursorShape((
79                "crosshair".to_owned(),
80                pointer.clone(),
81                *serial,
82            )),
83            LayerEvent::RequestMessages(DispatchMessage::MouseMotion {
84                time,
85                surface_x,
86                surface_y,
87            }) => {
88                println!("{time}, {surface_x}, {surface_y}");
89                ReturnData::None
90            }
91            LayerEvent::RequestMessages(DispatchMessage::KeyboardInput { event, .. }) => {
92                if let PhysicalKey::Code(KeyCode::Escape) = event.physical_key {
93                    ReturnData::RequestExit
94                } else {
95                    ReturnData::None
96                }
97            }
98            _ => ReturnData::None,
99        }
100    })
101    .unwrap();
102}
Source

pub fn set_anchor(&self, anchor: Anchor)

set the anchor of the current unit. please take the simple.rs as reference

Source

pub fn set_margin(&self, (top, right, bottom, left): (i32, i32, i32, i32))

you can reset the margin which bind to the surface

Source

pub fn set_layer(&self, layer: Layer)

set the layer

Source

pub fn set_anchor_with_size(&self, anchor: Anchor, (width, height): (u32, u32))

set the anchor and set the size together When you want to change layer from LEFT|RIGHT|BOTTOM to TOP|LEFT|BOTTOM, use it

Source

pub fn set_size(&self, (width, height): (u32, u32))

set the layer size of current unit

Source

pub fn set_exclusive_zone(&self, zone: i32)

set current exclusive_zone

Source

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.

Source

pub fn get_binding_mut(&mut self) -> Option<&mut T>

return the binding data, with mut reference

Source

pub fn get_binding(&self) -> Option<&T>

get the binding data

Source

pub fn get_size(&self) -> (u32, u32)

get the size of the surface

Source

pub fn request_refresh(&self, (width, height): (i32, i32))

this function will refresh whole surface. it will reattach the buffer, and damage whole, and final commit

Source

pub fn scale_u32(&self) -> u32

Source

pub fn scale_float(&self) -> f64

Trait Implementations§

Source§

impl<T: Debug> Debug for WindowStateUnit<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> HasDisplayHandle for WindowStateUnit<T>

Source§

fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>

Get a handle to the display controller of the windowing system.
Source§

impl<T> HasWindowHandle for WindowStateUnit<T>

Source§

fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>

Get a handle to the window.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HasRawDisplayHandle for T
where T: HasDisplayHandle + ?Sized,

Source§

fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>

👎Deprecated: Use HasDisplayHandle instead
Source§

impl<T> HasRawWindowHandle for T
where T: HasWindowHandle + ?Sized,

Source§

fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>

👎Deprecated: Use HasWindowHandle instead
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more