src/video/directfb/SDL_DirectFB_window.c
author Bob Pendleton <bob@pendleton.com>
Fri, 09 Jan 2009 20:43:30 +0000
changeset 3011 8f4ed5ec2b06
parent 2859 99210400e8b9
child 3013 8cc00819c8d6
permissions -rw-r--r--
I ran a global "make indent" it modified the following files.
slouken@2737
     1
/*
slouken@2737
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 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@2737
    21
*/
slouken@2737
    22
#include "SDL_config.h"
slouken@2737
    23
slouken@2737
    24
#include "SDL_syswm.h"
slouken@2737
    25
#include "../SDL_sysvideo.h"
slouken@2737
    26
#include "../../events/SDL_keyboard_c.h"
slouken@2737
    27
slouken@2737
    28
#include "SDL_DirectFB_video.h"
slouken@2737
    29
slouken@2737
    30
int
slouken@2737
    31
DirectFB_CreateWindow(_THIS, SDL_Window * window)
slouken@2737
    32
{
slouken@2737
    33
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
    34
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2737
    35
    DFB_WindowData *windata;
slouken@2737
    36
    DFBWindowOptions wopts;
slouken@2737
    37
    DFBWindowDescription desc;
slouken@2737
    38
    int ret, x, y;
slouken@2737
    39
slouken@2737
    40
    SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y,
slouken@2737
    41
                  window->w, window->h);
slouken@2737
    42
    window->driverdata = NULL;
slouken@2737
    43
    SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
slouken@2737
    44
    windata = (DFB_WindowData *) window->driverdata;
slouken@2737
    45
bob@3011
    46
    SDL_DFB_CHECKERR(devdata->
bob@3011
    47
                     dfb->SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
bob@3011
    48
    SDL_DFB_CHECKERR(dispdata->
bob@3011
    49
                     layer->SetCooperativeLevel(dispdata->layer,
bob@3011
    50
                                                DLSCL_ADMINISTRATIVE));
slouken@2737
    51
slouken@2737
    52
    /* Fill the window description. */
slouken@2737
    53
    if (window->x == SDL_WINDOWPOS_CENTERED) {
slouken@2737
    54
        x = (dispdata->cw - window->w) / 2;
slouken@2737
    55
    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
slouken@2737
    56
        x = 0;
slouken@2737
    57
    } else {
slouken@2737
    58
        x = window->x;
slouken@2737
    59
    }
slouken@2737
    60
    if (window->y == SDL_WINDOWPOS_CENTERED) {
slouken@2737
    61
        y = (dispdata->ch - window->h) / 2;
slouken@2737
    62
    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
slouken@2737
    63
        y = 0;
slouken@2737
    64
    } else {
slouken@2737
    65
        y = window->y;
slouken@2737
    66
    }
slouken@2737
    67
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@2737
    68
        x = 0;
slouken@2737
    69
        y = 0;
slouken@2737
    70
    }
slouken@2737
    71
slouken@2737
    72
    desc.flags = DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT;
slouken@2737
    73
    /*| DWDESC_CAPS | DWDESC_SURFACE_CAPS */
slouken@2737
    74
slouken@2737
    75
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
slouken@2737
    76
    /* Needed for 1.2 */
slouken@2737
    77
    desc.flags |= DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
slouken@2737
    78
    desc.posx = x;
slouken@2737
    79
    desc.posy = y;
slouken@2737
    80
#else
slouken@2737
    81
    if (!(window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2737
    82
        && window->x != SDL_WINDOWPOS_UNDEFINED
slouken@2737
    83
        && window->y != SDL_WINDOWPOS_UNDEFINED) {
slouken@2737
    84
        desc.flags |= DWDESC_POSX | DWDESC_POSY;
slouken@2737
    85
        desc.posx = x;
slouken@2737
    86
        desc.posy = y;
slouken@2737
    87
    }
slouken@2737
    88
#endif
slouken@2737
    89
slouken@2737
    90
    desc.width = window->w;
slouken@2737
    91
    desc.height = window->h;
slouken@2737
    92
    desc.pixelformat = dispdata->pixelformat;
slouken@2737
    93
#if 0
slouken@2737
    94
    desc.caps = 0;
slouken@2737
    95
    desc.surface_caps =
slouken@2737
    96
        DSCAPS_DOUBLE | DSCAPS_TRIPLE | DSCAPS_PREMULTIPLIED |
slouken@2737
    97
        DSCAPS_VIDEOONLY;
slouken@2737
    98
#endif
slouken@2737
    99
    desc.surface_caps = DSCAPS_PREMULTIPLIED;
slouken@2737
   100
    /* DSCAPS_VIDEOONLY has negative impact on performance */
slouken@2737
   101
slouken@2737
   102
    /* Create the window. */
bob@3011
   103
    SDL_DFB_CHECKERR(dispdata->
bob@3011
   104
                     layer->CreateWindow(dispdata->layer, &desc,
bob@3011
   105
                                         &windata->window));
slouken@2737
   106
slouken@2737
   107
    windata->window->GetOptions(windata->window, &wopts);
slouken@2737
   108
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
slouken@2737
   109
slouken@2737
   110
    if (window->flags & SDL_WINDOW_RESIZABLE)
slouken@2737
   111
        wopts |= DWOP_SCALE;
slouken@2737
   112
    else
slouken@2737
   113
        wopts |= DWOP_KEEP_SIZE;
slouken@2737
   114
#else
slouken@2737
   115
    wopts |= DWOP_KEEP_SIZE;    /* if not we will crash ... */
slouken@2737
   116
#endif
slouken@2737
   117
slouken@2737
   118
    if (window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2737
   119
        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
slouken@2737
   120
slouken@2737
   121
    windata->window->SetOptions(windata->window, wopts);
slouken@2737
   122
    /* Get the window's surface. */
bob@3011
   123
    SDL_DFB_CHECKERR(windata->
bob@3011
   124
                     window->GetSurface(windata->window, &windata->surface));
slouken@2737
   125
    windata->window->SetOpacity(windata->window, 0xFF);
bob@3011
   126
    SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
bob@3011
   127
                                                        &(windata->
bob@3011
   128
                                                          eventbuffer)));
