Added parts related to event mask. Should be feature complete and the header more or less finalized now, but who knows if it as much as compiles, leave alone runs or works...
This commit is contained in:
@@ -1,13 +1,18 @@
|
|||||||
#include "X11Helper.h"
|
#include "X11Helper.h"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include <X11/Xlib.h> // Display, Window
|
#include <X11/Xlib.h> // Display, Window
|
||||||
|
|
||||||
#include "RageDisplay.h" // RageDisplay
|
#include "RageDisplay.h" // RageDisplay
|
||||||
|
|
||||||
vector<Callback_t> pCBacks; // Callbacks for the rendering thread
|
vector<Callback_t> pCBacks; // Callbacks for the rendering
|
||||||
Display *pDpy; // Running X connection
|
// thread
|
||||||
Window *pWin; // Current window
|
list<long> pMasks; // Currently open masks
|
||||||
unsigned short int pCt = 0; // Number of subsystems using the X connection
|
Display *pDpy; // Running X connection
|
||||||
|
Window *pWin; // Current window
|
||||||
|
unsigned short int pCt = 0; // Number of subsystems using
|
||||||
|
// the X connection
|
||||||
|
|
||||||
bool X11Helper::Go()
|
bool X11Helper::Go()
|
||||||
{
|
{
|
||||||
@@ -26,19 +31,75 @@ Display *X11Helper::Dpy()
|
|||||||
return pDpy;
|
return pDpy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool pApplyMasks()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
long finalMask;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while(i < pMasks.size() )
|
||||||
|
{
|
||||||
|
finalMask |= pMasks[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(XSelectInput(pDpy, pWin, finalMask) == 0) { return false; }
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool X11Helper::OpenMask(long mask)
|
||||||
|
{
|
||||||
|
pMasks.push_back(mask);
|
||||||
|
return pApplyMasks();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool X11Helper::CloseMask(long mask)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
if(pMasks[i] == mask)
|
||||||
|
{
|
||||||
|
pMasks.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
if(i > pMasks.size()-1) { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return pApplyMasks();
|
||||||
|
}
|
||||||
|
|
||||||
bool X11Helper::MakeWindow(int screenNum, int depth, Visual *visual int width=64, int height=64)
|
bool X11Helper::MakeWindow(int screenNum, int depth, Visual *visual int width=64, int height=64)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
if(dpy == NULL) { return false; }
|
if(dpy == NULL) { return false; }
|
||||||
|
|
||||||
XSetWindowAttributes winAttribs;
|
XSetWindowAttributes winAttribs;
|
||||||
|
|
||||||
winAttribs.border_pixel = 0;
|
winAttribs.border_pixel = 0;
|
||||||
winAttribs.event_mask = StructureNotifyMask;
|
|
||||||
|
// XXX: Error catching/handling?
|
||||||
|
|
||||||
winAttribs.colormap = XCreateColorMap(pDpy, RootWindow(pDpy, screenNum),
|
winAttribs.colormap = XCreateColorMap(pDpy, RootWindow(pDpy, screenNum),
|
||||||
visual, AllocNone);
|
visual, AllocNone);
|
||||||
|
|
||||||
pWin = XCreateWindow(pDpy, RootWindow(pDpy, screenNum), 0, 0, width, height
|
pWin = XCreateWindow(pDpy, RootWindow(pDpy, screenNum), 0, 0, width,
|
||||||
|
height, 0, depth, InputOutput, visual,
|
||||||
|
CWBorderPixel | CWColorMap | CWEventMask, &winAttribs);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while(i < pCBacks.size() )
|
||||||
|
{
|
||||||
|
pCBacks[i](pWin);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pApplyMasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool X11Helper::Callback(Callback_t cb)
|
bool X11Helper::Callback(Callback_t cb)
|
||||||
@@ -55,7 +116,10 @@ void X11Helper::Stop()
|
|||||||
if(pCt == 0)
|
if(pCt == 0)
|
||||||
{
|
{
|
||||||
XCloseDisplay(pDpy);
|
XCloseDisplay(pDpy);
|
||||||
|
pMasks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -8,9 +8,11 @@
|
|||||||
|
|
||||||
namespace X11Helper
|
namespace X11Helper
|
||||||
{
|
{
|
||||||
|
// All functions in here that return a bool return true on success, and
|
||||||
|
// false on failure.
|
||||||
|
|
||||||
// Create the connection, if necessary; otherwise do some important
|
// Create the connection, if necessary; otherwise do some important
|
||||||
// internal session-tracking stuff (so you should call this anyway).
|
// internal session-tracking stuff (so you should call this anyway).
|
||||||
// True on success, false failure.
|
|
||||||
bool Go();
|
bool Go();
|
||||||
|
|
||||||
// Get the current Display (connection). Behavior is undefined if you
|
// Get the current Display (connection). Behavior is undefined if you
|
||||||
@@ -19,26 +21,28 @@ namespace X11Helper
|
|||||||
|
|
||||||
// (Re)create the window on the screen of this number with this depth,
|
// (Re)create the window on the screen of this number with this depth,
|
||||||
// this visual type, this width (optional -- you can resize the window
|
// this visual type, this width (optional -- you can resize the window
|
||||||
// in your callback later), and this height (optional). Returns true on
|
// in your callback later), and this height (optional).
|
||||||
// success, false on failure.
|
|
||||||
bool MakeWindow(int screenNum, int depth, Visual *visual, int width=64,
|
bool MakeWindow(int screenNum, int depth, Visual *visual, int width=64,
|
||||||
int height=64);
|
int height=64);
|
||||||
|
|
||||||
// Callback type.
|
// Callback type.
|
||||||
typedef void (*Callback_t)(Window*);
|
typedef void (*Callback_t)(Window*);
|
||||||
|
|
||||||
// TODO: We need to manage event masks here, to keep the InputHandler
|
// Unmask one X event type mask thingy (XSelectInput() arg 3) on the
|
||||||
// and LowLevelWindow code separate.
|
// current window. Masked/unmasked events will carry between windows.
|
||||||
|
bool OpenMask(long mask);
|
||||||
|
|
||||||
|
// (Re)mask one X event type mask thingy (XSelectInput() arg 3) on the
|
||||||
|
// current window. Masked/unmasked events will carry between windows.
|
||||||
|
bool CloseMask(long mask);
|
||||||
|
|
||||||
// Register a callback for new windows (including the initial window).
|
// Register a callback for new windows (including the initial window).
|
||||||
// This callback will be called with 0 if I try to create a new window,
|
// This callback will be called with 0 if I try to create a new window,
|
||||||
// but fail. Returns false if for some really messed up reason it fails
|
// but fail.
|
||||||
// (shouldn't happen), false otherwise
|
|
||||||
bool Callback(Callback_t cb);
|
bool Callback(Callback_t cb);
|
||||||
|
|
||||||
// Destroy the connection, if appropriate; otherwise do some important
|
// Destroy the connection, if appropriate; otherwise do some important
|
||||||
// internal session-tracking stuff (so you should call it anyway).
|
// internal session-tracking stuff (so you should call it anyway).
|
||||||
// True success, false failure.
|
|
||||||
void Stop();
|
void Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user