1+ use crate :: wrappers:: connection_poller:: { ConnectionPoller , PollStatus } ;
12use crate :: x11:: drag_n_drop:: DragNDropState ;
23use crate :: x11:: keyboard:: { convert_key_press_event, convert_key_release_event, key_mods} ;
34use crate :: x11:: { ParentHandle , Window , WindowInner } ;
@@ -6,7 +7,7 @@ use crate::{
67 WindowInfo ,
78} ;
89use std:: error:: Error ;
9- use std:: os :: fd :: AsRawFd ;
10+ use std:: rc :: Rc ;
1011use std:: time:: { Duration , Instant } ;
1112use x11rb:: connection:: Connection ;
1213use x11rb:: protocol:: Event as XEvent ;
@@ -63,13 +64,9 @@ impl EventLoop {
6364 }
6465
6566 // Event loop
66- // FIXME: poll() acts fine on linux, sometimes funky on *BSD. XCB upstream uses a define to
67- // switch between poll() and select() (the latter of which is fine on *BSD), and we should do
68- // the same.
6967 pub fn run ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
70- use nix:: poll:: * ;
71-
72- let xcb_fd = self . window . xcb_connection . conn . as_raw_fd ( ) ;
68+ let connection = Rc :: clone ( & self . window . xcb_connection ) ;
69+ let mut poller = ConnectionPoller :: new ( & connection. conn ) ?;
7370
7471 let mut last_frame = Instant :: now ( ) ;
7572 self . event_loop_running = true ;
@@ -87,24 +84,13 @@ impl EventLoop {
8784 last_frame = Instant :: max ( next_frame, Instant :: now ( ) - self . frame_interval ) ;
8885 }
8986
90- let mut fds = [ PollFd :: new ( xcb_fd, PollFlags :: POLLIN ) ] ;
91-
9287 // Check for any events in the internal buffers
9388 // before going to sleep:
9489 self . drain_xcb_events ( ) ?;
9590
9691 // FIXME: handle errors
97- poll ( & mut fds, next_frame. duration_since ( Instant :: now ( ) ) . subsec_millis ( ) as i32 )
98- . unwrap ( ) ;
99-
100- if let Some ( revents) = fds[ 0 ] . revents ( ) {
101- if revents. contains ( PollFlags :: POLLERR ) {
102- panic ! ( "xcb connection poll error" ) ;
103- }
104-
105- if revents. contains ( PollFlags :: POLLIN ) {
106- self . drain_xcb_events ( ) ?;
107- }
92+ if let PollStatus :: ReadAvailable = poller. wait ( next_frame) . unwrap ( ) {
93+ self . drain_xcb_events ( ) ?;
10894 }
10995
11096 // Check if the parents's handle was dropped (such as when the host
@@ -123,6 +109,8 @@ impl EventLoop {
123109 }
124110 }
125111
112+ poller. delete ( ) ?;
113+
126114 Ok ( ( ) )
127115 }
128116
0 commit comments