1
0
Fork 0

pass WindowHandler as trait object in x11 backend

This commit is contained in:
Micah Johnston 2020-12-08 19:27:26 -06:00 committed by glowcoil
parent e9507f8d86
commit 0633874266
3 changed files with 5 additions and 8 deletions

View file

@ -14,10 +14,7 @@ use objc::{
}; };
use uuid::Uuid; use uuid::Uuid;
use crate::{ use crate::{Event, MouseButton, MouseEvent, Point, WindowOpenOptions};
Event, MouseButton, MouseEvent, Point, WindowHandler,
WindowOpenOptions
};
use crate::MouseEvent::{ButtonPressed, ButtonReleased}; use crate::MouseEvent::{ButtonPressed, ButtonReleased};
use super::window::{ use super::window::{

View file

@ -59,7 +59,7 @@ impl Window {
options: WindowOpenOptions, options: WindowOpenOptions,
build: B build: B
) -> (crate::WindowHandle, Option<crate::AppRunner>) ) -> (crate::WindowHandle, Option<crate::AppRunner>)
where H: WindowHandler, where H: WindowHandler + 'static,
B: FnOnce(&mut crate::Window) -> H, B: FnOnce(&mut crate::Window) -> H,
B: Send + 'static B: Send + 'static
{ {

View file

@ -223,7 +223,7 @@ impl Window {
} }
#[inline] #[inline]
fn drain_xcb_events<H: WindowHandler>(&mut self, handler: &mut H) { fn drain_xcb_events(&mut self, handler: &mut dyn WindowHandler) {
// the X server has a tendency to send spurious/extraneous configure notify events when a // the X server has a tendency to send spurious/extraneous configure notify events when a
// window is resized, and we need to batch those together and just send one resize event // window is resized, and we need to batch those together and just send one resize event
// when they've all been coalesced. // when they've all been coalesced.
@ -252,7 +252,7 @@ impl Window {
// FIXME: poll() acts fine on linux, sometimes funky on *BSD. XCB upstream uses a define to // FIXME: poll() acts fine on linux, sometimes funky on *BSD. XCB upstream uses a define to
// switch between poll() and select() (the latter of which is fine on *BSD), and we should do // switch between poll() and select() (the latter of which is fine on *BSD), and we should do
// the same. // the same.
fn run_event_loop<H: WindowHandler>(&mut self, handler: &mut H) { fn run_event_loop(&mut self, handler: &mut dyn WindowHandler) {
use nix::poll::*; use nix::poll::*;
let xcb_fd = unsafe { let xcb_fd = unsafe {
@ -291,7 +291,7 @@ impl Window {
} }
} }
fn handle_xcb_event<H: WindowHandler>(&mut self, handler: &mut H, event: xcb::GenericEvent) { fn handle_xcb_event(&mut self, handler: &mut dyn WindowHandler, event: xcb::GenericEvent) {
let event_type = event.response_type() & !0x80; let event_type = event.response_type() & !0x80;
// For all of the keyboard and mouse events, you can fetch // For all of the keyboard and mouse events, you can fetch