37 lines
628 B
C++
37 lines
628 B
C++
|
|
#include "X11SharedDisplay.h"
|
|
|
|
namespace sp {
|
|
|
|
// Define a global display (for simplicity, we always connect to local one.)
|
|
::Display* sharedDisplay = NULL;
|
|
unsigned int refcount = 0;
|
|
|
|
::Display* XGetDisplay() {
|
|
|
|
// Create if we dont have any references.
|
|
if (refcount == 0) {
|
|
sharedDisplay = XOpenDisplay(NULL);
|
|
}
|
|
|
|
refcount++;
|
|
return sharedDisplay;
|
|
}
|
|
|
|
void XReleaseDisplay() {
|
|
|
|
if (refcount < 1) {
|
|
return;
|
|
}
|
|
|
|
if (--refcount == 0) {
|
|
XCloseDisplay(sharedDisplay);
|
|
}
|
|
}
|
|
|
|
Atom getAtom(const std::string& name, bool onlyIfExists) {
|
|
|
|
return XInternAtom(sharedDisplay, name.c_str(), onlyIfExists);
|
|
}
|
|
|
|
} // namespace sp
|