@@ -12,6 +12,12 @@ use std::sync::{atomic::Ordering, Mutex};
1212
1313use libc:: c_void;
1414
15+ #[ cfg( feature = "raw-window-handle" ) ]
16+ use raw_window_handle:: {
17+ DisplayHandle , HandleError , HasDisplayHandle , HasWindowHandle , WindowHandle , XcbDisplayHandle ,
18+ XcbWindowHandle ,
19+ } ;
20+
1521use crate :: connection:: {
1622 compute_length_field, Connection , ReplyOrError , RequestConnection , RequestKind ,
1723} ;
@@ -634,26 +640,26 @@ impl AsFd for XCBConnection {
634640}
635641
636642#[ cfg( feature = "raw-window-handle" ) ]
637- unsafe impl raw_window_handle :: HasRawDisplayHandle for XCBConnection {
643+ impl HasDisplayHandle for XCBConnection {
638644 #[ inline]
639- fn raw_display_handle ( & self ) -> raw_window_handle:: RawDisplayHandle {
640- let mut handle = raw_window_handle:: XcbDisplayHandle :: empty ( ) ;
641- handle. connection = self . get_raw_xcb_connection ( ) ;
645+ fn display_handle ( & self ) -> Result < DisplayHandle < ' _ > , HandleError > {
646+ // We do not have/know a screen, but people want this trait implemented anyway. We guess.
647+ let screen = 0 ;
648+ let connection = std:: ptr:: NonNull :: new ( self . get_raw_xcb_connection ( ) ) ;
649+ let handle = XcbDisplayHandle :: new ( connection, screen) ;
642650
643- raw_window_handle :: RawDisplayHandle :: Xcb ( handle)
651+ unsafe { Ok ( DisplayHandle :: borrow_raw ( handle. into ( ) ) ) }
644652 }
645653}
646654
647655#[ cfg( feature = "raw-window-handle" ) ]
648- unsafe impl raw_window_handle:: HasRawWindowHandle
649- for crate :: protocol:: xproto:: WindowWrapper < XCBConnection >
650- {
656+ impl HasWindowHandle for crate :: protocol:: xproto:: WindowWrapper < XCBConnection > {
651657 #[ inline]
652- fn raw_window_handle ( & self ) -> raw_window_handle :: RawWindowHandle {
653- let mut handle = raw_window_handle :: XcbWindowHandle :: empty ( ) ;
654- handle. window = self . window ( ) ;
658+ fn window_handle ( & self ) -> Result < WindowHandle < ' _ > , HandleError > {
659+ let window = std :: num :: NonZeroU32 :: new ( self . window ( ) ) . ok_or ( HandleError :: NotSupported ) ? ;
660+ let handle = XcbWindowHandle :: new ( window ) ;
655661
656- raw_window_handle :: RawWindowHandle :: Xcb ( handle)
662+ unsafe { Ok ( WindowHandle :: borrow_raw ( handle. into ( ) ) ) }
657663 }
658664}
659665
0 commit comments