Skip to main content

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