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