mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-11 10:56:25 +08:00
patch by jerry: fixed new event queue on Mac and Linu
This commit is contained in:
@@ -30,8 +30,8 @@ class CEventQueueTimer { };
|
||||
// COSXEventQueueBuffer
|
||||
//
|
||||
|
||||
COSXEventQueueBuffer::COSXEventQueueBuffer() :
|
||||
m_event(NULL)
|
||||
COSXEventQueueBuffer::COSXEventQueueBuffer(IEventQueue* events) :
|
||||
m_eventQueue(events), m_event(NULL)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
@@ -80,7 +80,7 @@ COSXEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
|
||||
|
||||
default:
|
||||
event = CEvent(CEvent::kSystem,
|
||||
m_events->getSystemTarget(), &m_event);
|
||||
m_eventQueue->getSystemTarget(), &m_event);
|
||||
return kSystem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,12 @@
|
||||
#include <Carbon/Carbon.h>
|
||||
#include "IEventQueueBuffer.h"
|
||||
|
||||
class IEventQueue;
|
||||
|
||||
//! Event queue buffer for OS X
|
||||
class COSXEventQueueBuffer : public IEventQueueBuffer {
|
||||
public:
|
||||
COSXEventQueueBuffer();
|
||||
COSXEventQueueBuffer(IEventQueue* eventQueue);
|
||||
virtual ~COSXEventQueueBuffer();
|
||||
|
||||
// IEventQueueBuffer overrides
|
||||
@@ -39,6 +41,7 @@ public:
|
||||
|
||||
private:
|
||||
EventRef m_event;
|
||||
IEventQueue* m_eventQueue;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -181,6 +181,7 @@ static const CKeyEntry s_controlKeys[] = {
|
||||
//
|
||||
|
||||
COSXKeyState::COSXKeyState(IEventQueue* events) :
|
||||
CKeyState(events),
|
||||
m_deadKeyState(0)
|
||||
{
|
||||
init();
|
||||
|
||||
@@ -64,7 +64,9 @@ enum {
|
||||
bool COSXScreen::s_testedForGHOM = false;
|
||||
bool COSXScreen::s_hasGHOM = false;
|
||||
|
||||
COSXScreen::COSXScreen(bool isPrimary, bool autoShowHideCursor) :
|
||||
COSXScreen::COSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCursor) :
|
||||
CPlatformScreen(events),
|
||||
m_events(events),
|
||||
MouseButtonEventMap(NumButtonIDs),
|
||||
m_isPrimary(isPrimary),
|
||||
m_isOnScreen(m_isPrimary),
|
||||
@@ -98,8 +100,8 @@ COSXScreen::COSXScreen(bool isPrimary, bool autoShowHideCursor) :
|
||||
try {
|
||||
m_displayID = CGMainDisplayID();
|
||||
updateScreenShape(m_displayID, 0);
|
||||
m_screensaver = new COSXScreenSaver(getEventTarget());
|
||||
m_keyState = new COSXKeyState();
|
||||
m_screensaver = new COSXScreenSaver(m_events, getEventTarget());
|
||||
m_keyState = new COSXKeyState(m_events);
|
||||
|
||||
// TODO: http://stackoverflow.com/questions/2950124/enable-access-for-assistive-device-programmatically
|
||||
if (m_isPrimary && !AXAPIEnabled())
|
||||
@@ -178,7 +180,7 @@ COSXScreen::COSXScreen(bool isPrimary, bool autoShowHideCursor) :
|
||||
&COSXScreen::handleSystemEvent));
|
||||
|
||||
// install the platform event queue
|
||||
m_events->adoptBuffer(new COSXEventQueueBuffer);
|
||||
m_events->adoptBuffer(new COSXEventQueueBuffer(m_events));
|
||||
}
|
||||
|
||||
COSXScreen::~COSXScreen()
|
||||
@@ -1036,7 +1038,7 @@ COSXScreen::onMouseMove(SInt32 mx, SInt32 my)
|
||||
|
||||
if (m_isOnScreen) {
|
||||
// motion on primary screen
|
||||
sendEvent(m_events->forIScreen().motionOnPrimary(),
|
||||
sendEvent(m_events->forIPrimaryScreen().motionOnPrimary(),
|
||||
CMotionInfo::alloc(m_xCursor, m_yCursor));
|
||||
}
|
||||
else {
|
||||
@@ -1058,7 +1060,7 @@ COSXScreen::onMouseMove(SInt32 mx, SInt32 my)
|
||||
}
|
||||
else {
|
||||
// send motion
|
||||
sendEvent(m_events->forIScreen().motionOnSecondary(), CMotionInfo::alloc(x, y));
|
||||
sendEvent(m_events->forIPrimaryScreen().motionOnSecondary(), CMotionInfo::alloc(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1494,7 +1496,7 @@ COSXScreen::updateScreenShape()
|
||||
|
||||
delete[] displays;
|
||||
// We want to notify the peer screen whether we are primary screen or not
|
||||
sendEvent(m_events->forIPrimaryScreen().shapeChanged());
|
||||
sendEvent(m_events->forIScreen().shapeChanged());
|
||||
|
||||
LOG((CLOG_DEBUG "screen shape: center=%d,%d size=%dx%d on %u %s",
|
||||
m_x, m_y, m_w, m_h, displayCount,
|
||||
@@ -1518,15 +1520,16 @@ COSXScreen::userSwitchCallback(EventHandlerCallRef nextHandler,
|
||||
{
|
||||
COSXScreen* screen = (COSXScreen*)inUserData;
|
||||
UInt32 kind = GetEventKind(theEvent);
|
||||
IEventQueue* events = screen->getEvents();
|
||||
|
||||
if (kind == kEventSystemUserSessionDeactivated) {
|
||||
LOG((CLOG_DEBUG "user session deactivated"));
|
||||
m_events->addEvent(CEvent(m_events->forIScreen().suspend(),
|
||||
events->addEvent(CEvent(events->forIScreen().suspend(),
|
||||
screen->getEventTarget()));
|
||||
}
|
||||
else if (kind == kEventSystemUserSessionActivated) {
|
||||
LOG((CLOG_DEBUG "user session activated"));
|
||||
m_events->addEvent(CEvent(m_events->forIScreen().resume(),
|
||||
events->addEvent(CEvent(events->forIScreen().resume(),
|
||||
screen->getEventTarget()));
|
||||
}
|
||||
return (CallNextEventHandler(nextHandler, theEvent));
|
||||
|
||||
@@ -49,13 +49,16 @@ class CMutex;
|
||||
class CThread;
|
||||
class COSXKeyState;
|
||||
class COSXScreenSaver;
|
||||
class IEventQueue;
|
||||
|
||||
//! Implementation of IPlatformScreen for OS X
|
||||
class COSXScreen : public CPlatformScreen {
|
||||
public:
|
||||
COSXScreen(bool isPrimary, bool autoShowHideCursor=true);
|
||||
COSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCursor=true);
|
||||
virtual ~COSXScreen();
|
||||
|
||||
IEventQueue* getEvents() const { return m_events; }
|
||||
|
||||
// IScreen overrides
|
||||
virtual void* getEventTarget() const;
|
||||
virtual bool getClipboard(ClipboardID id, IClipboard*) const;
|
||||
@@ -335,6 +338,8 @@ private:
|
||||
|
||||
// cursor will hide and show on enable and disable if true.
|
||||
bool m_autoShowHideCursor;
|
||||
|
||||
IEventQueue* m_events;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
// COSXScreenSaver
|
||||
//
|
||||
|
||||
COSXScreenSaver::COSXScreenSaver(void* eventTarget) :
|
||||
COSXScreenSaver::COSXScreenSaver(IEventQueue* events, void* eventTarget) :
|
||||
m_events(events),
|
||||
m_eventTarget(eventTarget),
|
||||
m_enabled(true)
|
||||
{
|
||||
|
||||
@@ -22,10 +22,12 @@
|
||||
#include "IScreenSaver.h"
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
class IEventQueue;
|
||||
|
||||
//! OSX screen saver implementation
|
||||
class COSXScreenSaver : public IScreenSaver {
|
||||
public:
|
||||
COSXScreenSaver(void* eventTarget);
|
||||
COSXScreenSaver(IEventQueue* events, void* eventTarget);
|
||||
virtual ~COSXScreenSaver();
|
||||
|
||||
// IScreenSaver overrides
|
||||
@@ -53,6 +55,7 @@ private:
|
||||
void* m_autoReleasePool;
|
||||
EventHandlerRef m_launchTerminationEventHandlerRef;
|
||||
ProcessSerialNumber m_screenSaverPSN;
|
||||
IEventQueue* m_events;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -51,7 +51,8 @@ class CEventQueueTimer { };
|
||||
//
|
||||
|
||||
CXWindowsEventQueueBuffer::CXWindowsEventQueueBuffer(
|
||||
Display* display, Window window) :
|
||||
Display* display, Window window, IEventQueue* events) :
|
||||
m_events(events),
|
||||
m_display(display),
|
||||
m_window(window),
|
||||
m_waiting(false)
|
||||
|
||||
@@ -28,10 +28,12 @@
|
||||
# include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
class IEventQueue;
|
||||
|
||||
//! Event queue buffer for X11
|
||||
class CXWindowsEventQueueBuffer : public IEventQueueBuffer {
|
||||
public:
|
||||
CXWindowsEventQueueBuffer(Display*, Window);
|
||||
CXWindowsEventQueueBuffer(Display*, Window, IEventQueue* events);
|
||||
virtual ~CXWindowsEventQueueBuffer();
|
||||
|
||||
// IEventQueueBuffer overrides
|
||||
@@ -56,7 +58,8 @@ private:
|
||||
XEvent m_event;
|
||||
CEventList m_postedEvents;
|
||||
bool m_waiting;
|
||||
int m_pipefd[2];
|
||||
int m_pipefd[2];
|
||||
IEventQueue* m_events;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,7 +38,10 @@
|
||||
|
||||
static const size_t ModifiersFromXDefaultSize = 32;
|
||||
|
||||
CXWindowsKeyState::CXWindowsKeyState(Display* display, bool useXKB) :
|
||||
CXWindowsKeyState::CXWindowsKeyState(
|
||||
Display* display, bool useXKB,
|
||||
IEventQueue* events) :
|
||||
CKeyState(events),
|
||||
m_display(display),
|
||||
m_modifierFromX(ModifiersFromXDefaultSize)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
class IEventQueue;
|
||||
|
||||
//! X Windows key state
|
||||
/*!
|
||||
A key state for X Windows.
|
||||
@@ -48,7 +50,7 @@ public:
|
||||
kGroupPollAndSet = -2
|
||||
};
|
||||
|
||||
CXWindowsKeyState(Display*, bool useXKB);
|
||||
CXWindowsKeyState(Display*, bool useXKB, IEventQueue* events);
|
||||
CXWindowsKeyState(Display*, bool useXKB,
|
||||
IEventQueue* events, CKeyMap& keyMap);
|
||||
~CXWindowsKeyState();
|
||||
|
||||
@@ -88,7 +88,12 @@ static int xi_opcode;
|
||||
|
||||
CXWindowsScreen* CXWindowsScreen::s_screen = NULL;
|
||||
|
||||
CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, bool disableXInitThreads, int mouseScrollDelta, IEventQueue* events) :
|
||||
CXWindowsScreen::CXWindowsScreen(
|
||||
const char* displayName,
|
||||
bool isPrimary,
|
||||
bool disableXInitThreads,
|
||||
int mouseScrollDelta,
|
||||
IEventQueue* events) :
|
||||
m_isPrimary(isPrimary),
|
||||
m_mouseScrollDelta(mouseScrollDelta),
|
||||
m_display(NULL),
|
||||
@@ -185,7 +190,8 @@ CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, bool d
|
||||
&CXWindowsScreen::handleSystemEvent));
|
||||
|
||||
// install the platform event queue
|
||||
m_events->adoptBuffer(new CXWindowsEventQueueBuffer(m_display, m_window));
|
||||
m_events->adoptBuffer(new CXWindowsEventQueueBuffer(
|
||||
m_display, m_window, m_events));
|
||||
}
|
||||
|
||||
CXWindowsScreen::~CXWindowsScreen()
|
||||
@@ -1317,7 +1323,7 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*)
|
||||
if (id != kClipboardEnd) {
|
||||
LOG((CLOG_DEBUG "lost clipboard %d ownership at time %d", id, xevent->xselectionclear.time));
|
||||
m_clipboard[id]->lost(xevent->xselectionclear.time);
|
||||
sendClipboardEvent(m_events->forIPrimaryScreen().clipboardGrabbed(), id);
|
||||
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1731,7 +1737,7 @@ CXWindowsScreen::onError()
|
||||
m_display = NULL;
|
||||
|
||||
// notify of failure
|
||||
sendEvent(m_events->forIPrimaryScreen().error(), NULL);
|
||||
sendEvent(m_events->forIScreen().error(), NULL);
|
||||
|
||||
// FIXME -- should ensure that we ignore operations that involve
|
||||
// m_display from now on. however, Xlib will simply exit the
|
||||
|
||||
@@ -36,7 +36,9 @@ class CXWindowsScreenSaver;
|
||||
//! Implementation of IPlatformScreen for X11
|
||||
class CXWindowsScreen : public CPlatformScreen {
|
||||
public:
|
||||
CXWindowsScreen(const char* displayName, bool isPrimary, bool disableXInitThreads, int mouseScrollDelta, IEventQueue* events);
|
||||
CXWindowsScreen(const char* displayName, bool isPrimary,
|
||||
bool disableXInitThreads, int mouseScrollDelta,
|
||||
IEventQueue* events);
|
||||
virtual ~CXWindowsScreen();
|
||||
|
||||
//! @name manipulators
|
||||
|
||||
@@ -398,12 +398,12 @@ CXWindowsScreenSaver::setXScreenSaverActive(bool activated)
|
||||
|
||||
if (activated) {
|
||||
m_events->addEvent(CEvent(
|
||||
m_events->forIPlatformScreen().screensaverActivated(),
|
||||
m_events->forIPrimaryScreen().screensaverActivated(),
|
||||
m_eventTarget));
|
||||
}
|
||||
else {
|
||||
m_events->addEvent(CEvent(
|
||||
m_events->forIPlatformScreen().screensaverDeactivated(),
|
||||
m_events->forIPrimaryScreen().screensaverDeactivated(),
|
||||
m_eventTarget));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user