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