src/video/directfb/SDL_DirectFB_window.c
changeset 2737 140a7edcf2bd
child 2859 99210400e8b9
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/directfb/SDL_DirectFB_window.c	Sun Aug 31 16:04:32 2008 +0000
     1.3 @@ -0,0 +1,325 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2006 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#include "SDL_syswm.h"
    1.28 +#include "../SDL_sysvideo.h"
    1.29 +#include "../../events/SDL_keyboard_c.h"
    1.30 +
    1.31 +#include "SDL_DirectFB_video.h"
    1.32 +
    1.33 +int
    1.34 +DirectFB_CreateWindow(_THIS, SDL_Window * window)
    1.35 +{
    1.36 +    SDL_DFB_DEVICEDATA(_this);
    1.37 +    SDL_DFB_DISPLAYDATA(_this, window);
    1.38 +    DFB_WindowData *windata;
    1.39 +    DFBWindowOptions wopts;
    1.40 +    DFBWindowDescription desc;
    1.41 +    int ret, x, y;
    1.42 +
    1.43 +    SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y,
    1.44 +                  window->w, window->h);
    1.45 +    window->driverdata = NULL;
    1.46 +    SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
    1.47 +    windata = (DFB_WindowData *) window->driverdata;
    1.48 +
    1.49 +    SDL_DFB_CHECKERR(devdata->dfb->
    1.50 +                     SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
    1.51 +    SDL_DFB_CHECKERR(dispdata->layer->
    1.52 +                     SetCooperativeLevel(dispdata->layer,
    1.53 +                                         DLSCL_ADMINISTRATIVE));
    1.54 +
    1.55 +    /* Fill the window description. */
    1.56 +    if (window->x == SDL_WINDOWPOS_CENTERED) {
    1.57 +        x = (dispdata->cw - window->w) / 2;
    1.58 +    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
    1.59 +        x = 0;
    1.60 +    } else {
    1.61 +        x = window->x;
    1.62 +    }
    1.63 +    if (window->y == SDL_WINDOWPOS_CENTERED) {
    1.64 +        y = (dispdata->ch - window->h) / 2;
    1.65 +    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
    1.66 +        y = 0;
    1.67 +    } else {
    1.68 +        y = window->y;
    1.69 +    }
    1.70 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.71 +        x = 0;
    1.72 +        y = 0;
    1.73 +    }
    1.74 +
    1.75 +    desc.flags = DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT;
    1.76 +    /*| DWDESC_CAPS | DWDESC_SURFACE_CAPS */
    1.77 +
    1.78 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
    1.79 +    /* Needed for 1.2 */
    1.80 +    desc.flags |= DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
    1.81 +    desc.posx = x;
    1.82 +    desc.posy = y;
    1.83 +#else
    1.84 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)
    1.85 +        && window->x != SDL_WINDOWPOS_UNDEFINED
    1.86 +        && window->y != SDL_WINDOWPOS_UNDEFINED) {
    1.87 +        desc.flags |= DWDESC_POSX | DWDESC_POSY;
    1.88 +        desc.posx = x;
    1.89 +        desc.posy = y;
    1.90 +    }
    1.91 +#endif
    1.92 +
    1.93 +    desc.width = window->w;
    1.94 +    desc.height = window->h;
    1.95 +    desc.pixelformat = dispdata->pixelformat;
    1.96 +#if 0
    1.97 +    desc.caps = 0;
    1.98 +    desc.surface_caps =
    1.99 +        DSCAPS_DOUBLE | DSCAPS_TRIPLE | DSCAPS_PREMULTIPLIED |
   1.100 +        DSCAPS_VIDEOONLY;
   1.101 +#endif
   1.102 +    desc.surface_caps = DSCAPS_PREMULTIPLIED;
   1.103 +    /* DSCAPS_VIDEOONLY has negative impact on performance */
   1.104 +
   1.105 +    /* Create the window. */
   1.106 +    SDL_DFB_CHECKERR(dispdata->layer->
   1.107 +                     CreateWindow(dispdata->layer, &desc, &windata->window));
   1.108 +
   1.109 +    windata->window->GetOptions(windata->window, &wopts);
   1.110 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   1.111 +
   1.112 +    if (window->flags & SDL_WINDOW_RESIZABLE)
   1.113 +        wopts |= DWOP_SCALE;
   1.114 +    else
   1.115 +        wopts |= DWOP_KEEP_SIZE;
   1.116 +#else
   1.117 +    wopts |= DWOP_KEEP_SIZE;    /* if not we will crash ... */
   1.118 +#endif
   1.119 +
   1.120 +    if (window->flags & SDL_WINDOW_FULLSCREEN)
   1.121 +        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
   1.122 +
   1.123 +    windata->window->SetOptions(windata->window, wopts);
   1.124 +    /* Get the window's surface. */
   1.125 +    SDL_DFB_CHECKERR(windata->window->
   1.126 +                     GetSurface(windata->window, &windata->surface));
   1.127 +    windata->window->SetOpacity(windata->window, 0xFF);
   1.128 +    SDL_DFB_CHECKERR(windata->window->
   1.129 +                     CreateEventBuffer(windata->window,
   1.130 +                                       &(windata->eventbuffer)));
   1.131 +    SDL_DFB_CHECKERR(windata->window->
   1.132 +                     EnableEvents(windata->window, DWET_ALL));
   1.133 +
   1.134 +    if (window->flags & SDL_WINDOW_FULLSCREEN)
   1.135 +        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
   1.136 +    /* Make it the top most window. */
   1.137 +    windata->window->RaiseToTop(windata->window);
   1.138 +
   1.139 +    windata->window->GetID(windata->window, &windata->windowID);
   1.140 +
   1.141 +    windata->window->GetSize(windata->window, &window->w, &window->h);
   1.142 +
   1.143 +    /* remember parent */
   1.144 +    windata->id = window->id;
   1.145 +
   1.146 +    /* Add to list ... */
   1.147 +
   1.148 +    windata->next = devdata->firstwin;
   1.149 +    windata->opacity = 0xFF;
   1.150 +    devdata->firstwin = windata;
   1.151 +
   1.152 +    return 0;
   1.153 +  error:
   1.154 +    SDL_DFB_RELEASE(windata->window);
   1.155 +    SDL_DFB_RELEASE(windata->surface);
   1.156 +    return -1;
   1.157 +}
   1.158 +
   1.159 +int
   1.160 +DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   1.161 +{
   1.162 +    SDL_Unsupported();
   1.163 +    return -1;
   1.164 +}
   1.165 +
   1.166 +void
   1.167 +DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
   1.168 +{
   1.169 +    SDL_Unsupported();
   1.170 +}
   1.171 +
   1.172 +void
   1.173 +DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
   1.174 +{
   1.175 +    SDL_DFB_WINDOWDATA(window);
   1.176 +    int x, y;
   1.177 +
   1.178 +    if (window->y == SDL_WINDOWPOS_UNDEFINED)
   1.179 +        y = 0;
   1.180 +    else
   1.181 +        y = window->y;
   1.182 +
   1.183 +    if (window->x == SDL_WINDOWPOS_UNDEFINED)
   1.184 +        x = 0;
   1.185 +    else
   1.186 +        x = window->x;
   1.187 +
   1.188 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   1.189 +        x = 0;
   1.190 +        y = 0;
   1.191 +    }
   1.192 +
   1.193 +    windata->window->MoveTo(windata->window, x, y);
   1.194 +}
   1.195 +
   1.196 +void
   1.197 +DirectFB_SetWindowSize(_THIS, SDL_Window * window)
   1.198 +{
   1.199 +    int ret;
   1.200 +    SDL_DFB_WINDOWDATA(window);
   1.201 +
   1.202 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   1.203 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   1.204 +        int cw;
   1.205 +        int ch;
   1.206 +
   1.207 +        /* Make sure all events are disabled for this operation ! */
   1.208 +        SDL_DFB_CHECKERR(windata->window->
   1.209 +                         DisableEvents(windata->window, DWET_ALL));
   1.210 +
   1.211 +        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &cw, &ch));
   1.212 +        if (cw != window->w || ch != window->h)
   1.213 +            SDL_DFB_CHECKERR(windata->window->
   1.214 +                             Resize(windata->window, window->w, window->h));
   1.215 +        SDL_DFB_CHECKERR(windata->window->
   1.216 +                         EnableEvents(windata->window, DWET_ALL));
   1.217 +
   1.218 +#else
   1.219 +        SDL_DFB_CHECKERR(windata->window->
   1.220 +                         Resize(windata->window, window->w, window->h));
   1.221 +#endif
   1.222 +        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h));    /* if a window manager should have decided otherwise */
   1.223 +
   1.224 +        SDL_OnWindowResized(window);
   1.225 +    }
   1.226 +    return;
   1.227 +  error:
   1.228 +    windata->window->EnableEvents(windata->window, DWET_ALL);
   1.229 +    return;
   1.230 +}
   1.231 +
   1.232 +void
   1.233 +DirectFB_ShowWindow(_THIS, SDL_Window * window)
   1.234 +{
   1.235 +    SDL_DFB_WINDOWDATA(window);
   1.236 +
   1.237 +    windata->window->SetOpacity(windata->window, windata->opacity);
   1.238 +
   1.239 +}
   1.240 +
   1.241 +void
   1.242 +DirectFB_HideWindow(_THIS, SDL_Window * window)
   1.243 +{
   1.244 +    SDL_DFB_WINDOWDATA(window);
   1.245 +
   1.246 +    windata->window->GetOpacity(windata->window, &windata->opacity);
   1.247 +    windata->window->SetOpacity(windata->window, 0);
   1.248 +}
   1.249 +
   1.250 +void
   1.251 +DirectFB_RaiseWindow(_THIS, SDL_Window * window)
   1.252 +{
   1.253 +    SDL_DFB_WINDOWDATA(window);
   1.254 +
   1.255 +    windata->window->RaiseToTop(windata->window);
   1.256 +    windata->window->RequestFocus(windata->window);
   1.257 +}
   1.258 +
   1.259 +void
   1.260 +DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
   1.261 +{
   1.262 +    /* FIXME: Size to Desktop ? */
   1.263 +
   1.264 +    SDL_Unsupported();
   1.265 +}
   1.266 +
   1.267 +void
   1.268 +DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
   1.269 +{
   1.270 +    /* FIXME: Size to 32x32 ? */
   1.271 +
   1.272 +    SDL_Unsupported();
   1.273 +}
   1.274 +
   1.275 +void
   1.276 +DirectFB_RestoreWindow(_THIS, SDL_Window * window)
   1.277 +{
   1.278 +    SDL_Unsupported();
   1.279 +}
   1.280 +
   1.281 +void
   1.282 +DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
   1.283 +{
   1.284 +    SDL_DFB_WINDOWDATA(window);
   1.285 +
   1.286 +    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
   1.287 +        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   1.288 +        windata->window->GrabPointer(windata->window);
   1.289 +        windata->window->GrabKeyboard(windata->window);
   1.290 +    } else {
   1.291 +        windata->window->UngrabPointer(windata->window);
   1.292 +        windata->window->UngrabKeyboard(windata->window);
   1.293 +    }
   1.294 +}
   1.295 +
   1.296 +void
   1.297 +DirectFB_DestroyWindow(_THIS, SDL_Window * window)
   1.298 +{
   1.299 +    SDL_DFB_DEVICEDATA(_this);
   1.300 +    SDL_DFB_WINDOWDATA(window);
   1.301 +    DFB_WindowData *p;
   1.302 +
   1.303 +    SDL_DFB_DEBUG("Trace\n");
   1.304 +
   1.305 +    SDL_DFB_RELEASE(windata->eventbuffer);
   1.306 +    SDL_DFB_RELEASE(windata->surface);
   1.307 +    SDL_DFB_RELEASE(windata->window);
   1.308 +
   1.309 +    /* Remove from list ... */
   1.310 +
   1.311 +    p = devdata->firstwin;
   1.312 +    while (p && p->next != windata)
   1.313 +        p = p->next;
   1.314 +    if (p)
   1.315 +        p->next = windata->next;
   1.316 +    else
   1.317 +        devdata->firstwin = windata->next;
   1.318 +    SDL_free(windata);
   1.319 +    return;
   1.320 +}
   1.321 +
   1.322 +SDL_bool
   1.323 +DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
   1.324 +                         struct SDL_SysWMinfo * info)
   1.325 +{
   1.326 +    SDL_Unsupported();
   1.327 +    return SDL_FALSE;
   1.328 +}