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