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