// X11Painter.cpp
#include "X11Painter.h"
X11Painter::~X11Painter()
{
}
X11Painter::X11Painter()
{
X11Painter(-1);
}
X11Painter::X11Painter(int screenno)
{
this->some_test = 1234;
printf("this->some_test=%i\n", this->some_test);
char* display;
int event_basep, error_basep;
display = getenv("DISPLAY");
if (!display)
{
throw DisplayUnknownException();
}
this->display = XOpenDisplay(display);
if (!this->display)
{
throw NoDisplayException();
}
if (screenno == -1)
{
this->screen = XDefaultScreen(this->display);
} else {
this->screen = screenno;
}
printf("this->screen:%i\n",this->screen);
Bool shapeExtensions = XShapeQueryExtension(this->display, &event_basep, &error_basep);
if (!shapeExtensions)
{
throw ShapeExtensionException();
}
this->depth = XDefaultDepth(this->display, this->screen);
this->visual = XDefaultVisual(this->display, this->screen);
{
this->screenwidth = XDisplayWidth(this->display, this->screen);
this->screenheight = XDisplayHeight(this->display, this->screen);
this->xpos = 0;
}
this->winattr.event_mask = NoEventMask;
this->winattr.do_not_propagate_mask = NoEventMask;
this->winattr.background_pixel = 0;
this->window = XCreateWindow (
this->display,
XRootWindow(this->display, this->screen),
0, 0,
100, 100,
0,
this->depth,
InputOutput,
CopyFromParent,
0, //CWBackPixel | CWBorderPixel | CWEventMask,
&(this->winattr)
);
XStoreName(this->display, this->window, "LaserFinger");
printf("1:: this->display='%p'; this->window='%lu'\n", this->display, (unsigned long)(this->window));
printf("width: %i\n", this->screenwidth);
printf("%p\n", this);
printf("this->some_test=%i\n", this->some_test);
}
void X11Painter::show()
{
printf("this->some_test=%i\n", this->some_test);
XMapWindow(this->display, this->window);
}
void X11Painter::showAt(int x, int y)
{
if (x < 0 || y < 0 || x > this->screenwidth || y > this->screenheight)
{
throw WrongPositionException();
}
this->show();
XMoveWindow(this->display, this->window, x, y);
}
void X11Painter::hide()
{
XUnmapWindow(this->display, this->window);
this->hide();
}