break out cef app wakeup code into separate pub function

This commit is contained in:
Mike Blumenkrantz 2015-05-26 21:16:04 -04:00
parent 64ff2c4a54
commit 45116dca71

View file

@ -458,44 +458,9 @@ struct CefCompositorProxy {
} }
impl CompositorProxy for CefCompositorProxy { impl CompositorProxy for CefCompositorProxy {
#[cfg(target_os="macos")]
fn send(&mut self, msg: compositor_task::Msg) {
use cocoa::appkit::{NSApp, NSApplication, NSApplicationDefined};
use cocoa::appkit::{NSEvent, NSEventModifierFlags, NSEventSubtype};
use cocoa::base::nil;
use cocoa::foundation::{NSAutoreleasePool, NSPoint};
// Send a message and kick the OS event loop awake.
self.sender.send(msg).unwrap();
unsafe {
let pool = NSAutoreleasePool::new(nil);
let event =
NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
nil,
NSApplicationDefined,
NSPoint::new(0.0, 0.0),
NSEventModifierFlags::empty(),
0.0,
0,
nil,
NSEventSubtype::NSWindowExposedEventType,
0,
0);
NSApp().postEvent_atStart_(event, 0);
pool.drain();
}
}
#[cfg(target_os="linux")]
fn send(&mut self, msg: compositor_task::Msg) { fn send(&mut self, msg: compositor_task::Msg) {
self.sender.send(msg).unwrap(); self.sender.send(msg).unwrap();
unsafe { if CEF_APP.is_null() { return; } } app_wakeup();
let capp = unsafe { CefApp::from_c_object_addref(CEF_APP) };
if unsafe { (*CEF_APP).get_browser_process_handler.is_some() } &&
check_ptr_exist!(capp.get_browser_process_handler(), on_work_available) {
capp.get_browser_process_handler().on_work_available();
}
} }
fn clone_compositor_proxy(&self) -> Box<CompositorProxy+Send> { fn clone_compositor_proxy(&self) -> Box<CompositorProxy+Send> {
@ -520,6 +485,42 @@ fn on_load_start(window: &Window) {
} }
} }
#[cfg(target_os="macos")]
pub fn app_wakeup() {
use cocoa::appkit::{NSApp, NSApplication, NSApplicationDefined};
use cocoa::appkit::{NSEvent, NSEventModifierFlags, NSEventSubtype};
use cocoa::base::nil;
use cocoa::foundation::{NSAutoreleasePool, NSPoint};
unsafe {
let pool = NSAutoreleasePool::new(nil);
let event =
NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
nil,
NSApplicationDefined,
NSPoint::new(0.0, 0.0),
NSEventModifierFlags::empty(),
0.0,
0,
nil,
NSEventSubtype::NSWindowExposedEventType,
0,
0);
NSApp().postEvent_atStart_(event, 0);
pool.drain();
}
}
#[cfg(target_os="linux")]
pub fn app_wakeup() {
unsafe { if CEF_APP.is_null() { return; } }
let capp = unsafe { CefApp::from_c_object_addref(CEF_APP) };
if unsafe { (*CEF_APP).get_browser_process_handler.is_some() } &&
check_ptr_exist!(capp.get_browser_process_handler(), on_work_available) {
capp.get_browser_process_handler().on_work_available();
}
}
#[cfg(target_os="linux")] #[cfg(target_os="linux")]
pub fn init_window() { pub fn init_window() {
unsafe { unsafe {