00001
00002
00003
00004
00005
00006 #ifndef __XCORE_H
00007 #define __XCORE_H
00008
00009 #include "ncwm.h"
00010
00011 extern "C" {
00012 #include <X11/Xlib.h>
00013 #include <X11/Xutil.h>
00014 #ifdef XFT_SUPPORT
00015 #include <X11/Xft/Xft.h>
00016 #endif // XFT_SUPPORT
00017 }
00018
00019 #include <string>
00020
00021 #include "singleton.h"
00022
00023 #define PDELETE 1
00024 #define PTAKEFOCUS 2
00025
00029 struct MWMHints {
00030
00031 long flags;
00032 long functions;
00033 long decorations;
00034 int inputMode;
00035 long status;
00036 };
00037
00038 class XCore;
00039 class Rectangle;
00040 class WFont;
00041
00046 class XCore : public Singleton<XCore>
00047 {
00048
00049 public:
00050
00052 XCore();
00053
00054 ~XCore();
00055
00056 void setDisplay(Display *display);
00057
00059 Window createWindow(Window root, XSetWindowAttributes *attr,
00060 int x, int y, unsigned int w, unsigned int h,
00061 unsigned long mask);
00062
00064 void selectEvents(Window window, long mask);
00065
00067 void setInputFocus(Window window);
00068
00070 void show(Window window);
00071
00073 void showRaised(Window window);
00074
00076 void hide(Window window);
00077
00081 GC createGC(Window window, unsigned long mask, XGCValues *gcv);
00082
00084 void grabKeyboard(Window window);
00085
00087 void ungrabKeyboard();
00088
00090 void free(void *data);
00091
00093 void sync(bool discard = False);
00094
00096 void setForeground(GC gc, unsigned long color);
00097
00099 void drawLines(Window window, GC gc, XPoint *points, unsigned int num);
00100
00102 void drawLine(Window window, GC gc, unsigned int x1, unsigned int y1,
00103 unsigned int x2, unsigned int y2);
00104
00106 void drawRectangle(Window window, GC gc, int x, int y, unsigned int w,
00107 unsigned int h);
00108
00110 void drawRectangle(Window window, GC gc, Rectangle *rect);
00111
00113 void clearArea(Window window, Rectangle *rect);
00114
00116 void clearArea(Window window, int x, int y, unsigned int w, unsigned int h);
00117
00119 void clearWindow(Window window);
00120
00122 void fillRectangle(Window window, GC gc, Rectangle *rect);
00123
00125 void fillRectangle(Window window, GC gc, int x, int y,
00126 unsigned int w, unsigned int h);
00127
00129 XFontStruct *loadQueryFont(string name);
00130
00132 void drawText(Window window, GC gc, int x, int y,
00133 string text);
00134
00136 int textWidth(XFontStruct *font, string text);
00137
00138 #ifdef XFT_SUPPORT
00139
00140 XftFont *xftOpenFontName(unsigned int screen, string name);
00141
00143 void xftCloseFont(XftFont *font);
00144
00146 void drawText(XftFont *font, Window window, GC gc,
00147 unsigned int screen, int x, int y,
00148 string text);
00149
00151 int textWidth(XftFont *font, string text);
00152 #endif
00153
00155 string className(Window window);
00156
00158 string instanceName(Window window);
00159
00161 int state(Window window);
00162
00164 void setState(Window window, int state);
00165
00167 string atomValue(Window window, Atom atom);
00168
00170 void updateSize(Window window,
00171 unsigned int *minW, unsigned int *minH,
00172 unsigned int *maxW, unsigned int *maxH,
00173 bool *isCentered);
00174
00176 bool hasDecoration(Window window);
00177
00179 Window transient(Window window);
00180
00182 int property(Window window, Atom atom, Atom type,
00183 long length, unsigned char **prop);
00184
00186 void configure(Window window, XConfigureEvent *event);
00187
00189 int protocols(Window window);
00190
00192 void sendMessage(Window window, Atom atom, long value);
00193
00195 void kill(Window window, int protos);
00196
00198 void moveResize(Window window, Rectangle *rect);
00199
00201 void destroy(Window window);
00202
00204 void raise(Window window);
00205
00207 void lower(Window window);
00208
00210 void reparent(Window child, Window parent, int x, int y);
00211
00213 void grabKey(Window window, unsigned int modMask, KeyCode keycode);
00214
00216 void ungrabKey(Window window, unsigned int modMask, KeyCode keycode);
00217
00219 void grabButton(Window window, unsigned int modMask, unsigned int button);
00220
00222 void ungrabButton(Window window, unsigned int modMask, unsigned int button);
00223
00225 void grabServer();
00226
00228 void ungrabServer();
00229
00231 void grabPointer(Window window, unsigned int mask, Time time,
00232 Cursor cursor = None);
00233
00235 void ungrabPointer(Time time);
00236
00238 Atom internAtom(string atom);
00239
00241 Cursor createFontCursor(unsigned int cursor);
00242
00244 void setWindowAttributes(Window window, unsigned int mask,
00245 XSetWindowAttributes *attr);
00246
00248 void windowAttributes(Window window, XWindowAttributes *attr);
00249
00251 KeyCode stringToKeyCode(string key);
00252
00254 string keyCodeToString(KeyCode keyCode);
00255
00257 KeySym keyCodeToKeySym(KeyCode keyCode);
00258
00260 string atomName(Atom atom);
00261
00263 void nextEvent(XEvent *event);
00264
00266 bool checkMaskEvent(long mask, XEvent *event);
00267
00273 void translateCoordinates(Window child, Window parent,
00274 int srcX, int srcY, int *destX, int *destY);
00275
00277 bool allocNamedColor(Colormap colormap, string name, XColor *color);
00278
00280 void installColormap(Colormap colormap);
00281
00282 Colormap defaultColormap(unsigned int id);
00283
00285 void queryTree(Window root, Window **windows, unsigned int *num);
00286
00288 KeySym lookupNextKeySym(XKeyEvent *event, int *count, char *buffer);
00289
00291 bool textProperty(Window window, Atom atom, string *value);
00292
00294 void stringListToTextProperty(string text, XTextProperty *textProperty);
00295 void setTextProperty(Display *display, Window window,
00296 XTextProperty *textProperty, Atom atom);
00297
00299 static int handleErrors(Display *display, XErrorEvent *e);
00300
00301 void configureWindow(Window window, unsigned int mask, XWindowChanges *wc);
00302
00304 XModifierKeymap *modifierMapping();
00305 void freeModifierMapping(XModifierKeymap *modmap);
00306
00307 void addToSaveSet(Window window);
00308 void removeFromSaveSet(Window window);
00309
00311 void sizeHints(Window window, XSizeHints *sizeHints);
00312
00313 void warpPointer(Window window, int x, int y);
00314
00315 void freeCursor(Cursor cursor);
00316
00317 void maskEvent(unsigned long mask, XEvent *event);
00318
00319 void sendEvent(Window window, unsigned long mask, XEvent *event);
00320
00321 XWMHints *getWMHints(Window window);
00322
00323 private:
00324
00325 Display *display_;
00326
00327 };
00328
00329 #endif // __XCORE_H