Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
453 lines (371 loc) · 12.8 KB

SDL_DirectFB_window.c

File metadata and controls

453 lines (371 loc) · 12.8 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 8, 2008
Dec 8, 2008
3
Copyright (C) 1997-2009 Sam Lantinga
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
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "SDL_syswm.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_keyboard_c.h"
#include "SDL_DirectFB_video.h"
Jan 11, 2009
Jan 11, 2009
30
31
32
33
34
35
int
DirectFB_CreateWindow(_THIS, SDL_Window * window)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_DISPLAYDATA(_this, window);
Jan 11, 2009
Jan 11, 2009
36
DFB_WindowData *windata = NULL;
37
38
DFBWindowOptions wopts;
DFBWindowDescription desc;
Jan 11, 2009
Jan 11, 2009
39
IDirectFBFont *font;
40
41
42
43
44
int ret, x, y;
SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
windata = (DFB_WindowData *) window->driverdata;
Jan 11, 2009
Jan 11, 2009
45
46
47
48
49
50
windata->is_managed = devdata->has_own_wm;
SDL_DFB_CHECKERR(devdata->dfb->SetCooperativeLevel(devdata->dfb,
DFSCL_NORMAL));
SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
DLSCL_ADMINISTRATIVE));
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Fill the window description. */
if (window->x == SDL_WINDOWPOS_CENTERED) {
x = (dispdata->cw - window->w) / 2;
} else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
x = 0;
} else {
x = window->x;
}
if (window->y == SDL_WINDOWPOS_CENTERED) {
y = (dispdata->ch - window->h) / 2;
} else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
y = 0;
} else {
y = window->y;
}
if (window->flags & SDL_WINDOW_FULLSCREEN) {
x = 0;
y = 0;
}
Jan 11, 2009
Jan 11, 2009
72
DirectFB_WM_AdjustWindowLayout(window);
73
Jan 11, 2009
Jan 11, 2009
74
75
76
77
/* Create Window */
desc.flags =
DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT | DWDESC_POSX
| DWDESC_POSY | DWDESC_SURFACE_CAPS;
78
79
desc.posx = x;
desc.posy = y;
Jan 11, 2009
Jan 11, 2009
80
81
desc.width = windata->size.w;
desc.height = windata->size.h;
82
83
84
85
desc.pixelformat = dispdata->pixelformat;
desc.surface_caps = DSCAPS_PREMULTIPLIED;
/* Create the window. */
Jan 11, 2009
Jan 11, 2009
86
87
SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc,
&windata->window));
88
Jan 11, 2009
Jan 11, 2009
89
/* Set Options */
90
91
92
93
94
95
96
windata->window->GetOptions(windata->window, &wopts);
if (window->flags & SDL_WINDOW_RESIZABLE)
wopts |= DWOP_SCALE;
else
wopts |= DWOP_KEEP_SIZE;
Jan 11, 2009
Jan 11, 2009
97
if (window->flags & SDL_WINDOW_FULLSCREEN) {
98
wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
Jan 11, 2009
Jan 11, 2009
99
100
windata->window->SetStackingClass(windata->window, DWSC_UPPER);
}
101
windata->window->SetOptions(windata->window, wopts);
Jan 11, 2009
Jan 11, 2009
102
103
/* See what we got */
Jan 14, 2009
Jan 14, 2009
104
105
SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
(_this, window, &window->w, &window->h));
Jan 11, 2009
Jan 11, 2009
106
107
/* Get the window's surface. */
Jan 11, 2009
Jan 11, 2009
108
109
110
111
112
113
114
SDL_DFB_CHECKERR(windata->window->GetSurface(windata->window,
&windata->window_surface));
/* And get a subsurface for rendering */
SDL_DFB_CHECKERR(windata->window_surface->
GetSubSurface(windata->window_surface, &windata->client,
&windata->surface));
115
116
windata->window->SetOpacity(windata->window, 0xFF);
Jan 11, 2009
Jan 11, 2009
117
118
/* Create Eventbuffer */
SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
Jan 14, 2009
Jan 14, 2009
119
120
121
122
&windata->
eventbuffer));
SDL_DFB_CHECKERR(windata->window->
EnableEvents(windata->window, DWET_ALL));
Jan 11, 2009
Jan 11, 2009
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* Create a font */
/* FIXME: once during Video_Init */
if (windata->is_managed) {
DFBFontDescription fdesc;
fdesc.flags = DFDESC_HEIGHT;
fdesc.height = windata->theme.font_size;
font = NULL;
SDL_DFB_CHECK(devdata->
dfb->CreateFont(devdata->dfb, windata->theme.font,
&fdesc, &font));
windata->window_surface->SetFont(windata->window_surface, font);
SDL_DFB_RELEASE(font);
}
139
140
141
142
/* Make it the top most window. */
windata->window->RaiseToTop(windata->window);
/* remember parent */
Jan 21, 2010
Jan 21, 2010
143
windata->window = window;
144
145
146
147
148
149
150
/* Add to list ... */
windata->next = devdata->firstwin;
windata->opacity = 0xFF;
devdata->firstwin = windata;
Jan 11, 2009
Jan 11, 2009
151
152
153
/* Draw Frame */
DirectFB_WM_RedrawLayout(window);
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
return 0;
error:
SDL_DFB_RELEASE(windata->window);
SDL_DFB_RELEASE(windata->surface);
return -1;
}
int
DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{
SDL_Unsupported();
return -1;
}
void
DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
{
Jan 11, 2009
Jan 11, 2009
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
SDL_DFB_WINDOWDATA(window);
if (windata->is_managed) {
windata->wm_needs_redraw = 1;
} else
SDL_Unsupported();
}
void
DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_Surface *surface = NULL;
DFBResult ret;
if (icon) {
SDL_PixelFormat format;
DFBSurfaceDescription dsc;
Uint32 *dest;
Uint32 *p;
int pitch, i;
/* Convert the icon to ARGB for modern window managers */
SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
0xFF000000);
surface = SDL_ConvertSurface(icon, &format, 0);
if (!surface) {
return;
}
dsc.flags =
DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
dsc.caps = DSCAPS_VIDEOONLY;
dsc.width = surface->w;
dsc.height = surface->h;
dsc.pixelformat = DSPF_ARGB;
SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
&windata->icon));
SDL_DFB_CHECKERR(windata->icon->Lock(windata->icon, DSLF_WRITE,
(void *) &dest, &pitch));
p = surface->pixels;
for (i = 0; i < surface->h; i++)
memcpy((char *) dest + i * pitch,
(char *) p + i * surface->pitch, 4 * surface->w);
windata->icon->Unlock(windata->icon);
SDL_FreeSurface(surface);
} else {
SDL_DFB_RELEASE(windata->icon);
}
return;
error:
if (surface)
SDL_FreeSurface(surface);
SDL_DFB_RELEASE(windata->icon);
return;
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
}
void
DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
int x, y;
if (window->y == SDL_WINDOWPOS_UNDEFINED)
y = 0;
else
y = window->y;
if (window->x == SDL_WINDOWPOS_UNDEFINED)
x = 0;
else
x = window->x;
if (window->flags & SDL_WINDOW_FULLSCREEN) {
x = 0;
y = 0;
}
Jan 11, 2009
Jan 11, 2009
252
DirectFB_WM_AdjustWindowLayout(window);
253
254
255
256
257
258
windata->window->MoveTo(windata->window, x, y);
}
void
DirectFB_SetWindowSize(_THIS, SDL_Window * window)
{
Jan 11, 2009
Jan 11, 2009
259
SDL_DFB_DEVICEDATA(_this);
260
SDL_DFB_WINDOWDATA(window);
Jan 11, 2009
Jan 11, 2009
261
int ret;
262
263
264
265
266
267
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
int cw;
int ch;
/* Make sure all events are disabled for this operation ! */
Jan 11, 2009
Jan 11, 2009
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
SDL_DFB_CHECKERR(windata->window->DisableEvents(windata->window,
DWET_ALL));
SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &cw, &ch));
if (cw != window->w || ch != window->h) {
DirectFB_WM_AdjustWindowLayout(window);
SDL_DFB_CHECKERR(windata->window->Resize(windata->window,
windata->size.w,
windata->size.h));
}
SDL_DFB_CHECKERR(windata->window->EnableEvents(windata->window,
DWET_ALL));
Jan 14, 2009
Jan 14, 2009
284
285
SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
(_this, window, &window->w, &window->h));
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
314
315
316
317
318
319
320
321
322
323
324
SDL_OnWindowResized(window);
}
return;
error:
windata->window->EnableEvents(windata->window, DWET_ALL);
return;
}
void
DirectFB_ShowWindow(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
windata->window->SetOpacity(windata->window, windata->opacity);
}
void
DirectFB_HideWindow(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
windata->window->GetOpacity(windata->window, &windata->opacity);
windata->window->SetOpacity(windata->window, 0);
}
void
DirectFB_RaiseWindow(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
windata->window->RaiseToTop(windata->window);
windata->window->RequestFocus(windata->window);
}
void
DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
{
Jan 11, 2009
Jan 11, 2009
325
SDL_DFB_WINDOWDATA(window);
326
Jan 11, 2009
Jan 11, 2009
327
if (windata->is_managed) {
Jan 14, 2009
Jan 14, 2009
328
DirectFB_WM_MaximizeWindow(_this, window);
Jan 11, 2009
Jan 11, 2009
329
330
} else
SDL_Unsupported();
331
332
333
334
335
336
337
338
339
340
341
342
343
}
void
DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
{
/* FIXME: Size to 32x32 ? */
SDL_Unsupported();
}
void
DirectFB_RestoreWindow(_THIS, SDL_Window * window)
{
Jan 11, 2009
Jan 11, 2009
344
345
346
SDL_DFB_WINDOWDATA(window);
if (windata->is_managed) {
Jan 14, 2009
Jan 14, 2009
347
DirectFB_WM_RestoreWindow(_this, window);
Jan 11, 2009
Jan 11, 2009
348
349
} else
SDL_Unsupported();
350
351
352
353
354
355
356
}
void
DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
Jan 11, 2009
Jan 11, 2009
357
if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
windata->window->GrabPointer(windata->window);
windata->window->GrabKeyboard(windata->window);
} else {
windata->window->UngrabPointer(windata->window);
windata->window->UngrabKeyboard(windata->window);
}
}
void
DirectFB_DestroyWindow(_THIS, SDL_Window * window)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
DFB_WindowData *p;
SDL_DFB_DEBUG("Trace\n");
Jan 11, 2009
Jan 11, 2009
375
376
377
378
379
380
/* Some cleanups */
windata->window->UngrabPointer(windata->window);
windata->window->UngrabKeyboard(windata->window);
windata->window_surface->SetFont(windata->window_surface, NULL);
SDL_DFB_RELEASE(windata->icon);
381
382
SDL_DFB_RELEASE(windata->eventbuffer);
SDL_DFB_RELEASE(windata->surface);
Jan 11, 2009
Jan 11, 2009
383
384
SDL_DFB_RELEASE(windata->window_surface);
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
SDL_DFB_RELEASE(windata->window);
/* Remove from list ... */
p = devdata->firstwin;
while (p && p->next != windata)
p = p->next;
if (p)
p->next = windata->next;
else
devdata->firstwin = windata->next;
SDL_free(windata);
return;
}
SDL_bool
DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo * info)
{
SDL_Unsupported();
return SDL_FALSE;
}
Jan 11, 2009
Jan 11, 2009
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
void
DirectFB_AdjustWindowSurface(SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
int adjust = windata->wm_needs_redraw;
int cw, ch;
int ret;
DirectFB_WM_AdjustWindowLayout(window);
SDL_DFB_CHECKERR(windata->
window_surface->GetSize(windata->window_surface, &cw,
&ch));
if (cw != windata->size.w || ch != windata->size.h) {
adjust = 1;
}
if (adjust) {
Jan 13, 2009
Jan 13, 2009
426
#if DFB_VERSION_ATLEAST(1,2,1)
Jan 14, 2009
Jan 14, 2009
427
SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window,
Jan 11, 2009
Jan 11, 2009
428
429
windata->size.w,
windata->size.h));
Jan 14, 2009
Jan 14, 2009
430
SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface,
Jan 11, 2009
Jan 11, 2009
431
432
433
windata->
window_surface,
&windata->client));
Jan 13, 2009
Jan 13, 2009
434
#else
Jan 14, 2009
Jan 14, 2009
435
436
437
438
439
440
441
442
443
444
445
446
447
DFBWindowOptions opts;
SDL_DFB_CHECKERR(windata->window->GetOptions(windata->window, &opts));
/* recreate subsurface */
SDL_DFB_RELEASE(windata->surface);
if (opts & DWOP_SCALE)
SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window,
windata->size.w,
windata->size.h));
SDL_DFB_CHECKERR(windata->window_surface->
GetSubSurface(windata->window_surface,
&windata->client, &windata->surface));
Jan 13, 2009
Jan 13, 2009
448
#endif
Jan 14, 2009
Jan 14, 2009
449
DirectFB_WM_RedrawLayout(window);
Jan 11, 2009
Jan 11, 2009
450
451
452
453
}
error:
return;
}