From 4dc9f893c3bf2734574d6e530b092cec67b60585 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Wed, 13 Dec 2017 09:42:41 -0500 Subject: [PATCH 1/4] Quit when failed to create quartz event tap --- src/lib/platform/OSXScreen.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index dea25877..33b83da2 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -203,11 +203,13 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso if (!m_eventTapPort) { LOG((CLOG_ERR "failed to create quartz event tap")); + m_events->addEvent(Event(Event::kQuit)); } m_eventTapRLSR = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, m_eventTapPort, 0); if (!m_eventTapRLSR) { LOG((CLOG_ERR "failed to create a CFRunLoopSourceRef for the quartz event tap")); + m_events->addEvent(Event(Event::kQuit)); } CFRunLoopAddSource(CFRunLoopGetCurrent(), m_eventTapRLSR, kCFRunLoopDefaultMode); From adcb1b9b1fe7007d329c6038120b2f4d2be51a26 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Wed, 13 Dec 2017 10:13:39 -0500 Subject: [PATCH 2/4] Log for creating quartz event tap --- src/lib/platform/OSXScreen.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index 33b83da2..864671c9 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -192,6 +192,7 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso this); } else { + LOG((CLOG_DEBUG "creating quartz event tap")); // there may be a better way to do this, but we register an event handler even if we're // not on the primary display (acting as a client). This way, if a local event comes in // (either keyboard or mouse), we can make sure to show the cursor if we've hidden it. From d770160e005499247e053e8607a013deaeef77aa Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Wed, 13 Dec 2017 10:59:41 -0500 Subject: [PATCH 3/4] Add log for releasing quartz event tap --- src/lib/platform/OSXScreen.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index 864671c9..43fe7615 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -758,6 +758,7 @@ OSXScreen::disable() // FIXME -- stop watching jump zones, stop capturing input if (m_eventTapRLSR) { + LOG((CLOG_DEBUG "releasing quartz event tap")); CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_eventTapRLSR, kCFRunLoopDefaultMode); CFRelease(m_eventTapRLSR); m_eventTapRLSR = nullptr; From 6368207dec27ff2a7d76d2358171bc0eb11b3582 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Wed, 13 Dec 2017 11:47:26 -0500 Subject: [PATCH 4/4] Release quartz event tap in screen Dtor --- src/lib/platform/OSXScreen.mm | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index 43fe7615..9049f33c 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -251,6 +251,13 @@ OSXScreen::~OSXScreen() delete m_keyState; delete m_screensaver; + if (m_eventTapRLSR) { + LOG((CLOG_DEBUG "releasing quartz event tap")); + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_eventTapRLSR, kCFRunLoopDefaultMode); + CFRelease(m_eventTapRLSR); + m_eventTapRLSR = nullptr; + } + if (m_eventTapPort) { CGEventTapEnable(m_eventTapPort, false); CFRelease(m_eventTapPort); @@ -755,20 +762,7 @@ OSXScreen::disable() showCursor(); } - // FIXME -- stop watching jump zones, stop capturing input - - if (m_eventTapRLSR) { - LOG((CLOG_DEBUG "releasing quartz event tap")); - CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_eventTapRLSR, kCFRunLoopDefaultMode); - CFRelease(m_eventTapRLSR); - m_eventTapRLSR = nullptr; - } - - if (m_eventTapPort) { - CGEventTapEnable(m_eventTapPort, false); - CFRelease(m_eventTapPort); - m_eventTapPort = nullptr; - } + // FIXME -- stop watching jump zones, stop capturing input // FIXME -- allow system to enter power saving mode // disable drag handling