src/video/directfb/SDL_DirectFB_window.c
author Sam Lantinga
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5495 b3680e05286d
child 6044 35448a5ea044
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
slouken@2737
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@5535
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@2737
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@2737
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@2737
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@2737
    20
*/
slouken@2737
    21
slouken@2737
    22
#include "SDL_DirectFB_video.h"
slouken@5199
    23
#include "SDL_DirectFB_modes.h"
slouken@5199
    24
#include "SDL_DirectFB_window.h"
slouken@5199
    25
#include "SDL_DirectFB_shape.h"
slouken@5199
    26
slouken@4636
    27
#if SDL_DIRECTFB_OPENGL
slouken@4636
    28
#include "SDL_DirectFB_opengl.h"
slouken@4636
    29
#endif
slouken@2737
    30
slouken@5199
    31
#include "SDL_syswm.h"
slouken@5199
    32
slouken@5199
    33
#include "../SDL_pixels_c.h"
couriersud@3023
    34
slouken@2737
    35
int
slouken@2737
    36
DirectFB_CreateWindow(_THIS, SDL_Window * window)
slouken@2737
    37
{
slouken@2737
    38
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
    39
    SDL_DFB_DISPLAYDATA(window);
couriersud@3023
    40
    DFB_WindowData *windata = NULL;
slouken@2737
    41
    DFBWindowOptions wopts;
slouken@2737
    42
    DFBWindowDescription desc;
slouken@4636
    43
    int x, y;
slouken@5199
    44
    int bshaped = 0;
slouken@2737
    45
slouken@5199
    46
    SDL_DFB_ALLOC_CLEAR(window->driverdata, sizeof(DFB_WindowData));
slouken@2737
    47
    windata = (DFB_WindowData *) window->driverdata;
slouken@2737
    48
couriersud@3023
    49
    windata->is_managed = devdata->has_own_wm;
slouken@5199
    50
#if 1
couriersud@3023
    51
    SDL_DFB_CHECKERR(devdata->dfb->SetCooperativeLevel(devdata->dfb,
couriersud@3023
    52
                                                       DFSCL_NORMAL));
couriersud@3023
    53
    SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
couriersud@3023
    54
                                                          DLSCL_ADMINISTRATIVE));
slouken@5199
    55
#endif
slouken@5199
    56
	/* FIXME ... ughh, ugly */
slouken@5199
    57
	if (window->x == -1000 && window->y == -1000)
slouken@5199
    58
		bshaped = 1;
slouken@5199
    59
	
slouken@2737
    60
    /* Fill the window description. */
slouken@5495
    61
    x = window->x;
slouken@5495
    62
    y = window->y;
slouken@2737
    63
slouken@4636
    64
    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
slouken@2737
    65
couriersud@3023
    66
    /* Create Window */
slouken@5199
    67
	desc.caps = 0;
couriersud@3023
    68
    desc.flags =
slouken@5199
    69
        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
slouken@5199
    70
slouken@5199
    71
    if (bshaped) {
slouken@5199
    72
    	desc.flags |= DWDESC_CAPS;
slouken@5199
    73
    	desc.caps |= DWCAPS_ALPHACHANNEL;
slouken@5199
    74
    }
slouken@5199
    75
    else
slouken@5199
    76
    {
slouken@5199
    77
    	desc.flags |= DWDESC_PIXELFORMAT;
slouken@5199
    78
    }
slouken@5199
    79
slouken@5199
    80
    if (!(window->flags & SDL_WINDOW_BORDERLESS))
slouken@5199
    81
		desc.caps |= DWCAPS_NODECORATION;
slouken@5199
    82
slouken@2737
    83
    desc.posx = x;
slouken@2737
    84
    desc.posy = y;
couriersud@3023
    85
    desc.width = windata->size.w;
couriersud@3023
    86
    desc.height = windata->size.h;
slouken@2737
    87
    desc.pixelformat = dispdata->pixelformat;
slouken@2737
    88
    desc.surface_caps = DSCAPS_PREMULTIPLIED;
slouken@5199
    89
    
slouken@2737
    90
    /* Create the window. */
couriersud@3023
    91
    SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc,
slouken@5199
    92
                                                   &windata->dfbwin));
slouken@2737
    93
couriersud@3023
    94
    /* Set Options */
slouken@5199
    95
    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
slouken@2737
    96
slouken@5199
    97
    /* explicit rescaling of surface */
slouken@5199
    98
    wopts |= DWOP_SCALE;
slouken@5199
    99
    if (window->flags & SDL_WINDOW_RESIZABLE) {
slouken@5199
   100
        wopts &= ~DWOP_KEEP_SIZE;
slouken@5199
   101
    }
slouken@5199
   102
    else {
slouken@2737
   103
        wopts |= DWOP_KEEP_SIZE;
slouken@5199
   104
    }
slouken@2737
   105
couriersud@3023
   106
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@2737
   107
        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
slouken@5199
   108
        SDL_DFB_CHECK(windata->dfbwin->SetStackingClass(windata->dfbwin, DWSC_UPPER));
couriersud@3023
   109
    }
slouken@5199
   110
    
slouken@5199
   111
    if (bshaped) {
slouken@5199
   112
        wopts |= DWOP_SHAPED | DWOP_ALPHACHANNEL;
slouken@5199
   113
        wopts &= ~DWOP_OPAQUE_REGION;
slouken@5199
   114
    }
slouken@5199
   115
slouken@5199
   116
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@2737
   117
couriersud@3023
   118
    /* See what we got */
slouken@5199
   119
    SDL_DFB_CHECK(DirectFB_WM_GetClientSize
slouken@3040
   120
                     (_this, window, &window->w, &window->h));
couriersud@3023
   121
slouken@2737
   122
    /* Get the window's surface. */
slouken@5199
   123
    SDL_DFB_CHECKERR(windata->dfbwin->GetSurface(windata->dfbwin,
couriersud@3023
   124
                                                 &windata->window_surface));
slouken@5199
   125
couriersud@3023
   126
    /* And get a subsurface for rendering */
couriersud@3023
   127
    SDL_DFB_CHECKERR(windata->window_surface->
couriersud@3023
   128
                     GetSubSurface(windata->window_surface, &windata->client,
couriersud@3023
   129
                                   &windata->surface));
couriersud@3023
   130
slouken@5199
   131
    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, 0xFF));
couriersud@3023
   132
couriersud@3023
   133
    /* Create Eventbuffer */
slouken@5199
   134
slouken@5199
   135
    SDL_DFB_CHECKERR(windata->dfbwin->CreateEventBuffer(windata->dfbwin,
slouken@3040
   136
                                                        &windata->
slouken@3040
   137
                                                        eventbuffer));
slouken@5199
   138
    SDL_DFB_CHECKERR(windata->dfbwin->
slouken@5199
   139
                     EnableEvents(windata->dfbwin, DWET_ALL));
slouken@2737
   140
couriersud@3023
   141
    /* Create a font */
couriersud@3023
   142
    /* FIXME: once during Video_Init */
slouken@4636
   143
    windata->font = NULL;
couriersud@3023
   144
slouken@2737
   145
    /* Make it the top most window. */
slouken@5199
   146
    SDL_DFB_CHECK(windata->dfbwin->RaiseToTop(windata->dfbwin));
slouken@2737
   147
slouken@2737
   148
    /* remember parent */
slouken@5199
   149
    //windata->sdlwin = window;
slouken@2737
   150
slouken@2737
   151
    /* Add to list ... */
slouken@2737
   152
slouken@2737
   153
    windata->next = devdata->firstwin;
slouken@2737
   154
    windata->opacity = 0xFF;
slouken@5199
   155
    devdata->firstwin = window;
slouken@2737
   156
couriersud@3023
   157
    /* Draw Frame */
slouken@4636
   158
    DirectFB_WM_RedrawLayout(_this, window);
couriersud@3023
   159
slouken@2737
   160
    return 0;
slouken@2737
   161
  error:
slouken@5199
   162
	SDL_DFB_RELEASE(windata->surface);
slouken@5199
   163
    SDL_DFB_RELEASE(windata->dfbwin);
slouken@2737
   164
    return -1;
slouken@2737
   165
}
slouken@2737
   166
slouken@2737
   167
int
slouken@2737
   168
DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@2737
   169
{
slouken@2737
   170
    SDL_Unsupported();
slouken@2737
   171
    return -1;
slouken@2737
   172
}
slouken@2737
   173
slouken@2737
   174
void
slouken@2737
   175
DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
slouken@2737
   176
{
couriersud@3023
   177
    SDL_DFB_WINDOWDATA(window);
couriersud@3023
   178
couriersud@3023
   179
    if (windata->is_managed) {
couriersud@3023
   180
        windata->wm_needs_redraw = 1;
slouken@4636
   181
        DirectFB_WM_RedrawLayout(_this, window);
couriersud@3023
   182
    } else
couriersud@3023
   183
        SDL_Unsupported();
couriersud@3023
   184
}
couriersud@3023
   185
couriersud@3023
   186
void
couriersud@3023
   187
DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
couriersud@3023
   188
{
couriersud@3023
   189
    SDL_DFB_DEVICEDATA(_this);
couriersud@3023
   190
    SDL_DFB_WINDOWDATA(window);
couriersud@3023
   191
    SDL_Surface *surface = NULL;
couriersud@3023
   192
couriersud@3023
   193
    if (icon) {
couriersud@3023
   194
        SDL_PixelFormat format;
couriersud@3023
   195
        DFBSurfaceDescription dsc;
couriersud@3023
   196
        Uint32 *dest;
couriersud@3023
   197
        Uint32 *p;
couriersud@3023
   198
        int pitch, i;
couriersud@3023
   199
couriersud@3023
   200
        /* Convert the icon to ARGB for modern window managers */
slouken@5288
   201
        SDL_InitFormat(&format, SDL_PIXELFORMAT_ARGB8888);
couriersud@3023
   202
        surface = SDL_ConvertSurface(icon, &format, 0);
couriersud@3023
   203
        if (!surface) {
couriersud@3023
   204
            return;
couriersud@3023
   205
        }
couriersud@3023
   206
        dsc.flags =
couriersud@3023
   207
            DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
couriersud@3023
   208
        dsc.caps = DSCAPS_VIDEOONLY;
couriersud@3023
   209
        dsc.width = surface->w;
couriersud@3023
   210
        dsc.height = surface->h;
couriersud@3023
   211
        dsc.pixelformat = DSPF_ARGB;
couriersud@3023
   212
couriersud@3023
   213
        SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
couriersud@3023
   214
                                                     &windata->icon));
couriersud@3023
   215
couriersud@3023
   216
        SDL_DFB_CHECKERR(windata->icon->Lock(windata->icon, DSLF_WRITE,
couriersud@3023
   217
                                             (void *) &dest, &pitch));
couriersud@3023
   218
couriersud@3023
   219
        p = surface->pixels;
couriersud@3023
   220
        for (i = 0; i < surface->h; i++)
couriersud@3023
   221
            memcpy((char *) dest + i * pitch,
couriersud@3023
   222
                   (char *) p + i * surface->pitch, 4 * surface->w);
couriersud@3023
   223
slouken@4636
   224
        SDL_DFB_CHECK(windata->icon->Unlock(windata->icon));
couriersud@3023
   225
        SDL_FreeSurface(surface);
couriersud@3023
   226
    } else {
couriersud@3023
   227
        SDL_DFB_RELEASE(windata->icon);
couriersud@3023
   228
    }
couriersud@3023
   229
    return;
couriersud@3023
   230
  error:
couriersud@3023
   231
    if (surface)
couriersud@3023
   232
        SDL_FreeSurface(surface);
couriersud@3023
   233
    SDL_DFB_RELEASE(windata->icon);
couriersud@3023
   234
    return;
slouken@2737
   235
}
slouken@2737
   236
slouken@2737
   237
void
slouken@2737
   238
DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
slouken@2737
   239
{
slouken@2737
   240
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   241
    int x, y;
slouken@2737
   242
slouken@5478
   243
    x = window->x;
slouken@5478
   244
    y = window->y;
slouken@2737
   245
slouken@4636
   246
    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
slouken@5199
   247
    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, x, y));
slouken@2737
   248
}
slouken@2737
   249
slouken@2737
   250
void
slouken@2737
   251
DirectFB_SetWindowSize(_THIS, SDL_Window * window)
slouken@2737
   252
{
couriersud@3023
   253
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   254
slouken@5199
   255
    if(SDL_IsShapedWindow(window))
slouken@5199
   256
        DirectFB_ResizeWindowShape(window);
slouken@5199
   257
slouken@2737
   258
    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
slouken@2737
   259
        int cw;
slouken@2737
   260
        int ch;
slouken@2737
   261
slouken@2737
   262
        /* Make sure all events are disabled for this operation ! */
slouken@5199
   263
        SDL_DFB_CHECKERR(windata->dfbwin->DisableEvents(windata->dfbwin,
couriersud@3023
   264
                                                        DWET_ALL));
couriersud@3023
   265
        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &cw, &ch));
couriersud@3023
   266
couriersud@3023
   267
        if (cw != window->w || ch != window->h) {
slouken@2737
   268
slouken@4636
   269
		    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
slouken@5199
   270
            SDL_DFB_CHECKERR(windata->dfbwin->Resize(windata->dfbwin,
couriersud@3023
   271
                                                     windata->size.w,
couriersud@3023
   272
                                                     windata->size.h));
couriersud@3023
   273
        }
slouken@2737
   274
slouken@4636
   275
        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
slouken@4636
   276
                     (_this, window, &window->w, &window->h));
slouken@5199
   277
        DirectFB_AdjustWindowSurface(window);
slouken@4636
   278
slouken@5199
   279
        SDL_DFB_CHECKERR(windata->dfbwin->EnableEvents(windata->dfbwin,
couriersud@3023
   280
                                                       DWET_ALL));
couriersud@3023
   281
slouken@2737
   282
    }
slouken@2737
   283
    return;
slouken@2737
   284
  error:
slouken@5199
   285
    SDL_DFB_CHECK(windata->dfbwin->EnableEvents(windata->dfbwin, DWET_ALL));
slouken@2737
   286
    return;
slouken@2737
   287
}
slouken@2737
   288
slouken@2737
   289
void
slouken@2737
   290
DirectFB_ShowWindow(_THIS, SDL_Window * window)
slouken@2737
   291
{
slouken@2737
   292
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   293
slouken@5199
   294
    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, windata->opacity));
slouken@2737
   295
slouken@2737
   296
}
slouken@2737
   297
slouken@2737
   298
void
slouken@2737
   299
DirectFB_HideWindow(_THIS, SDL_Window * window)
slouken@2737
   300
{
slouken@2737
   301
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   302
slouken@5199
   303
    SDL_DFB_CHECK(windata->dfbwin->GetOpacity(windata->dfbwin, &windata->opacity));
slouken@5199
   304
    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, 0));
slouken@2737
   305
}
slouken@2737
   306
slouken@2737
   307
void
slouken@2737
   308
DirectFB_RaiseWindow(_THIS, SDL_Window * window)
slouken@2737
   309
{
slouken@2737
   310
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   311
slouken@5199
   312
    SDL_DFB_CHECK(windata->dfbwin->RaiseToTop(windata->dfbwin));
slouken@5199
   313
    SDL_DFB_CHECK(windata->dfbwin->RequestFocus(windata->dfbwin));
slouken@2737
   314
}
slouken@2737
   315
slouken@2737
   316
void
slouken@2737
   317
DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
slouken@2737
   318
{
couriersud@3023
   319
    SDL_DFB_WINDOWDATA(window);
slouken@5246
   320
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@5199
   321
    DFBWindowOptions wopts;
slouken@2737
   322
slouken@5199
   323
    SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin,
slouken@5199
   324
                                 &windata->restore.x, &windata->restore.y));
slouken@5199
   325
    SDL_DFB_CHECK(windata->dfbwin->GetSize(windata->dfbwin, &windata->restore.w,
slouken@5199
   326
                             &windata->restore.h));
slouken@5199
   327
slouken@5199
   328
    DirectFB_WM_AdjustWindowLayout(window, window->flags | SDL_WINDOW_MAXIMIZED, display->current_mode.w, display->current_mode.h) ;
slouken@5199
   329
slouken@5199
   330
    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, 0, 0));
slouken@5199
   331
    SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin,
slouken@5199
   332
                            display->current_mode.w, display->current_mode.h));
slouken@5199
   333
slouken@5199
   334
    /* Set Options */
slouken@5199
   335
    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
slouken@5199
   336
    wopts |= DWOP_KEEP_SIZE | DWOP_KEEP_POSITION;
slouken@5199
   337
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@2737
   338
}
slouken@2737
   339
slouken@2737
   340
void
slouken@2737
   341
DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
slouken@2737
   342
{
slouken@2737
   343
    /* FIXME: Size to 32x32 ? */
slouken@2737
   344
slouken@2737
   345
    SDL_Unsupported();
slouken@2737
   346
}
slouken@2737
   347
slouken@2737
   348
void
slouken@2737
   349
DirectFB_RestoreWindow(_THIS, SDL_Window * window)
slouken@2737
   350
{
couriersud@3023
   351
    SDL_DFB_WINDOWDATA(window);
slouken@5199
   352
    DFBWindowOptions wopts;
couriersud@3023
   353
slouken@5199
   354
    /* Set Options */
slouken@5199
   355
    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
slouken@5199
   356
    wopts &= ~(DWOP_KEEP_SIZE | DWOP_KEEP_POSITION);
slouken@5199
   357
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@5199
   358
slouken@5199
   359
    /* Window layout */
slouken@5199
   360
    DirectFB_WM_AdjustWindowLayout(window, window->flags & ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED),
slouken@5199
   361
    	windata->restore.w, windata->restore.h);
