DirectFB cleanups & simple window manager
authorCouriersud <couriersud@arcor.de>
Sun, 11 Jan 2009 23:49:23 +0000
changeset 3023d72a0dd80e8b
parent 3022 db20dde98dd3
child 3024 1a08749aebce
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
README.DirectFB
src/video/directfb/SDL_DirectFB_WM.c
src/video/directfb/SDL_DirectFB_WM.h
src/video/directfb/SDL_DirectFB_dyn.c
src/video/directfb/SDL_DirectFB_dyn.h
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_modes.c
src/video/directfb/SDL_DirectFB_mouse.c
src/video/directfb/SDL_DirectFB_opengl.c
src/video/directfb/SDL_DirectFB_render.c
src/video/directfb/SDL_DirectFB_video.c
src/video/directfb/SDL_DirectFB_video.h
src/video/directfb/SDL_DirectFB_window.c
src/video/directfb/SDL_DirectFB_window.h
     1.1 --- a/README.DirectFB	Sun Jan 11 23:39:11 2009 +0000
     1.2 +++ b/README.DirectFB	Sun Jan 11 23:49:23 2009 +0000
     1.3 @@ -49,6 +49,19 @@
     1.4  to make the YUV texture an underlay. This will make the cursor to
     1.5  be shown.
     1.6  
     1.7 +Simple Window Manager
     1.8 +=====================
     1.9 +
    1.10 +The driver has support for a very, very basic window manager you may
    1.11 +want to use when runnning with "wm=default". Use
    1.12 +
    1.13 +export SDL_DIRECTFB_WM=1
    1.14 +
    1.15 +to enable basic window borders. In order to have the window title rendered,
    1.16 +you need to have the following font installed:
    1.17 +
    1.18 +/usr/share/fonts/truetype/freefont/FreeSans.ttf
    1.19 +
    1.20  OPENGL Support
    1.21  ==============
    1.22  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/video/directfb/SDL_DirectFB_WM.c	Sun Jan 11 23:49:23 2009 +0000
     2.3 @@ -0,0 +1,361 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 1997-2009 Sam Lantinga
     2.7 +
     2.8 +    This library is free software; you can redistribute it and/or
     2.9 +    modify it under the terms of the GNU Lesser General Public
    2.10 +    License as published by the Free Software Foundation; either
    2.11 +    version 2.1 of the License, or (at your option) any later version.
    2.12 +
    2.13 +    This library is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 +    Lesser General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU Lesser General Public
    2.19 +    License along with this library; if not, write to the Free Software
    2.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 +
    2.22 +    Sam Lantinga
    2.23 +    slouken@libsdl.org
    2.24 +*/
    2.25 +#include "SDL_config.h"
    2.26 +
    2.27 +//#include "SDL_syswm.h"
    2.28 +//#include "../SDL_sysvideo.h"
    2.29 +//#include "../../events/SDL_keyboard_c.h"
    2.30 +
    2.31 +#include "SDL_DirectFB_video.h"
    2.32 +
    2.33 +#define COLOR_EXPAND(col) col.r, col.g, col.b, col.a
    2.34 +
    2.35 +static DFB_Theme theme_std = {
    2.36 +    4, 4, 8, 8,
    2.37 +    {255, 200, 200, 200},
    2.38 +    24,
    2.39 +    {255, 0, 0, 255},
    2.40 +    16,
    2.41 +    {255, 255, 255, 255},
    2.42 +    "/usr/share/fonts/truetype/freefont/FreeSans.ttf",
    2.43 +    {255, 255, 0, 0},
    2.44 +    {255, 255, 255, 0},
    2.45 +};
    2.46 +
    2.47 +static DFB_Theme theme_none = {
    2.48 +    0, 0, 0, 0,
    2.49 +    {0, 0, 0, 0},
    2.50 +    0,
    2.51 +    {0, 0, 0, 0},
    2.52 +    0,
    2.53 +    {0, 0, 0, 0},
    2.54 +    NULL
    2.55 +};
    2.56 +
    2.57 +static void
    2.58 +DrTriangle(IDirectFBSurface * s, int down, int x, int y, int w)
    2.59 +{
    2.60 +    int x1, x2, x3;
    2.61 +    int y1, y2, y3;
    2.62 +
    2.63 +    if (down) {
    2.64 +        x1 = x + w / 2;
    2.65 +        x2 = x;
    2.66 +        x3 = x + w;
    2.67 +        y1 = y + w;
    2.68 +        y2 = y;
    2.69 +        y3 = y;
    2.70 +    } else {
    2.71 +        x1 = x + w / 2;
    2.72 +        x2 = x;
    2.73 +        x3 = x + w;
    2.74 +        y1 = y;
    2.75 +        y2 = y + w;
    2.76 +        y3 = y + w;
    2.77 +    }
    2.78 +    s->FillTriangle(s, x1, y1, x2, y2, x3, y3);
    2.79 +}
    2.80 +
    2.81 +static void
    2.82 +DrCaption(IDirectFBSurface * s, int x, int y, char *text)
    2.83 +{
    2.84 +    DFBSurfaceTextFlags flags;
    2.85 +
    2.86 +    flags = DSTF_CENTER | DSTF_TOP;
    2.87 +
    2.88 +    s->DrawString(s, text, -1, x, y, flags);
    2.89 +}
    2.90 +
    2.91 +void
    2.92 +DirectFB_WM_RedrawLayout(SDL_Window * window)
    2.93 +{
    2.94 +    SDL_DFB_WINDOWDATA(window);
    2.95 +    IDirectFBSurface *s = windata->window_surface;
    2.96 +    DFB_Theme *t = &windata->theme;
    2.97 +    int i;
    2.98 +    int d = (t->caption_size - t->font_size) / 2;
    2.99 +    int x, y, w;
   2.100 +
   2.101 +
   2.102 +    if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN))
   2.103 +        return;
   2.104 +
   2.105 +    //s->SetDrawingFlags(s, DSDRAW_BLEND);
   2.106 +    s->SetColor(s, COLOR_EXPAND(t->frame_color));
   2.107 +    /* top */
   2.108 +    for (i = 0; i < t->top_size; i++)
   2.109 +        s->DrawLine(s, 0, i, windata->size.w, i);
   2.110 +    /* bottom */
   2.111 +    for (i = windata->size.h - t->bottom_size; i < windata->size.h; i++)
   2.112 +        s->DrawLine(s, 0, i, windata->size.w, i);
   2.113 +    /* left */
   2.114 +    for (i = 0; i < t->left_size; i++)
   2.115 +        s->DrawLine(s, i, 0, i, windata->size.h);
   2.116 +    /* right */
   2.117 +    for (i = windata->size.w - t->right_size; i < windata->size.w; i++)
   2.118 +        s->DrawLine(s, i, 0, i, windata->size.h);
   2.119 +    /* Caption */
   2.120 +    s->SetColor(s, COLOR_EXPAND(t->caption_color));
   2.121 +    s->FillRectangle(s, t->left_size, t->top_size, windata->client.w,
   2.122 +                     t->caption_size);
   2.123 +    /* Close Button */
   2.124 +    w = t->caption_size;
   2.125 +    x = windata->size.w - t->right_size - w + d;
   2.126 +    y = t->top_size + d;
   2.127 +    s->SetColor(s, COLOR_EXPAND(t->close_color));
   2.128 +    DrTriangle(s, 1, x, y, w - 2 * d);
   2.129 +    /* Max Button */
   2.130 +    s->SetColor(s, COLOR_EXPAND(t->max_color));
   2.131 +    DrTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w,
   2.132 +               y, w - 2 * d);
   2.133 +
   2.134 +    /* Caption */
   2.135 +    if (window->title) {
   2.136 +        s->SetColor(s, COLOR_EXPAND(t->font_color));
   2.137 +        DrCaption(s, (x - w) / 2, t->top_size + d, window->title);
   2.138 +    }
   2.139 +    /* Icon */
   2.140 +    if (windata->icon) {
   2.141 +        DFBRectangle dr;
   2.142 +
   2.143 +        dr.x = t->left_size + d;
   2.144 +        dr.y = t->top_size + d;
   2.145 +        dr.w = w - 2 * d;
   2.146 +        dr.h = w - 2 * d;
   2.147 +        s->SetBlittingFlags(s, DSBLIT_BLEND_ALPHACHANNEL);
   2.148 +
   2.149 +        s->StretchBlit(s, windata->icon, NULL, &dr);
   2.150 +    }
   2.151 +    windata->wm_needs_redraw = 0;
   2.152 +}
   2.153 +
   2.154 +DFBResult
   2.155 +DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch)
   2.156 +{
   2.157 +    SDL_DFB_WINDOWDATA(window);
   2.158 +    DFBResult ret;
   2.159 +
   2.160 +    ret = windata->window->GetSize(windata->window, cw, ch);
   2.161 +    *cw -= windata->theme.left_size + windata->theme.right_size;
   2.162 +    *ch -=
   2.163 +        windata->theme.top_size + windata->theme.caption_size +
   2.164 +        windata->theme.bottom_size;
   2.165 +    return ret;
   2.166 +}
   2.167 +
   2.168 +void
   2.169 +DirectFB_WM_AdjustWindowLayout(SDL_Window * window)
   2.170 +{
   2.171 +    SDL_DFB_WINDOWDATA(window);
   2.172 +
   2.173 +    if (!windata->is_managed)
   2.174 +        windata->theme = theme_none;
   2.175 +    else if (window->flags & SDL_WINDOW_FULLSCREEN) {
   2.176 +        windata->theme = theme_none;
   2.177 +    } else if (window->flags & SDL_WINDOW_MAXIMIZED) {
   2.178 +        windata->theme = theme_std;
   2.179 +        windata->theme.left_size = 0;
   2.180 +        windata->theme.right_size = 0;
   2.181 +        windata->theme.top_size = 0;
   2.182 +        windata->theme.bottom_size = 0;
   2.183 +    } else {
   2.184 +        windata->theme = theme_std;
   2.185 +    }
   2.186 +
   2.187 +    windata->client.x = windata->theme.left_size;
   2.188 +    windata->client.y = windata->theme.top_size + windata->theme.caption_size;
   2.189 +    windata->client.w = window->w;
   2.190 +    windata->client.h = window->h;
   2.191 +    windata->size.w =
   2.192 +        window->w + windata->theme.left_size + windata->theme.right_size;
   2.193 +    windata->size.h =
   2.194 +        window->h + windata->theme.top_size +
   2.195 +        windata->theme.caption_size + windata->theme.bottom_size;
   2.196 +}
   2.197 +
   2.198 +void
   2.199 +DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window)
   2.200 +{
   2.201 +    SDL_DFB_WINDOWDATA(window);
   2.202 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   2.203 +
   2.204 +    windata->window->GetPosition(windata->window,
   2.205 +                                     &windata->restore.x,
   2.206 +                                     &windata->restore.y);
   2.207 +    windata->window->GetSize(windata->window, &windata->restore.w,
   2.208 +                                 &windata->restore.h);
   2.209 +
   2.210 +    /* Do this already here */
   2.211 +    window->flags |= SDL_WINDOW_MAXIMIZED;
   2.212 +    DirectFB_WM_AdjustWindowLayout(window);
   2.213 +
   2.214 +    windata->window->MoveTo(windata->window, 0, 0);
   2.215 +    windata->window->Resize(windata->window,
   2.216 +                            display->current_mode.w,
   2.217 +                            display->current_mode.h);
   2.218 +    SDL_SendWindowEvent(windata->sdl_id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   2.219 +}
   2.220 +
   2.221 +void
   2.222 +DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window)
   2.223 +{
   2.224 +    SDL_DFB_WINDOWDATA(window);
   2.225 +
   2.226 +    /* Do this already here */
   2.227 +    //window->flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED);
   2.228 +
   2.229 +    DirectFB_WM_AdjustWindowLayout(window);
   2.230 +    windata->window->MoveTo(windata->window, windata->restore.x,
   2.231 +                            windata->restore.y);
   2.232 +    windata->window->Resize(windata->window, windata->restore.w,
   2.233 +                            windata->restore.h);
   2.234 +    SDL_SendWindowEvent(windata->sdl_id, SDL_WINDOWEVENT_RESTORED, 0, 0);
   2.235 +}
   2.236 +
   2.237 +enum
   2.238 +{
   2.239 +    WM_POS_NONE = 0x00,
   2.240 +    WM_POS_CAPTION = 0x01,
   2.241 +    WM_POS_CLOSE = 0x02,
   2.242 +    WM_POS_MAX = 0x04,
   2.243 +    WM_POS_LEFT = 0x08,
   2.244 +    WM_POS_RIGHT = 0x10,
   2.245 +    WM_POS_TOP = 0x20,
   2.246 +    WM_POS_BOTTOM = 0x40,
   2.247 +};
   2.248 +
   2.249 +static int
   2.250 +WMIsClient(DFB_WindowData * p, int x, int y)
   2.251 +{
   2.252 +    x -= p->client.x;
   2.253 +    y -= p->client.y;
   2.254 +    if (x < 0 || y < 0)
   2.255 +        return 0;
   2.256 +    if (x >= p->client.w || y >= p->client.h)
   2.257 +        return 0;
   2.258 +    return 1;
   2.259 +}
   2.260 +
   2.261 +static int
   2.262 +WMPos(DFB_WindowData * p, int x, int y)
   2.263 +{
   2.264 +    int pos = WM_POS_NONE;
   2.265 +
   2.266 +    if (!WMIsClient(p, x, y)) {
   2.267 +        if (y < p->theme.top_size) {
   2.268 +            pos |= WM_POS_TOP;
   2.269 +        } else if (y < p->client.y) {
   2.270 +            if (x <
   2.271 +                p->size.w - p->theme.right_size - 2 * p->theme.caption_size) {
   2.272 +                pos |= WM_POS_CAPTION;
   2.273 +            } else if (x <
   2.274 +                       p->size.w - p->theme.right_size -
   2.275 +                       p->theme.caption_size) {
   2.276 +                pos |= WM_POS_MAX;
   2.277 +            } else {
   2.278 +                pos |= WM_POS_CLOSE;
   2.279 +            }
   2.280 +        } else if (y >= p->size.h - p->theme.bottom_size) {
   2.281 +            pos |= WM_POS_BOTTOM;
   2.282 +        }
   2.283 +        if (x < p->theme.left_size) {
   2.284 +            pos |= WM_POS_LEFT;
   2.285 +        } else if (x >= p->size.w - p->theme.right_size) {
   2.286 +            pos |= WM_POS_RIGHT;
   2.287 +        }
   2.288 +    }
   2.289 +    return pos;
   2.290 +}
   2.291 +
   2.292 +static int wm_grab;
   2.293 +static int wm_lastx;
   2.294 +static int wm_lasty;
   2.295 +
   2.296 +int
   2.297 +DirectFB_WM_ProcessEvent(_THIS, SDL_Window *window, DFBWindowEvent * evt)
   2.298 +{
   2.299 +    SDL_DFB_WINDOWDATA(window);
   2.300 +
   2.301 +    if (!windata->is_managed)
   2.302 +        return 0;
   2.303 +
   2.304 +    switch (evt->type) {
   2.305 +    case DWET_BUTTONDOWN:
   2.306 +        if (evt->buttons & DIBM_LEFT) {
   2.307 +            int pos = WMPos(windata, evt->x, evt->y);
   2.308 +            switch (pos) {
   2.309 +            case WM_POS_NONE:
   2.310 +                return 0;
   2.311 +            case WM_POS_CLOSE:
   2.312 +                SDL_SendWindowEvent(windata->sdl_id, SDL_WINDOWEVENT_CLOSE, 0, 0);
   2.313 +                return 1;
   2.314 +            case WM_POS_MAX:
   2.315 +                if (window->flags & SDL_WINDOW_MAXIMIZED) {
   2.316 +                    DirectFB_WM_RestoreWindow(_this, window);
   2.317 +                } else {
   2.318 +                	DirectFB_WM_MaximizeWindow(_this, window);
   2.319 +                }
   2.320 +                return 1;
   2.321 +            default:
   2.322 +                wm_grab = pos;
   2.323 +                windata->window->GrabPointer(windata->window);
   2.324 +                wm_lastx = evt->cx;
   2.325 +                wm_lasty = evt->cy;
   2.326 +            }
   2.327 +        }
   2.328 +        return 1;
   2.329 +    case DWET_BUTTONUP:
   2.330 +        break;
   2.331 +    case DWET_MOTION:
   2.332 +        if (!wm_grab)
   2.333 +            return 0;
   2.334 +        if (evt->buttons & DIBM_LEFT) {
   2.335 +            int dx = evt->cx - wm_lastx;
   2.336 +            int dy = evt->cy - wm_lasty;
   2.337 +            int cw, ch;
   2.338 +
   2.339 +            if (wm_grab & WM_POS_CAPTION)
   2.340 +                windata->window->Move(windata->window, dx, dy);
   2.341 +            if (wm_grab & WM_POS_RIGHT) {
   2.342 +                windata->window->GetSize(windata->window, &cw, &ch);
   2.343 +                windata->window->Resize(windata->window, cw + dx, ch);
   2.344 +            }
   2.345 +            if (wm_grab & WM_POS_BOTTOM) {
   2.346 +                windata->window->GetSize(windata->window, &cw, &ch);
   2.347 +                windata->window->Resize(windata->window, cw, ch + dy);
   2.348 +            }
   2.349 +            wm_lastx = evt->cx;
   2.350 +            wm_lasty = evt->cy;
   2.351 +            return 1;
   2.352 +        }
   2.353 +        windata->window->UngrabPointer(windata->window);
   2.354 +        wm_grab = WM_POS_NONE;
   2.355 +        break;
   2.356 +    case DWET_KEYDOWN:
   2.357 +        break;
   2.358 +    case DWET_KEYUP:
   2.359 +        break;
   2.360 +    default:
   2.361 +        ;
   2.362 +    }
   2.363 +    return 0;
   2.364 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/video/directfb/SDL_DirectFB_WM.h	Sun Jan 11 23:49:23 2009 +0000
     3.3 @@ -0,0 +1,56 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2009 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +#include "SDL_config.h"
    3.26 +
    3.27 +#ifndef _SDL_directfb_wm_h
    3.28 +#define _SDL_directfb_wm_h
    3.29 +
    3.30 +typedef struct _DFB_Theme DFB_Theme;
    3.31 +struct _DFB_Theme
    3.32 +{
    3.33 +    int left_size;
    3.34 +    int right_size;
    3.35 +    int top_size;
    3.36 +    int bottom_size;
    3.37 +    DFBColor frame_color;
    3.38 +    int caption_size;
    3.39 +    DFBColor caption_color;
    3.40 +    int font_size;
    3.41 +    DFBColor font_color;
    3.42 +    char *font;
    3.43 +    DFBColor close_color;
    3.44 +    DFBColor max_color;
    3.45 +};
    3.46 +
    3.47 +extern void DirectFB_WM_AdjustWindowLayout(SDL_Window * window);
    3.48 +extern void DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window);
    3.49 +extern void DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window);
    3.50 +extern void DirectFB_WM_RedrawLayout(SDL_Window * window);
    3.51 +
    3.52 +extern int DirectFB_WM_ProcessEvent(_THIS, SDL_Window *window, DFBWindowEvent * evt);
    3.53 +
    3.54 +extern DFBResult DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch);
    3.55 +
    3.56 +
    3.57 +#endif /* _SDL_directfb_wm_h */
    3.58 +
    3.59 +/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/directfb/SDL_DirectFB_dyn.c	Sun Jan 11 23:39:11 2009 +0000
     4.2 +++ b/src/video/directfb/SDL_DirectFB_dyn.c	Sun Jan 11 23:49:23 2009 +0000
     4.3 @@ -21,8 +21,8 @@
     4.4  */
     4.5  #include "SDL_config.h"
     4.6  
     4.7 +#include "SDL_DirectFB_video.h"
     4.8  #include "SDL_DirectFB_dyn.h"
     4.9 -#include "SDL_DirectFB_video.h"
    4.10  
    4.11  #ifdef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
    4.12  #include "SDL_name.h"
    4.13 @@ -69,11 +69,11 @@
    4.14          }
    4.15      }
    4.16      if (retval) {
    4.17 +        const char *stemp = DirectFBCheckVersion(DIRECTFB_MAJOR_VERSION,
    4.18 +                                                 DIRECTFB_MINOR_VERSION,
    4.19 +                                                 DIRECTFB_MICRO_VERSION);
    4.20          /* Version Check */
    4.21 -        if ((*SDL_DirectFB_Symbols.directfb_major_version !=
    4.22 -             DIRECTFB_MAJOR_VERSION)
    4.23 -            || (*SDL_DirectFB_Symbols.directfb_minor_version !=
    4.24 -                DIRECTFB_MINOR_VERSION)) {
    4.25 +        if (stemp != NULL) {
    4.26              fprintf(stderr,
    4.27                      "DirectFB Lib: Version mismatch. Compiled: %d.%d.%d Library %d.%d.%d\n",
    4.28                      DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION,
     5.1 --- a/src/video/directfb/SDL_DirectFB_dyn.h	Sun Jan 11 23:39:11 2009 +0000
     5.2 +++ b/src/video/directfb/SDL_DirectFB_dyn.h	Sun Jan 11 23:49:23 2009 +0000
     5.3 @@ -30,8 +30,9 @@
     5.4  	DFB_SYM(const char *, DirectFBUsageString, ( void ), (), return) \
     5.5  	DFB_SYM(DFBResult, DirectFBInit, (int *argc, char *(*argv[]) ), (argc, argv), return) \
     5.6  	DFB_SYM(DFBResult, DirectFBSetOption, (const char *name, const char *value), (name, value), return) \
     5.7 -	DFB_SYM(DFBResult, DirectFBCreate, (IDirectFB **interface), (interface), return)
     5.8 -
     5.9 +	DFB_SYM(DFBResult, DirectFBCreate, (IDirectFB **interface), (interface), return) \
    5.10 +	DFB_SYM(const char *, DirectFBCheckVersion, (unsigned int required_major, unsigned int required_minor, unsigned int required_micro), \
    5.11 +				(required_major, required_minor, required_micro), return)
    5.12  // #define SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "/usr/lib/libdirectfb-1.2.so.0"
    5.13  
    5.14  int SDL_DirectFB_LoadLibrary(void);
     6.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Sun Jan 11 23:39:11 2009 +0000
     6.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Sun Jan 11 23:49:23 2009 +0000
     6.3 @@ -60,8 +60,8 @@
     6.4      int ret;
     6.5  
     6.6      if (dispdata->vidIDinuse)
     6.7 -        SDL_DFB_CHECKERR(dispdata->vidlayer->
     6.8 -                         SwitchContext(dispdata->vidlayer, DFB_TRUE));
     6.9 +        SDL_DFB_CHECKERR(dispdata->vidlayer->SwitchContext(dispdata->vidlayer,
    6.10 +                                                           DFB_TRUE));
    6.11  
    6.12    error:
    6.13      return;
    6.14 @@ -117,6 +117,254 @@
    6.15      return -1;
    6.16  }
    6.17  
    6.18 +static int
    6.19 +ClientXY(DFB_WindowData * p, int *x, int *y)
    6.20 +{
    6.21 +    int cx, cy;
    6.22 +
    6.23 +    cx = *x;
    6.24 +    cy = *y;
    6.25 +
    6.26 +    cx -= p->client.x;
    6.27 +    cy -= p->client.y;
    6.28 +
    6.29 +    if (cx < 0 || cy < 0)
    6.30 +        return 0;
    6.31 +    if (cx >= p->client.w || cy >= p->client.h)
    6.32 +        return 0;
    6.33 +    *x = cx;
    6.34 +    *y = cy;
    6.35 +    return 1;
    6.36 +}
    6.37 +
    6.38 +static void
    6.39 +ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags,
    6.40 +                   DFBWindowEvent * evt)
    6.41 +{
    6.42 +    SDL_DFB_DEVICEDATA(_this);
    6.43 +    SDL_keysym keysym;
    6.44 +    char text[5];
    6.45 +
    6.46 +    if (evt->clazz == DFEC_WINDOW) {
    6.47 +        switch (evt->type) {
    6.48 +        case DWET_BUTTONDOWN:
    6.49 +            if (ClientXY(p, &evt->x, &evt->y)) {
    6.50 +                if (!devdata->use_linux_input) {
    6.51 +                    SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt->x,
    6.52 +                                        evt->y, 0);
    6.53 +                    SDL_SendMouseButton(devdata->mouse_id[0],
    6.54 +                                        SDL_PRESSED,
    6.55 +                                        DirectFB_TranslateButton
    6.56 +                                        (evt->button));
    6.57 +                } else {
    6.58 +                    MotionAllMice(_this, evt->x, evt->y);
    6.59 +                }
    6.60 +            }
    6.61 +            break;
    6.62 +        case DWET_BUTTONUP:
    6.63 +            if (ClientXY(p, &evt->x, &evt->y)) {
    6.64 +                if (!devdata->use_linux_input) {
    6.65 +                    SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt->x,
    6.66 +                                        evt->y, 0);
    6.67 +                    SDL_SendMouseButton(devdata->mouse_id[0],
    6.68 +                                        SDL_RELEASED,
    6.69 +                                        DirectFB_TranslateButton
    6.70 +                                        (evt->button));
    6.71 +                } else {
    6.72 +                    MotionAllMice(_this, evt->x, evt->y);
    6.73 +                }
    6.74 +            }
    6.75 +            break;
    6.76 +        case DWET_MOTION:
    6.77 +            if (ClientXY(p, &evt->x, &evt->y)) {
    6.78 +            	SDL_Window *window = SDL_GetWindowFromID(p->sdl_id);
    6.79 +                if (!devdata->use_linux_input) {
    6.80 +                    if (!(flags & SDL_WINDOW_INPUT_GRABBED))
    6.81 +                        SDL_SendMouseMotion(devdata->mouse_id[0], 0,
    6.82 +                                            evt->x, evt->y, 0);
    6.83 +                } else {
    6.84 +                    /* relative movements are not exact! 
    6.85 +                     * This code should limit the number of events sent.
    6.86 +                     * However it kills MAME axis recognition ... */
    6.87 +                    static int cnt = 0;
    6.88 +                    if (1 && ++cnt > 20) {
    6.89 +                        MotionAllMice(_this, evt->x, evt->y);
    6.90 +                        cnt = 0;
    6.91 +                    }
    6.92 +                }
    6.93 +                if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS))
    6.94 +                    SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_ENTER, 0, 0);
    6.95 +            }
    6.96 +            break;
    6.97 +        case DWET_KEYDOWN:
    6.98 +            if (!devdata->use_linux_input) {
    6.99 +                DirectFB_TranslateKey(_this, evt, &keysym);
   6.100 +                SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode);
   6.101 +                if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
   6.102 +                    SDL_memcpy(text, &keysym.unicode, 4);
   6.103 +                    text[4] = 0;
   6.104 +                    if (*text) {
   6.105 +                        SDL_SendKeyboardText(0, text);
   6.106 +                    }
   6.107 +                }
   6.108 +            }
   6.109 +            break;
   6.110 +        case DWET_KEYUP:
   6.111 +            if (!devdata->use_linux_input) {
   6.112 +                DirectFB_TranslateKey(_this, evt, &keysym);
   6.113 +                SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode);
   6.114 +            }
   6.115 +            break;
   6.116 +        case DWET_POSITION:
   6.117 +            if (ClientXY(p, &evt->x, &evt->y)) {
   6.118 +                SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_MOVED,
   6.119 +                                    evt->x, evt->y);
   6.120 +            }
   6.121 +            break;
   6.122 +        case DWET_POSITION_SIZE:
   6.123 +            if (ClientXY(p, &evt->x, &evt->y)) {
   6.124 +                SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_MOVED,
   6.125 +                                    evt->x, evt->y);
   6.126 +            }
   6.127 +            /* fall throught */
   6.128 +        case DWET_SIZE:
   6.129 +            // FIXME: what about < 0
   6.130 +            evt->w -= (p->theme.right_size + p->theme.left_size);
   6.131 +            evt->h -=
   6.132 +                (p->theme.top_size + p->theme.bottom_size +
   6.133 +                 p->theme.caption_size);
   6.134 +            SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_RESIZED,
   6.135 +                                evt->w, evt->h);
   6.136 +            break;
   6.137 +        case DWET_CLOSE:
   6.138 +            SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_CLOSE, 0, 0);
   6.139 +            break;
   6.140 +        case DWET_GOTFOCUS:
   6.141 +            DirectFB_SetContext(_this, p->sdl_id);
   6.142 +            FocusAllKeyboards(_this, p->sdl_id);
   6.143 +            SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_FOCUS_GAINED,
   6.144 +                                0, 0);
   6.145 +            break;
   6.146 +        case DWET_LOSTFOCUS:
   6.147 +            SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
   6.148 +            FocusAllKeyboards(_this, 0);
   6.149 +            break;
   6.150 +        case DWET_ENTER:
   6.151 +            /* SDL_DirectFB_ReshowCursor(_this, 0); */
   6.152 +            FocusAllMice(_this, p->sdl_id);
   6.153 +            // FIXME: when do we really enter ?
   6.154 +            if (ClientXY(p, &evt->x, &evt->y))
   6.155 +                MotionAllMice(_this, evt->x, evt->y);
   6.156 +            SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_ENTER, 0, 0);
   6.157 +            break;
   6.158 +        case DWET_LEAVE:
   6.159 +            SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_LEAVE, 0, 0);
   6.160 +            FocusAllMice(_this, 0);
   6.161 +            /* SDL_DirectFB_ReshowCursor(_this, 1); */
   6.162 +            break;
   6.163 +        default:
   6.164 +            ;
   6.165 +        }
   6.166 +    } else
   6.167 +        printf("Event Clazz %d\n", evt->clazz);
   6.168 +}
   6.169 +
   6.170 +static void
   6.171 +ProcessInputEvent(_THIS, Sint32 grabbed_window, DFBInputEvent * ievt)
   6.172 +{
   6.173 +    SDL_DFB_DEVICEDATA(_this);
   6.174 +    SDL_keysym keysym;
   6.175 +    int kbd_idx;
   6.176 +    char text[5];
   6.177 +
   6.178 +    if (!devdata->use_linux_input) {
   6.179 +        if (ievt->type == DIET_AXISMOTION) {
   6.180 +            if ((grabbed_window >= 0) && (ievt->flags & DIEF_AXISREL)) {
   6.181 +                if (ievt->axis == DIAI_X)
   6.182 +                    SDL_SendMouseMotion(ievt->device_id, 1,
   6.183 +                                        ievt->axisrel, 0, 0);
   6.184 +                else if (ievt->axis == DIAI_Y)
   6.185 +                    SDL_SendMouseMotion(ievt->device_id, 1, 0,
   6.186 +                                        ievt->axisrel, 0);
   6.187 +            }
   6.188 +        }
   6.189 +    } else {
   6.190 +        static int last_x, last_y;
   6.191 +
   6.192 +        switch (ievt->type) {
   6.193 +        case DIET_AXISMOTION:
   6.194 +            if (ievt->flags & DIEF_AXISABS) {
   6.195 +                if (ievt->axis == DIAI_X)
   6.196 +                    last_x = ievt->axisabs;
   6.197 +                else if (ievt->axis == DIAI_Y)
   6.198 +                    last_y = ievt->axisabs;
   6.199 +                if (!(ievt->flags & DIEF_FOLLOW)) {
   6.200 +                    SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id);
   6.201 +                    SDL_Window *window = SDL_GetWindowFromID(mouse->focus);
   6.202 +                    if (window) {
   6.203 +                        DFB_WindowData *windata =
   6.204 +                            (DFB_WindowData *) window->driverdata;
   6.205 +                        int x, y;
   6.206 +
   6.207 +                        windata->window->GetPosition(windata->window, &x, &y);
   6.208 +                        SDL_SendMouseMotion(ievt->device_id, 0,
   6.209 +                                            last_x - (x +
   6.210 +                                                      windata->client.x),
   6.211 +                                            last_y - (y +
   6.212 +                                                      windata->client.y), 0);
   6.213 +                    } else {
   6.214 +                        SDL_SendMouseMotion(ievt->device_id, 0, last_x,
   6.215 +                                            last_y, 0);
   6.216 +                    }
   6.217 +                }
   6.218 +            } else if (ievt->flags & DIEF_AXISREL) {
   6.219 +                if (ievt->axis == DIAI_X)
   6.220 +                    SDL_SendMouseMotion(ievt->device_id, 1,
   6.221 +                                        ievt->axisrel, 0, 0);
   6.222 +                else if (ievt->axis == DIAI_Y)
   6.223 +                    SDL_SendMouseMotion(ievt->device_id, 1, 0,
   6.224 +                                        ievt->axisrel, 0);
   6.225 +            }
   6.226 +            break;
   6.227 +        case DIET_KEYPRESS:
   6.228 +            kbd_idx = KbdIndex(_this, ievt->device_id);
   6.229 +            DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym);
   6.230 +            SDL_SendKeyboardKey(kbd_idx, SDL_PRESSED, keysym.scancode);
   6.231 +            if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
   6.232 +                SDL_memcpy(text, &keysym.unicode, 4);
   6.233 +                text[4] = 0;
   6.234 +                if (*text) {
   6.235 +                    SDL_SendKeyboardText(kbd_idx, text);
   6.236 +                }
   6.237 +            }
   6.238 +            break;
   6.239 +        case DIET_KEYRELEASE:
   6.240 +            kbd_idx = KbdIndex(_this, ievt->device_id);
   6.241 +            DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym);
   6.242 +            SDL_SendKeyboardKey(kbd_idx, SDL_RELEASED, keysym.scancode);
   6.243 +            break;
   6.244 +        case DIET_BUTTONPRESS:
   6.245 +            if (ievt->buttons & DIBM_LEFT)
   6.246 +                SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 1);
   6.247 +            if (ievt->buttons & DIBM_MIDDLE)
   6.248 +                SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 2);
   6.249 +            if (ievt->buttons & DIBM_RIGHT)
   6.250 +                SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 3);
   6.251 +            break;
   6.252 +        case DIET_BUTTONRELEASE:
   6.253 +            if (!(ievt->buttons & DIBM_LEFT))
   6.254 +                SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 1);
   6.255 +            if (!(ievt->buttons & DIBM_MIDDLE))
   6.256 +                SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 2);
   6.257 +            if (!(ievt->buttons & DIBM_RIGHT))
   6.258 +                SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 3);
   6.259 +            break;
   6.260 +        default:
   6.261 +            break;              /* please gcc */
   6.262 +        }
   6.263 +    }
   6.264 +}
   6.265 +
   6.266  void
   6.267  DirectFB_PumpEventsWindow(_THIS)
   6.268  {
   6.269 @@ -124,216 +372,28 @@
   6.270      DFB_WindowData *p;
   6.271      DFBInputEvent ievt;
   6.272      Sint32 /* SDL_WindowID */ grabbed_window;
   6.273 -    char text[5];
   6.274 -    int kbd_idx;
   6.275  
   6.276      grabbed_window = -1;
   6.277  
   6.278      for (p = devdata->firstwin; p != NULL; p = p->next) {
   6.279          DFBWindowEvent evt;
   6.280 -        SDL_Window *w = SDL_GetWindowFromID(p->id);
   6.281 +        SDL_Window *w = SDL_GetWindowFromID(p->sdl_id);
   6.282  
   6.283          if (w->flags & SDL_WINDOW_INPUT_GRABBED) {
   6.284 -            grabbed_window = p->id;
   6.285 +            grabbed_window = p->sdl_id;
   6.286          }
   6.287  
   6.288          while (p->eventbuffer->GetEvent(p->eventbuffer,
   6.289                                          DFB_EVENT(&evt)) == DFB_OK) {
   6.290 -            SDL_keysym keysym;
   6.291 -
   6.292 -            if (evt.clazz == DFEC_WINDOW) {
   6.293 -                switch (evt.type) {
   6.294 -                case DWET_BUTTONDOWN:
   6.295 -                    if (!devdata->use_linux_input) {
   6.296 -                        SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx,
   6.297 -                                            evt.cy, 0);
   6.298 -                        SDL_SendMouseButton(devdata->mouse_id[0], SDL_PRESSED,
   6.299 -                                            DirectFB_TranslateButton(evt.
   6.300 -                                                                     button));
   6.301 -                    } else {
   6.302 -                        MotionAllMice(_this, evt.x, evt.y);
   6.303 -                    }
   6.304 -                    break;
   6.305 -                case DWET_BUTTONUP:
   6.306 -                    if (!devdata->use_linux_input) {
   6.307 -                        SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx,
   6.308 -                                            evt.cy, 0);
   6.309 -                        SDL_SendMouseButton(devdata->mouse_id[0],
   6.310 -                                            SDL_RELEASED,
   6.311 -                                            DirectFB_TranslateButton(evt.
   6.312 -                                                                     button));
   6.313 -                    } else {
   6.314 -                        MotionAllMice(_this, evt.x, evt.y);
   6.315 -                    }
   6.316 -                    break;
   6.317 -                case DWET_MOTION:
   6.318 -                    if (!devdata->use_linux_input) {
   6.319 -                        if (!(w->flags & SDL_WINDOW_INPUT_GRABBED))
   6.320 -                            SDL_SendMouseMotion(devdata->mouse_id[0], 0,
   6.321 -                                                evt.cx, evt.cy, 0);
   6.322 -                    } else {
   6.323 -                        /* relative movements are not exact! 
   6.324 -                         * This code should limit the number of events sent.
   6.325 -                         * However it kills MAME axis recognition ... */
   6.326 -                        static int cnt = 0;
   6.327 -                        if (1 && ++cnt > 20) {
   6.328 -                            MotionAllMice(_this, evt.x, evt.y);
   6.329 -                            cnt = 0;
   6.330 -                        }
   6.331 -                    }
   6.332 -                    break;
   6.333 -                case DWET_KEYDOWN:
   6.334 -                    if (!devdata->use_linux_input) {
   6.335 -                        DirectFB_TranslateKey(_this, &evt, &keysym);
   6.336 -                        SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode);
   6.337 -                        if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
   6.338 -                            SDL_memcpy(text, &keysym.unicode, 4);
   6.339 -                            text[4] = 0;
   6.340 -                            if (*text) {
   6.341 -                                SDL_SendKeyboardText(0, text);
   6.342 -                            }
   6.343 -                        }
   6.344 -                    }
   6.345 -                    break;
   6.346 -                case DWET_KEYUP:
   6.347 -                    if (!devdata->use_linux_input) {
   6.348 -                        DirectFB_TranslateKey(_this, &evt, &keysym);
   6.349 -                        SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode);
   6.350 -                    }
   6.351 -                    break;
   6.352 -                case DWET_POSITION_SIZE:
   6.353 -                    if (evt.x != w->x || evt.y != w->y)
   6.354 -                        SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED,
   6.355 -                                            evt.x, evt.y);
   6.356 -                    if (evt.w != w->w || evt.h != w->h)
   6.357 -                        SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED,
   6.358 -                                            evt.w, evt.h);
   6.359 -                    break;
   6.360 -                case DWET_POSITION:
   6.361 -                    if (evt.x != w->x || evt.y != w->y)
   6.362 -                        SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED,
   6.363 -                                            evt.x, evt.y);
   6.364 -                    break;
   6.365 -                case DWET_SIZE:
   6.366 -                    if (evt.w != w->w || evt.h != w->h)
   6.367 -                        SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED,
   6.368 -                                            evt.w, evt.h);
   6.369 -                    break;
   6.370 -                case DWET_CLOSE:
   6.371 -                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
   6.372 -                    break;
   6.373 -                case DWET_GOTFOCUS:
   6.374 -                    DirectFB_SetContext(_this, p->id);
   6.375 -                    FocusAllKeyboards(_this, p->id);
   6.376 -                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_GAINED,
   6.377 -                                        0, 0);
   6.378 -                    break;
   6.379 -                case DWET_LOSTFOCUS:
   6.380 -                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0,
   6.381 -                                        0);
   6.382 -                    FocusAllKeyboards(_this, 0);
   6.383 -                    break;
   6.384 -                case DWET_ENTER:
   6.385 -                    /* SDL_DirectFB_ReshowCursor(_this, 0); */
   6.386 -                    FocusAllMice(_this, p->id);
   6.387 -                    MotionAllMice(_this, evt.x, evt.y);
   6.388 -                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0);
   6.389 -                    break;
   6.390 -                case DWET_LEAVE:
   6.391 -                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
   6.392 -                    FocusAllMice(_this, 0);
   6.393 -                    /* SDL_DirectFB_ReshowCursor(_this, 1); */
   6.394 -                    break;
   6.395 -                default:
   6.396 -                    ;
   6.397 -                }
   6.398 -            } else
   6.399 -                printf("Event Clazz %d\n", evt.clazz);
   6.400 -
   6.401 +            if (!DirectFB_WM_ProcessEvent(_this, w, &evt))
   6.402 +                ProcessWindowEvent(_this, p, w->flags, &evt);
   6.403          }
   6.404      }
   6.405  
   6.406      /* Now get relative events in case we need them */
   6.407      while (devdata->events->GetEvent(devdata->events,
   6.408                                       DFB_EVENT(&ievt)) == DFB_OK) {
   6.409 -        SDL_keysym keysym;
   6.410 -
   6.411 -        switch (ievt.type) {
   6.412 -        case DIET_AXISMOTION:
   6.413 -            if (!devdata->use_linux_input) {
   6.414 -                if ((grabbed_window >= 0) && (ievt.flags & DIEF_AXISREL)) {
   6.415 -                    printf("rel devid %d\n", ievt.device_id);
   6.416 -                    if (ievt.axis == DIAI_X)
   6.417 -                        SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel,
   6.418 -                                            0, 0);
   6.419 -                    else if (ievt.axis == DIAI_Y)
   6.420 -                        SDL_SendMouseMotion(ievt.device_id, 1, 0,
   6.421 -                                            ievt.axisrel, 0);
   6.422 -                }
   6.423 -            }
   6.424 -            break;
   6.425 -        }
   6.426 -        if (devdata->use_linux_input) {
   6.427 -            IDirectFBInputDevice *idev;
   6.428 -            static int last_x, last_y;
   6.429 -
   6.430 -            switch (ievt.type) {
   6.431 -            case DIET_AXISMOTION:
   6.432 -                if (ievt.flags & DIEF_AXISABS) {
   6.433 -                    if (ievt.axis == DIAI_X)
   6.434 -                        last_x = ievt.axisabs;
   6.435 -                    else if (ievt.axis == DIAI_Y)
   6.436 -                        last_y = ievt.axisabs;
   6.437 -                    if (!(ievt.flags & DIEF_FOLLOW))
   6.438 -                        SDL_SendMouseMotion(ievt.device_id, 0, last_x, last_y,
   6.439 -                                            0);
   6.440 -                } else if (ievt.flags & DIEF_AXISREL) {
   6.441 -                    //printf("rel %d %d\n", ievt.device_id, ievt.axisrel);
   6.442 -                    if (ievt.axis == DIAI_X)
   6.443 -                        SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel,
   6.444 -                                            0, 0);
   6.445 -                    else if (ievt.axis == DIAI_Y)
   6.446 -                        SDL_SendMouseMotion(ievt.device_id, 1, 0,
   6.447 -                                            ievt.axisrel, 0);
   6.448 -                }
   6.449 -                break;
   6.450 -            case DIET_KEYPRESS:
   6.451 -                kbd_idx = KbdIndex(_this, ievt.device_id);
   6.452 -                DirectFB_TranslateKeyInputEvent(_this, kbd_idx, &ievt,
   6.453 -                                                &keysym);
   6.454 -                SDL_SendKeyboardKey(kbd_idx, SDL_PRESSED, keysym.scancode);
   6.455 -                if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
   6.456 -                    SDL_memcpy(text, &keysym.unicode, 4);
   6.457 -                    text[4] = 0;
   6.458 -                    if (*text) {
   6.459 -                        SDL_SendKeyboardText(kbd_idx, text);
   6.460 -                    }
   6.461 -                }
   6.462 -                break;
   6.463 -            case DIET_KEYRELEASE:
   6.464 -                kbd_idx = KbdIndex(_this, ievt.device_id);
   6.465 -                DirectFB_TranslateKeyInputEvent(_this, kbd_idx, &ievt,
   6.466 -                                                &keysym);
   6.467 -                SDL_SendKeyboardKey(kbd_idx, SDL_RELEASED, keysym.scancode);
   6.468 -                break;
   6.469 -            case DIET_BUTTONPRESS:
   6.470 -                if (ievt.buttons & DIBM_LEFT)
   6.471 -                    SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 1);
   6.472 -                if (ievt.buttons & DIBM_MIDDLE)
   6.473 -                    SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 2);
   6.474 -                if (ievt.buttons & DIBM_RIGHT)
   6.475 -                    SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 3);
   6.476 -                break;
   6.477 -            case DIET_BUTTONRELEASE:
   6.478 -                if (!(ievt.buttons & DIBM_LEFT))
   6.479 -                    SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 1);
   6.480 -                if (!(ievt.buttons & DIBM_MIDDLE))
   6.481 -                    SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 2);
   6.482 -                if (!(ievt.buttons & DIBM_RIGHT))
   6.483 -                    SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 3);
   6.484 -                break;
   6.485 -            }
   6.486 -        }
   6.487 +        ProcessInputEvent(_this, grabbed_window, &ievt);
   6.488      }
   6.489  }
   6.490  
   6.491 @@ -470,14 +530,14 @@
   6.492  {
   6.493      SDL_DFB_DEVICEDATA(_this);
   6.494  
   6.495 -    if (evt->key_code >= 0
   6.496 -        && evt->key_code < SDL_arraysize(linux_scancode_table))
   6.497 +    if (evt->key_code >= 0 &&
   6.498 +        evt->key_code < SDL_arraysize(linux_scancode_table))
   6.499          keysym->scancode = linux_scancode_table[evt->key_code];
   6.500      else
   6.501          keysym->scancode = SDL_SCANCODE_UNKNOWN;
   6.502  
   6.503 -    if (keysym->scancode == SDL_SCANCODE_UNKNOWN
   6.504 -        || devdata->keyboard[0].is_generic) {
   6.505 +    if (keysym->scancode == SDL_SCANCODE_UNKNOWN ||
   6.506 +        devdata->keyboard[0].is_generic) {
   6.507          if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
   6.508              keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
   6.509          else
   6.510 @@ -486,8 +546,8 @@
   6.511  
   6.512      keysym->unicode =
   6.513          (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
   6.514 -    if (keysym->unicode == 0
   6.515 -        && (evt->key_symbol > 0 && evt->key_symbol < 255))
   6.516 +    if (keysym->unicode == 0 &&
   6.517 +        (evt->key_symbol > 0 && evt->key_symbol < 255))
   6.518          keysym->unicode = evt->key_symbol;
   6.519  
   6.520      return keysym;
   6.521 @@ -499,14 +559,14 @@
   6.522  {
   6.523      SDL_DFB_DEVICEDATA(_this);
   6.524  
   6.525 -    if (evt->key_code >= 0
   6.526 -        && evt->key_code < SDL_arraysize(linux_scancode_table))
   6.527 +    if (evt->key_code >= 0 &&
   6.528 +        evt->key_code < SDL_arraysize(linux_scancode_table))
   6.529          keysym->scancode = linux_scancode_table[evt->key_code];
   6.530      else
   6.531          keysym->scancode = SDL_SCANCODE_UNKNOWN;
   6.532  
   6.533 -    if (keysym->scancode == SDL_SCANCODE_UNKNOWN
   6.534 -        || devdata->keyboard[index].is_generic) {
   6.535 +    if (keysym->scancode == SDL_SCANCODE_UNKNOWN ||
   6.536 +        devdata->keyboard[index].is_generic) {
   6.537          if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
   6.538              keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
   6.539          else
   6.540 @@ -515,12 +575,13 @@
   6.541  
   6.542      keysym->unicode =
   6.543          (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
   6.544 -    if (keysym->unicode == 0
   6.545 -        && (evt->key_symbol > 0 && evt->key_symbol < 255))
   6.546 +    if (keysym->unicode == 0 &&
   6.547 +        (evt->key_symbol > 0 && evt->key_symbol < 255))
   6.548          keysym->unicode = evt->key_symbol;
   6.549  
   6.550      return keysym;
   6.551  }
   6.552 +
   6.553  static int
   6.554  DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
   6.555  {
   6.556 @@ -537,8 +598,8 @@
   6.557  }
   6.558  
   6.559  static DFBEnumerationResult
   6.560 -input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
   6.561 -                void *callbackdata)
   6.562 +input_device_cb(DFBInputDeviceID device_id,
   6.563 +                DFBInputDeviceDescription desc, void *callbackdata)
   6.564  {
   6.565      DFB_DeviceData *devdata = callbackdata;
   6.566      SDL_Keyboard keyboard;
   6.567 @@ -562,8 +623,8 @@
   6.568  }
   6.569  
   6.570  static DFBEnumerationResult
   6.571 -EnumKeyboards(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
   6.572 -              void *callbackdata)
   6.573 +EnumKeyboards(DFBInputDeviceID device_id,
   6.574 +              DFBInputDeviceDescription desc, void *callbackdata)
   6.575  {
   6.576      DFB_DeviceData *devdata = callbackdata;
   6.577      SDL_Keyboard keyboard;
   6.578 @@ -606,14 +667,14 @@
   6.579                        EnumInputDevices(devdata->dfb, EnumKeyboards, devdata));
   6.580          if (devdata->num_keyboard == 0) {
   6.581              sys_ids = 1;
   6.582 -            SDL_DFB_CHECK(devdata->dfb->
   6.583 -                          EnumInputDevices(devdata->dfb, EnumKeyboards,
   6.584 -                                           devdata));
   6.585 +            SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
   6.586 +                                                         EnumKeyboards,
   6.587 +                                                         devdata));
   6.588          }
   6.589      } else {
   6.590 -        SDL_DFB_CHECK(devdata->dfb->
   6.591 -                      EnumInputDevices(devdata->dfb, input_device_cb,
   6.592 -                                       devdata));
   6.593 +        SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
   6.594 +                                                     input_device_cb,
   6.595 +                                                     devdata));
   6.596      }
   6.597  }
   6.598  
   6.599 @@ -649,34 +710,30 @@
   6.600  
   6.601              switch (evt.type) {
   6.602              case DIET_BUTTONPRESS:
   6.603 -                posted += SDL_PrivateMouseButton(SDL_PRESSED,
   6.604 -                                                 DirectFB_TranslateButton(evt.
   6.605 -                                                                          button),
   6.606 -                                                 0, 0);
   6.607 +                posted +=
   6.608 +                    SDL_PrivateMouseButton(SDL_PRESSED,
   6.609 +                                           DirectFB_TranslateButton
   6.610 +                                           (evt.button), 0, 0);
   6.611                  break;
   6.612              case DIET_BUTTONRELEASE:
   6.613 -                posted += SDL_PrivateMouseButton(SDL_RELEASED,
   6.614 -                                                 DirectFB_TranslateButton(evt.
   6.615 -                                                                          button),
   6.616 -                                                 0, 0);
   6.617 +                posted +=
   6.618 +                    SDL_PrivateMouseButton(SDL_RELEASED,
   6.619 +                                           DirectFB_TranslateButton
   6.620 +                                           (evt.button), 0, 0);
   6.621                  break;
   6.622              case DIET_KEYPRESS:
   6.623 -                posted += SDL_PrivateKeyboard(SDL_PRESSED,
   6.624 -                                              DirectFB_TranslateKey(evt.
   6.625 -                                                                    key_id,
   6.626 -                                                                    evt.
   6.627 -                                                                    key_symbol,
   6.628 -                                                                    mod,
   6.629 -                                                                    &keysym));
   6.630 +                posted +=
   6.631 +                    SDL_PrivateKeyboard(SDL_PRESSED,
   6.632 +                                        DirectFB_TranslateKey
   6.633 +                                        (evt.key_id, evt.key_symbol,
   6.634 +                                         mod, &keysym));
   6.635                  break;
   6.636              case DIET_KEYRELEASE:
   6.637 -                posted += SDL_PrivateKeyboard(SDL_RELEASED,
   6.638 -                                              DirectFB_TranslateKey(evt.
   6.639 -                                                                    key_id,
   6.640 -                                                                    evt.
   6.641 -                                                                    key_symbol,
   6.642 -                                                                    mod,
   6.643 -                                                                    &keysym));
   6.644 +                posted +=
   6.645 +                    SDL_PrivateKeyboard(SDL_RELEASED,
   6.646 +                                        DirectFB_TranslateKey
   6.647 +                                        (evt.key_id, evt.key_symbol,
   6.648 +                                         mod, &keysym));
   6.649                  break;
   6.650              case DIET_AXISMOTION:
   6.651                  if (evt.flags & DIEF_AXISREL) {
     7.1 --- a/src/video/directfb/SDL_DirectFB_modes.c	Sun Jan 11 23:39:11 2009 +0000
     7.2 +++ b/src/video/directfb/SDL_DirectFB_modes.c	Sun Jan 11 23:49:23 2009 +0000
     7.3 @@ -204,8 +204,8 @@
     7.4      DFBDisplayLayerConfigFlags failed;
     7.5      int ret;
     7.6  
     7.7 -    SDL_DFB_CHECKERR(data->layer->
     7.8 -                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
     7.9 +    SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
    7.10 +                                                      DLSCL_ADMINISTRATIVE));
    7.11      config.width = mode->w;
    7.12      config.height = mode->h;
    7.13      config.pixelformat = SDLToDFBPixelFormat(mode->format);
    7.14 @@ -216,13 +216,13 @@
    7.15      }
    7.16      failed = 0;
    7.17      data->layer->TestConfiguration(data->layer, &config, &failed);
    7.18 -    SDL_DFB_CHECKERR(data->layer->
    7.19 -                     SetCooperativeLevel(data->layer, DLSCL_SHARED));
    7.20 +    SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
    7.21 +                                                      DLSCL_SHARED));
    7.22      if (failed == 0)
    7.23          SDL_AddDisplayMode(_this->current_display, mode);
    7.24      else
    7.25 -        SDL_DFB_DEBUG("Mode %d x %d not available: %x\n", mode->w, mode->h,
    7.26 -                      failed);
    7.27 +        SDL_DFB_DEBUG("Mode %d x %d not available: %x\n", mode->w,
    7.28 +                      mode->h, failed);
    7.29  
    7.30      return;
    7.31    error:
    7.32 @@ -235,13 +235,9 @@
    7.33      SDL_DFB_DEVICEDATA(_this);
    7.34      IDirectFBDisplayLayer *layer = NULL;
    7.35      SDL_VideoDisplay display;
    7.36 -    DFB_DisplayData *dispdata;
    7.37 +    DFB_DisplayData *dispdata = NULL;
    7.38      SDL_DisplayMode mode;
    7.39 -#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
    7.40 -    DFBCardCapabilities caps;
    7.41 -#else
    7.42      DFBGraphicsDeviceDescription caps;
    7.43 -#endif
    7.44      DFBDisplayLayerConfig dlc;
    7.45      struct scn_callback_t *screencbdata;
    7.46  
    7.47 @@ -259,28 +255,20 @@
    7.48          screencbdata->vidlayer[i] = -1;
    7.49      }
    7.50  
    7.51 -    SDL_DFB_CHECKERR(devdata->dfb->
    7.52 -                     EnumScreens(devdata->dfb, &cbScreens, screencbdata));
    7.53 +    SDL_DFB_CHECKERR(devdata->dfb->EnumScreens(devdata->dfb, &cbScreens,
    7.54 +                                               screencbdata));
    7.55  
    7.56      for (i = 0; i < screencbdata->numscreens; i++) {
    7.57          IDirectFBScreen *screen;
    7.58  
    7.59 -        SDL_DFB_CHECKERR(devdata->dfb->
    7.60 -                         GetScreen(devdata->dfb, screencbdata->screenid[i],
    7.61 -                                   &screen));
    7.62 +        SDL_DFB_CHECKERR(devdata->dfb->GetScreen(devdata->dfb,
    7.63 +                                                 screencbdata->screenid
    7.64 +                                                 [i], &screen));
    7.65  
    7.66          screencbdata->aux = i;
    7.67 -        SDL_DFB_CHECKERR(screen->
    7.68 -                         EnumDisplayLayers(screen, &cbLayers, screencbdata));
    7.69 -#if (DIRECTFB_MAJOR_VERSION >= 1)
    7.70 +        SDL_DFB_CHECKERR(screen->EnumDisplayLayers(screen, &cbLayers,
    7.71 +                                                   screencbdata));
    7.72          screen->GetSize(screen, &tcw[i], &tch[i]);
    7.73 -#else
    7.74 -        /* FIXME: this is only used to center windows
    7.75 -         *        Should be done otherwise, e.g. get surface from layer
    7.76 -         */
    7.77 -        tcw[i] = 800;
    7.78 -        tch[i] = 600;
    7.79 -#endif
    7.80          screen->Release(screen);
    7.81      }
    7.82  
    7.83 @@ -293,12 +281,12 @@
    7.84      SDL_DFB_DEBUG("Found %d screens\n", screencbdata->numscreens);
    7.85  
    7.86      for (i = 0; i < screencbdata->numscreens; i++) {
    7.87 -        SDL_DFB_CHECKERR(devdata->dfb->
    7.88 -                         GetDisplayLayer(devdata->dfb,
    7.89 -                                         screencbdata->gralayer[i], &layer));
    7.90 +        SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
    7.91 +                                                       screencbdata->gralayer
    7.92 +                                                       [i], &layer));
    7.93  
    7.94 -        SDL_DFB_CHECKERR(layer->
    7.95 -                         SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE));
    7.96 +        SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer,
    7.97 +                                                    DLSCL_ADMINISTRATIVE));
    7.98          layer->EnableCursor(layer, 1);
    7.99          SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
   7.100  
   7.101 @@ -381,8 +369,8 @@
   7.102      data.nummodes = 0;
   7.103      /* Enumerate the available fullscreen modes */
   7.104      SDL_DFB_CALLOC(data.modelist, DFB_MAX_MODES, sizeof(SDL_DisplayMode));
   7.105 -    SDL_DFB_CHECKERR(devdata->dfb->
   7.106 -                     EnumVideoModes(devdata->dfb, EnumModesCallback, &data));
   7.107 +    SDL_DFB_CHECKERR(devdata->dfb->EnumVideoModes(devdata->dfb,
   7.108 +                                                  EnumModesCallback, &data));
   7.109  
   7.110      for (i = 0; i < data.nummodes; ++i) {
   7.111          mode = data.modelist[i];
   7.112 @@ -419,8 +407,8 @@
   7.113      DFBDisplayLayerConfigFlags fail = 0;
   7.114      DFBResult ret;
   7.115  
   7.116 -    SDL_DFB_CHECKERR(data->layer->
   7.117 -                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
   7.118 +    SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
   7.119 +                                                      DLSCL_ADMINISTRATIVE));
   7.120  
   7.121      SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
   7.122      config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
   7.123 @@ -440,8 +428,8 @@
   7.124      data->layer->TestConfiguration(data->layer, &config, &fail);
   7.125  
   7.126      if (fail &
   7.127 -        (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT | DLCONF_OPTIONS))
   7.128 -    {
   7.129 +        (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
   7.130 +         DLCONF_OPTIONS)) {
   7.131          SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
   7.132                      mode->format);
   7.133          return -1;
   7.134 @@ -453,18 +441,16 @@
   7.135  #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
   7.136      /* Need to call this twice ! */
   7.137      SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
   7.138 -    //SDL_DFB_CHECKERR(data->layer->SetSourceRectangle(data->layer, 0, 0, config.width, config.height));
   7.139  #endif
   7.140  
   7.141      /* Double check */
   7.142      SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
   7.143 -    SDL_DFB_CHECKERR(data->layer->
   7.144 -                     SetCooperativeLevel(data->layer, DLSCL_SHARED));
   7.145 +    SDL_DFB_CHECKERR(data->
   7.146 +                     layer->SetCooperativeLevel(data->layer, DLSCL_SHARED));
   7.147  
   7.148 -    if ((config.width != rconfig.width) ||
   7.149 -        (config.height != rconfig.height) ||
   7.150 -        ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
   7.151 -         && (config.pixelformat != rconfig.pixelformat))) {
   7.152 +    if ((config.width != rconfig.width) || (config.height != rconfig.height)
   7.153 +        || ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
   7.154 +            && (config.pixelformat != rconfig.pixelformat))) {
   7.155          SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
   7.156                      mode->format);
   7.157          return -1;
   7.158 @@ -483,7 +469,7 @@
   7.159  void
   7.160  DirectFB_QuitModes(_THIS)
   7.161  {
   7.162 -    DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
   7.163 +    //DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
   7.164      SDL_DisplayMode tmode;
   7.165      DFBResult ret;
   7.166      int i;
   7.167 @@ -502,13 +488,14 @@
   7.168              (DFB_DisplayData *) _this->displays[i].driverdata;
   7.169  
   7.170          if (dispdata->layer) {
   7.171 -            SDL_DFB_CHECK(dispdata->layer->
   7.172 -                          SetCooperativeLevel(dispdata->layer,
   7.173 -                                              DLSCL_ADMINISTRATIVE));
   7.174 -            SDL_DFB_CHECK(dispdata->layer->
   7.175 -                          SetCursorOpacity(dispdata->layer, 0x00));
   7.176 -            SDL_DFB_CHECK(dispdata->layer->
   7.177 -                          SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
   7.178 +            SDL_DFB_CHECK(dispdata->
   7.179 +                          layer->SetCooperativeLevel(dispdata->layer,
   7.180 +                                                     DLSCL_ADMINISTRATIVE));
   7.181 +            SDL_DFB_CHECK(dispdata->
   7.182 +                          layer->SetCursorOpacity(dispdata->layer, 0x00));
   7.183 +            SDL_DFB_CHECK(dispdata->
   7.184 +                          layer->SetCooperativeLevel(dispdata->layer,
   7.185 +                                                     DLSCL_SHARED));
   7.186          }
   7.187  
   7.188          SDL_DFB_RELEASE(dispdata->layer);
     8.1 --- a/src/video/directfb/SDL_DirectFB_mouse.c	Sun Jan 11 23:39:11 2009 +0000
     8.2 +++ b/src/video/directfb/SDL_DirectFB_mouse.c	Sun Jan 11 23:49:23 2009 +0000
     8.3 @@ -26,8 +26,8 @@
     8.4  #include "../SDL_sysvideo.h"
     8.5  #include "../../events/SDL_mouse_c.h"
     8.6  
     8.7 -static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface, int hot_x,
     8.8 -                                         int hot_y);
     8.9 +static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface,
    8.10 +                                         int hot_x, int hot_y);
    8.11  static int DirectFB_ShowCursor(SDL_Cursor * cursor);
    8.12  static void DirectFB_MoveCursor(SDL_Cursor * cursor);
    8.13  static void DirectFB_FreeCursor(SDL_Cursor * cursor);
    8.14 @@ -38,8 +38,8 @@
    8.15  static int id_mask;
    8.16  
    8.17  static DFBEnumerationResult
    8.18 -EnumMice(DFBInputDeviceID device_id,
    8.19 -         DFBInputDeviceDescription desc, void *callbackdata)
    8.20 +EnumMice(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
    8.21 +         void *callbackdata)
    8.22  {
    8.23      DFB_DeviceData *devdata = callbackdata;
    8.24  
    8.25 @@ -132,20 +132,20 @@
    8.26      dsc.height = surface->h;
    8.27      dsc.pixelformat = DSPF_ARGB;
    8.28  
    8.29 -    SDL_DFB_CHECKERR(devdata->dfb->
    8.30 -                     CreateSurface(devdata->dfb, &dsc, &curdata->surf));
    8.31 +    SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
    8.32 +                                                 &curdata->surf));
    8.33      curdata->hotx = hot_x;
    8.34      curdata->hoty = hot_y;
    8.35      cursor->driverdata = curdata;
    8.36  
    8.37 -    SDL_DFB_CHECKERR(curdata->surf->
    8.38 -                     Lock(curdata->surf, DSLF_WRITE, (void *) &dest, &pitch));
    8.39 +    SDL_DFB_CHECKERR(curdata->surf->Lock(curdata->surf, DSLF_WRITE,
    8.40 +                                         (void *) &dest, &pitch));
    8.41  
    8.42      /* Relies on the fact that this is only called with ARGB surface. */
    8.43      p = surface->pixels;
    8.44      for (i = 0; i < surface->h; i++)
    8.45 -        memcpy((char *) dest + i * pitch, (char *) p + i * surface->pitch,
    8.46 -               4 * surface->w);
    8.47 +        memcpy((char *) dest + i * pitch,
    8.48 +               (char *) p + i * surface->pitch, 4 * surface->w);
    8.49  
    8.50      curdata->surf->Unlock(curdata->surf);
    8.51      return cursor;
    8.52 @@ -162,7 +162,7 @@
    8.53      SDL_WindowID wid;
    8.54  
    8.55      wid = SDL_GetFocusWindow();
    8.56 -    if (wid < 0)
    8.57 +    if (wid <= 0)
    8.58          return -1;
    8.59      else {
    8.60          SDL_Window *window = SDL_GetWindowFromID(wid);
    8.61 @@ -179,7 +179,6 @@
    8.62                                                  curdata->surf, curdata->hotx,
    8.63                                                  curdata->hoty));
    8.64  
    8.65 -            /* fprintf(stdout, "Cursor is %s\n", cursor ? "on" : "off"); */
    8.66              SDL_DFB_CHECKERR(dispdata->layer->
    8.67                               SetCooperativeLevel(dispdata->layer,
    8.68                                                   DLSCL_ADMINISTRATIVE));
    8.69 @@ -227,8 +226,9 @@
    8.70      int cx, cy;
    8.71  
    8.72      SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy));
    8.73 -    SDL_DFB_CHECKERR(dispdata->layer->
    8.74 -                     WarpCursor(dispdata->layer, cx + x, cy + y));
    8.75 +    SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer,
    8.76 +                                                 cx + x + windata->client.x,
    8.77 +                                                 cy + y + windata->client.y));
    8.78  
    8.79    error:
    8.80      return;
     9.1 --- a/src/video/directfb/SDL_DirectFB_opengl.c	Sun Jan 11 23:39:11 2009 +0000
     9.2 +++ b/src/video/directfb/SDL_DirectFB_opengl.c	Sun Jan 11 23:49:23 2009 +0000
     9.3 @@ -173,8 +173,8 @@
     9.4  
     9.5      SDL_DFB_CALLOC(context, 1, sizeof(*context));
     9.6  
     9.7 -    SDL_DFB_CHECKERR(windata->surface->
     9.8 -                     GetGL(windata->surface, &context->context));
     9.9 +    SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface,
    9.10 +                                             &context->context));
    9.11  
    9.12      if (!context->context)
    9.13          return NULL;
    9.14 @@ -208,16 +208,9 @@
    9.15          p->context->Unlock(p->context);
    9.16  
    9.17      if (windata) {
    9.18 -        int cw, ch;
    9.19 -
    9.20          windata->gl_context = NULL;
    9.21          /* Everything is unlocked, check for a resize */
    9.22 -        SDL_DFB_CHECKERR(windata->surface->
    9.23 -                         GetSize(windata->surface, &cw, &ch));
    9.24 -        if (cw != window->w || ch != window->h)
    9.25 -            SDL_DFB_CHECKERR(windata->window->
    9.26 -                             ResizeSurface(windata->window, window->w,
    9.27 -                                           window->h));
    9.28 +        DirectFB_AdjustWindowSurface(window);
    9.29      }
    9.30  
    9.31      if (ctx != NULL) {
    9.32 @@ -266,8 +259,8 @@
    9.33  
    9.34      if (1 || windata->gl_context) {
    9.35          /* SDL_DFB_CHECKERR(windata->gl_context->context->Unlock(windata->gl_context->context)); */
    9.36 -        SDL_DFB_CHECKERR(windata->surface->
    9.37 -                         Flip(windata->surface, &region, DSFLIP_ONSYNC));
    9.38 +        SDL_DFB_CHECKERR(windata->surface->Flip(windata->surface, &region,
    9.39 +                                                DSFLIP_ONSYNC));
    9.40          /* SDL_DFB_CHECKERR(windata->gl_context->context->Lock(windata->gl_context->context)); */
    9.41  
    9.42      }
    10.1 --- a/src/video/directfb/SDL_DirectFB_render.c	Sun Jan 11 23:39:11 2009 +0000
    10.2 +++ b/src/video/directfb/SDL_DirectFB_render.c	Sun Jan 11 23:49:23 2009 +0000
    10.3 @@ -41,16 +41,16 @@
    10.4  static int DirectFB_CreateTexture(SDL_Renderer * renderer,
    10.5                                    SDL_Texture * texture);
    10.6  static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
    10.7 -                                       SDL_Texture * texture, void **pixels,
    10.8 -                                       int *pitch);
    10.9 +                                       SDL_Texture * texture,
   10.10 +                                       void **pixels, int *pitch);
   10.11  static int DirectFB_SetTexturePalette(SDL_Renderer * renderer,
   10.12                                        SDL_Texture * texture,
   10.13                                        const SDL_Color * colors,
   10.14                                        int firstcolor, int ncolors);
   10.15  static int DirectFB_GetTexturePalette(SDL_Renderer * renderer,
   10.16                                        SDL_Texture * texture,
   10.17 -                                      SDL_Color * colors, int firstcolor,
   10.18 -                                      int ncolors);
   10.19 +                                      SDL_Color * colors,
   10.20 +                                      int firstcolor, int ncolors);
   10.21  static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer,
   10.22                                         SDL_Texture * texture);
   10.23  static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer,
   10.24 @@ -61,11 +61,12 @@
   10.25                                          SDL_Texture * texture);
   10.26  static int DirectFB_UpdateTexture(SDL_Renderer * renderer,
   10.27                                    SDL_Texture * texture,
   10.28 -                                  const SDL_Rect * rect, const void *pixels,
   10.29 -                                  int pitch);
   10.30 +                                  const SDL_Rect * rect,
   10.31 +                                  const void *pixels, int pitch);
   10.32  static int DirectFB_LockTexture(SDL_Renderer * renderer,
   10.33 -                                SDL_Texture * texture, const SDL_Rect * rect,
   10.34 -                                int markDirty, void **pixels, int *pitch);
   10.35 +                                SDL_Texture * texture,
   10.36 +                                const SDL_Rect * rect, int markDirty,
   10.37 +                                void **pixels, int *pitch);
   10.38  static void DirectFB_UnlockTexture(SDL_Renderer * renderer,
   10.39                                     SDL_Texture * texture);
   10.40  static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
   10.41 @@ -76,7 +77,8 @@
   10.42                                 int x2, int y2);
   10.43  static int DirectFB_RenderFill(SDL_Renderer * renderer,
   10.44                                 const SDL_Rect * rect);
   10.45 -static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   10.46 +static int DirectFB_RenderCopy(SDL_Renderer * renderer,
   10.47 +                               SDL_Texture * texture,
   10.48                                 const SDL_Rect * srcrect,
   10.49                                 const SDL_Rect * dstrect);
   10.50  static void DirectFB_RenderPresent(SDL_Renderer * renderer);
   10.51 @@ -94,8 +96,8 @@
   10.52        SDL_RENDERER_ACCELERATED),
   10.53       (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
   10.54        SDL_TEXTUREMODULATE_ALPHA),
   10.55 -     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
   10.56 -      SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
   10.57 +     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND |
   10.58 +      SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
   10.59       (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
   10.60        SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST),
   10.61       14,
   10.62 @@ -327,7 +329,7 @@
   10.63          renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
   10.64  
   10.65      data->isyuvdirect = 0;      /* default is off! */
   10.66 -    p = getenv(DFBENV_USE_YUV_DIRECT);
   10.67 +    p = SDL_getenv(DFBENV_USE_YUV_DIRECT);
   10.68      if (p)
   10.69          data->isyuvdirect = atoi(p);
   10.70  
   10.71 @@ -414,20 +416,10 @@
   10.72      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   10.73      SDL_DFB_WINDOWDATA(window);
   10.74  
   10.75 -    if (renddata->size_changed) {
   10.76 -        int cw, ch;
   10.77 -        int ret;
   10.78 -
   10.79 -        SDL_DFB_CHECKERR(windata->surface->
   10.80 -                         GetSize(windata->surface, &cw, &ch));
   10.81 -        if (cw != window->w || ch != window->h)
   10.82 -            SDL_DFB_CHECKERR(windata->window->
   10.83 -                             ResizeSurface(windata->window, window->w,
   10.84 -                                           window->h));
   10.85 +    if (renddata->size_changed || windata->wm_needs_redraw) {
   10.86 +        DirectFB_AdjustWindowSurface(window);
   10.87      }
   10.88      return 0;
   10.89 -  error:
   10.90 -    return -1;
   10.91  }
   10.92  
   10.93  static int
   10.94 @@ -462,22 +454,24 @@
   10.95          layconf.pixelformat = SDLToDFBPixelFormat(data->format);
   10.96          layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE;
   10.97  
   10.98 -        SDL_DFB_CHECKERR(devdata->dfb->
   10.99 -                         GetDisplayLayer(devdata->dfb, dispdata->vidID,
  10.100 -                                         &dispdata->vidlayer));
  10.101 -        SDL_DFB_CHECKERR(dispdata->vidlayer->
  10.102 -                         SetCooperativeLevel(dispdata->vidlayer,
  10.103 -                                             DLSCL_EXCLUSIVE));
  10.104 +        SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
  10.105 +                                                       dispdata->vidID,
  10.106 +                                                       &dispdata->vidlayer));
  10.107 +        SDL_DFB_CHECKERR(dispdata->
  10.108 +                         vidlayer->SetCooperativeLevel(dispdata->vidlayer,
  10.109 +                                                       DLSCL_EXCLUSIVE));
  10.110  
  10.111          if (devdata->use_yuv_underlays) {
  10.112              ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1);
  10.113              if (ret != DFB_OK)
  10.114                  SDL_DFB_DEBUG("Underlay Setlevel not supported\n");
  10.115          }
  10.116 -        SDL_DFB_CHECKERR(dispdata->vidlayer->
  10.117 -                         SetConfiguration(dispdata->vidlayer, &layconf));
  10.118 -        SDL_DFB_CHECKERR(dispdata->vidlayer->
  10.119 -                         GetSurface(dispdata->vidlayer, &data->surface));
  10.120 +        SDL_DFB_CHECKERR(dispdata->
  10.121 +                         vidlayer->SetConfiguration(dispdata->vidlayer,
  10.122 +                                                    &layconf));
  10.123 +        SDL_DFB_CHECKERR(dispdata->
  10.124 +                         vidlayer->GetSurface(dispdata->vidlayer,
  10.125 +                                              &data->surface));
  10.126          dispdata->vidIDinuse = 1;
  10.127          data->display = display;
  10.128          return 0;
  10.129 @@ -486,9 +480,9 @@
  10.130    error:
  10.131      if (dispdata->vidlayer) {
  10.132          SDL_DFB_RELEASE(data->surface);
  10.133 -        SDL_DFB_CHECKERR(dispdata->vidlayer->
  10.134 -                         SetCooperativeLevel(dispdata->vidlayer,
  10.135 -                                             DLSCL_ADMINISTRATIVE));
  10.136 +        SDL_DFB_CHECKERR(dispdata->
  10.137 +                         vidlayer->SetCooperativeLevel(dispdata->vidlayer,
  10.138 +                                                       DLSCL_ADMINISTRATIVE));
  10.139          SDL_DFB_RELEASE(dispdata->vidlayer);
  10.140      }
  10.141      return 1;
  10.142 @@ -540,12 +534,12 @@
  10.143          data->pixels = NULL;
  10.144  
  10.145          /* Create the surface */
  10.146 -        SDL_DFB_CHECKERR(devdata->dfb->
  10.147 -                         CreateSurface(devdata->dfb, &dsc, &data->surface));
  10.148 +        SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
  10.149 +                                                     &data->surface));
  10.150          if (SDL_ISPIXELFORMAT_INDEXED(data->format)
  10.151              && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
  10.152 -            SDL_DFB_CHECKERR(data->surface->
  10.153 -                             GetPalette(data->surface, &data->palette));
  10.154 +            SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface,
  10.155 +                                                       &data->palette));
  10.156          }
  10.157  
  10.158      }
  10.159 @@ -568,8 +562,8 @@
  10.160  }
  10.161  
  10.162  static int
  10.163 -DirectFB_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
  10.164 -                            void **pixels, int *pitch)
  10.165 +DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
  10.166 +                            SDL_Texture * texture, void **pixels, int *pitch)
  10.167  {
  10.168      DirectFB_TextureData *texturedata =
  10.169          (DirectFB_TextureData *) texture->driverdata;
  10.170 @@ -584,7 +578,8 @@
  10.171  }
  10.172  
  10.173  static int
  10.174 -DirectFB_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
  10.175 +DirectFB_SetTexturePalette(SDL_Renderer * renderer,
  10.176 +                           SDL_Texture * texture,
  10.177                             const SDL_Color * colors, int firstcolor,
  10.178                             int ncolors)
  10.179  {
  10.180 @@ -602,9 +597,9 @@
  10.181              entries[i].b = colors[i].b;
  10.182              entries[i].a = 0xFF;
  10.183          }
  10.184 -        SDL_DFB_CHECKERR(data->palette->
  10.185 -                         SetEntries(data->palette, entries, ncolors,
  10.186 -                                    firstcolor));
  10.187 +        SDL_DFB_CHECKERR(data->
  10.188 +                         palette->SetEntries(data->palette, entries, ncolors,
  10.189 +                                             firstcolor));
  10.190          return 0;
  10.191      } else {
  10.192          SDL_SetError("YUV textures don't have a palette");
  10.193 @@ -615,8 +610,9 @@
  10.194  }
  10.195  
  10.196  static int
  10.197 -DirectFB_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
  10.198 -                           SDL_Color * colors, int firstcolor, int ncolors)
  10.199 +DirectFB_GetTexturePalette(SDL_Renderer * renderer,
  10.200 +                           SDL_Texture * texture, SDL_Color * colors,
  10.201 +                           int firstcolor, int ncolors)
  10.202  {
  10.203      DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
  10.204      DFBResult ret;
  10.205 @@ -626,9 +622,9 @@
  10.206          DFBColor entries[256];
  10.207          int i;
  10.208  
  10.209 -        SDL_DFB_CHECKERR(data->palette->
  10.210 -                         GetEntries(data->palette, entries, ncolors,
  10.211 -                                    firstcolor));
  10.212 +        SDL_DFB_CHECKERR(data->
  10.213 +                         palette->GetEntries(data->palette, entries, ncolors,
  10.214 +                                             firstcolor));
  10.215  
  10.216          for (i = 0; i < ncolors; ++i) {
  10.217              colors[i].r = entries[i].r;
  10.218 @@ -737,8 +733,8 @@
  10.219  
  10.220  static int
  10.221  DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  10.222 -                     const SDL_Rect * rect, int markDirty, void **pixels,
  10.223 -                     int *pitch)
  10.224 +                     const SDL_Rect * rect, int markDirty,
  10.225 +                     void **pixels, int *pitch)
  10.226  {
  10.227      DirectFB_TextureData *texturedata =
  10.228          (DirectFB_TextureData *) texture->driverdata;
  10.229 @@ -807,8 +803,8 @@
  10.230      a = renderer->a;
  10.231  
  10.232      SetBlendMode(data, renderer->blendMode, NULL);
  10.233 -    SDL_DFB_CHECKERR(data->surface->
  10.234 -                     SetDrawingFlags(data->surface, data->drawFlags));
  10.235 +    SDL_DFB_CHECKERR(data->surface->SetDrawingFlags(data->surface,
  10.236 +                                                    data->drawFlags));
  10.237  
  10.238      switch (renderer->blendMode) {
  10.239      case SDL_BLENDMODE_NONE:
  10.240 @@ -868,9 +864,9 @@
  10.241      DFBResult ret;
  10.242  
  10.243      PrepareDraw(renderer);
  10.244 -    SDL_DFB_CHECKERR(data->surface->
  10.245 -                     FillRectangle(data->surface, rect->x, rect->y, rect->w,
  10.246 -                                   rect->h));
  10.247 +    SDL_DFB_CHECKERR(data->
  10.248 +                     surface->FillRectangle(data->surface, rect->x, rect->y,
  10.249 +                                            rect->w, rect->h));
  10.250  
  10.251      return 0;
  10.252    error:
  10.253 @@ -894,15 +890,20 @@
  10.254          SDL_VideoDisplay *display = texturedata->display;
  10.255          DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
  10.256  
  10.257 -        SDL_DFB_CHECKERR(dispdata->vidlayer->
  10.258 -                         SetSourceRectangle(dispdata->vidlayer, srcrect->x,
  10.259 -                                            srcrect->y, srcrect->w,
  10.260 -                                            srcrect->h));
  10.261 +        SDL_DFB_CHECKERR(dispdata->
  10.262 +                         vidlayer->SetSourceRectangle(dispdata->vidlayer,
  10.263 +                                                      srcrect->x, srcrect->y,
  10.264 +                                                      srcrect->w,
  10.265 +                                                      srcrect->h));
  10.266          windata->window->GetPosition(windata->window, &px, &py);
  10.267 -        SDL_DFB_CHECKERR(dispdata->vidlayer->
  10.268 -                         SetScreenRectangle(dispdata->vidlayer,
  10.269 -                                            px + dstrect->x, py + dstrect->y,
  10.270 -                                            dstrect->w, dstrect->h));
  10.271 +        px += windata->client.x;
  10.272 +        py += windata->client.y;
  10.273 +        SDL_DFB_CHECKERR(dispdata->
  10.274 +                         vidlayer->SetScreenRectangle(dispdata->vidlayer,
  10.275 +                                                      px + dstrect->x,
  10.276 +                                                      py + dstrect->y,
  10.277 +                                                      dstrect->w,
  10.278 +                                                      dstrect->h));
  10.279      } else {
  10.280          DFBRectangle sr, dr;
  10.281          DFBSurfaceBlittingFlags flags = 0;
  10.282 @@ -928,34 +929,37 @@
  10.283          SDLtoDFBRect(srcrect, &sr);
  10.284          SDLtoDFBRect(dstrect, &dr);
  10.285  
  10.286 -        SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
  10.287 -                                                 0xFF, 0xFF, 0xFF));
  10.288 -        if (texture->
  10.289 -            modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
  10.290 -        {
  10.291 +        SDL_DFB_CHECKERR(data->
  10.292 +                         surface->SetColor(data->surface, 0xFF, 0xFF, 0xFF,
  10.293 +                                           0xFF));
  10.294 +        if (texture->modMode &
  10.295 +            (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA)) {
  10.296              if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
  10.297                  alpha = texture->a;
  10.298 -                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
  10.299 -                                                         0xFF, 0xFF, alpha));
  10.300 +                SDL_DFB_CHECKERR(data->
  10.301 +                                 surface->SetColor(data->surface, 0xFF, 0xFF,
  10.302 +                                                   0xFF, alpha));
  10.303              }
  10.304              if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
  10.305  
  10.306 -                SDL_DFB_CHECKERR(data->surface->
  10.307 -                                 SetColor(data->surface, texture->r,
  10.308 -                                          texture->g, texture->b, alpha));
  10.309 +                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface,
  10.310 +                                                         texture->r,
  10.311 +                                                         texture->g,
  10.312 +                                                         texture->b, alpha));
  10.313                  flags |= DSBLIT_COLORIZE;
  10.314              }
  10.315              if (alpha < 0xFF)
  10.316                  flags |= DSBLIT_SRC_PREMULTCOLOR;
  10.317          } else
  10.318 -            SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
  10.319 -                                                     0xFF, 0xFF, 0xFF));
  10.320 +            SDL_DFB_CHECKERR(data->
  10.321 +                             surface->SetColor(data->surface, 0xFF, 0xFF,
  10.322 +                                               0xFF, 0xFF));
  10.323  
  10.324          SetBlendMode(data, texture->blendMode, texturedata);
  10.325  
  10.326 -        SDL_DFB_CHECKERR(data->surface->
  10.327 -                         SetBlittingFlags(data->surface,
  10.328 -                                          data->blitFlags | flags));
  10.329 +        SDL_DFB_CHECKERR(data->surface->SetBlittingFlags(data->surface,
  10.330 +                                                         data->blitFlags
  10.331 +                                                         | flags));
  10.332  
  10.333  #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
  10.334          SDL_DFB_CHECKERR(data->surface->SetRenderOptions(data->surface,
  10.335 @@ -964,13 +968,13 @@
  10.336  #endif
  10.337  
  10.338          if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
  10.339 -            SDL_DFB_CHECKERR(data->surface->
  10.340 -                             Blit(data->surface, texturedata->surface,
  10.341 -                                  &sr, dr.x, dr.y));
  10.342 +            SDL_DFB_CHECKERR(data->surface->Blit(data->surface,
  10.343 +                                                 texturedata->surface,
  10.344 +                                                 &sr, dr.x, dr.y));
  10.345          } else {
  10.346 -            SDL_DFB_CHECKERR(data->surface->
  10.347 -                             StretchBlit(data->surface, texturedata->surface,
  10.348 -                                         &sr, &dr));
  10.349 +            SDL_DFB_CHECKERR(data->surface->StretchBlit(data->surface,
  10.350 +                                                        texturedata->surface,
  10.351 +                                                        &sr, &dr));
  10.352          }
  10.353      }
  10.354      return 0;
  10.355 @@ -983,6 +987,7 @@
  10.356  {
  10.357      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  10.358      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
  10.359 +    SDL_DFB_WINDOWDATA(window);
  10.360  
  10.361      DFBRectangle sr;
  10.362      DFBResult ret;
  10.363 @@ -993,12 +998,8 @@
  10.364      sr.h = window->h;
  10.365  
  10.366      /* Send the data to the display */
  10.367 -    SDL_DFB_CHECKERR(data->surface->
  10.368 -                     Flip(data->surface, NULL, data->flipflags));
  10.369 -
  10.370 -    return;
  10.371 -  error:
  10.372 -    return;
  10.373 +    SDL_DFB_CHECK(windata->window_surface->Flip(windata->window_surface, NULL,
  10.374 +                                                data->flipflags));
  10.375  }
  10.376  
  10.377  static void
    11.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Sun Jan 11 23:39:11 2009 +0000
    11.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Sun Jan 11 23:49:23 2009 +0000
    11.3 @@ -35,6 +35,7 @@
    11.4  
    11.5  #include <directfb.h>
    11.6  #include <directfb_version.h>
    11.7 +#include <directfb_strings.h>
    11.8  
    11.9  #include "SDL_video.h"
   11.10  #include "SDL_mouse.h"
   11.11 @@ -55,8 +56,10 @@
   11.12  static int DirectFB_Available(void);
   11.13  static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
   11.14  
   11.15 +#if 0
   11.16  static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp);
   11.17  static int DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp);
   11.18 +#endif
   11.19  
   11.20  VideoBootStrap DirectFB_bootstrap = {
   11.21      "directfb", "DirectFB",
   11.22 @@ -111,6 +114,7 @@
   11.23      device->CreateWindow = DirectFB_CreateWindow;
   11.24      device->CreateWindowFrom = DirectFB_CreateWindowFrom;
   11.25      device->SetWindowTitle = DirectFB_SetWindowTitle;
   11.26 +    device->SetWindowIcon = DirectFB_SetWindowIcon;
   11.27      device->SetWindowPosition = DirectFB_SetWindowPosition;
   11.28      device->SetWindowSize = DirectFB_SetWindowSize;
   11.29      device->ShowWindow = DirectFB_ShowWindow;
   11.30 @@ -145,6 +149,50 @@
   11.31      return (0);
   11.32  }
   11.33  
   11.34 +static const DirectFBSurfaceDrawingFlagsNames(drawing_flags);
   11.35 +static const DirectFBSurfaceBlittingFlagsNames(blitting_flags);
   11.36 +static const DirectFBAccelerationMaskNames(acceleration_mask);
   11.37 +
   11.38 +static void
   11.39 +DirectFB_DeviceInformation(IDirectFB * dfb)
   11.40 +{
   11.41 +    DFBGraphicsDeviceDescription desc;
   11.42 +    int n;
   11.43 +
   11.44 +    dfb->GetDeviceDescription(dfb, &desc);
   11.45 +
   11.46 +    fprintf(LOG_CHANNEL, "DirectFB Device Information\n");
   11.47 +    fprintf(LOG_CHANNEL, "===========================\n");
   11.48 +    fprintf(LOG_CHANNEL, "Name:           %s\n", desc.name);
   11.49 +    fprintf(LOG_CHANNEL, "Vendor:         %s\n", desc.vendor);
   11.50 +    fprintf(LOG_CHANNEL, "Driver Name:    %s\n", desc.driver.name);
   11.51 +    fprintf(LOG_CHANNEL, "Driver Vendor:  %s\n", desc.driver.vendor);
   11.52 +    fprintf(LOG_CHANNEL, "Driver Version: %d.%d\n", desc.driver.major,
   11.53 +            desc.driver.minor);
   11.54 +
   11.55 +    fprintf(LOG_CHANNEL, "\nVideo memoory:  %d\n", desc.video_memory);
   11.56 +
   11.57 +    fprintf(LOG_CHANNEL, "\nBlitting flags:\n");
   11.58 +    for (n = 0; blitting_flags[n].flag; n++) {
   11.59 +        if (desc.blitting_flags & blitting_flags[n].flag)
   11.60 +            printf("    %s\n", blitting_flags[n].name);
   11.61 +    }
   11.62 +
   11.63 +    fprintf(LOG_CHANNEL, "\nDrawing flags:\n");
   11.64 +    for (n = 0; drawing_flags[n].flag; n++) {
   11.65 +        if (desc.drawing_flags & drawing_flags[n].flag)
   11.66 +            printf("    %s\n", drawing_flags[n].name);
   11.67 +    }
   11.68 +
   11.69 +    fprintf(LOG_CHANNEL, "\nAcceleration flags:\n");
   11.70 +    for (n = 0; acceleration_mask[n].mask; n++) {
   11.71 +        if (desc.acceleration_mask & acceleration_mask[n].mask)
   11.72 +            printf("    %s\n", acceleration_mask[n].name);
   11.73 +    }
   11.74 +
   11.75 +
   11.76 +}
   11.77 +
   11.78  static int
   11.79  DirectFB_VideoInit(_THIS)
   11.80  {
   11.81 @@ -159,21 +207,21 @@
   11.82  
   11.83      /* avoid switching to the framebuffer when we
   11.84       * are running X11 */
   11.85 -    stemp = getenv(DFBENV_USE_X11_CHECK);
   11.86 +    stemp = SDL_getenv(DFBENV_USE_X11_CHECK);
   11.87      if (stemp)
   11.88          ret = atoi(stemp);
   11.89      else
   11.90          ret = 1;
   11.91  
   11.92      if (ret) {
   11.93 -        if (getenv("DISPLAY"))
   11.94 +        if (SDL_getenv("DISPLAY"))
   11.95              DirectFBSetOption("system", "x11");
   11.96          else
   11.97              DirectFBSetOption("disable-module", "x11input");
   11.98      }
   11.99  
  11.100      devdata->use_linux_input = 1;       /* default: on */
  11.101 -    stemp = getenv(DFBENV_USE_LINUX_INPUT);
  11.102 +    stemp = SDL_getenv(DFBENV_USE_LINUX_INPUT);
  11.103      if (stemp)
  11.104          devdata->use_linux_input = atoi(stemp);
  11.105  
  11.106 @@ -182,25 +230,34 @@
  11.107  
  11.108      SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
  11.109  
  11.110 +    DirectFB_DeviceInformation(dfb);
  11.111      devdata->use_yuv_underlays = 0;     /* default: off */
  11.112 -    stemp = getenv(DFBENV_USE_YUV_UNDERLAY);
  11.113 +    stemp = SDL_getenv(DFBENV_USE_YUV_UNDERLAY);
  11.114      if (stemp)
  11.115          devdata->use_yuv_underlays = atoi(stemp);
  11.116  
  11.117  
  11.118      /* Create global Eventbuffer for axis events */
  11.119      if (devdata->use_linux_input) {
  11.120 -        SDL_DFB_CHECKERR(dfb->
  11.121 -                         CreateInputEventBuffer(dfb, DICAPS_ALL,
  11.122 -                                                DFB_TRUE, &devdata->events));
  11.123 +        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_ALL,
  11.124 +                                                     DFB_TRUE,
  11.125 +                                                     &devdata->events));
  11.126      } else {
  11.127 -        SDL_DFB_CHECKERR(dfb->
  11.128 -                         CreateInputEventBuffer(dfb,
  11.129 -                                                DICAPS_AXES /*DICAPS_ALL */ ,
  11.130 -                                                DFB_TRUE, &devdata->events));
  11.131 +        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_AXES
  11.132 +                                                     /*DICAPS_ALL */ ,
  11.133 +                                                     DFB_TRUE,
  11.134 +                                                     &devdata->events));
  11.135      }
  11.136  
  11.137      devdata->initialized = 1;
  11.138 +
  11.139 +    /* simple window manager support */
  11.140 +    stemp = SDL_getenv(DFBENV_USE_WM);
  11.141 +    if (stemp)
  11.142 +    	devdata->has_own_wm = atoi(stemp);
  11.143 +    else
  11.144 +    	devdata->has_own_wm = 0;
  11.145 +
  11.146      devdata->dfb = dfb;
  11.147      devdata->firstwin = NULL;
  11.148  
  11.149 @@ -216,7 +273,6 @@
  11.150      DirectFB_InitMouse(_this);
  11.151      DirectFB_InitKeyboard(_this);
  11.152  
  11.153 -
  11.154      return 0;
  11.155  
  11.156  
  11.157 @@ -245,6 +301,7 @@
  11.158      devdata->initialized = 0;
  11.159  }
  11.160  
  11.161 +#if 0
  11.162  static int
  11.163  DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp)
  11.164  {
  11.165 @@ -256,3 +313,4 @@
  11.166  {
  11.167      return -1;
  11.168  }
  11.169 +#endif
    12.1 --- a/src/video/directfb/SDL_DirectFB_video.h	Sun Jan 11 23:39:11 2009 +0000
    12.2 +++ b/src/video/directfb/SDL_DirectFB_video.h	Sun Jan 11 23:49:23 2009 +0000
    12.3 @@ -34,8 +34,8 @@
    12.4  #define DEBUG 0
    12.5  #define LOG_CHANNEL 	stdout
    12.6  
    12.7 -#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
    12.8 -#error "SDL_DIRECTFB: Please compile against libdirectfb version >=0.9.24"
    12.9 +#if (DIRECTFB_MAJOR_VERSION < 1)
   12.10 +#error "SDL_DIRECTFB: Please compile against libdirectfb version >= 1.0.0"
   12.11  #endif
   12.12  
   12.13  #if (DIRECTFB_MAJOR_VERSION >= 1) && (DIRECTFB_MINOR_VERSION >= 0) && (DIRECTFB_MICRO_VERSION >= 0 )
   12.14 @@ -56,11 +56,13 @@
   12.15  #include "SDL_DirectFB_mouse.h"
   12.16  #include "SDL_DirectFB_opengl.h"
   12.17  #include "SDL_DirectFB_window.h"
   12.18 +#include "SDL_DirectFB_WM.h"
   12.19  
   12.20  #define DFBENV_USE_YUV_UNDERLAY 	"SDL_DIRECTFB_YUV_UNDERLAY"     /* Default: off */
   12.21  #define DFBENV_USE_YUV_DIRECT   	"SDL_DIRECTFB_YUV_DIRECT"       /* Default: off */
   12.22  #define DFBENV_USE_X11_CHECK		"SDL_DIRECTFB_X11_CHECK"        /* Default: on  */
   12.23  #define DFBENV_USE_LINUX_INPUT		"SDL_DIRECTFB_LINUX_INPUT"      /* Default: on  */
   12.24 +#define DFBENV_USE_WM				"SDL_DIRECTFB_WM"		      	/* Default: off  */
   12.25  
   12.26  #define SDL_DFB_RELEASE(x) do { if ( x ) { x->Release(x); x = NULL; } } while (0)
   12.27  #define SDL_DFB_FREE(x) do { if ( x ) { SDL_free(x); x = NULL; } } while (0)
   12.28 @@ -88,6 +90,8 @@
   12.29            ret = x;                                                    \
   12.30            if (ret != DFB_OK) {                                        \
   12.31                 fprintf(LOG_CHANNEL, "%s <%d>:\n\t", __FILE__, __LINE__ ); 	      \
   12.32 +               fprintf(LOG_CHANNEL, "\t%s\n", #x ); \
   12.33 +               fprintf(LOG_CHANNEL, "\t%s\n", DirectFBErrorString (ret) ); \
   12.34                 SDL_SetError( #x, DirectFBErrorString (ret) );         \
   12.35            }                                                           \
   12.36       } while (0)
   12.37 @@ -116,7 +120,7 @@
   12.38  
   12.39  /* Private display data */
   12.40  
   12.41 -#define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (DFB_DeviceData *) ((dev)->driverdata)
   12.42 +#define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (dev ? (DFB_DeviceData *) ((dev)->driverdata) : NULL)
   12.43  
   12.44  #define DFB_MAX_SCREENS 10
   12.45  
   12.46 @@ -138,6 +142,7 @@
   12.47  
   12.48      int use_yuv_underlays;
   12.49      int use_linux_input;
   12.50 +    int has_own_wm;
   12.51  
   12.52      /* OpenGL */
   12.53      void (*glFinish) (void);
    13.1 --- a/src/video/directfb/SDL_DirectFB_window.c	Sun Jan 11 23:39:11 2009 +0000
    13.2 +++ b/src/video/directfb/SDL_DirectFB_window.c	Sun Jan 11 23:49:23 2009 +0000
    13.3 @@ -27,27 +27,27 @@
    13.4  
    13.5  #include "SDL_DirectFB_video.h"
    13.6  
    13.7 +
    13.8  int
    13.9  DirectFB_CreateWindow(_THIS, SDL_Window * window)
   13.10  {
   13.11      SDL_DFB_DEVICEDATA(_this);
   13.12      SDL_DFB_DISPLAYDATA(_this, window);
   13.13 -    DFB_WindowData *windata;
   13.14 +    DFB_WindowData *windata = NULL;
   13.15      DFBWindowOptions wopts;
   13.16      DFBWindowDescription desc;
   13.17 +    IDirectFBFont *font;
   13.18      int ret, x, y;
   13.19  
   13.20 -    SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y,
   13.21 -                  window->w, window->h);
   13.22 -    window->driverdata = NULL;
   13.23      SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
   13.24      windata = (DFB_WindowData *) window->driverdata;
   13.25  
   13.26 -    SDL_DFB_CHECKERR(devdata->dfb->
   13.27 -                     SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
   13.28 -    SDL_DFB_CHECKERR(dispdata->layer->
   13.29 -                     SetCooperativeLevel(dispdata->layer,
   13.30 -                                         DLSCL_ADMINISTRATIVE));
   13.31 +    windata->is_managed = devdata->has_own_wm;
   13.32 +
   13.33 +    SDL_DFB_CHECKERR(devdata->dfb->SetCooperativeLevel(devdata->dfb,
   13.34 +                                                       DFSCL_NORMAL));
   13.35 +    SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
   13.36 +                                                          DLSCL_ADMINISTRATIVE));
   13.37  
   13.38      /* Fill the window description. */
   13.39      if (window->x == SDL_WINDOWPOS_CENTERED) {
   13.40 @@ -69,76 +69,76 @@
   13.41          y = 0;
   13.42      }
   13.43  
   13.44 -    desc.flags = DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT;
   13.45 -    /*| DWDESC_CAPS | DWDESC_SURFACE_CAPS */
   13.46 +    DirectFB_WM_AdjustWindowLayout(window);
   13.47  
   13.48 -#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   13.49 -    /* Needed for 1.2 */
   13.50 -    desc.flags |= DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
   13.51 +    /* Create Window */
   13.52 +    desc.flags =
   13.53 +        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT | DWDESC_POSX
   13.54 +        | DWDESC_POSY | DWDESC_SURFACE_CAPS;
   13.55      desc.posx = x;
   13.56      desc.posy = y;
   13.57 -#else
   13.58 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN)
   13.59 -        && window->x != SDL_WINDOWPOS_UNDEFINED
   13.60 -        && window->y != SDL_WINDOWPOS_UNDEFINED) {
   13.61 -        desc.flags |= DWDESC_POSX | DWDESC_POSY;
   13.62 -        desc.posx = x;
   13.63 -        desc.posy = y;
   13.64 -    }
   13.65 -#endif
   13.66 -
   13.67 -    desc.width = window->w;
   13.68 -    desc.height = window->h;
   13.69 +    desc.width = windata->size.w;
   13.70 +    desc.height = windata->size.h;
   13.71      desc.pixelformat = dispdata->pixelformat;
   13.72 -#if 0
   13.73 -    desc.caps = 0;
   13.74 -    desc.surface_caps =
   13.75 -        DSCAPS_DOUBLE | DSCAPS_TRIPLE | DSCAPS_PREMULTIPLIED |
   13.76 -        DSCAPS_VIDEOONLY;
   13.77 -#endif
   13.78      desc.surface_caps = DSCAPS_PREMULTIPLIED;
   13.79 -    /* DSCAPS_VIDEOONLY has negative impact on performance */
   13.80  
   13.81      /* Create the window. */
   13.82 -    SDL_DFB_CHECKERR(dispdata->layer->
   13.83 -                     CreateWindow(dispdata->layer, &desc, &windata->window));
   13.84 +    SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc,
   13.85 +                                                   &windata->window));
   13.86  
   13.87 +    /* Set Options */
   13.88      windata->window->GetOptions(windata->window, &wopts);
   13.89 -#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   13.90  
   13.91      if (window->flags & SDL_WINDOW_RESIZABLE)
   13.92          wopts |= DWOP_SCALE;
   13.93      else
   13.94          wopts |= DWOP_KEEP_SIZE;
   13.95 -#else
   13.96 -    wopts |= DWOP_KEEP_SIZE;    /* if not we will crash ... */
   13.97 -#endif
   13.98  
   13.99 -    if (window->flags & SDL_WINDOW_FULLSCREEN)
  13.100 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  13.101          wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
  13.102 +        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
  13.103 +    }
  13.104 +    windata->window->SetOptions(windata->window, wopts);
  13.105  
  13.106 -    windata->window->SetOptions(windata->window, wopts);
  13.107 +    /* See what we got */
  13.108 +    SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &window->w, &window->h));
  13.109 +
  13.110      /* Get the window's surface. */
  13.111 -    SDL_DFB_CHECKERR(windata->window->
  13.112 -                     GetSurface(windata->window, &windata->surface));
  13.113 +    SDL_DFB_CHECKERR(windata->window->GetSurface(windata->window,
  13.114 +                                                 &windata->window_surface));
  13.115 +    /* And get a subsurface for rendering */
  13.116 +    SDL_DFB_CHECKERR(windata->window_surface->
  13.117 +                     GetSubSurface(windata->window_surface, &windata->client,
  13.118 +                                   &windata->surface));
  13.119 +
  13.120      windata->window->SetOpacity(windata->window, 0xFF);
  13.121 -    SDL_DFB_CHECKERR(windata->window->
  13.122 -                     CreateEventBuffer(windata->window,
  13.123 -                                       &(windata->eventbuffer)));
  13.124 -    SDL_DFB_CHECKERR(windata->window->
  13.125 -                     EnableEvents(windata->window, DWET_ALL));
  13.126  
  13.127 -    if (window->flags & SDL_WINDOW_FULLSCREEN)
  13.128 -        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
  13.129 +    /* Create Eventbuffer */
  13.130 +    SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
  13.131 +                                                        &windata->eventbuffer));
  13.132 +    SDL_DFB_CHECKERR(windata->
  13.133 +                     window->EnableEvents(windata->window, DWET_ALL));
  13.134 +
  13.135 +    /* Create a font */
  13.136 +    /* FIXME: once during Video_Init */
  13.137 +    if (windata->is_managed) {
  13.138 +        DFBFontDescription fdesc;
  13.139 +
  13.140 +        fdesc.flags = DFDESC_HEIGHT;
  13.141 +        fdesc.height = windata->theme.font_size;
  13.142 +        font = NULL;
  13.143 +        SDL_DFB_CHECK(devdata->
  13.144 +                      dfb->CreateFont(devdata->dfb, windata->theme.font,
  13.145 +                                      &fdesc, &font));
  13.146 +        windata->window_surface->SetFont(windata->window_surface, font);
  13.147 +        SDL_DFB_RELEASE(font);
  13.148 +    }
  13.149 +
  13.150      /* Make it the top most window. */
  13.151      windata->window->RaiseToTop(windata->window);
  13.152  
  13.153 -    windata->window->GetID(windata->window, &windata->windowID);
  13.154 -
  13.155 -    windata->window->GetSize(windata->window, &window->w, &window->h);
  13.156 -
  13.157      /* remember parent */
  13.158 -    windata->id = window->id;
  13.159 +    windata->sdl_id = window->id;
  13.160  
  13.161      /* Add to list ... */
  13.162  
  13.163 @@ -146,6 +146,9 @@
  13.164      windata->opacity = 0xFF;
  13.165      devdata->firstwin = windata;
  13.166  
  13.167 +    /* Draw Frame */
  13.168 +    DirectFB_WM_RedrawLayout(window);
  13.169 +
  13.170      return 0;
  13.171    error:
  13.172      SDL_DFB_RELEASE(windata->window);
  13.173 @@ -163,7 +166,65 @@
  13.174  void
  13.175  DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
  13.176  {
  13.177 -    SDL_Unsupported();
  13.178 +    SDL_DFB_WINDOWDATA(window);
  13.179 +
  13.180 +    if (windata->is_managed) {
  13.181 +        windata->wm_needs_redraw = 1;
  13.182 +    } else
  13.183 +        SDL_Unsupported();
  13.184 +}
  13.185 +
  13.186 +void
  13.187 +DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
  13.188 +{
  13.189 +    SDL_DFB_DEVICEDATA(_this);
  13.190 +    SDL_DFB_WINDOWDATA(window);
  13.191 +    SDL_Surface *surface = NULL;
  13.192 +    DFBResult ret;
  13.193 +
  13.194 +    if (icon) {
  13.195 +        SDL_PixelFormat format;
  13.196 +        DFBSurfaceDescription dsc;
  13.197 +        Uint32 *dest;
  13.198 +        Uint32 *p;
  13.199 +        int pitch, i;
  13.200 +
  13.201 +        /* Convert the icon to ARGB for modern window managers */
  13.202 +        SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
  13.203 +                       0xFF000000);
  13.204 +        surface = SDL_ConvertSurface(icon, &format, 0);
  13.205 +        if (!surface) {
  13.206 +            return;
  13.207 +        }
  13.208 +        dsc.flags =
  13.209 +            DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
  13.210 +        dsc.caps = DSCAPS_VIDEOONLY;
  13.211 +        dsc.width = surface->w;
  13.212 +        dsc.height = surface->h;
  13.213 +        dsc.pixelformat = DSPF_ARGB;
  13.214 +
  13.215 +        SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
  13.216 +                                                     &windata->icon));
  13.217 +
  13.218 +        SDL_DFB_CHECKERR(windata->icon->Lock(windata->icon, DSLF_WRITE,
  13.219 +                                             (void *) &dest, &pitch));
  13.220 +
  13.221 +        p = surface->pixels;
  13.222 +        for (i = 0; i < surface->h; i++)
  13.223 +            memcpy((char *) dest + i * pitch,
  13.224 +                   (char *) p + i * surface->pitch, 4 * surface->w);
  13.225 +
  13.226 +        windata->icon->Unlock(windata->icon);
  13.227 +        SDL_FreeSurface(surface);
  13.228 +    } else {
  13.229 +        SDL_DFB_RELEASE(windata->icon);
  13.230 +    }
  13.231 +    return;
  13.232 +  error:
  13.233 +    if (surface)
  13.234 +        SDL_FreeSurface(surface);
  13.235 +    SDL_DFB_RELEASE(windata->icon);
  13.236 +    return;
  13.237  }
  13.238  
  13.239  void
  13.240 @@ -186,37 +247,39 @@
  13.241          x = 0;
  13.242          y = 0;
  13.243      }
  13.244 -
  13.245 +    DirectFB_WM_AdjustWindowLayout(window);
  13.246      windata->window->MoveTo(windata->window, x, y);
  13.247  }
  13.248  
  13.249  void
  13.250  DirectFB_SetWindowSize(_THIS, SDL_Window * window)
  13.251  {
  13.252 +    SDL_DFB_DEVICEDATA(_this);
  13.253 +    SDL_DFB_WINDOWDATA(window);
  13.254      int ret;
  13.255 -    SDL_DFB_WINDOWDATA(window);
  13.256  
  13.257      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
  13.258 -#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
  13.259          int cw;
  13.260          int ch;
  13.261  
  13.262          /* Make sure all events are disabled for this operation ! */
  13.263 -        SDL_DFB_CHECKERR(windata->window->
  13.264 -                         DisableEvents(windata->window, DWET_ALL));
  13.265 +        SDL_DFB_CHECKERR(windata->window->DisableEvents(windata->window,
  13.266 +                                                        DWET_ALL));
  13.267  
  13.268 -        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &cw, &ch));
  13.269 -        if (cw != window->w || ch != window->h)
  13.270 -            SDL_DFB_CHECKERR(windata->window->
  13.271 -                             Resize(windata->window, window->w, window->h));
  13.272 -        SDL_DFB_CHECKERR(windata->window->
  13.273 -                         EnableEvents(windata->window, DWET_ALL));
  13.274 +        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &cw, &ch));
  13.275  
  13.276 -#else
  13.277 -        SDL_DFB_CHECKERR(windata->window->
  13.278 -                         Resize(windata->window, window->w, window->h));
  13.279 -#endif
  13.280 -        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h));    /* if a window manager should have decided otherwise */
  13.281 +        if (cw != window->w || ch != window->h) {
  13.282 +
  13.283 +            DirectFB_WM_AdjustWindowLayout(window);
  13.284 +            SDL_DFB_CHECKERR(windata->window->Resize(windata->window,
  13.285 +                                                     windata->size.w,
  13.286 +                                                     windata->size.h));
  13.287 +        }
  13.288 +
  13.289 +        SDL_DFB_CHECKERR(windata->window->EnableEvents(windata->window,
  13.290 +                                                       DWET_ALL));
  13.291 +
  13.292 +        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &window->w, &window->h));
  13.293  
  13.294          SDL_OnWindowResized(window);
  13.295      }
  13.296 @@ -256,9 +319,12 @@
  13.297  void
  13.298  DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
  13.299  {
  13.300 -    /* FIXME: Size to Desktop ? */
  13.301 +    SDL_DFB_WINDOWDATA(window);
  13.302  
  13.303 -    SDL_Unsupported();
  13.304 +    if (windata->is_managed) {
  13.305 +    	DirectFB_WM_MaximizeWindow(_this, window);
  13.306 +    } else
  13.307 +        SDL_Unsupported();
  13.308  }
  13.309  
  13.310  void
  13.311 @@ -272,7 +338,12 @@
  13.312  void
  13.313  DirectFB_RestoreWindow(_THIS, SDL_Window * window)
  13.314  {
  13.315 -    SDL_Unsupported();
  13.316 +    SDL_DFB_WINDOWDATA(window);
  13.317 +
  13.318 +    if (windata->is_managed) {
  13.319 +    	DirectFB_WM_RestoreWindow(_this, window);
  13.320 +    } else
  13.321 +        SDL_Unsupported();
  13.322  }
  13.323  
  13.324  void
  13.325 @@ -280,8 +351,7 @@
  13.326  {
  13.327      SDL_DFB_WINDOWDATA(window);
  13.328  
  13.329 -    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
  13.330 -        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
  13.331 +    if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
  13.332          windata->window->GrabPointer(windata->window);
  13.333          windata->window->GrabKeyboard(windata->window);
  13.334      } else {
  13.335 @@ -299,8 +369,16 @@
  13.336  
  13.337      SDL_DFB_DEBUG("Trace\n");
  13.338  
  13.339 +    /* Some cleanups */
  13.340 +    windata->window->UngrabPointer(windata->window);
  13.341 +    windata->window->UngrabKeyboard(windata->window);
  13.342 +
  13.343 +    windata->window_surface->SetFont(windata->window_surface, NULL);
  13.344 +    SDL_DFB_RELEASE(windata->icon);
  13.345      SDL_DFB_RELEASE(windata->eventbuffer);
  13.346      SDL_DFB_RELEASE(windata->surface);
  13.347 +    SDL_DFB_RELEASE(windata->window_surface);
  13.348 +
  13.349      SDL_DFB_RELEASE(windata->window);
  13.350  
  13.351      /* Remove from list ... */
  13.352 @@ -323,3 +401,35 @@
  13.353      SDL_Unsupported();
  13.354      return SDL_FALSE;
  13.355  }
  13.356 +
  13.357 +void
  13.358 +DirectFB_AdjustWindowSurface(SDL_Window * window)
  13.359 +{
  13.360 +    SDL_DFB_WINDOWDATA(window);
  13.361 +    int adjust = windata->wm_needs_redraw;
  13.362 +    int cw, ch;
  13.363 +    int ret;
  13.364 +
  13.365 +    DirectFB_WM_AdjustWindowLayout(window);
  13.366 +
  13.367 +    SDL_DFB_CHECKERR(windata->
  13.368 +                     window_surface->GetSize(windata->window_surface, &cw,
  13.369 +                                             &ch));
  13.370 +    if (cw != windata->size.w || ch != windata->size.h) {
  13.371 +        adjust = 1;
  13.372 +    }
  13.373 +
  13.374 +    if (adjust) {
  13.375 +        SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window,
  13.376 +                                                        windata->size.w,
  13.377 +                                                        windata->size.h));
  13.378 +        SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface,
  13.379 +                                                          windata->
  13.380 +                                                          window_surface,
  13.381 +                                                          &windata->client));
  13.382 +        DirectFB_WM_RedrawLayout(window);
  13.383 +    }
  13.384 +  error:
  13.385 +    return;
  13.386 +}
  13.387 +
    14.1 --- a/src/video/directfb/SDL_DirectFB_window.h	Sun Jan 11 23:39:11 2009 +0000
    14.2 +++ b/src/video/directfb/SDL_DirectFB_window.h	Sun Jan 11 23:49:23 2009 +0000
    14.3 @@ -24,25 +24,38 @@
    14.4  #ifndef _SDL_directfb_window_h
    14.5  #define _SDL_directfb_window_h
    14.6  
    14.7 +#include "SDL_DirectFB_WM.h"
    14.8 +
    14.9  #define SDL_DFB_WINDOWDATA(win)  DFB_WindowData *windata = ((win) ? (DFB_WindowData *) ((win)->driverdata) : NULL)
   14.10  
   14.11  typedef struct _DFB_WindowData DFB_WindowData;
   14.12  struct _DFB_WindowData
   14.13  {
   14.14      IDirectFBSurface *surface;
   14.15 +    IDirectFBSurface *window_surface;   /* only used with has_own_wm */
   14.16      IDirectFBWindow *window;
   14.17      DirectFB_GLContext *gl_context;
   14.18      IDirectFBEventBuffer *eventbuffer;
   14.19 -    DFBWindowID windowID;
   14.20 +    SDL_WindowID sdl_id;
   14.21      DFB_WindowData *next;
   14.22      Uint8 opacity;
   14.23 -    SDL_WindowID id;
   14.24 +    DFBRectangle client;
   14.25 +    DFBDimension size;
   14.26 +    /* WM extras */
   14.27 +    DFBRectangle restore;
   14.28 +    int is_managed;
   14.29 +    int wm_needs_redraw;
   14.30 +    IDirectFBSurface *icon;
   14.31 +    DFB_Theme theme;
   14.32  };
   14.33  
   14.34  extern int DirectFB_CreateWindow(_THIS, SDL_Window * window);
   14.35  extern int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window,
   14.36                                       const void *data);
   14.37  extern void DirectFB_SetWindowTitle(_THIS, SDL_Window * window);
   14.38 +extern void DirectFB_SetWindowIcon(_THIS, SDL_Window * window,
   14.39 +                                   SDL_Surface * icon);
   14.40 +
   14.41  extern void DirectFB_SetWindowPosition(_THIS, SDL_Window * window);
   14.42  extern void DirectFB_SetWindowSize(_THIS, SDL_Window * window);
   14.43  extern void DirectFB_ShowWindow(_THIS, SDL_Window * window);
   14.44 @@ -56,6 +69,8 @@
   14.45  extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
   14.46                                           struct SDL_SysWMinfo *info);
   14.47  
   14.48 +extern void DirectFB_AdjustWindowSurface(SDL_Window * window);
   14.49 +
   14.50  #endif /* _SDL_directfb_window_h */
   14.51  
   14.52  /* vi: set ts=4 sw=4 expandtab: */