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?
More examples
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 }