comparison src/video/directfb/SDL_DirectFB_WM.c @ 4636:b196d2758026

Couriersud to Sam Hi Sam, 20100815_1.diff contains updates for the directfb driver: - more documentation, mainly on software OpenGL in README.directfb - Revised error handling leading to leaner code - Improved/fixed OpenGL handling of multiple contexts. - Made the built-in simple window manager handle OpenGL windows. - Rewrote pixelformat mapping - this was quite ugly before. Well, all software GL, but working :-)
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Aug 2010 09:04:55 -0700
parents 25b9cd8bdc30
children 164f20ba08eb
comparison
equal deleted inserted replaced
4635:0a07d002f10b 4636:b196d2758026
24 //#include "SDL_syswm.h" 24 //#include "SDL_syswm.h"
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
30 #include "../../events/SDL_windowevents_c.h"
29 31
30 #define COLOR_EXPAND(col) col.r, col.g, col.b, col.a 32 #define COLOR_EXPAND(col) col.r, col.g, col.b, col.a
31 33
32 static DFB_Theme theme_std = { 34 static DFB_Theme theme_std = {
33 4, 4, 8, 8, 35 4, 4, 8, 8,
50 {0, 0, 0, 0}, 52 {0, 0, 0, 0},
51 NULL 53 NULL
52 }; 54 };
53 55
54 static void 56 static void
55 DrTriangle(IDirectFBSurface * s, int down, int x, int y, int w) 57 DrawTriangle(IDirectFBSurface * s, int down, int x, int y, int w)
56 { 58 {
57 int x1, x2, x3; 59 int x1, x2, x3;
58 int y1, y2, y3; 60 int y1, y2, y3;
59 61
60 if (down) { 62 if (down) {
74 } 76 }
75 s->FillTriangle(s, x1, y1, x2, y2, x3, y3); 77 s->FillTriangle(s, x1, y1, x2, y2, x3, y3);
76 } 78 }
77 79
78 static void 80 static void
79 DrCaption(IDirectFBSurface * s, int x, int y, char *text) 81 LoadFont(_THIS, SDL_Window * window)
82 {
83 SDL_DFB_DEVICEDATA(_this);
84 SDL_DFB_WINDOWDATA(window);
85
86 if (windata->font != NULL) {
87 SDL_DFB_RELEASE(windata->font);
88 windata->font = NULL;
89 SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, windata->font));
90 }
91
92 if (windata->theme.font != NULL)
93 {
94 DFBFontDescription fdesc;
95
96 SDL_zero(fdesc);
97 fdesc.flags = DFDESC_HEIGHT;
98 fdesc.height = windata->theme.font_size;
99 SDL_DFB_CHECK(devdata->
100 dfb->CreateFont(devdata->dfb, windata->theme.font,
101 &fdesc, &windata->font));
102 SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, windata->font));
103 }
104 }
105
106 static void
107 DrawCraption(_THIS, IDirectFBSurface * s, int x, int y, char *text)
80 { 108 {
81 DFBSurfaceTextFlags flags; 109 DFBSurfaceTextFlags flags;
82 110
83 flags = DSTF_CENTER | DSTF_TOP; 111 flags = DSTF_CENTER | DSTF_TOP;
84 112
85 s->DrawString(s, text, -1, x, y, flags); 113 s->DrawString(s, text, -1, x, y, flags);
86 } 114 }
87 115
88 void 116 void
89 DirectFB_WM_RedrawLayout(SDL_Window * window) 117 DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window)
90 { 118 {
91 SDL_DFB_WINDOWDATA(window); 119 SDL_DFB_WINDOWDATA(window);
92 IDirectFBSurface *s = windata->window_surface; 120 IDirectFBSurface *s = windata->window_surface;
93 DFB_Theme *t = &windata->theme; 121 DFB_Theme *t = &windata->theme;
94 int i; 122 int i;
97 125
98 126
99 if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN)) 127 if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN))
100 return; 128 return;
101 129
130 LoadFont(_this, window);
102 //s->SetDrawingFlags(s, DSDRAW_BLEND); 131 //s->SetDrawingFlags(s, DSDRAW_BLEND);
103 s->SetColor(s, COLOR_EXPAND(t->frame_color)); 132 s->SetColor(s, COLOR_EXPAND(t->frame_color));
104 /* top */ 133 /* top */
105 for (i = 0; i < t->top_size; i++) 134 for (i = 0; i < t->top_size; i++)
106 s->DrawLine(s, 0, i, windata->size.w, i); 135 s->DrawLine(s, 0, i, windata->size.w, i);
120 /* Close Button */ 149 /* Close Button */
121 w = t->caption_size; 150 w = t->caption_size;
122 x = windata->size.w - t->right_size - w + d; 151 x = windata->size.w - t->right_size - w + d;
123 y = t->top_size + d; 152 y = t->top_size + d;
124 s->SetColor(s, COLOR_EXPAND(t->close_color)); 153 s->SetColor(s, COLOR_EXPAND(t->close_color));
125 DrTriangle(s, 1, x, y, w - 2 * d); 154 DrawTriangle(s, 1, x, y, w - 2 * d);
126 /* Max Button */ 155 /* Max Button */
127 s->SetColor(s, COLOR_EXPAND(t->max_color)); 156 s->SetColor(s, COLOR_EXPAND(t->max_color));
128 DrTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w, 157 DrawTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w,
129 y, w - 2 * d); 158 y, w - 2 * d);
130 159
131 /* Caption */ 160 /* Caption */
132 if (window->title) { 161 if (window->title) {
133 s->SetColor(s, COLOR_EXPAND(t->font_color)); 162 s->SetColor(s, COLOR_EXPAND(t->font_color));
134 DrCaption(s, (x - w) / 2, t->top_size + d, window->title); 163 DrawCraption(_this, s, (x - w) / 2, t->top_size + d, window->title);
135 } 164 }
136 /* Icon */ 165 /* Icon */
137 if (windata->icon) { 166 if (windata->icon) {
138 DFBRectangle dr; 167 DFBRectangle dr;
139 168
150 179
151 DFBResult 180 DFBResult
152 DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch) 181 DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch)
153 { 182 {
154 SDL_DFB_WINDOWDATA(window); 183 SDL_DFB_WINDOWDATA(window);
155 DFBResult ret; 184
156 185 SDL_DFB_CHECK(windata->window->GetSize(windata->window, cw, ch));
157 ret = windata->window->GetSize(windata->window, cw, ch);
158 *cw -= windata->theme.left_size + windata->theme.right_size; 186 *cw -= windata->theme.left_size + windata->theme.right_size;
159 *ch -= 187 *ch -=
160 windata->theme.top_size + windata->theme.caption_size + 188 windata->theme.top_size + windata->theme.caption_size +
161 windata->theme.bottom_size; 189 windata->theme.bottom_size;
162 return ret; 190 return DFB_OK;
163 } 191 }
164 192
165 void 193 void
166 DirectFB_WM_AdjustWindowLayout(SDL_Window * window) 194 DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h)
167 { 195 {
168 SDL_DFB_WINDOWDATA(window); 196 SDL_DFB_WINDOWDATA(window);
169 197
170 if (!windata->is_managed) 198 if (!windata->is_managed)
171 windata->theme = theme_none; 199 windata->theme = theme_none;
172 else if (window->flags & SDL_WINDOW_FULLSCREEN) { 200 else if (flags & SDL_WINDOW_FULLSCREEN) {
173 windata->theme = theme_none; 201 windata->theme = theme_none;
174 } else if (window->flags & SDL_WINDOW_MAXIMIZED) { 202 } else if (flags & SDL_WINDOW_MAXIMIZED) {
175 windata->theme = theme_std; 203 windata->theme = theme_std;
176 windata->theme.left_size = 0; 204 windata->theme.left_size = 0;
177 windata->theme.right_size = 0; 205 windata->theme.right_size = 0;
178 windata->theme.top_size = 0; 206 windata->theme.top_size = 0;
179 windata->theme.bottom_size = 0; 207 windata->theme.bottom_size = 0;
181 windata->theme = theme_std; 209 windata->theme = theme_std;
182 } 210 }
183 211
184 windata->client.x = windata->theme.left_size; 212 windata->client.x = windata->theme.left_size;
185 windata->client.y = windata->theme.top_size + windata->theme.caption_size; 213 windata->client.y = windata->theme.top_size + windata->theme.caption_size;
186 windata->client.w = window->w; 214 windata->client.w = w;
187 windata->client.h = window->h; 215 windata->client.h = h;
188 windata->size.w = 216 windata->size.w =
189 window->w + windata->theme.left_size + windata->theme.right_size; 217 w + windata->theme.left_size + windata->theme.right_size;
190 windata->size.h = 218 windata->size.h =
191 window->h + windata->theme.top_size + 219 h + windata->theme.top_size +
192 windata->theme.caption_size + windata->theme.bottom_size; 220 windata->theme.caption_size + windata->theme.bottom_size;
193 } 221 }
194 222
195 void 223 void
196 DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window) 224 DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window)
197 { 225 {
198 SDL_DFB_WINDOWDATA(window); 226 SDL_DFB_WINDOWDATA(window);
199 SDL_VideoDisplay *display = window->display; 227 SDL_VideoDisplay *display = window->display;
200 228
201 windata->window->GetPosition(windata->window, 229 SDL_DFB_CHECK(windata->window->GetPosition(windata->window,
202 &windata->restore.x, &windata->restore.y); 230 &windata->restore.x, &windata->restore.y));
203 windata->window->GetSize(windata->window, &windata->restore.w, 231 SDL_DFB_CHECK(windata->window->GetSize(windata->window, &windata->restore.w,
204 &windata->restore.h); 232 &windata->restore.h));
205 233
206 /* Do this already here */ 234 DirectFB_WM_AdjustWindowLayout(window, window->flags | SDL_WINDOW_MAXIMIZED, display->current_mode.w, display->current_mode.h) ;
207 window->flags |= SDL_WINDOW_MAXIMIZED; 235
208 DirectFB_WM_AdjustWindowLayout(window); 236 SDL_DFB_CHECK(windata->window->MoveTo(windata->window, 0, 0));
209 237 SDL_DFB_CHECK(windata->window->Resize(windata->window,
210 windata->window->MoveTo(windata->window, 0, 0); 238 display->current_mode.w, display->current_mode.h));
211 windata->window->Resize(windata->window,
212 display->current_mode.w, display->current_mode.h);
213 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
214 } 239 }
215 240
216 void 241 void
217 DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window) 242 DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window)
218 { 243 {
219 SDL_DFB_WINDOWDATA(window); 244 SDL_DFB_WINDOWDATA(window);
220 245
221 /* Do this already here */ 246 DirectFB_WM_AdjustWindowLayout(window, window->flags & ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED),
222 //window->flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED); 247 windata->restore.w, windata->restore.h);
223 248
224 DirectFB_WM_AdjustWindowLayout(window); 249 SDL_DFB_CHECK(windata->window->Resize(windata->window, windata->restore.w,
225 windata->window->MoveTo(windata->window, windata->restore.x, 250 windata->restore.h));
226 windata->restore.y); 251 SDL_DFB_CHECK(windata->window->MoveTo(windata->window, windata->restore.x,
227 windata->window->Resize(windata->window, windata->restore.w, 252 windata->restore.y));
228 windata->restore.h);
229 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
230 } 253 }
231 254
232 enum 255 enum
233 { 256 {
234 WM_POS_NONE = 0x00, 257 WM_POS_NONE = 0x00,
289 static int wm_lasty; 312 static int wm_lasty;
290 313
291 int 314 int
292 DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt) 315 DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
293 { 316 {
294 SDL_DFB_WINDOWDATA(window); 317 SDL_DFB_DEVICEDATA(_this);
318 SDL_DFB_WINDOWDATA(window);
319 DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
295 320
296 if (!windata->is_managed) 321 if (!windata->is_managed)
297 return 0; 322 return 0;
298 323
299 switch (evt->type) { 324 switch (evt->type) {
302 int pos = WMPos(windata, evt->x, evt->y); 327 int pos = WMPos(windata, evt->x, evt->y);
303 switch (pos) { 328 switch (pos) {
304 case WM_POS_NONE: 329 case WM_POS_NONE:
305 return 0; 330 return 0;
306 case WM_POS_CLOSE: 331 case WM_POS_CLOSE:
332 wm_grab = WM_POS_NONE;
307 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0, 333 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0,
308 0); 334 0);
309 return 1; 335 return 1;
310 case WM_POS_MAX: 336 case WM_POS_MAX:
337 wm_grab = WM_POS_NONE;
311 if (window->flags & SDL_WINDOW_MAXIMIZED) { 338 if (window->flags & SDL_WINDOW_MAXIMIZED) {
312 DirectFB_WM_RestoreWindow(_this, window); 339 SDL_RestoreWindow(window);
313 } else { 340 } else {
314 DirectFB_WM_MaximizeWindow(_this, window); 341 SDL_MaximizeWindow(window);
315 } 342 }
316 return 1; 343 return 1;
344 case WM_POS_CAPTION:
345 DirectFB_RaiseWindow(_this, window);
346 /* fall through */
317 default: 347 default:
318 wm_grab = pos; 348 wm_grab = pos;
319 windata->window->GrabPointer(windata->window); 349 if (gwindata != NULL)
350 SDL_DFB_CHECK(gwindata->window->UngrabPointer(gwindata->window));
351 SDL_DFB_CHECK(windata->window->GrabPointer(windata->window));
320 wm_lastx = evt->cx; 352 wm_lastx = evt->cx;
321 wm_lasty = evt->cy; 353 wm_lasty = evt->cy;
322 } 354 }
323 } 355 }
324 return 1; 356 return 1;
331 int dx = evt->cx - wm_lastx; 363 int dx = evt->cx - wm_lastx;
332 int dy = evt->cy - wm_lasty; 364 int dy = evt->cy - wm_lasty;
333 int cw, ch; 365 int cw, ch;
334 366
335 if (wm_grab & WM_POS_CAPTION) 367 if (wm_grab & WM_POS_CAPTION)
336 windata->window->Move(windata->window, dx, dy); 368 SDL_DFB_CHECK(windata->window->Move(windata->window, dx, dy));
337 if (wm_grab & WM_POS_RIGHT) { 369 if (wm_grab & (WM_POS_RIGHT | WM_POS_BOTTOM)) {
338 windata->window->GetSize(windata->window, &cw, &ch); 370 if ((wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_BOTTOM)
339 windata->window->Resize(windata->window, cw + dx, ch); 371 dx = 0;
340 } 372 else if ((wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_RIGHT)
341 if (wm_grab & WM_POS_BOTTOM) { 373 dy = 0;
342 windata->window->GetSize(windata->window, &cw, &ch); 374 SDL_DFB_CHECK(windata->window->GetSize(windata->window, &cw, &ch));
343 windata->window->Resize(windata->window, cw, ch + dy); 375 SDL_DFB_CHECK(windata->window->Resize(windata->window, cw + dx, ch + dy));
344 } 376 }
345 wm_lastx = evt->cx; 377 wm_lastx = evt->cx;
346 wm_lasty = evt->cy; 378 wm_lasty = evt->cy;
347 return 1; 379 return 1;
348 } 380 }
349 windata->window->UngrabPointer(windata->window); 381 SDL_DFB_CHECK(windata->window->UngrabPointer(windata->window));
382 if (gwindata != NULL)
383 SDL_DFB_CHECK(gwindata->window->GrabPointer(gwindata->window));
350 wm_grab = WM_POS_NONE; 384 wm_grab = WM_POS_NONE;
351 break; 385 break;
352 case DWET_KEYDOWN: 386 case DWET_KEYDOWN:
353 break; 387 break;
354 case DWET_KEYUP: 388 case DWET_KEYUP: