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

Latest commit

 

History

History
449 lines (368 loc) · 12.7 KB

SDL_DirectFB_window.c

File metadata and controls

449 lines (368 loc) · 12.7 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
104
105
/* See what we got */
SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &window->w, &window->h));
106
/* Get the window's surface. */
Jan 11, 2009
Jan 11, 2009
107
108
109
110
111
112
113
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));
114
115
windata->window->SetOpacity(windata->window, 0xFF);
Jan 11, 2009
Jan 11, 2009
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* Create Eventbuffer */
SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
&windata->eventbuffer));
SDL_DFB_CHECKERR(windata->
window->EnableEvents(windata->window, DWET_ALL));
/* 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);
}
137
138
139
140
/* Make it the top most window. */
windata->window->RaiseToTop(windata->window);
/* remember parent */
Jan 11, 2009
Jan 11, 2009
141
windata->sdl_id = window->id;
142
143
144
145
146
147
148
/* Add to list ... */
windata->next = devdata->firstwin;
windata->opacity = 0xFF;
devdata->firstwin = windata;
Jan 11, 2009
Jan 11, 2009
149
150
151
/* Draw Frame */
DirectFB_WM_RedrawLayout(window);
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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
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
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;
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
}
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
250
DirectFB_WM_AdjustWindowLayout(window);
251
252
253
254
255
256
windata->window->MoveTo(windata->window, x, y);
}
void
DirectFB_SetWindowSize(_THIS, SDL_Window * window)
{
Jan 11, 2009
Jan 11, 2009
257
SDL_DFB_DEVICEDATA(_this);
258
SDL_DFB_WINDOWDATA(window);
Jan 11, 2009
Jan 11, 2009
259
int ret;
260
261
262
263
264
265
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
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));
SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &window->w, &window->h));
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
314
315
316
317
318
319
320
321
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
322
SDL_DFB_WINDOWDATA(window);
323
Jan 11, 2009
Jan 11, 2009
324
325
326
327
if (windata->is_managed) {
DirectFB_WM_MaximizeWindow(_this, window);
} else
SDL_Unsupported();
328
329
330
331
332
333
334
335
336
337
338
339
340
}
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
341
342
343
344
345
346
SDL_DFB_WINDOWDATA(window);
if (windata->is_managed) {
DirectFB_WM_RestoreWindow(_this, window);
} else
SDL_Unsupported();
347
348
349
350
351
352
353
}
void
DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
Jan 11, 2009
Jan 11, 2009
354
if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
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
372
373
374
375
376
377
/* 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);
378
379
SDL_DFB_RELEASE(windata->eventbuffer);
SDL_DFB_RELEASE(windata->surface);
Jan 11, 2009
Jan 11, 2009
380
381
SDL_DFB_RELEASE(windata->window_surface);
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
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
423
424
#if DFB_VERSION_ATLEAST(1,2,0)
SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window,
Jan 11, 2009
Jan 11, 2009
425
426
windata->size.w,
windata->size.h));
Jan 13, 2009
Jan 13, 2009
427
SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface,
Jan 11, 2009
Jan 11, 2009
428
429
430
windata->
window_surface,
&windata->client));
Jan 13, 2009
Jan 13, 2009
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#else
/* recreate subsurface */
windata->surface->ReleaseSource(windata->surface);
windata->window_surface->ReleaseSource(windata->window_surface);
SDL_DFB_RELEASE(windata->surface);
windata->surface = NULL;
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));
#endif
DirectFB_WM_RedrawLayout(window);
Jan 11, 2009
Jan 11, 2009
445
446
447
448
}
error:
return;
}