src/video/directfb/SDL_DirectFB_window.c
author Sam Lantinga
Fri, 11 Feb 2011 22:37:15 -0800
changeset 5262 b530ef003506
parent 5246 58265e606e4e
child 5288 d4381f3b0d1e
permissions -rw-r--r--
Happy 2011! :)
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 */
couriersud@3023
   223
        SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
couriersud@3023
   224
                       0xFF000000);
couriersud@3023
   225
        surface = SDL_ConvertSurface(icon, &format, 0);
couriersud@3023
   226
        if (!surface) {
couriersud@3023
   227
            return;
couriersud@3023
   228
        }
couriersud@3023
   229
        dsc.flags =
couriersud@3023
   230
            DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
couriersud@3023
   231
        dsc.caps = DSCAPS_VIDEOONLY;
couriersud@3023
   232
        dsc.width = surface->w;
couriersud@3023
   233
        dsc.height = surface->h;
couriersud@3023
   234
        dsc.pixelformat = DSPF_ARGB;
couriersud@3023
   235
couriersud@3023
   236
        SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
couriersud@3023
   237
                                                     &windata->icon));
couriersud@3023
   238
couriersud@3023
   239
        SDL_DFB_CHECKERR(windata->icon->Lock(windata->icon, DSLF_WRITE,
couriersud@3023
   240
                                             (void *) &dest, &pitch));
couriersud@3023
   241
couriersud@3023
   242
        p = surface->pixels;
couriersud@3023
   243
        for (i = 0; i < surface->h; i++)
couriersud@3023
   244
            memcpy((char *) dest + i * pitch,
couriersud@3023
   245
                   (char *) p + i * surface->pitch, 4 * surface->w);
couriersud@3023
   246
slouken@4636
   247
        SDL_DFB_CHECK(windata->icon->Unlock(windata->icon));
couriersud@3023
   248
        SDL_FreeSurface(surface);
couriersud@3023
   249
    } else {
couriersud@3023
   250
        SDL_DFB_RELEASE(windata->icon);
couriersud@3023
   251
    }
couriersud@3023
   252
    return;
couriersud@3023
   253
  error:
couriersud@3023
   254
    if (surface)
couriersud@3023
   255
        SDL_FreeSurface(surface);
couriersud@3023
   256
    SDL_DFB_RELEASE(windata->icon);
couriersud@3023
   257
    return;
slouken@2737
   258
}
slouken@2737
   259
slouken@2737
   260
void
slouken@2737
   261
DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
slouken@2737
   262
{
slouken@2737
   263
    SDL_DFB_WINDOWDATA(window);
slouken@5199
   264
    SDL_DFB_DISPLAYDATA(window);
slouken@2737
   265
    int x, y;
slouken@2737
   266
slouken@5246
   267
    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
slouken@5199
   268
        x = (dispdata->cw - window->w) / 2;
slouken@5246
   269
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
slouken@5199
   270
        x = 0;
slouken@5199
   271
    } else {
slouken@5199
   272
        x = window->x;
slouken@5199
   273
    }
slouken@5199
   274
    
slouken@5246
   275
    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
slouken@5199
   276
        y = (dispdata->ch - window->h) / 2;
slouken@5246
   277
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
slouken@2737
   278
        y = 0;
slouken@5199
   279
    } else {
slouken@2737
   280
        y = window->y;
slouken@5199
   281
    }
slouken@2737
   282
slouken@2737
   283
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@2737
   284
        x = 0;
slouken@2737
   285
        y = 0;
slouken@2737
   286
    }
slouken@4636
   287
    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
slouken@5199
   288
    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, x, y));
slouken@2737
   289
}
slouken@2737
   290
slouken@2737
   291
void
slouken@2737
   292
DirectFB_SetWindowSize(_THIS, SDL_Window * window)
slouken@2737
   293
{
couriersud@3023
   294
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   295
slouken@5199
   296
    if(SDL_IsShapedWindow(window))
slouken@5199
   297
        DirectFB_ResizeWindowShape(window);
slouken@5199
   298
slouken@2737
   299
    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
slouken@2737
   300
        int cw;
slouken@2737
   301
        int ch;
slouken@2737
   302
slouken@2737
   303
        /* Make sure all events are disabled for this operation ! */
slouken@5199
   304
        SDL_DFB_CHECKERR(windata->dfbwin->DisableEvents(windata->dfbwin,
couriersud@3023
   305
                                                        DWET_ALL));
couriersud@3023
   306
        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &cw, &ch));
couriersud@3023
   307
