This is old C++ code originally intended to be a playground for 3D math.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

194 lines
6.2 KiB

/**
* \file xclass.h
*
* \brief Drei Klassen für die zentralen XWindows Objekte.
*
* Verpackt die drei zentralen Elemente für ein XWindows Programm
* in drei Klassen.
* <ul type="circle">
* <li>\ref xdisplay f&uuml;r das display</li>
* <li>\ref xscreen f&uuml;r alle screens</li>
* <li>\ref xwindow f&uuml;r alle windows</li>
* </ul>
* Dabei ist die Struktur so das zu ein display aus 1-n screens bestehen
* In denen dann wiederum jeweils 1-n windows existieren. Es existiert
* mindestens das rootwindow.
* Alle in dieser Datei definierten Klassen arbeiten sehr eng zusammen,
* daher ist jede friend der aller anderen.
*
* \author Georg Steffers <georg@steffers.org>
*
* \date 04.12.2003
*
* \version ..2001 (Georg Steffers): erste implementation
* \version 2001-2003 (Georg Steffers): diverse Modifikationen
* \version 05.12.2003 (Georg Steffers): beginn der Dokumentation via doxygen
*/
/*
* Copyright (C)2003 Georg Steffers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __xclass_h__
#define __xclass_h__
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/extensions/Xdbe.h>
class xscreen;
class xwindow;
/**
* \brief Das Display ist die Verbindung zum X-Server
*
* Verbindung zum X-Server, entwerder &uuml;ber TCP/IP oder
* Unix Domain Sockets. Je nach Server und Hardware auf der dieser
* l&auml;ft kann dieser 1-n screens zur verf&uuml;gung stellen.
* Es existiert zumindest der \ref default_screen.
*/
class xdisplay {
friend class xscreen; //!< Da ein xscreen sehr eng mit einem xdisplay
//! zusammenarbeitet
friend class xwindow; //!< Da ein xwindow sehr eng mit einem xdisplay
//! zusammenarbeitet
private:
// Exceptionklassen
class noconnect_exception {}; //!< no connection to display
class nofont_exception {}; //!< no font-file to load
Display* display; //!< \brief Der Descriptor f&uuml;r die eigentliche
//! Verbindung zum X-Server
char* display_name; //!< \brief Hardwarename des Displays
//!
//! Wenn display_name NULL ist, so wird f&uuml;r
//! den Hardwarenamen der Wert der in der
//! Environmentvariable \$DISPLAY steht genommen.
int screen_anz; //<! Anzahl moeglicher screens dieses Displays
int default_screen; //<! default screen dieses Displays
xscreen** screens; //<! Liste aller screens dieses Displays
int wincount; //<! Anzahle der existierenden Windows
xwindow** wins; //<! Referenz zu allen Windows
XFontStruct* font_info; //<! Fontinformationen
public:
xdisplay(char* name=NULL); //!< Defaultkonstruktor
xdisplay(const xdisplay&); //!< Copyconstruktor
~xdisplay(); //!< Destruktor
xdisplay& operator=(const xdisplay&); //!< Zuweisungsoperator
// Queryfunktionen...
Display* getdisplay(void) { return display; }
XFontStruct* getfont(void) { return font_info; }
xwindow* getXwinById(Window id);
xscreen* defaultscreen(void);
int defaultscreenid(void) { return default_screen; }
void loadfont(char* name="9x15");
};
class xscreen {
friend class xwindow;
friend class xdisplay;
private:
xdisplay* x_disp;
int screen_num;
Screen* screen;
xwindow* rootwin;
unsigned int width;
unsigned int height;
Visual* vis;
XVisualInfo vi;
int depth;
int bytespp;
int scanline_pad;
GC gc;
Colormap default_cm;
unsigned long black_pixel;
unsigned long white_pixel;
public:
xscreen(xdisplay* disp=NULL, int screen_num=-1);
xscreen(const xscreen&);
~xscreen();
xscreen& operator=(const xscreen&);
// queryfunktionen.....
Screen* getscreen(void) { return screen; }
int getscreennum(void) {return screen_num; }
xdisplay* getxdisp(void) { return x_disp; }
Visual* getvisual(void) { return vis; }
int getdepth(void) { return depth; }
int getbytespp(void) { return bytespp; }
int getscanlinepad(void) { return scanline_pad; }
GC getgc(void) { return gc; }
unsigned getwidth(void) { return width; }
unsigned getheight(void) { return height; }
xwindow* getrootwin(void) { return rootwin; }
Colormap getdefaultcm(void) { return default_cm; }
unsigned long blackpixel(void) { return black_pixel; }
unsigned long whitepixel(void) { return white_pixel; }
unsigned long getcolor(unsigned short, unsigned short,
unsigned short);
};
class xwindow {
friend class xscreen;
friend class xdisplay;
private:
xscreen* screen;
Window window;
XdbeBackBuffer back;
XdbeSwapInfo swapinfo;
public:
xwindow(xwindow*, int, int, unsigned int,
unsigned int, unsigned int);
xwindow(xscreen* screen);
xwindow(const xwindow&);
xwindow() {
screen=NULL;
}
~xwindow() {
XDestroyWindow(screen->x_disp->display, window);
}
xwindow& operator=(const xwindow&);
xscreen* getxscr(void) { return screen; }
Window getwindow(void) { return window; }
void initWM(void);
void map(void) { XMapWindow(screen->x_disp->display, window); }
};
#endif // __xclass_h__