Temporary close handling for Xlib (needs a proper solution)

This commit is contained in:
2015-11-05 01:28:51 -08:00
parent 4a92735119
commit 1e5ae0c89b
4 changed files with 122 additions and 36 deletions

View File

@@ -45,20 +45,12 @@ static Window GetWindowOfEvent(XEvent* event, bool& windowEvent)
return event->xconfigure.window;
}
case KeyPress:
{
windowEvent = true;
return event->xkey.window;
}
case KeyRelease:
{
windowEvent = true;
return event->xkey.window;
}
case ButtonPress:
{
windowEvent = true;
return event->xbutton.window;
}
case ButtonRelease:
{
windowEvent = true;
@@ -69,6 +61,18 @@ static Window GetWindowOfEvent(XEvent* event, bool& windowEvent)
windowEvent = true;
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:
{
if (event->xgeneric.extension == XINPUT_OPCODE)
@@ -223,12 +227,12 @@ public:
return 1;
/* Spawn client thread */
int clientReturn = 0;
int clientReturn = INT_MIN;
std::thread clientThread([&]()
{clientReturn = m_callback.appMain(this);});
/* Begin application event loop */
while (true)
while (clientReturn == INT_MIN)
{
fd_set fds;
FD_ZERO(&fds);

View File

@@ -451,7 +451,7 @@ public:
XSetWindowAttributes swa;
swa.colormap = m_colormapId;
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,
CopyFromParent, CopyFromParent, selectedVisual,
@@ -471,16 +471,7 @@ public:
/* Register netwm extension atom for window closing */
#if 0
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
XSetWMProtocols(m_xDisp, m_windowId, &S_ATOMS->m_wmDeleteWindow, 1);
/* Set the title of the window */
const unsigned char* c_title = (unsigned char*)title.c_str();
@@ -760,10 +751,21 @@ public:
XEvent* event = (XEvent*)e;
switch (event->type)
{
case ClientMessage:
{
if (event->xclient.data.l[0] == S_ATOMS->m_wmDeleteWindow && m_callback)
m_callback->destroyed();
return;
}
case Expose:
{
m_wx = event->xexpose.x;
m_wy = event->xexpose.y;
Window nw;
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_wh = event->xexpose.height;
if (m_callback)
@@ -776,19 +778,21 @@ public:
}
case ConfigureNotify:
{
if (event->xconfigure.width && event->xconfigure.height)
{
m_wx = event->xconfigure.x;
m_wy = event->xconfigure.y;
m_ww = event->xconfigure.width;
m_wh = event->xconfigure.height;
Window nw;
XWindowAttributes wxa;
int x, 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_wh = event->xconfigure.height;
if (m_callback)
{
SWindowRect rect =
{ {m_wx, m_wy}, {m_ww, m_wh} };
m_callback->resized(rect);
}
if (m_callback)
{
SWindowRect rect =
{ {m_wx, m_wy}, {m_ww, m_wh} };
m_callback->windowMoved(rect);
}
return;
}
@@ -900,6 +904,18 @@ public:
}
return;
}
case FocusIn:
{
if (m_callback)
m_callback->focusGained();
return;
}
case FocusOut:
{
if (m_callback)
m_callback->focusLost();
return;
}
case MotionNotify:
{
if (m_callback)
@@ -915,6 +931,36 @@ public:
}
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:
{
if (event->xgeneric.extension == XINPUT_OPCODE)