couriersud@3023
   308
        if (cw != window->w || ch != window->h) {
slouken@2737
   309
slouken@4636
   310
		    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
slouken@5199
   311
            SDL_DFB_CHECKERR(windata->dfbwin->Resize(windata->dfbwin,
couriersud@3023
   312
                                                     windata->size.w,
couriersud@3023
   313
                                                     windata->size.h));
couriersud@3023
   314
        }
slouken@2737
   315
slouken@4636
   316
        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
slouken@4636
   317
                     (_this, window, &window->w, &window->h));
slouken@5199
   318
        DirectFB_AdjustWindowSurface(window);
slouken@4636
   319
slouken@5199
   320
        SDL_DFB_CHECKERR(windata->dfbwin->EnableEvents(windata->dfbwin,
couriersud@3023
   321
                                                       DWET_ALL));
couriersud@3023
   322
slouken@2737
   323
    }
slouken@2737
   324
    return;
slouken@2737
   325
  error:
slouken@5199
   326
    SDL_DFB_CHECK(windata->dfbwin->EnableEvents(windata->dfbwin, DWET_ALL));
slouken@2737
   327
    return;
slouken@2737
   328
}
slouken@2737
   329
slouken@2737
   330
void
slouken@2737
   331
DirectFB_ShowWindow(_THIS, SDL_Window * window)
slouken@2737
   332
{
slouken@2737
   333
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   334
slouken@5199
   335
    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, windata->opacity));
slouken@2737
   336
slouken@2737
   337
}
slouken@2737
   338
slouken@2737
   339
void
slouken@2737
   340
DirectFB_HideWindow(_THIS, SDL_Window * window)
slouken@2737
   341
{
slouken@2737
   342
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   343
slouken@5199
   344
    SDL_DFB_CHECK(windata->dfbwin->GetOpacity(windata->dfbwin, &windata->opacity));
slouken@5199
   345
    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, 0));
slouken@2737
   346
}
slouken@2737
   347
slouken@2737
   348
void
slouken@2737
   349
DirectFB_RaiseWindow(_THIS, SDL_Window * window)
slouken@2737
   350
{
slouken@2737
   351
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   352
slouken@5199
   353
    SDL_DFB_CHECK(windata->dfbwin->RaiseToTop(windata->dfbwin));
slouken@5199
   354
    SDL_DFB_CHECK(windata->dfbwin->RequestFocus(windata->dfbwin));
slouken@2737
   355
}
slouken@2737
   356
slouken@2737
   357
void
slouken@2737
   358
DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
slouken@2737
   359
{
couriersud@3023
   360
    SDL_DFB_WINDOWDATA(window);
slouken@5246
   361
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@5199
   362
    DFBWindowOptions wopts;
slouken@2737
   363
slouken@5199
   364
    SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin,
slouken@5199
   365
                                 &windata->restore.x, &windata->restore.y));
slouken@5199
   366
    SDL_DFB_CHECK(windata->dfbwin->GetSize(windata->dfbwin, &windata->restore.w,
slouken@5199
   367
                             &windata->restore.h));
slouken@5199
   368
slouken@5199
   369
    DirectFB_WM_AdjustWindowLayout(window, window->flags | SDL_WINDOW_MAXIMIZED, display->current_mode.w, display->current_mode.h) ;
slouken@5199
   370
slouken@5199
   371
    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, 0, 0));
slouken@5199
   372
    SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin,
slouken@5199
   373
                            display->current_mode.w, display->current_mode.h));
slouken@5199
   374
slouken@5199
   375
    /* Set Options */
slouken@5199
   376
    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
slouken@5199
   377
    wopts |= DWOP_KEEP_SIZE | DWOP_KEEP_POSITION;
slouken@5199
   378
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@2737
   379
}
slouken@2737
   380
slouken@2737
   381
void
slouken@2737
   382
DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
slouken@2737
   383
{
slouken@2737
   384
    /* FIXME: Size to 32x32 ? */
slouken@2737
   385
slouken@2737
   386
    SDL_Unsupported();
slouken@2737
   387
}
slouken@2737
   388
slouken@2737
   389
void
slouken@2737
   390
DirectFB_RestoreWindow(_THIS, SDL_Window * window)
slouken@2737
   391
{
couriersud@3023
   392
    SDL_DFB_WINDOWDATA(window);
slouken@5199
   393
    DFBWindowOptions wopts;
couriersud@3023
   394
slouken@5199
   395
    /* Set Options */
slouken@5199
   396
    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
slouken@5199
   397
    wopts &= ~(DWOP_KEEP_SIZE | DWOP_KEEP_POSITION);
slouken@5199
   398
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@5199
   399
slouken@5199
   400
    /* Window layout */
slouken@5199
   401
    DirectFB_WM_AdjustWindowLayout(window, window->flags & ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED),
slouken@5199
   402
    	windata->restore.w, windata->restore.h);
slouken@5199
   403
    SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin, windata->restore.w,
slouken@5199
   404
                            windata->restore.h));
slouken@5199
   405
    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, windata->restore.x,
slouken@5199
   406
                            windata->restore.y));
slouken@5199
   407
slouken@5199
   408
    if (!(window->flags & SDL_WINDOW_RESIZABLE))
slouken@5199
   409
        wopts |= DWOP_KEEP_SIZE;
slouken@5199
   410
slouken@5199
   411
    if (window->flags & SDL_WINDOW_FULLSCREEN)
slouken@5199
   412
        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_SIZE;
slouken@5199
   413
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@5199
   414
slouken@5199
   415
slouken@2737
   416
}
slouken@2737
   417
slouken@2737
   418
void
slouken@2737
   419
DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
slouken@2737
   420
{
slouken@4636
   421
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
   422
    SDL_DFB_WINDOWDATA(window);
slouken@4636
   423
    DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
slouken@2737
   424
couriersud@3023
   425
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
slouken@4636
   426
        if (gwindata != NULL)
slouken@4636
   427
        {
slouken@5199
   428
		    SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
slouken@5199
   429
		    SDL_DFB_CHECK(gwindata->dfbwin->UngrabKeyboard(gwindata->dfbwin));
slouken@4636
   430
        }
slouken@5199
   431
        SDL_DFB_CHECK(windata->dfbwin->GrabPointer(windata->dfbwin));
slouken@5199
   432
        SDL_DFB_CHECK(windata->dfbwin->GrabKeyboard(windata->dfbwin));
slouken@4636
   433
        devdata->grabbed_window = window;
slouken@2737
   434
    } else {
slouken@5199
   435
        SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
slouken@5199
   436
        SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
slouken@4636
   437
        devdata->grabbed_window = NULL;
slouken@2737
   438
    }
slouken@2737
   439
}
slouken@2737
   440
slouken@2737
   441
void
slouken@2737
   442
DirectFB_DestroyWindow(_THIS, SDL_Window * window)
slouken@2737
   443
{
slouken@2737
   444
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
   445
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   446
    DFB_WindowData *p;
slouken@2737
   447
slouken@4636
   448
    /* Some cleanups */
slouken@5199
   449
    SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
slouken@5199
   450
    SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
slouken@2737
   451
slouken@4636
   452
#if SDL_DIRECTFB_OPENGL
slouken@4636
   453
	DirectFB_GL_DestroyWindowContexts(_this, window);
slouken@4636
   454
#endif
couriersud@3023
   455
slouken@5199
   456
	if (window->shaper)
slouken@5199
   457
	{
slouken@5199
   458
	    SDL_ShapeData *data = window->shaper->driverdata;
slouken@5199
   459
	    SDL_DFB_CHECK(data->surface->ReleaseSource(data->surface));
slouken@5199
   460
    	SDL_DFB_RELEASE(data->surface);
slouken@5199
   461
    	SDL_DFB_FREE(data);
slouken@5199
   462
    	SDL_DFB_FREE(window->shaper);
slouken@5199
   463
	}
slouken@5199
   464
slouken@4636
   465
    SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, NULL));
slouken@4636
   466
    SDL_DFB_CHECK(windata->surface->ReleaseSource(windata->surface));
slouken@4636
   467
    SDL_DFB_CHECK(windata->window_surface->ReleaseSource(windata->window_surface));
slouken@4636
   468
  	SDL_DFB_RELEASE(windata->icon);
slouken@4636
   469
    SDL_DFB_RELEASE(windata->font);
slouken@2737
   470
    SDL_DFB_RELEASE(windata->eventbuffer);
slouken@2737
   471
    SDL_DFB_RELEASE(windata->surface);
couriersud@3023
   472
    SDL_DFB_RELEASE(windata->window_surface);
couriersud@3023
   473
slouken@5199
   474
    SDL_DFB_RELEASE(windata->dfbwin);
slouken@2737
   475
slouken@2737
   476
    /* Remove from list ... */
slouken@2737
   477
slouken@5199
   478
    p = devdata->firstwin->driverdata;
slouken@5199
   479
slouken@5199
   480
    while (p && p->next != window)
