destroy

Function destroy 

Source
pub fn destroy(proxy: &impl UntypedOwnedProxyWrapper)
Expand description

Destroys a proxy without sending a wayland message.

This function only destroys the proxy in libwayland without sending a message to the compositor. You might use this function in the following situations:

  • The type does not provide a destructor request.
  • In an event handler that destroys the object, e.g. wl_callback.done.
  • You want to deliberately leak the wayland object without leaking memory.

This function does nothing if the proxy is already destroyed.

§Panic

This function might panic if the proxy is attached to a local queue and the current thread is not the thread in which the queue was created.

§Example

let lib = Libwayland::open().unwrap();
let con = lib.connect_to_default_display().unwrap();
let queue = con.create_queue(c"");
let display: WlDisplay = queue.display();

let sync = display.sync();
let sync2 = sync.clone();
proxy::set_event_handler(&sync, WlCallback::on_done(move |_, _| {
    proxy::destroy(&sync2);
}));

queue.dispatch_roundtrip_blocking().unwrap();
assert!(proxy::wl_proxy(&*sync).is_none());
Examples found in repository?
examples/simple-window/../common/singletons.rs (line 52)
47    fn drop(&mut self) {
48        if let Some(fixes) = self.get_opt::<WlFixes>(1, 1) {
49            fixes.destroy_registry(&self.wl_registry);
50            fixes.destroy();
51        }
52        proxy::destroy(&self.wl_registry);
53    }
More examples
Hide additional examples
examples/async-wait/main.rs (line 29)
23fn create_sync(queue: &Queue, n: u64) {
24    let sync = queue.display::<WlDisplay>().sync();
25    proxy::set_event_handler(
26        &sync.clone(),
27        WlCallback::on_done(move |_, _| {
28            println!("done! ({n})");
29            proxy::destroy(&sync);
30            create_sync(proxy::queue(&sync), n + 1);
31        }),
32    );
33}
examples/poll-integration/main.rs (line 54)
48fn create_sync(queue: &Queue, n: u64) {
49    let sync = queue.display::<WlDisplay>().sync();
50    proxy::set_event_handler(
51        &sync.clone(),
52        WlCallback::on_done(move |_, _| {
53            println!("done! ({n})");
54            proxy::destroy(&sync);
55            create_sync(proxy::queue(&sync), n + 1);
56        }),
57    );
58}
examples/simple-window/../common/simple_window.rs (line 163)
153    fn global_remove(&self, _slf: &WlRegistryRef, name: u32) {
154        let seats = &mut *self.seats.borrow_mut();
155        let Some(seat) = seats.remove(&name) else {
156            return;
157        };
158        let data = &mut *seat.borrow_mut();
159        data.destroy_pointer();
160        if proxy::version(&*data.seat) >= WlSeat::REQ__RELEASE__SINCE {
161            data.seat.release();
162        } else {
163            proxy::destroy(&data.seat);
164        }
165    }
166}
167
168struct SeatEventHandler {
169    wp_cursor_shape_manager_v1: WpCursorShapeManagerV1,
170    data: Rc<RefCell<SeatData>>,
171}
172
173struct SeatData {
174    seat: WlSeat,
175    pointer: Option<WlPointer>,
176    shape: Option<WpCursorShapeDeviceV1>,
177}
178
179impl SeatData {
180    fn destroy_pointer(&mut self) {
181        if let Some(shape) = self.shape.take() {
182            shape.destroy();
183        }
184        if let Some(pointer) = self.pointer.take() {
185            if proxy::version(&*pointer) >= WlPointer::REQ__RELEASE__SINCE {
186                pointer.release();
187            } else {
188                proxy::destroy(&pointer);
189            }
190        }
191    }
examples/keyboard-events/main.rs (line 79)
73    fn global_remove(&self, _slf: &WlRegistryRef, name: u32) {
74        if let Some(seat) = self.seats.borrow_mut().remove(&name) {
75            if let Some(kb) = seat.wl_keyboard.take() {
76                if proxy::version(&*kb) >= WlKeyboard::REQ__RELEASE__SINCE {
77                    kb.release();
78                } else {
79                    proxy::destroy(&kb);
80                }
81            }
82            if proxy::version(&*seat.wl_seat) >= WlSeat::REQ__RELEASE__SINCE {
83                seat.wl_seat.release();
84            } else {
85                proxy::destroy(&seat.wl_seat);
86            }
87        }
88    }
89}
90
91impl WlSeatEventHandler for SeatEventHandler {
92    fn capabilities(&self, _slf: &WlSeatRef, capabilities: WlSeatCapability) {
93        let kb = &mut *self.0.wl_keyboard.borrow_mut();
94        if capabilities.contains(WlSeatCapability::KEYBOARD) {
95            if kb.is_none() {
96                let wl_keyboard = self.0.wl_seat.get_keyboard();
97                proxy::set_event_handler_local(&wl_keyboard, self.clone());
98                *kb = Some(wl_keyboard);
99            }
100        } else {
101            if let Some(kb) = kb.take() {
102                if proxy::version(&*kb) >= WlKeyboard::REQ__RELEASE__SINCE {
103                    kb.release();
104                } else {
105                    proxy::destroy(&kb);
106                }
107            }
108        }
109    }