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