slouken@5199
   481
        p = (p->next ? p->next->driverdata : NULL);
slouken@2737
   482
    if (p)
slouken@2737
   483
        p->next = windata->next;
slouken@2737
   484
    else
slouken@2737
   485
        devdata->firstwin = windata->next;
slouken@2737
   486
    SDL_free(windata);
slouken@2737
   487
    return;
slouken@2737
   488
}
slouken@2737
   489
slouken@2737
   490
SDL_bool
slouken@2737
   491
DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
slouken@2737
   492
                         struct SDL_SysWMinfo * info)
slouken@2737
   493
{
slouken@5199
   494
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
   495
    SDL_DFB_WINDOWDATA(window);
slouken@5199
   496
slouken@5199
   497
    if (info->version.major == SDL_MAJOR_VERSION &&
slouken@5199
   498
        info->version.minor == SDL_MINOR_VERSION) {
slouken@5199
   499
        info->subsystem = SDL_SYSWM_DIRECTFB;
slouken@5199
   500
        info->info.dfb.dfb = devdata->dfb;
slouken@5199
   501
        info->info.dfb.window = windata->dfbwin;
slouken@5199
   502
        info->info.dfb.surface = windata->surface;
slouken@5199
   503
        return SDL_TRUE;
slouken@5199
   504
    } else {
slouken@5199
   505
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@5199
   506
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@5199
   507
        return SDL_FALSE;
slouken@5199
   508
    }
slouken@2737
   509
}
couriersud@3023
   510
slouken@5199
   511
void
slouken@5199
   512
DirectFB_AdjustWindowSurface(SDL_Window * window)
couriersud@3023
   513
{
couriersud@3023
   514
    SDL_DFB_WINDOWDATA(window);
couriersud@3023
   515
    int adjust = windata->wm_needs_redraw;
couriersud@3023
   516
    int cw, ch;
couriersud@3023
   517
slouken@4636
   518
    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
couriersud@3023
   519
couriersud@3023
   520
    SDL_DFB_CHECKERR(windata->
couriersud@3023
   521
                     window_surface->GetSize(windata->window_surface, &cw,
couriersud@3023
   522
                                             &ch));
couriersud@3023
   523
    if (cw != windata->size.w || ch != windata->size.h) {
couriersud@3023
   524
        adjust = 1;
couriersud@3023
   525
    }
couriersud@3023
   526
couriersud@3023
   527
    if (adjust) {
slouken@4636
   528
#if SDL_DIRECTFB_OPENGL
slouken@5246
   529
		DirectFB_GL_FreeWindowContexts(SDL_GetVideoDevice(), window);
slouken@4636
   530
#endif
slouken@4636
   531
slouken@5199
   532
#if (DFB_VERSION_ATLEAST(1,2,1))
slouken@5199
   533
        SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
couriersud@3023
   534
                                                        windata->size.w,
couriersud@3023
   535
                                                        windata->size.h));
slouken@3040
   536
        SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface,
couriersud@3023
   537
                                                          windata->
couriersud@3023
   538
                                                          window_surface,
couriersud@3023
   539
                                                          &windata->client));
couriersud@3037
   540
#else
slouken@3040
   541
        DFBWindowOptions opts;
slouken@3040
   542
slouken@5199
   543
        SDL_DFB_CHECKERR(windata->dfbwin->GetOptions(windata->dfbwin, &opts));
slouken@3040
   544
        /* recreate subsurface */
slouken@3040
   545
        SDL_DFB_RELEASE(windata->surface);
couriersud@3039
   546
slouken@3040
   547
        if (opts & DWOP_SCALE)
slouken@5199
   548
            SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
slouken@3040
   549
                                                            windata->size.w,
slouken@3040
   550
                                                            windata->size.h));
slouken@3040
   551
        SDL_DFB_CHECKERR(windata->window_surface->
slouken@3040
   552
                         GetSubSurface(windata->window_surface,
slouken@3040
   553
                                       &windata->client, &windata->surface));
couriersud@3037
   554
#endif
slouken@5246
   555
        DirectFB_WM_RedrawLayout(SDL_GetVideoDevice(), window);
slouken@4636
   556
        
slouken@4636
   557
#if SDL_DIRECTFB_OPENGL
slouken@5246
   558
		DirectFB_GL_ReAllocWindowContexts(SDL_GetVideoDevice(), window);
slouken@4636
   559
#endif
slouken@4636
   560
   }
couriersud@3023
   561
  error:
couriersud@3023
   562
    return;
couriersud@3023
   563
}