Advertisement
Guest User

X11Painter.cpp

a guest
Dec 11th, 2010
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. // X11Painter.cpp
  2. #include "X11Painter.h"
  3.  
  4. X11Painter::~X11Painter()
  5. {
  6.  
  7. }
  8.  
  9. X11Painter::X11Painter()
  10. {
  11.     X11Painter(-1);
  12. }
  13.  
  14. X11Painter::X11Painter(int screenno)
  15. {
  16.     this->some_test = 1234;
  17.     printf("this->some_test=%i\n", this->some_test);
  18.  
  19.     char* display;
  20.     int event_basep, error_basep;
  21.  
  22.     display = getenv("DISPLAY");
  23.     if (!display)
  24.     {
  25.         throw DisplayUnknownException();
  26.     }
  27.  
  28.     this->display = XOpenDisplay(display);
  29.     if (!this->display)
  30.     {
  31.         throw NoDisplayException();
  32.     }
  33.    
  34.     if (screenno == -1)
  35.     {
  36.         this->screen = XDefaultScreen(this->display);
  37.     } else {
  38.         this->screen = screenno;
  39.     }
  40.     printf("this->screen:%i\n",this->screen);
  41.  
  42.     Bool shapeExtensions = XShapeQueryExtension(this->display, &event_basep, &error_basep);
  43.     if (!shapeExtensions)
  44.     {
  45.         throw ShapeExtensionException();
  46.     }
  47.     this->depth = XDefaultDepth(this->display, this->screen);
  48.     this->visual = XDefaultVisual(this->display, this->screen);
  49.    
  50.     {
  51.         this->screenwidth = XDisplayWidth(this->display, this->screen);
  52.         this->screenheight = XDisplayHeight(this->display, this->screen);
  53.         this->xpos = 0;
  54.     }
  55.     this->winattr.event_mask = NoEventMask;
  56.     this->winattr.do_not_propagate_mask = NoEventMask;
  57.     this->winattr.background_pixel = 0;
  58.     this->window = XCreateWindow (
  59.         this->display,
  60.         XRootWindow(this->display, this->screen),
  61.         00,
  62.         100,    100,
  63.         0,
  64.         this->depth,
  65.         InputOutput,
  66.         CopyFromParent,
  67.         0, //CWBackPixel | CWBorderPixel | CWEventMask,
  68.         &(this->winattr)
  69.     );
  70.    
  71.     XStoreName(this->display, this->window, "LaserFinger");
  72.    
  73.     printf("1:: this->display='%p'; this->window='%lu'\n", this->display, (unsigned long)(this->window));
  74.     printf("width: %i\n", this->screenwidth);
  75.     printf("%p\n", this);
  76.  
  77.     printf("this->some_test=%i\n", this->some_test);
  78. }
  79.  
  80. void X11Painter::show()
  81. {
  82.     printf("this->some_test=%i\n", this->some_test);
  83.     XMapWindow(this->display, this->window);
  84. }
  85.  
  86. void X11Painter::showAt(int x, int y)
  87. {
  88.     if (x < 0 || y < 0 || x > this->screenwidth || y > this->screenheight)
  89.     {
  90.         throw WrongPositionException();
  91.     }
  92.     this->show();
  93.     XMoveWindow(this->display, this->window, x, y);
  94. }
  95.  
  96. void X11Painter::hide()
  97. {
  98.     XUnmapWindow(this->display, this->window);
  99.     this->hide();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement