]> icculus.org git repositories - mikachu/openbox.git/blob - otk/surface.cc
remove the XImage from Surface
[mikachu/openbox.git] / otk / surface.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef    HAVE_CONFIG_H
4 #  include "../config.h"
5 #endif // HAVE_CONFIG_H
6
7 #include "surface.hh"
8 #include "display.hh"
9 #include "screeninfo.hh"
10
11 extern "C" {
12 #include <X11/Xutil.h>
13 }
14
15 namespace otk {
16
17 Surface::Surface(int screen)
18   : _screen(screen),
19     _size(1, 1),
20     _pm(None),
21     _xftdraw(0)
22 {
23   createObjects();
24 }
25
26 Surface::Surface(int screen, const Point &size)
27   : _screen(screen),
28     _size(size),
29     _pm(None),
30     _xftdraw(0)
31 {
32   createObjects();
33 }
34
35 Surface::~Surface()
36 {
37   destroyObjects();
38 }
39
40 void Surface::createObjects()
41 {
42   assert(_pm == None); assert(!_xftdraw);
43
44   const ScreenInfo *info = display->screenInfo(_screen);
45   
46   _pm = XCreatePixmap(**display, info->rootWindow(), _size.x(), _size.y(),
47                       info->depth());
48
49   _xftdraw = XftDrawCreate(**display, _pm, info->visual(), info->colormap());
50 }
51
52 void Surface::destroyObjects()
53 {
54   assert(_pm != None); assert(_xftdraw);
55
56   XftDrawDestroy(_xftdraw);
57   _xftdraw = 0;
58
59   XFreePixmap(**display, _pm);
60   _pm = None;
61 }
62
63 void Surface::setSize(int w, int h)
64 {
65   if (w == _size.x() && h == _size.y()) return; // no change
66   
67   _size.setPoint(w, h);
68   destroyObjects();
69   createObjects();
70 }
71
72 }