mirror of https://github.com/AxioDL/boo.git
Temporary close handling for Xlib (needs a proper solution)
This commit is contained in:
parent
4a92735119
commit
1e5ae0c89b
|
@ -98,6 +98,10 @@ public:
|
||||||
{(void)coord;(void)button;(void)mods;}
|
{(void)coord;(void)button;(void)mods;}
|
||||||
virtual void mouseMove(const SWindowCoord& coord)
|
virtual void mouseMove(const SWindowCoord& coord)
|
||||||
{(void)coord;}
|
{(void)coord;}
|
||||||
|
virtual void mouseEnter(const SWindowCoord& coord)
|
||||||
|
{(void)coord;}
|
||||||
|
virtual void mouseLeave(const SWindowCoord& coord)
|
||||||
|
{(void)coord;}
|
||||||
virtual void scroll(const SWindowCoord& coord, const SScrollDelta& scroll)
|
virtual void scroll(const SWindowCoord& coord, const SScrollDelta& scroll)
|
||||||
{(void)coord;(void)scroll;}
|
{(void)coord;(void)scroll;}
|
||||||
|
|
||||||
|
@ -119,6 +123,13 @@ public:
|
||||||
virtual void modKeyDown(EModifierKey mod, bool isRepeat)
|
virtual void modKeyDown(EModifierKey mod, bool isRepeat)
|
||||||
{(void)mod;(void)isRepeat;}
|
{(void)mod;(void)isRepeat;}
|
||||||
virtual void modKeyUp(EModifierKey mod) {(void)mod;}
|
virtual void modKeyUp(EModifierKey mod) {(void)mod;}
|
||||||
|
virtual void focusLost() {}
|
||||||
|
virtual void focusGained() {}
|
||||||
|
virtual void windowMoved(const SWindowRect& rect)
|
||||||
|
{ (void)rect; }
|
||||||
|
|
||||||
|
virtual void destroyed()
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ETouchType
|
enum ETouchType
|
||||||
|
|
|
@ -45,20 +45,12 @@ static Window GetWindowOfEvent(XEvent* event, bool& windowEvent)
|
||||||
return event->xconfigure.window;
|
return event->xconfigure.window;
|
||||||
}
|
}
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
{
|
|
||||||
windowEvent = true;
|
|
||||||
return event->xkey.window;
|
|
||||||
}
|
|
||||||
case KeyRelease:
|
case KeyRelease:
|
||||||
{
|
{
|
||||||
windowEvent = true;
|
windowEvent = true;
|
||||||
return event->xkey.window;
|
return event->xkey.window;
|
||||||
}
|
}
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
{
|
|
||||||
windowEvent = true;
|
|
||||||
return event->xbutton.window;
|
|
||||||
}
|
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
{
|
{
|
||||||
windowEvent = true;
|
windowEvent = true;
|
||||||
|
@ -69,6 +61,18 @@ static Window GetWindowOfEvent(XEvent* event, bool& windowEvent)
|
||||||
windowEvent = true;
|
windowEvent = true;
|
||||||
return event->xmotion.window;
|
return event->xmotion.window;
|
||||||
}
|
}
|
||||||
|
case EnterNotify:
|
||||||
|
case LeaveNotify:
|
||||||
|
{
|
||||||
|
windowEvent = true;
|
||||||
|
return event->xcrossing.window;
|
||||||
|
}
|
||||||
|
case FocusIn:
|
||||||
|
case FocusOut:
|
||||||
|
{
|
||||||
|
windowEvent = true;
|
||||||
|
return event->xfocus.window;
|
||||||
|
}
|
||||||
case GenericEvent:
|
case GenericEvent:
|
||||||
{
|
{
|
||||||
if (event->xgeneric.extension == XINPUT_OPCODE)
|
if (event->xgeneric.extension == XINPUT_OPCODE)
|
||||||
|
@ -223,12 +227,12 @@ public:
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Spawn client thread */
|
/* Spawn client thread */
|
||||||
int clientReturn = 0;
|
int clientReturn = INT_MIN;
|
||||||
std::thread clientThread([&]()
|
std::thread clientThread([&]()
|
||||||
{clientReturn = m_callback.appMain(this);});
|
{clientReturn = m_callback.appMain(this);});
|
||||||
|
|
||||||
/* Begin application event loop */
|
/* Begin application event loop */
|
||||||
while (true)
|
while (clientReturn == INT_MIN)
|
||||||
{
|
{
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
|
|
|
@ -451,7 +451,7 @@ public:
|
||||||
XSetWindowAttributes swa;
|
XSetWindowAttributes swa;
|
||||||
swa.colormap = m_colormapId;
|
swa.colormap = m_colormapId;
|
||||||
swa.border_pixmap = None;
|
swa.border_pixmap = None;
|
||||||
swa.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | StructureNotifyMask;
|
swa.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | StructureNotifyMask | LeaveWindowMask | EnterWindowMask;
|
||||||
|
|
||||||
m_windowId = XCreateWindow(display, screen->root, x, y, w, h, 10,
|
m_windowId = XCreateWindow(display, screen->root, x, y, w, h, 10,
|
||||||
CopyFromParent, CopyFromParent, selectedVisual,
|
CopyFromParent, CopyFromParent, selectedVisual,
|
||||||
|
@ -471,16 +471,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/* Register netwm extension atom for window closing */
|
/* Register netwm extension atom for window closing */
|
||||||
#if 0
|
XSetWMProtocols(m_xDisp, m_windowId, &S_ATOMS->m_wmDeleteWindow, 1);
|
||||||
xcb_change_property(m_xcbConn, XCB_PROP_MODE_REPLACE, m_windowId, S_ATOMS->m_wmProtocols,
|
|
||||||
XCB_ATOM_ATOM, 32, 1, &S_ATOMS->m_wmDeleteWindow);
|
|
||||||
const xcb_atom_t wm_protocols[1] = {
|
|
||||||
S_ATOMS->m_wmDeleteWindow,
|
|
||||||
};
|
|
||||||
xcb_change_property(m_xcbConn, XCB_PROP_MODE_REPLACE, m_windowId,
|
|
||||||
S_ATOMS->m_wmProtocols, 4,
|
|
||||||
32, 1, wm_protocols);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set the title of the window */
|
/* Set the title of the window */
|
||||||
const unsigned char* c_title = (unsigned char*)title.c_str();
|
const unsigned char* c_title = (unsigned char*)title.c_str();
|
||||||
|
@ -760,10 +751,21 @@ public:
|
||||||
XEvent* event = (XEvent*)e;
|
XEvent* event = (XEvent*)e;
|
||||||
switch (event->type)
|
switch (event->type)
|
||||||
{
|
{
|
||||||
|
case ClientMessage:
|
||||||
|
{
|
||||||
|
if (event->xclient.data.l[0] == S_ATOMS->m_wmDeleteWindow && m_callback)
|
||||||
|
m_callback->destroyed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
case Expose:
|
case Expose:
|
||||||
{
|
{
|
||||||
m_wx = event->xexpose.x;
|
Window nw;
|
||||||
m_wy = event->xexpose.y;
|
XWindowAttributes wxa;
|
||||||
|
int x, y;
|
||||||
|
XTranslateCoordinates(m_xDisp, m_windowId, DefaultRootWindow(m_xDisp), event->xexpose.x, event->xexpose.y, &x, &y, &nw);
|
||||||
|
XGetWindowAttributes(m_xDisp, m_windowId, &wxa);
|
||||||
|
m_wx = x - wxa.x;
|
||||||
|
m_wy = y - wxa.y;
|
||||||
m_ww = event->xexpose.width;
|
m_ww = event->xexpose.width;
|
||||||
m_wh = event->xexpose.height;
|
m_wh = event->xexpose.height;
|
||||||
if (m_callback)
|
if (m_callback)
|
||||||
|
@ -776,10 +778,13 @@ public:
|
||||||
}
|
}
|
||||||
case ConfigureNotify:
|
case ConfigureNotify:
|
||||||
{
|
{
|
||||||
if (event->xconfigure.width && event->xconfigure.height)
|
Window nw;
|
||||||
{
|
XWindowAttributes wxa;
|
||||||
m_wx = event->xconfigure.x;
|
int x, y;
|
||||||
m_wy = event->xconfigure.y;
|
XTranslateCoordinates(m_xDisp, m_windowId, DefaultRootWindow(m_xDisp), event->xconfigure.x, event->xconfigure.y, &x, &y, &nw);
|
||||||
|
XGetWindowAttributes(m_xDisp, m_windowId, &wxa);
|
||||||
|
m_wx = x - wxa.x;
|
||||||
|
m_wy = y - wxa.y;
|
||||||
m_ww = event->xconfigure.width;
|
m_ww = event->xconfigure.width;
|
||||||
m_wh = event->xconfigure.height;
|
m_wh = event->xconfigure.height;
|
||||||
|
|
||||||
|
@ -787,8 +792,7 @@ public:
|
||||||
{
|
{
|
||||||
SWindowRect rect =
|
SWindowRect rect =
|
||||||
{ {m_wx, m_wy}, {m_ww, m_wh} };
|
{ {m_wx, m_wy}, {m_ww, m_wh} };
|
||||||
m_callback->resized(rect);
|
m_callback->windowMoved(rect);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -900,6 +904,18 @@ public:
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case FocusIn:
|
||||||
|
{
|
||||||
|
if (m_callback)
|
||||||
|
m_callback->focusGained();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case FocusOut:
|
||||||
|
{
|
||||||
|
if (m_callback)
|
||||||
|
m_callback->focusLost();
|
||||||
|
return;
|
||||||
|
}
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
{
|
{
|
||||||
if (m_callback)
|
if (m_callback)
|
||||||
|
@ -915,6 +931,36 @@ public:
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case EnterNotify:
|
||||||
|
{
|
||||||
|
if (m_callback)
|
||||||
|
{
|
||||||
|
getWindowFrame(m_wx, m_wy, m_ww, m_wh);
|
||||||
|
SWindowCoord coord =
|
||||||
|
{
|
||||||
|
{(unsigned)event->xcrossing.x, (unsigned)event->xcrossing.y},
|
||||||
|
{(unsigned)(event->xcrossing.x / m_pixelFactor), (unsigned)(event->xmotion.y / m_pixelFactor)},
|
||||||
|
{event->xcrossing.x / (float)m_ww, event->xcrossing.y / (float)m_wh}
|
||||||
|
};
|
||||||
|
m_callback->mouseEnter(coord);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case LeaveNotify:
|
||||||
|
{
|
||||||
|
if (m_callback)
|
||||||
|
{
|
||||||
|
getWindowFrame(m_wx, m_wy, m_ww, m_wh);
|
||||||
|
SWindowCoord coord =
|
||||||
|
{
|
||||||
|
{(unsigned)event->xcrossing.x, (unsigned)event->xcrossing.y},
|
||||||
|
{(unsigned)(event->xcrossing.x / m_pixelFactor), (unsigned)(event->xmotion.y / m_pixelFactor)},
|
||||||
|
{event->xcrossing.x / (float)m_ww, event->xcrossing.y / (float)m_wh}
|
||||||
|
};
|
||||||
|
m_callback->mouseLeave(coord);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
case GenericEvent:
|
case GenericEvent:
|
||||||
{
|
{
|
||||||
if (event->xgeneric.extension == XINPUT_OPCODE)
|
if (event->xgeneric.extension == XINPUT_OPCODE)
|
||||||
|
|
|
@ -128,6 +128,7 @@ struct CTestWindowCallback : IWindowCallback
|
||||||
bool m_fullscreenToggleRequested = false;
|
bool m_fullscreenToggleRequested = false;
|
||||||
SWindowRect m_lastRect;
|
SWindowRect m_lastRect;
|
||||||
bool m_rectDirty = false;
|
bool m_rectDirty = false;
|
||||||
|
bool m_windowInvalid = false;
|
||||||
|
|
||||||
void resized(const SWindowRect& rect)
|
void resized(const SWindowRect& rect)
|
||||||
{
|
{
|
||||||
|
@ -148,6 +149,14 @@ struct CTestWindowCallback : IWindowCallback
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Mouse Move (%f,%f)\n", coord.norm[0], coord.norm[1]);
|
fprintf(stderr, "Mouse Move (%f,%f)\n", coord.norm[0], coord.norm[1]);
|
||||||
}
|
}
|
||||||
|
void mouseEnter(const SWindowCoord &coord)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Mouse entered (%f,%f)\n", coord.norm[0], coord.norm[1]);
|
||||||
|
}
|
||||||
|
void mouseLeave(const SWindowCoord &coord)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Mouse left (%f,%f)\n", coord.norm[0], coord.norm[1]);
|
||||||
|
}
|
||||||
void scroll(const SWindowCoord& coord, const SScrollDelta& scroll)
|
void scroll(const SWindowCoord& coord, const SScrollDelta& scroll)
|
||||||
{
|
{
|
||||||
//fprintf(stderr, "Mouse Scroll (%f,%f) (%f,%f)\n", coord.norm[0], coord.norm[1], scroll.delta[0], scroll.delta[1]);
|
//fprintf(stderr, "Mouse Scroll (%f,%f) (%f,%f)\n", coord.norm[0], coord.norm[1], scroll.delta[0], scroll.delta[1]);
|
||||||
|
@ -192,6 +201,16 @@ struct CTestWindowCallback : IWindowCallback
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void windowMoved(const SWindowRect& rect)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Moved %d, %d (%d, %d)\n", rect.size[0], rect.size[1], rect.location[0], rect.location[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyed()
|
||||||
|
{
|
||||||
|
m_windowInvalid = true;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TestApplicationCallback : IApplicationCallback
|
struct TestApplicationCallback : IApplicationCallback
|
||||||
|
@ -367,6 +386,12 @@ struct TestApplicationCallback : IApplicationCallback
|
||||||
size_t lastCheck = 0;
|
size_t lastCheck = 0;
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
|
if (windowCallback.m_windowInvalid)
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
mainWindow->waitForRetrace();
|
mainWindow->waitForRetrace();
|
||||||
|
|
||||||
if (windowCallback.m_rectDirty)
|
if (windowCallback.m_rectDirty)
|
||||||
|
|
Loading…
Reference in New Issue