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>

source

pub fn id(&self) -> Id

source

pub fn gen_wrapper(&self) -> WindowWrapper

source§

impl<T: Debug> WindowStateUnit<T>

source§

impl<T: Debug> WindowStateUnit<T>

source

pub fn get_wlsurface(&self) -> &WlSurface

get the wl surface from WindowState

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 52)
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();
}
source

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?
examples/simplelayer.rs (line 93)
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();
}
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)

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_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 finall commit

Trait Implementations§

source§

impl<T: Debug + 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: Debug> 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: Debug> 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 + Sync + Send>

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

§

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

§

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