Back to index

unity  6.0.0
x11-window.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical Ltd.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Authored By:
00019  * Sam Spilsbury <sam.spilsbury@canonical.com>
00020  */
00021 
00022 #include "x11-window.h"
00023 
00024 #ifndef _GNU_SOURCE
00025 #define _GNU_SOURCE
00026 #endif
00027 
00028 X11Window::X11Window (Display *dpy, Window id)
00029 {
00030   if (id == 0)
00031   {
00032     XSetWindowAttributes attrib;
00033     XEvent                e;
00034 
00035     attrib.background_pixel = 0x0;
00036     attrib.backing_pixel = 0x0;
00037 
00038     id = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0, 100, 100, 0,
00039                         DefaultDepth (dpy, DefaultScreen (dpy)), InputOutput,
00040                         DefaultVisual (dpy, DefaultScreen (dpy)), CWBackingPixel | CWBackPixel, &attrib);
00041 
00042     XSelectInput (dpy, id, ExposureMask | StructureNotifyMask);
00043     XMapRaised (dpy, id);
00044 
00045     while (1)
00046     {
00047       XNextEvent (dpy, &e);
00048       bool exposed = false;
00049 
00050       switch (e.type)
00051       {
00052       case Expose:
00053         if (e.xexpose.window == id)
00054           exposed = true;
00055         break;
00056       default:
00057         break;
00058       }
00059 
00060       if (exposed)
00061         break;
00062     }
00063 
00064     XClearWindow (dpy, id);
00065 
00066     mCreated = true;
00067   }
00068   else
00069     mCreated = false;
00070 
00071   mXid = id;
00072   mDpy = dpy;
00073 }
00074 
00075 X11Window::~X11Window ()
00076 {
00077   if (mCreated)
00078     XDestroyWindow (mDpy, mXid);
00079 }