wmcube: imported Upstream version 0.99-pre1
[dockapps.git] / wmcube / wmapp / xwrapper.h
blob4f1b03877fdcfe265a21c8b220146c4f0e9ba9df
1 #include "colors.h"
3 #ifndef _MY_XWRAPPER_H
4 #define _MY_XWRAPPER_H
6 //These must be included here so that important types and functions aren't
7 //dragged into the X namespace, but left undefined in the global namespace.
8 extern "C" {
9 # include <stddef.h>
10 # include <stdlib.h>
11 # include <sys/types.h>
12 # include <malloc.h>
14 namespace X {
15 // Unfortunately, many common X calls are actually macros and the X::
16 // prefix must be avoided when using them. Still, it is nice to use
17 // a separate namespace whenever possible.
19 // the next line ensures that X macros are expanded correctly into functions
20 // in the X namespace, since _XPrivDisplay appears to be the only
21 // real X object used by all X macros:
22 # define _XPrivDisplay X::_XPrivDisplay
24 // this is just so I can easily see which identifiers are macros from Xlib
25 // that can't be prefixed by "X::"
26 # define X_MACRO(x) (x)
28 extern "C" {
29 # include <X11/X.h>
30 # include <X11/Xlib.h>
31 # include <X11/xpm.h>
32 # include <X11/extensions/shape.h>
36 // forward declaration for rectangle
37 struct WMRectangle;
39 struct WMPixmap {
40 X::Pixmap pixmap;
41 X::Pixmap mask;
42 X::GC gc;
43 X::XpmAttributes attr;
46 // global X thingies
47 extern X::Window wActiveWin, wProgramWin;
48 extern X::Atom deleteWin, _XA_GNUSTEP_WM_FUNC;
50 class Xwrapper {
51 private:
52 X::Display * xDisplay;
53 X::Window xRootWindow;
54 X::XWindowAttributes xAttributes;
55 mutable X::GC xGC;
57 unsigned long color_to_xcolor(Color) const;
58 void set_GC(X::GC, Color) const;
60 public:
61 Xwrapper();
62 ~Xwrapper();
64 X::Display * xdisplay() const;
65 const X::Window xrootwin() const;
66 X::GC get_GC() const;
68 bool create_pixmap(WMPixmap & dest, char * pixmap_bytes[]) const;
69 bool create_pixmap(WMPixmap & dest, const WMPixmap & source) const;
70 bool create_pixmap(WMPixmap & dest, const WMPixmap * source) const;
71 bool create_pixmap(WMPixmap & dest, int width, int height) const;
72 bool create_pixmap(WMPixmap & dest, int width, int height, int depth) const;
74 void free_pixmap(WMPixmap & dest) const;
76 Color get_point(const WMPixmap & src, int x, int y) const;
78 void draw_point(WMPixmap & dest, int x, int y, Color c) const;
79 void draw_line(WMPixmap & dest, int x1, int y1, int x2, int y2, Color c)
80 const;
81 void draw_arc(WMPixmap & dest, int x, int y, int width, int height,
82 int angle1, int angle2, Color c); //angles are in units of degrees * 64
83 void draw_lines(WMPixmap & dest, const X::XPoint* points, int npoints,
84 Color c) const; //X::XPoint is simply a struct { short x, y };
86 // draws a color gradient from left to right or bottom to top from color1
87 // to color2. amount is the proportion of the gradient to draw i.e. 0.5
88 // draws half the gradient. It should always be at least 2 pixels wide.
89 void draw_horizontal_gradient(WMPixmap & dest, int x1, int y1, int x2, int y2, Color c1, Color c2, double amount = 1.0);
90 void draw_vertical_gradient(WMPixmap & dest, int x1, int y1, int x2, int y2, Color c1, Color c2, double amount = 1.0);
92 void draw_border(WMPixmap & dest, int x, int y, int width, int height,
93 int thickness, Color topleft, Color botright, Color corner)
94 const;
95 void draw_border(WMPixmap & dest, const WMRectangle & posn, int thickness,
96 Color topleft, Color botright, Color corner) const;
98 void fill_rectangle(WMPixmap & dest, int x, int y, int width, int height,
99 Color c) const;
100 void fill_rectangle(WMPixmap & dest, const WMRectangle & posn, Color c)
101 const;
103 void fill_arc(WMPixmap & dest, int x, int y, int width, int height,
104 int angle1, int angle2, Color c); //angles are in units of degrees * 64
106 enum XShape { complex = X_MACRO(Complex), convex = X_MACRO(Convex),
107 nonconvex = X_MACRO(Nonconvex) };
108 void fill_polygon(WMPixmap & dest, const X::XPoint* points, int npoints,
109 Color c, XShape shape = complex) const;
110 //shape is simply a hint to the X server about what type of shape is
111 //being drawn. See XFillPolygon(3) for a complete description.
113 void clear_rectangle(WMPixmap & dest, int x, int y, int width, int height)
114 const;
115 void clear_rectangle(WMPixmap & dest, const WMRectangle & posn) const;
117 void copy_rectangle(const WMPixmap & source, WMPixmap & dest,
118 int source_x, int source_y, int source_w, int source_h,
119 int dest_x = 0, int dest_y = 0) const;
120 void copy_rectangle(const WMPixmap & source, WMPixmap & dest,
121 const WMRectangle & posn, int dest_x = 0, int dest_y = 0)
122 const;
123 void copy_rectangle(const WMPixmap & source, X::Drawable & dest,
124 int source_x, int source_y, int source_w, int source_h,
125 int dest_x = 0, int dest_y = 0) const;
126 void copy_rectangle(const WMPixmap & source, X::Drawable & dest,
127 const WMRectangle & posn, int dest_x = 0, int dest_y = 0)
128 const;
131 inline X::Display *
132 Xwrapper::xdisplay() const { return xDisplay; }
134 inline const X::Window
135 Xwrapper::xrootwin() const { return xRootWindow; }
137 inline X::GC
138 Xwrapper::get_GC() const { return xGC; }
140 #endif