slouken@5199
   362
    SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin, windata->restore.w,
slouken@5199
   363
                            windata->restore.h));
slouken@5199
   364
    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, windata->restore.x,
slouken@5199
   365
                            windata->restore.y));
slouken@5199
   366
slouken@5199
   367
    if (!(window->flags & SDL_WINDOW_RESIZABLE))
slouken@5199
   368
        wopts |= DWOP_KEEP_SIZE;
slouken@5199
   369
slouken@5199
   370
    if (window->flags & SDL_WINDOW_FULLSCREEN)
slouken@5199
   371
        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_SIZE;
slouken@5199
   372
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@5199
   373
slouken@5199
   374
slouken@2737
   375
}
slouken@2737
   376
slouken@2737
   377
void
slouken@2737
   378
DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
slouken@2737
   379
{
slouken@4636
   380
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
   381
    SDL_DFB_WINDOWDATA(window);
slouken@4636
   382
    DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
slouken@2737
   383
couriersud@3023
   384
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
slouken@4636
   385
        if (gwindata != NULL)
slouken@4636
   386
        {
slouken@5199
   387
		    SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
slouken@5199
   388
		    SDL_DFB_CHECK(gwindata->dfbwin->UngrabKeyboard(gwindata->dfbwin));
slouken@4636
   389
        }
slouken@5199
   390
        SDL_DFB_CHECK(windata->dfbwin->GrabPointer(windata->dfbwin));
slouken@5199
   391
        SDL_DFB_CHECK(windata->dfbwin->GrabKeyboard(windata->dfbwin));
slouken@4636
   392
        devdata->grabbed_window = window;
slouken@2737
   393
    } else {
slouken@5199
   394
        SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
slouken@5199
   395
        SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
slouken@4636
   396
        devdata->grabbed_window = NULL;
slouken@2737
   397
    }
slouken@2737
   398
}
slouken@2737
   399
slouken@2737
   400
void
slouken@2737
   401
DirectFB_DestroyWindow(_THIS, SDL_Window * window)
slouken@2737
   402
{
slouken@2737
   403
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
   404
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   405
    DFB_WindowData *p;
slouken@2737
   406
slouken@4636
   407
    /* Some cleanups */
slouken@5199
   408
    SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
slouken@5199
   409
    SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
slouken@2737
   410
slouken@4636
   411
#if SDL_DIRECTFB_OPENGL
slouken@4636
   412
	DirectFB_GL_DestroyWindowContexts(_this, window);
slouken@4636
   413
#endif
couriersud@3023
   414
slouken@5199
   415
	if (window->shaper)
slouken@5199
   416
	{
slouken@5199
   417
	    SDL_ShapeData *data = window->shaper->driverdata;
slouken@5199
   418
	    SDL_DFB_CHECK(data->surface->ReleaseSource(data->surface));
slouken@5199
   419
    	SDL_DFB_RELEASE(data->surface);
slouken@5199
   420
    	SDL_DFB_FREE(data);
slouken@5199
   421
    	SDL_DFB_FREE(window->shaper);
slouken@5199
   422
	}
slouken@5199
   423
slouken@4636
   424
    SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, NULL));
slouken@4636
   425
    SDL_DFB_CHECK(windata->surface->ReleaseSource(windata->surface));
slouken@4636
   426
    SDL_DFB_CHECK(windata->window_surface->ReleaseSource(windata->window_surface));
slouken@4636
   427
  	SDL_DFB_RELEASE(windata->icon);
slouken@4636
   428
    SDL_DFB_RELEASE(windata->font);
slouken@2737
   429
    SDL_DFB_RELEASE(windata->eventbuffer);
slouken@2737
   430
    SDL_DFB_RELEASE(windata->surface);
couriersud@3023
   431
    SDL_DFB_RELEASE(windata->window_surface);
couriersud@3023
   432
slouken@5199
   433
    SDL_DFB_RELEASE(windata->dfbwin);
slouken@2737
   434
slouken@2737
   435
    /* Remove from list ... */
slouken@2737
   436
slouken@5199
   437
    p = devdata->firstwin->driverdata;
slouken@5199
   438
slouken@5199
   439
    while (p && p->next != window)
