fn handle_event<'a>(
        processor: &mut input::Processor<'a, ActionContext<'a, N>>,
        event: Event,
        ref_test: bool,
        resize_tx: &mpsc::Sender<(u32, u32)>,
        hide_cursor: &mut bool,
        window_is_focused: &mut bool,
    ) {
        match event {
            // Pass on device events
            Event::DeviceEvent { .. } | Event::Suspended { .. } => (),
            Event::WindowEvent { event, .. } => {
                use glutin::WindowEvent::*;
                match event {
                    Closed => {
                        if ref_test {
                            // dump grid state
                            let grid = processor.ctx.terminal.grid();

                            let serialized_grid = json::to_string(&grid)
                                .expect("serialize grid");

                            let serialized_size = json::to_string(processor.ctx.terminal.size_info())
                                .expect("serialize size");

                            File::create("./grid.json")
                                .and_then(|mut f| f.write_all(serialized_grid.as_bytes()))
                                .expect("write grid.json");

                            File::create("./size.json")
                                .and_then(|mut f| f.write_all(serialized_size.as_bytes()))
                                .expect("write size.json");
                        }

                        // FIXME should do a more graceful shutdown
                        ::std::process::exit(0);
                    },
                    Resized(w, h) => {
                        resize_tx.send((w, h)).expect("send new size");
                        processor.ctx.terminal.dirty = true;
                    },
                    KeyboardInput { input, .. } => {
                        let glutin::KeyboardInput { state, virtual_keycode, modifiers, .. } = input;
                        processor.process_key(state, virtual_keycode, &modifiers);
                        if state == ElementState::Pressed {
                            // Hide cursor while typing
                            *hide_cursor = true;
                        }
                    },
                    ReceivedCharacter(c) => {
                        processor.received_char(c);
                    },
                    MouseInput { state, button, modifiers, .. } => {
                        *hide_cursor = false;
                        processor.mouse_input(state, button, modifiers);
                        processor.ctx.terminal.dirty = true;
                    },
                    CursorMoved { position: (x, y), modifiers, .. } => {
                        let x = x as i32;
                        let y = y as i32;
                        let x = limit(x, 0, processor.ctx.size_info.width as i32);
                        let y = limit(y, 0, processor.ctx.size_info.height as i32);

                        *hide_cursor = false;
                        processor.mouse_moved(x as u32, y as u32, modifiers);

                        if !processor.ctx.selection.is_none() {
                            processor.ctx.terminal.dirty = true;
                        }
                    },
                    MouseWheel { delta, phase, modifiers, .. } => {
                        *hide_cursor = false;
                        processor.on_mouse_wheel(delta, phase, modifiers);
                    },
                    Refresh => {
                        processor.ctx.terminal.dirty = true;
                    },
                    Focused(is_focused) => {
                        *window_is_focused = is_focused;

                        if is_focused {
                            processor.ctx.terminal.dirty = true;
                            processor.ctx.terminal.next_is_urgent = Some(false);
                        } else {
                            processor.ctx.terminal.dirty = true;
                            *hide_cursor = false;
                        }

                        processor.on_focus_change(is_focused);
                    }
                    _ => (),
                }
            },
            Event::Awakened => {
                processor.ctx.terminal.dirty = true;
            }
        }
    }
/// Handle events from glutin
///
/// Doesn't take self mutably due to borrow checking. Kinda uggo but w/e.
Handle events from glutin
Doesn't take self mutably due to borrow checking. Kinda uggo but w/e.
Handle events from glutin Doesn ' t take self mutably due to borrow checking . Kinda uggo but w / e .
fn handle_event<'a>(
        processor: &mut input::Processor<'a, ActionContext<'a, N>>,
        event: Event,
        ref_test: bool,
        resize_tx: &mpsc::Sender<(u32, u32)>,
        hide_cursor: &mut bool,
        window_is_focused: &mut bool,
    ) {
        match event {
            // Pass on device events
            Event::DeviceEvent { .. } | Event::Suspended { .. } => (),
            Event::WindowEvent { event, .. } => {
                use glutin::WindowEvent::*;
                match event {
                    Closed => {
                        if ref_test {
                            // dump grid state
                            let grid = processor.ctx.terminal.grid();
                            let serialized_grid = json::to_string(&grid)
                                .expect("serialize grid");
                            let serialized_size = json::to_string(processor.ctx.terminal.size_info())
                                .expect("serialize size");
                            File::create("./grid.json")
                                .and_then(|mut f| f.write_all(serialized_grid.as_bytes()))
                                .expect("write grid.json");
                            File::create("./size.json")
                                .and_then(|mut f| f.write_all(serialized_size.as_bytes()))
                                .expect("write size.json");
                        }
                        // FIXME should do a more graceful shutdown
                        ::std::process::exit(0);
                    },
                    Resized(w, h) => {
                        resize_tx.send((w, h)).expect("send new size");
                        processor.ctx.terminal.dirty = true;
                    },
                    KeyboardInput { input, .. } => {
                        let glutin::KeyboardInput { state, virtual_keycode, modifiers, .. } = input;
                        processor.process_key(state, virtual_keycode, &modifiers);
                        if state == ElementState::Pressed {
                            // Hide cursor while typing
                            *hide_cursor = true;
                        }
                    },
                    ReceivedCharacter(c) => {
                        processor.received_char(c);
                    },
                    MouseInput { state, button, modifiers, .. } => {
                        *hide_cursor = false;
                        processor.mouse_input(state, button, modifiers);
                        processor.ctx.terminal.dirty = true;
                    },
                    CursorMoved { position: (x, y), modifiers, .. } => {
                        let x = x as i32;
                        let y = y as i32;
                        let x = limit(x, 0, processor.ctx.size_info.width as i32);
                        let y = limit(y, 0, processor.ctx.size_info.height as i32);
                        *hide_cursor = false;
                        processor.mouse_moved(x as u32, y as u32, modifiers);
                        if !processor.ctx.selection.is_none() {
                            processor.ctx.terminal.dirty = true;
                        }
                    },
                    MouseWheel { delta, phase, modifiers, .. } => {
                        *hide_cursor = false;
                        processor.on_mouse_wheel(delta, phase, modifiers);
                    },
                    Refresh => {
                        processor.ctx.terminal.dirty = true;
                    },
                    Focused(is_focused) => {
                        *window_is_focused = is_focused;
                        if is_focused {
                            processor.ctx.terminal.dirty = true;
                            processor.ctx.terminal.next_is_urgent = Some(false);
                        } else {
                            processor.ctx.terminal.dirty = true;
                            *hide_cursor = false;
                        }
                        processor.on_focus_change(is_focused);
                    }
                    _ => (),
                }
            },
            Event::Awakened => {
                processor.ctx.terminal.dirty = true;
            }
        }
    }
