xclass.cpp
7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
using namespace std;
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "xclass.h"
xdisplay::xdisplay(char* name) {
if(name) {
display_name=new char[strlen(name)+1];
strcpy(display_name, name);
}
else {
display_name=NULL;
}
/* Connect to X server */
if ((display=XOpenDisplay(display_name)) == NULL)
throw noconnect_exception();
wincount=0;
screen_anz=ScreenCount(display);
default_screen=DefaultScreen(display);
screens=new xscreen*[screen_anz];
for(int i=0; i<screen_anz; i++) {
screens[i]=new xscreen(this, i);
}
font_info=NULL;
}
xdisplay::xdisplay(const xdisplay& xd) {
if(xd.display_name) {
display_name=new char[strlen(xd.display_name)+1];
strcpy(display_name, xd.display_name);
}
else {
display_name=NULL;
}
display=xd.display;
wincount=xd.wincount;
screen_anz=xd.screen_anz;
default_screen=xd.default_screen;
screens=new xscreen*[screen_anz];
for(int i=0; i<screen_anz; i++) {
screens[i]=(xd.screens)[i];
}
font_info=NULL;
}
xdisplay::~xdisplay() {
if(display_name)
delete [] display_name;
// das ueberlass ich dem Destructor von xscreen!
// for(int i=0; i<wincount; i++)
// delete wins[i];
// delete [] wins;
//for(int i=0; i<screen_anz; i++)
// delete screens[i];
//delete [] screens;
XCloseDisplay(display);
}
xdisplay& xdisplay::operator=(const xdisplay& xd) {
if(xd.display_name) {
display_name=new char[strlen(xd.display_name)+1];
strcpy(display_name, xd.display_name);
}
else {
display_name=NULL;
}
display=xd.display;
wincount=xd.wincount;
screen_anz=xd.screen_anz;
default_screen=xd.default_screen;
screens=new xscreen*[screen_anz];
for(int i=0; i<screen_anz; i++) {
screens[i]=(xd.screens)[i];
}
font_info=NULL;
return *this;
}
xscreen* xdisplay::defaultscreen(void) {
return screens[default_screen];
}
void xdisplay::loadfont(char* fname) {
/* Load font and get font information structure */
if((font_info = XLoadQueryFont(display,fname)) == NULL)
throw nofont_exception();
}
xscreen::xscreen(xdisplay* d, int screen_num) {
this->screen_num=screen_num;
this->x_disp=d;
if(screen_num!=-1) {
XPixmapFormatValues* pixmap_formats;
int count;
screen=XScreenOfDisplay(d->display, screen_num);
width=WidthOfScreen(screen);
height=HeightOfScreen(screen);
default_cm=DefaultColormapOfScreen(screen);
black_pixel=XBlackPixelOfScreen(screen);
white_pixel=XWhitePixelOfScreen(screen);
rootwin=new xwindow(this); // Ich kann nicht this nehmen,
// da das aktuelle Object dem
// Array zugewiesen wird und
// danach weg is.
vis=DefaultVisual(d->display, 0);
pixmap_formats=XListPixmapFormats(d->display, &count);
depth=0;
for(int i=0, result=0; i<count; i++) {
if(pixmap_formats[i].depth > depth) {
// OK, das vi existiert jetzt nur fuer TrueColor, ich muss
// noch fuer alle anderen VisualTypes eins einbauen.
if(XMatchVisualInfo(d->display, d->default_screen,
pixmap_formats[i].depth, TrueColor, &vi)) {
depth=pixmap_formats[i].depth;
bytespp=pixmap_formats[i].bits_per_pixel/8;
scanline_pad=pixmap_formats[i].scanline_pad;
}
}
}
gc=DefaultGC(d->display, d->defaultscreenid());
}
else {
screen=NULL;
rootwin=NULL;
}
}
xscreen::xscreen(const xscreen& scr) {
x_disp=scr.x_disp;
screen_num=scr.screen_num;
screen=scr.screen;
rootwin=scr.rootwin;
width=scr.width;
height=scr.height;
vis=scr.vis;
memcpy(&vi, &scr.vi, sizeof(XVisualInfo));
depth=scr.depth;
bytespp=scr.bytespp;
scanline_pad=scr.scanline_pad;
memcpy(&gc, &scr.gc, sizeof(GC));
default_cm=scr.default_cm;
black_pixel=scr.black_pixel;
white_pixel=scr.white_pixel;
}
xscreen::~xscreen() {
delete rootwin;
XFreeGC(x_disp->display, gc);
XFreeColormap(x_disp->display, default_cm);
}
xscreen& xscreen::operator=(const xscreen& scr) {
x_disp=scr.x_disp;
screen_num=scr.screen_num;
screen=scr.screen;
rootwin=scr.rootwin;
width=scr.width;
height=scr.height;
vis=scr.vis;
memcpy(&vi, &scr.vi, sizeof(XVisualInfo));
depth=scr.depth;
bytespp=scr.bytespp;
scanline_pad=scr.scanline_pad;
memcpy(&gc, &scr.gc, sizeof(GC));
default_cm=scr.default_cm;
black_pixel=scr.black_pixel;
white_pixel=scr.white_pixel;
return *this;
}
xwindow* xdisplay::getXwinById(Window id) {
int i;
for(i=0; i<wincount; i++)
if(wins[i]->window == id)
return wins[i];
return NULL;
}
xwindow::xwindow(xscreen* xs) {
screen=xs;
window=XRootWindowOfScreen(xs->screen);
screen->x_disp->wincount++;
xwindow** temp=new xwindow*[screen->x_disp->wincount];
for(int i=0; i<screen->x_disp->wincount-1; i++)
temp[i]=screen->x_disp->wins[i];
temp[screen->x_disp->wincount-1]=this;
delete[] screen->x_disp->wins;
screen->x_disp->wins=temp;
}
xwindow::xwindow(xwindow* win, int x, int y,
unsigned int bwidth, unsigned int width,
unsigned int height) {
screen=win->screen;
window=XCreateSimpleWindow(screen->x_disp->display, win->window,
x, y, width, height, bwidth,
screen->black_pixel, screen->white_pixel);
screen->x_disp->wincount++;
xwindow** temp=new xwindow*[screen->x_disp->wincount];
for(int i=0; i<screen->x_disp->wincount-1; i++)
temp[i]=screen->x_disp->wins[i];
temp[screen->x_disp->wincount-1]=this;
delete[] screen->x_disp->wins;
screen->x_disp->wins=temp;
XSelectInput(screen->x_disp->display, window,
ExposureMask|KeyPressMask|ButtonPressMask|StructureNotifyMask);
}
xwindow::xwindow(const xwindow& xw) {
screen=xw.screen;
window=xw.window;
back=xw.back;
swapinfo=xw.swapinfo;
}
xwindow& xwindow::operator=(const xwindow& xw) {
screen=xw.screen;
window=xw.window;
back=xw.back;
swapinfo=xw.swapinfo;
return *this;
}
// Dies sollte nochmal in mehrere kleinere Methoden zum einstellen der
// diversen Dinge fuer den WM aufgesplittet werden.
void xwindow::initWM(void) {
XSizeHints* size_hints; // Informationen fuer WM ueber
// minimale Groessen fuer App
XWMHints* wm_hints; // weiter Infos fuer WM z.B. Icon
// Input/Output initialisierung
XClassHint* class_hints; // noch mehr infos fuer WM
if (!(size_hints = XAllocSizeHints())) {
fprintf(stderr, "failure allocating memory\n");
exit(1); //throw exception...
}
if (!(wm_hints = XAllocWMHints())) {
fprintf(stderr, "failure allocating memory\n");
exit(1); //throw exception...
}
if (!(class_hints = XAllocClassHint())) {
fprintf(stderr, "failure allocating memory\n");
exit(1); //throw exception...
}
size_hints->flags = PPosition | PSize | PMinSize;
size_hints->min_width = 300;
size_hints->min_height = 200;
wm_hints->initial_state = NormalState;
wm_hints->input = True;
// wm_hints->icon_pixmap = icon_pixmap;
wm_hints->flags = StateHint | IconPixmapHint | InputHint;
class_hints->res_name = "jokus"; //screen->x_disp->argv[0];
class_hints->res_class = "Basicwin";
// XSetWMProperties(screen->x_disp->display, window, NULL, NULL, /*&iconName*/
// screen->x_disp->argv, screen->x_disp->argc, size_hints,
// wm_hints, class_hints);
XStoreName(screen->x_disp->display, window, "jokus");
}