slouken@5199
   440
        p = (p->next ? p->next->driverdata : NULL);
slouken@2737
   441
    if (p)
slouken@2737
   442
        p->next = windata->next;
slouken@2737
   443
    else
slouken@2737
   444
        devdata->firstwin = windata->next;
slouken@2737
   445
    SDL_free(windata);
slouken@2737
   446
    return;
slouken@2737
   447
}
slouken@2737
   448
slouken@2737
   449
SDL_bool
slouken@2737
   450
DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
slouken@2737
   451
                         struct SDL_SysWMinfo * info)
slouken@2737
   452
{
slouken@5199
   453
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
   454
    SDL_DFB_WINDOWDATA(window);
slouken@5199
   455
slouken@5199
   456
    if (info->version.major == SDL_MAJOR_VERSION &&
slouken@5199
   457
        info->version.minor == SDL_MINOR_VERSION) {
slouken@5199
   458
        info->subsystem = SDL_SYSWM_DIRECTFB;
slouken@5199
   459
        info->info.dfb.dfb = devdata->dfb;
slouken@5199
   460
        info->info.dfb.window = windata->dfbwin;
slouken@5199
   461
        info->info.dfb.surface = windata->surface;
slouken@5199
   462
        return SDL_TRUE;
slouken@5199
   463
    } else {
slouken@5199
   464
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@5199
   465
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@5199
   466
        return SDL_FALSE;
slouken@5199
   467
    }
slouken@2737
   468
}
couriersud@3023
   469
slouken@5199
   470
void
slouken@5199
   471
DirectFB_AdjustWindowSurface(SDL_Window * window)
couriersud@3023
   472
{
couriersud@3023
   473
    SDL_DFB_WINDOWDATA(window);
couriersud@3023
   474
    int adjust = windata->wm_needs_redraw;
couriersud@3023
   475
    int cw, ch;
couriersud@3023
   476
slouken@4636
   477
    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
couriersud@3023
   478
couriersud@3023
   479
    SDL_DFB_CHECKERR(windata->
couriersud@3023
   480
                     window_surface->GetSize(windata->window_surface, &cw,
couriersud@3023
   481
                                             &ch));
couriersud@3023
   482
    if (cw != windata->size.w || ch != windata->size.h) {
couriersud@3023
   483
        adjust = 1;
couriersud@3023
   484
    }
couriersud@3023
   485
couriersud@3023
   486
    if (adjust) {
slouken@4636
   487
#if SDL_DIRECTFB_OPENGL
slouken@5246
   488
		DirectFB_GL_FreeWindowContexts(SDL_GetVideoDevice(), window);
slouken@4636
   489
#endif
slouken@4636
   490
slouken@5199
   491
#if (DFB_VERSION_ATLEAST(1,2,1))
slouken@5199
   492
        SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
couriersud@3023
   493
                                                        windata->size.w,
couriersud@3023
   494
                                                        windata->size.h));
slouken@3040
   495
        SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface,
couriersud@3023
   496
                                                          windata->
couriersud@3023
   497
                                                          window_surface,
couriersud@3023
   498
                                                          &windata->client));
couriersud@3037
   499
#else
slouken@3040
   500
        DFBWindowOptions opts;
slouken@3040
   501
slouken@5199
   502
        SDL_DFB_CHECKERR(windata->dfbwin->GetOptions(windata->dfbwin, &opts));
slouken@3040
   503
        /* recreate subsurface */
slouken@3040
   504
        SDL_DFB_RELEASE(windata->surface);
couriersud@3039
   505
slouken@3040
   506
        if (opts & DWOP_SCALE)
slouken@5199
   507
            SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
slouken@3040
   508
                                                            windata->size.w,
slouken@3040
   509
                                                            windata->size.h));
slouken@3040
   510
        SDL_DFB_CHECKERR(windata->window_surface->
slouken@3040
   511
                         GetSubSurface(windata->window_surface,
slouken@3040
   512
                                       &windata->client, &windata->surface));
couriersud@3037
   513
#endif
slouken@5246
   514
        DirectFB_WM_RedrawLayout(SDL_GetVideoDevice(), window);
slouken@4636
   515
        
slouken@4636
   516
#if SDL_DIRECTFB_OPENGL
slouken@5246
   517
		DirectFB_GL_ReAllocWindowContexts(SDL_GetVideoDevice(), window);
slouken@4636
   518
#endif
slouken@4636
   519
   }
couriersud@3023
   520
  error:
couriersud@3023
   521
    return;
couriersud@3023
   522
}