fn handle_event < ' a > ( processor : & mut input :: Processor < ' a , ActionContext < ' a , N > > , event : Event , ref_test : bool , resize_tx : & mpsc :: Sender < ( u32 , u32 ) > , hide_cursor : & mut bool , window_is_focused : & mut bool , ) { match event { // Pass on device events Event :: DeviceEvent { .. } | Event :: Suspended { .. } => ( ) , Event :: WindowEvent { event , .. } => { use glutin :: WindowEvent :: * ; match event { Closed => { if ref_test { // dump grid state let grid = processor . ctx . terminal . grid ( ) ; let serialized_grid = json :: to_string ( & grid ) . expect ( " " ) ; let serialized_size = json :: to_string ( processor . ctx . terminal . size_info ( ) ) . expect ( " " ) ; File :: create ( " " ) . and_then ( | mut f | f . write_all ( serialized_grid . as_bytes ( ) ) ) . expect ( " " ) ; File :: create ( " " ) . and_then ( | mut f | f . write_all ( serialized_size . as_bytes ( ) ) ) . expect ( " " ) ; } // FIXME should do a more graceful shutdown :: std :: process :: exit ( 0 ) ; } , Resized ( w , h ) => { resize_tx . send ( ( w , h ) ) . expect ( " " ) ; processor . ctx . terminal . dirty = true ; } , KeyboardInput { input , .. } => { let glutin :: KeyboardInput { state , virtual_keycode , modifiers , .. } = input ; processor . process_key ( state , virtual_keycode , & modifiers ) ; if state == ElementState :: Pressed { // Hide cursor while typing * hide_cursor = true ; } } , ReceivedCharacter ( c ) => { processor . received_char ( c ) ; } , MouseInput { state , button , modifiers , .. } => { * hide_cursor = false ; processor . mouse_input ( state , button , modifiers ) ; processor . ctx . terminal . dirty = true ; } , CursorMoved { position : ( x , y ) , modifiers , .. } => { let x = x as i32 ; let y = y as i32 ; let x = limit ( x , 0 , processor . ctx . size_info . width as i32 ) ; let y = limit ( y , 0 , processor . ctx . size_info . height as i32 ) ; * hide_cursor = false ; processor . mouse_moved ( x as u32 , y as u32 , modifiers ) ; if ! processor . ctx . selection . is_none ( ) { processor . ctx . terminal . dirty = true ; } } , MouseWheel { delta , phase , modifiers , .. } => { * hide_cursor = false ; processor . on_mouse_wheel ( delta , phase , modifiers ) ; } , Refresh => { processor . ctx . terminal . dirty = true ; } , Focused ( is_focused ) => { * window_is_focused = is_focused ; if is_focused { processor . ctx . terminal . dirty = true ; processor . ctx . terminal . next_is_urgent = Some ( false ) ; } else { processor . ctx . terminal . dirty = true ; * hide_cursor = false ; } processor . on_focus_change ( is_focused ) ; } _ => ( ) , } } , Event :: Awakened => { processor . ctx . terminal . dirty = true ; } } }
Handle events from glutin
Doesn't take self mutably due to borrow checking.
Handle events from glutin Doesn ' t take self mutably due to borrow checking .
processor
&mut input::Processor<'a, ActionContext<'a, N>>
event
Event
ref_test
bool
resize_tx
&mpsc::Sender<(u32, u32)>
hide_cursor
&mut bool
window_is_focused
&mut bool
processor
&mut input::Processor<'a, ActionContext<'a, N>>
event
Event
ref_test
bool
resize_tx
&mpsc::Sender<(u32, u32)>
hide_cursor
&mut bool
window_is_focused
&mut bool