Mercurial > sdl-ios-xcode
comparison src/video/directfb/SDL_DirectFB_window.c @ 3023:d72a0dd80e8b
DirectFB cleanups & simple window manager
- use SDL_getenv, not getenv ...
- no more support for 0.9.25 - not even mentioned any longer on directfb.org
- fix fullscreen issues
- add a simple window manager unless the directfb team comes up with a working wm.
The driver has support for a very, very basic window manager you may
want to use when runnning with "wm=default". Use
export SDL_DIRECTFB_WM=1
to enable basic window borders including icon support. In order to have the window title rendered,
you need to have the following font installed:
/usr/share/fonts/truetype/freefont/FreeSans.ttf
author | Couriersud <couriersud@arcor.de> |
---|---|
date | Sun, 11 Jan 2009 23:49:23 +0000 |
parents | 8cc00819c8d6 |
children | 490f3e4fe753 |
comparison
equal
deleted
inserted
replaced
3022:db20dde98dd3 | 3023:d72a0dd80e8b |
---|---|
25 #include "../SDL_sysvideo.h" | 25 #include "../SDL_sysvideo.h" |
26 #include "../../events/SDL_keyboard_c.h" | 26 #include "../../events/SDL_keyboard_c.h" |
27 | 27 |
28 #include "SDL_DirectFB_video.h" | 28 #include "SDL_DirectFB_video.h" |
29 | 29 |
30 | |
30 int | 31 int |
31 DirectFB_CreateWindow(_THIS, SDL_Window * window) | 32 DirectFB_CreateWindow(_THIS, SDL_Window * window) |
32 { | 33 { |
33 SDL_DFB_DEVICEDATA(_this); | 34 SDL_DFB_DEVICEDATA(_this); |
34 SDL_DFB_DISPLAYDATA(_this, window); | 35 SDL_DFB_DISPLAYDATA(_this, window); |
35 DFB_WindowData *windata; | 36 DFB_WindowData *windata = NULL; |
36 DFBWindowOptions wopts; | 37 DFBWindowOptions wopts; |
37 DFBWindowDescription desc; | 38 DFBWindowDescription desc; |
39 IDirectFBFont *font; | |
38 int ret, x, y; | 40 int ret, x, y; |
39 | 41 |
40 SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y, | |
41 window->w, window->h); | |
42 window->driverdata = NULL; | |
43 SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData)); | 42 SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData)); |
44 windata = (DFB_WindowData *) window->driverdata; | 43 windata = (DFB_WindowData *) window->driverdata; |
45 | 44 |
46 SDL_DFB_CHECKERR(devdata->dfb-> | 45 windata->is_managed = devdata->has_own_wm; |
47 SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL)); | 46 |
48 SDL_DFB_CHECKERR(dispdata->layer-> | 47 SDL_DFB_CHECKERR(devdata->dfb->SetCooperativeLevel(devdata->dfb, |
49 SetCooperativeLevel(dispdata->layer, | 48 DFSCL_NORMAL)); |
50 DLSCL_ADMINISTRATIVE)); | 49 SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer, |
50 DLSCL_ADMINISTRATIVE)); | |
51 | 51 |
52 /* Fill the window description. */ | 52 /* Fill the window description. */ |
53 if (window->x == SDL_WINDOWPOS_CENTERED) { | 53 if (window->x == SDL_WINDOWPOS_CENTERED) { |
54 x = (dispdata->cw - window->w) / 2; | 54 x = (dispdata->cw - window->w) / 2; |
55 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { | 55 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { |
67 if (window->flags & SDL_WINDOW_FULLSCREEN) { | 67 if (window->flags & SDL_WINDOW_FULLSCREEN) { |
68 x = 0; | 68 x = 0; |
69 y = 0; | 69 y = 0; |
70 } | 70 } |
71 | 71 |
72 desc.flags = DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT; | 72 DirectFB_WM_AdjustWindowLayout(window); |
73 /*| DWDESC_CAPS | DWDESC_SURFACE_CAPS */ | 73 |
74 | 74 /* Create Window */ |
75 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0) | 75 desc.flags = |
76 /* Needed for 1.2 */ | 76 DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT | DWDESC_POSX |
77 desc.flags |= DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS; | 77 | DWDESC_POSY | DWDESC_SURFACE_CAPS; |
78 desc.posx = x; | 78 desc.posx = x; |
79 desc.posy = y; | 79 desc.posy = y; |
80 #else | 80 desc.width = windata->size.w; |
81 if (!(window->flags & SDL_WINDOW_FULLSCREEN) | 81 desc.height = windata->size.h; |
82 && window->x != SDL_WINDOWPOS_UNDEFINED | |
83 && window->y != SDL_WINDOWPOS_UNDEFINED) { | |
84 desc.flags |= DWDESC_POSX | DWDESC_POSY; | |
85 desc.posx = x; | |
86 desc.posy = y; | |
87 } | |
88 #endif | |
89 | |
90 desc.width = window->w; | |
91 desc.height = window->h; | |
92 desc.pixelformat = dispdata->pixelformat; | 82 desc.pixelformat = dispdata->pixelformat; |
93 #if 0 | |
94 desc.caps = 0; | |
95 desc.surface_caps = | |
96 DSCAPS_DOUBLE | DSCAPS_TRIPLE | DSCAPS_PREMULTIPLIED | | |
97 DSCAPS_VIDEOONLY; | |
98 #endif | |
99 desc.surface_caps = DSCAPS_PREMULTIPLIED; | 83 desc.surface_caps = DSCAPS_PREMULTIPLIED; |
100 /* DSCAPS_VIDEOONLY has negative impact on performance */ | |
101 | 84 |
102 /* Create the window. */ | 85 /* Create the window. */ |
103 SDL_DFB_CHECKERR(dispdata->layer-> | 86 SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc, |
104 CreateWindow(dispdata->layer, &desc, &windata->window)); | 87 &windata->window)); |
105 | 88 |
89 /* Set Options */ | |
106 windata->window->GetOptions(windata->window, &wopts); | 90 windata->window->GetOptions(windata->window, &wopts); |
107 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0) | |
108 | 91 |
109 if (window->flags & SDL_WINDOW_RESIZABLE) | 92 if (window->flags & SDL_WINDOW_RESIZABLE) |
110 wopts |= DWOP_SCALE; | 93 wopts |= DWOP_SCALE; |
111 else | 94 else |
112 wopts |= DWOP_KEEP_SIZE; | 95 wopts |= DWOP_KEEP_SIZE; |
113 #else | 96 |
114 wopts |= DWOP_KEEP_SIZE; /* if not we will crash ... */ | 97 if (window->flags & SDL_WINDOW_FULLSCREEN) { |
115 #endif | |
116 | |
117 if (window->flags & SDL_WINDOW_FULLSCREEN) | |
118 wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE; | 98 wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE; |
119 | 99 windata->window->SetStackingClass(windata->window, DWSC_UPPER); |
100 } | |
120 windata->window->SetOptions(windata->window, wopts); | 101 windata->window->SetOptions(windata->window, wopts); |
102 | |
103 /* See what we got */ | |
104 SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &window->w, &window->h)); | |
105 | |
121 /* Get the window's surface. */ | 106 /* Get the window's surface. */ |
122 SDL_DFB_CHECKERR(windata->window-> | 107 SDL_DFB_CHECKERR(windata->window->GetSurface(windata->window, |
123 GetSurface(windata->window, &windata->surface)); | 108 &windata->window_surface)); |
109 /* And get a subsurface for rendering */ | |
110 SDL_DFB_CHECKERR(windata->window_surface-> | |
111 GetSubSurface(windata->window_surface, &windata->client, | |
112 &windata->surface)); | |
113 | |
124 windata->window->SetOpacity(windata->window, 0xFF); | 114 windata->window->SetOpacity(windata->window, 0xFF); |
125 SDL_DFB_CHECKERR(windata->window-> | 115 |
126 CreateEventBuffer(windata->window, | 116 /* Create Eventbuffer */ |
127 &(windata->eventbuffer))); | 117 SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window, |
128 SDL_DFB_CHECKERR(windata->window-> | 118 &windata->eventbuffer)); |
129 EnableEvents(windata->window, DWET_ALL)); | 119 SDL_DFB_CHECKERR(windata-> |
130 | 120 window->EnableEvents(windata->window, DWET_ALL)); |
131 if (window->flags & SDL_WINDOW_FULLSCREEN) | 121 |
132 windata->window->SetStackingClass(windata->window, DWSC_UPPER); | 122 /* Create a font */ |
123 /* FIXME: once during Video_Init */ | |
124 if (windata->is_managed) { | |
125 DFBFontDescription fdesc; | |
126 | |
127 fdesc.flags = DFDESC_HEIGHT; | |
128 fdesc.height = windata->theme.font_size; | |
129 font = NULL; | |
130 SDL_DFB_CHECK(devdata-> | |
131 dfb->CreateFont(devdata->dfb, windata->theme.font, | |
132 &fdesc, &font)); | |
133 windata->window_surface->SetFont(windata->window_surface, font); | |
134 SDL_DFB_RELEASE(font); | |
135 } | |
136 | |
133 /* Make it the top most window. */ | 137 /* Make it the top most window. */ |
134 windata->window->RaiseToTop(windata->window); | 138 windata->window->RaiseToTop(windata->window); |
135 | 139 |
136 windata->window->GetID(windata->window, &windata->windowID); | |
137 | |
138 windata->window->GetSize(windata->window, &window->w, &window->h); | |
139 | |
140 /* remember parent */ | 140 /* remember parent */ |
141 windata->id = window->id; | 141 windata->sdl_id = window->id; |
142 | 142 |
143 /* Add to list ... */ | 143 /* Add to list ... */ |
144 | 144 |
145 windata->next = devdata->firstwin; | 145 windata->next = devdata->firstwin; |
146 windata->opacity = 0xFF; | 146 windata->opacity = 0xFF; |
147 devdata->firstwin = windata; | 147 devdata->firstwin = windata; |
148 | |
149 /* Draw Frame */ | |
150 DirectFB_WM_RedrawLayout(window); | |
148 | 151 |
149 return 0; | 152 return 0; |
150 error: | 153 error: |
151 SDL_DFB_RELEASE(windata->window); | 154 SDL_DFB_RELEASE(windata->window); |
152 SDL_DFB_RELEASE(windata->surface); | 155 SDL_DFB_RELEASE(windata->surface); |
161 } | 164 } |
162 | 165 |
163 void | 166 void |
164 DirectFB_SetWindowTitle(_THIS, SDL_Window * window) | 167 DirectFB_SetWindowTitle(_THIS, SDL_Window * window) |
165 { | 168 { |
166 SDL_Unsupported(); | 169 SDL_DFB_WINDOWDATA(window); |
170 | |
171 if (windata->is_managed) { | |
172 windata->wm_needs_redraw = 1; | |
173 } else | |
174 SDL_Unsupported(); | |
175 } | |
176 | |
177 void | |
178 DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) | |
179 { | |
180 SDL_DFB_DEVICEDATA(_this); | |
181 SDL_DFB_WINDOWDATA(window); | |
182 SDL_Surface *surface = NULL; | |
183 DFBResult ret; | |
184 | |
185 if (icon) { | |
186 SDL_PixelFormat format; | |
187 DFBSurfaceDescription dsc; | |
188 Uint32 *dest; | |
189 Uint32 *p; | |
190 int pitch, i; | |
191 | |
192 /* Convert the icon to ARGB for modern window managers */ | |
193 SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, | |
194 0xFF000000); | |
195 surface = SDL_ConvertSurface(icon, &format, 0); | |
196 if (!surface) { | |
197 return; | |
198 } | |
199 dsc.flags = | |
200 DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; | |
201 dsc.caps = DSCAPS_VIDEOONLY; | |
202 dsc.width = surface->w; | |
203 dsc.height = surface->h; | |
204 dsc.pixelformat = DSPF_ARGB; | |
205 | |
206 SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, | |
207 &windata->icon)); | |
208 | |
209 SDL_DFB_CHECKERR(windata->icon->Lock(windata->icon, DSLF_WRITE, | |
210 (void *) &dest, &pitch)); | |
211 | |
212 p = surface->pixels; | |
213 for (i = 0; i < surface->h; i++) | |
214 memcpy((char *) dest + i * pitch, | |
215 (char *) p + i * surface->pitch, 4 * surface->w); | |
216 | |
217 windata->icon->Unlock(windata->icon); | |
218 SDL_FreeSurface(surface); | |
219 } else { | |
220 SDL_DFB_RELEASE(windata->icon); | |
221 } | |
222 return; | |
223 error: | |
224 if (surface) | |
225 SDL_FreeSurface(surface); | |
226 SDL_DFB_RELEASE(windata->icon); | |
227 return; | |
167 } | 228 } |
168 | 229 |
169 void | 230 void |
170 DirectFB_SetWindowPosition(_THIS, SDL_Window * window) | 231 DirectFB_SetWindowPosition(_THIS, SDL_Window * window) |
171 { | 232 { |
184 | 245 |
185 if (window->flags & SDL_WINDOW_FULLSCREEN) { | 246 if (window->flags & SDL_WINDOW_FULLSCREEN) { |
186 x = 0; | 247 x = 0; |
187 y = 0; | 248 y = 0; |
188 } | 249 } |
189 | 250 DirectFB_WM_AdjustWindowLayout(window); |
190 windata->window->MoveTo(windata->window, x, y); | 251 windata->window->MoveTo(windata->window, x, y); |
191 } | 252 } |
192 | 253 |
193 void | 254 void |
194 DirectFB_SetWindowSize(_THIS, SDL_Window * window) | 255 DirectFB_SetWindowSize(_THIS, SDL_Window * window) |
195 { | 256 { |
257 SDL_DFB_DEVICEDATA(_this); | |
258 SDL_DFB_WINDOWDATA(window); | |
196 int ret; | 259 int ret; |
197 SDL_DFB_WINDOWDATA(window); | |
198 | 260 |
199 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { | 261 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { |
200 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0) | |
201 int cw; | 262 int cw; |
202 int ch; | 263 int ch; |
203 | 264 |
204 /* Make sure all events are disabled for this operation ! */ | 265 /* Make sure all events are disabled for this operation ! */ |
205 SDL_DFB_CHECKERR(windata->window-> | 266 SDL_DFB_CHECKERR(windata->window->DisableEvents(windata->window, |
206 DisableEvents(windata->window, DWET_ALL)); | 267 DWET_ALL)); |
207 | 268 |
208 SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &cw, &ch)); | 269 SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &cw, &ch)); |
209 if (cw != window->w || ch != window->h) | 270 |
210 SDL_DFB_CHECKERR(windata->window-> | 271 if (cw != window->w || ch != window->h) { |
211 Resize(windata->window, window->w, window->h)); | 272 |
212 SDL_DFB_CHECKERR(windata->window-> | 273 DirectFB_WM_AdjustWindowLayout(window); |
213 EnableEvents(windata->window, DWET_ALL)); | 274 SDL_DFB_CHECKERR(windata->window->Resize(windata->window, |
214 | 275 windata->size.w, |
215 #else | 276 windata->size.h)); |
216 SDL_DFB_CHECKERR(windata->window-> | 277 } |
217 Resize(windata->window, window->w, window->h)); | 278 |
218 #endif | 279 SDL_DFB_CHECKERR(windata->window->EnableEvents(windata->window, |
219 SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h)); /* if a window manager should have decided otherwise */ | 280 DWET_ALL)); |
281 | |
282 SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &window->w, &window->h)); | |
220 | 283 |
221 SDL_OnWindowResized(window); | 284 SDL_OnWindowResized(window); |
222 } | 285 } |
223 return; | 286 return; |
224 error: | 287 error: |
254 } | 317 } |
255 | 318 |
256 void | 319 void |
257 DirectFB_MaximizeWindow(_THIS, SDL_Window * window) | 320 DirectFB_MaximizeWindow(_THIS, SDL_Window * window) |
258 { | 321 { |
259 /* FIXME: Size to Desktop ? */ | 322 SDL_DFB_WINDOWDATA(window); |
323 | |
324 if (windata->is_managed) { | |
325 DirectFB_WM_MaximizeWindow(_this, window); | |
326 } else | |
327 SDL_Unsupported(); | |
328 } | |
329 | |
330 void | |
331 DirectFB_MinimizeWindow(_THIS, SDL_Window * window) | |
332 { | |
333 /* FIXME: Size to 32x32 ? */ | |
260 | 334 |
261 SDL_Unsupported(); | 335 SDL_Unsupported(); |
262 } | 336 } |
263 | 337 |
264 void | 338 void |
265 DirectFB_MinimizeWindow(_THIS, SDL_Window * window) | |
266 { | |
267 /* FIXME: Size to 32x32 ? */ | |
268 | |
269 SDL_Unsupported(); | |
270 } | |
271 | |
272 void | |
273 DirectFB_RestoreWindow(_THIS, SDL_Window * window) | 339 DirectFB_RestoreWindow(_THIS, SDL_Window * window) |
274 { | 340 { |
275 SDL_Unsupported(); | 341 SDL_DFB_WINDOWDATA(window); |
342 | |
343 if (windata->is_managed) { | |
344 DirectFB_WM_RestoreWindow(_this, window); | |
345 } else | |
346 SDL_Unsupported(); | |
276 } | 347 } |
277 | 348 |
278 void | 349 void |
279 DirectFB_SetWindowGrab(_THIS, SDL_Window * window) | 350 DirectFB_SetWindowGrab(_THIS, SDL_Window * window) |
280 { | 351 { |
281 SDL_DFB_WINDOWDATA(window); | 352 SDL_DFB_WINDOWDATA(window); |
282 | 353 |
283 if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && | 354 if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) { |
284 (window->flags & SDL_WINDOW_INPUT_FOCUS)) { | |
285 windata->window->GrabPointer(windata->window); | 355 windata->window->GrabPointer(windata->window); |
286 windata->window->GrabKeyboard(windata->window); | 356 windata->window->GrabKeyboard(windata->window); |
287 } else { | 357 } else { |
288 windata->window->UngrabPointer(windata->window); | 358 windata->window->UngrabPointer(windata->window); |
289 windata->window->UngrabKeyboard(windata->window); | 359 windata->window->UngrabKeyboard(windata->window); |
297 SDL_DFB_WINDOWDATA(window); | 367 SDL_DFB_WINDOWDATA(window); |
298 DFB_WindowData *p; | 368 DFB_WindowData *p; |
299 | 369 |
300 SDL_DFB_DEBUG("Trace\n"); | 370 SDL_DFB_DEBUG("Trace\n"); |
301 | 371 |
372 /* Some cleanups */ | |
373 windata->window->UngrabPointer(windata->window); | |
374 windata->window->UngrabKeyboard(windata->window); | |
375 | |
376 windata->window_surface->SetFont(windata->window_surface, NULL); | |
377 SDL_DFB_RELEASE(windata->icon); | |
302 SDL_DFB_RELEASE(windata->eventbuffer); | 378 SDL_DFB_RELEASE(windata->eventbuffer); |
303 SDL_DFB_RELEASE(windata->surface); | 379 SDL_DFB_RELEASE(windata->surface); |
380 SDL_DFB_RELEASE(windata->window_surface); | |
381 | |
304 SDL_DFB_RELEASE(windata->window); | 382 SDL_DFB_RELEASE(windata->window); |
305 | 383 |
306 /* Remove from list ... */ | 384 /* Remove from list ... */ |
307 | 385 |
308 p = devdata->firstwin; | 386 p = devdata->firstwin; |
321 struct SDL_SysWMinfo * info) | 399 struct SDL_SysWMinfo * info) |
322 { | 400 { |
323 SDL_Unsupported(); | 401 SDL_Unsupported(); |
324 return SDL_FALSE; | 402 return SDL_FALSE; |
325 } | 403 } |
404 | |
405 void | |
406 DirectFB_AdjustWindowSurface(SDL_Window * window) | |
407 { | |
408 SDL_DFB_WINDOWDATA(window); | |
409 int adjust = windata->wm_needs_redraw; | |
410 int cw, ch; | |
411 int ret; | |
412 | |
413 DirectFB_WM_AdjustWindowLayout(window); | |
414 | |
415 SDL_DFB_CHECKERR(windata-> | |
416 window_surface->GetSize(windata->window_surface, &cw, | |
417 &ch)); | |
418 if (cw != windata->size.w || ch != windata->size.h) { | |
419 adjust = 1; | |
420 } | |
421 | |
422 if (adjust) { | |
423 SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window, | |
424 windata->size.w, | |
425 windata->size.h)); | |
426 SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface, | |
427 windata-> | |
428 window_surface, | |
429 &windata->client)); | |
430 DirectFB_WM_RedrawLayout(window); | |
431 } | |
432 error: | |
433 return; | |
434 } | |
435 |