bob@3011
   129
    SDL_DFB_CHECKERR(windata->
bob@3011
   130
                     window->EnableEvents(windata->window, DWET_ALL));
slouken@2737
   131
slouken@2737
   132
    if (window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2737
   133
        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
slouken@2737
   134
    /* Make it the top most window. */
slouken@2737
   135
    windata->window->RaiseToTop(windata->window);
slouken@2737
   136
slouken@2737
   137
    windata->window->GetID(windata->window, &windata->windowID);
slouken@2737
   138
slouken@2737
   139
    windata->window->GetSize(windata->window, &window->w, &window->h);
slouken@2737
   140
slouken@2737
   141
    /* remember parent */
slouken@2737
   142
    windata->id = window->id;
slouken@2737
   143
slouken@2737
   144
    /* Add to list ... */
slouken@2737
   145
slouken@2737
   146
    windata->next = devdata->firstwin;
slouken@2737
   147
    windata->opacity = 0xFF;
slouken@2737
   148
    devdata->firstwin = windata;
slouken@2737
   149
slouken@2737
   150
    return 0;
slouken@2737
   151
  error:
slouken@2737
   152
    SDL_DFB_RELEASE(windata->window);
slouken@2737
   153
    SDL_DFB_RELEASE(windata->surface);
slouken@2737
   154
    return -1;
slouken@2737
   155
}
slouken@2737
   156
slouken@2737
   157
int
slouken@2737
   158
DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@2737
   159
{
slouken@2737
   160
    SDL_Unsupported();
slouken@2737
   161
    return -1;
slouken@2737
   162
}
slouken@2737
   163
slouken@2737
   164
void
slouken@2737
   165
DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
slouken@2737
   166
{
slouken@2737
   167
    SDL_Unsupported();
slouken@2737
   168
}
slouken@2737
   169
slouken@2737
   170
void
slouken@2737
   171
DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
slouken@2737
   172
{
slouken@2737
   173
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   174
    int x, y;
slouken@2737
   175
slouken@2737
   176
    if (window->y == SDL_WINDOWPOS_UNDEFINED)
slouken@2737
   177
        y = 0;
slouken@2737
   178
    else
slouken@2737
   179
        y = window->y;
slouken@2737
   180
slouken@2737
   181
    if (window->x == SDL_WINDOWPOS_UNDEFINED)
slouken@2737
   182
        x = 0;
slouken@2737
   183
    else
slouken@2737
   184
        x = window->x;
slouken@2737
   185
slouken@2737
   186
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@2737
   187
        x = 0;
slouken@2737
   188
        y = 0;
slouken@2737
   189
    }
slouken@2737
   190
slouken@2737
   191
    windata->window->MoveTo(windata->window, x, y);
slouken@2737
   192
}
slouken@2737
   193
slouken@2737
   194
void
slouken@2737
   195
DirectFB_SetWindowSize(_THIS, SDL_Window * window)
slouken@2737
   196
{
slouken@2737
   197
    int ret;
slouken@2737
   198
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   199
slouken@2737
   200
    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
slouken@2737
   201
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
slouken@2737
   202
        int cw;
slouken@2737
   203
        int ch;
slouken@2737
   204
slouken@2737
   205
        /* Make sure all events are disabled for this operation ! */
bob@3011
   206
        SDL_DFB_CHECKERR(windata->
bob@3011
   207
                         window->DisableEvents(windata->window, DWET_ALL));
slouken@2737
   208
slouken@2737
   209
        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &cw, &ch));
slouken@2737
   210
        if (cw != window->w || ch != window->h)
bob@3011
   211
            SDL_DFB_CHECKERR(windata->
bob@3011
   212
                             window->Resize(windata->window, window->w,
bob@3011
   213
                                            window->h));
bob@3011
   214
        SDL_DFB_CHECKERR(windata->
bob@3011
   215
                         window->EnableEvents(windata->window, DWET_ALL));
slouken@2737
   216
slouken@2737
   217
#else
bob@3011
   218
        SDL_DFB_CHECKERR(windata->
bob@3011
   219
                         window->Resize(windata->window, window->w,
bob@3011
   220
                                        window->h));
slouken@2737
   221
#endif
slouken@2737
   222
        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h));    /* if a window manager should have decided otherwise */
slouken@2737
   223
slouken@2737
   224
        SDL_OnWindowResized(window);
slouken@2737
   225
    }
slouken@2737
   226
    return;
slouken@2737
   227
  error:
slouken@2737
   228
    windata->window->EnableEvents(windata->window, DWET_ALL);
slouken@2737
   229
    return;
slouken@2737
   230
}
slouken@2737
   231
slouken@2737
   232
void
slouken@2737
   233
DirectFB_ShowWindow(_THIS, SDL_Window * window)
slouken@2737
   234
{
slouken@2737
   235
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   236
slouken@2737
   237
    windata->window->SetOpacity(windata->window, windata->opacity);
slouken@2737
   238
slouken@2737
   239
}
slouken@2737
   240
slouken@2737
   241
void
slouken@2737
   242
DirectFB_HideWindow(_THIS, SDL_Window * window)
slouken@2737
   243
{
slouken@2737
   244
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   245
slouken@2737
   246
    windata->window->GetOpacity(windata->window, &windata->opacity);
slouken@2737
   247
    windata->window->SetOpacity(windata->window, 0);
slouken@2737
   248
}
slouken@2737
   249
slouken@2737
   250
void
slouken@2737
   251
DirectFB_RaiseWindow(_THIS, SDL_Window * window)
slouken@2737
   252
{
slouken@2737
   253
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   254
slouken@2737
   255
    windata->window->RaiseToTop(windata->window);
slouken@2737
   256
    windata->window->RequestFocus(windata->window);
slouken@2737
   257
}
slouken@2737
   258
slouken@2737
   259
void
slouken@2737
   260
DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
slouken@2737
   261
{
slouken@2737
   262
    /* FIXME: Size to Desktop ? */
slouken@2737
   263
slouken@2737
   264
    SDL_Unsupported();
slouken@2737
   265
}
slouken@2737
   266
slouken@2737
   267
void
slouken@2737
   268
DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
slouken@2737
   269
{
slouken@2737
   270
    /* FIXME: Size to 32x32 ? */
slouken@2737
   271
slouken@2737
   272
    SDL_Unsupported();
slouken@2737
   273
}
slouken@2737
   274
slouken@2737
   275
void
slouken@2737
   276
DirectFB_RestoreWindow(_THIS, SDL_Window * window)
slouken@2737
   277
{
slouken@2737
   278
    SDL_Unsupported();
slouken@2737
   279
}
slouken@2737
   280
slouken@2737
   281
void
slouken@2737
   282
DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
slouken@2737
   283
{
slouken@2737
   284
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   285
slouken@2737
   286
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@2737
   287
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@2737
   288
        windata->window->GrabPointer(windata->window);
slouken@2737
   289
        windata->window->GrabKeyboard(windata->window);
slouken@2737
   290
    } else {
slouken@2737
   291
        windata->window->UngrabPointer(windata->window);
slouken@2737
   292
        windata->window->UngrabKeyboard(windata->window);
slouken@2737
   293
    }
slouken@2737
   294
}
slouken@2737
   295
slouken@2737
   296
void
slouken@2737
   297
DirectFB_DestroyWindow(_THIS, SDL_Window * window)
slouken@2737
   298
{
slouken@2737
   299
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
   300
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   301
    DFB_WindowData *p;
slouken@2737
   302
slouken@2737
   303
    SDL_DFB_DEBUG("Trace\n");
slouken@2737
   304
slouken@2737
   305
    SDL_DFB_RELEASE(windata->eventbuffer);
slouken@2737
   306
    SDL_DFB_RELEASE(windata->surface);
slouken@2737
   307
    SDL_DFB_RELEASE(windata->window);
slouken@2737
   308
slouken@2737
   309
    /* Remove from list ... */
slouken@2737
   310
slouken@2737
   311
    p = devdata->firstwin;
slouken@2737
   312
    while (p && p->next != windata)
slouken@2737
   313
        p = p->next;
slouken@2737
   314
    if (p)
slouken@2737
   315
        p->next = windata->next;
slouken@2737
   316
    else
slouken@2737
   317
        devdata->firstwin = windata->next;
slouken@2737
   318
    SDL_free(windata);
slouken@2737
   319
    return;
slouken@2737
   320
}
slouken@2737
   321
slouken@2737
   322
SDL_bool
slouken@2737
   323
DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
slouken@2737
   324
                         struct SDL_SysWMinfo * info)
slouken@2737
   325
{
slouken@2737
   326
    SDL_Unsupported();
slouken@2737
   327
    return SDL_FALSE;
slouken@2737
   328
}