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.
     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->
    47                      dfb->SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
    48     SDL_DFB_CHECKERR(dispdata->
    49                      layer->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->
   104                      layer->CreateWindow(dispdata->layer, &desc,
   105                                          &windata->window));
   106 
   107     windata->window->GetOptions(windata->window, &wopts);
   108 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   109 
   110     if (window->flags & SDL_WINDOW_RESIZABLE)
   111         wopts |= DWOP_SCALE;
   112     else
   113         wopts |= DWOP_KEEP_SIZE;
   114 #else
   115     wopts |= DWOP_KEEP_SIZE;    /* if not we will crash ... */
   116 #endif
   117 
   118     if (window->flags & SDL_WINDOW_FULLSCREEN)
   119         wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
   120 
   121     windata->window->SetOptions(windata->window, wopts);
   122     /* Get the window's surface. */
   123     SDL_DFB_CHECKERR(windata->
   124                      window->GetSurface(windata->window, &windata->surface));
   125     windata->window->SetOpacity(windata->window, 0xFF);
   126     SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
   127                                                         &(windata->
   128                                                           eventbuffer)));
   129     SDL_DFB_CHECKERR(windata->
   130                      window->EnableEvents(windata->window, DWET_ALL));
   131 
   132     if (window->flags & SDL_WINDOW_FULLSCREEN)
   133         windata->window->SetStackingClass(windata->window, DWSC_UPPER);
   134     /* Make it the top most window. */
   135     windata->window->RaiseToTop(windata->window);
   136 
   137     windata->window->GetID(windata->window, &windata->windowID);
   138 
   139     windata->window->GetSize(windata->window, &window->w, &window->h);
   140 
   141     /* remember parent */
   142     windata->id = window->id;
   143 
   144     /* Add to list ... */
   145 
   146     windata->next = devdata->firstwin;
   147     windata->opacity = 0xFF;
   148     devdata->firstwin = windata;
   149 
   150     return 0;
   151   error:
   152     SDL_DFB_RELEASE(windata->window);
   153     SDL_DFB_RELEASE(windata->surface);
   154     return -1;
   155 }
   156 
   157 int
   158 DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   159 {
   160     SDL_Unsupported();
   161     return -1;
   162 }
   163 
   164 void
   165 DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
   166 {
   167     SDL_Unsupported();
   168 }
   169 
   170 void
   171 DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
   172 {
   173     SDL_DFB_WINDOWDATA(window);
   174     int x, y;
   175 
   176     if (window->y == SDL_WINDOWPOS_UNDEFINED)
   177         y = 0;
   178     else
   179         y = window->y;
   180 
   181     if (window->x == SDL_WINDOWPOS_UNDEFINED)
   182         x = 0;
   183     else
   184         x = window->x;
   185 
   186     if (window->flags & SDL_WINDOW_FULLSCREEN) {
   187         x = 0;
   188         y = 0;
   189     }
   190 
   191     windata->window->MoveTo(windata->window, x, y);
   192 }
   193 
   194 void
   195 DirectFB_SetWindowSize(_THIS, SDL_Window * window)
   196 {
   197     int ret;
   198     SDL_DFB_WINDOWDATA(window);
   199 
   200     if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   201 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   202         int cw;
   203         int ch;
   204 
   205         /* Make sure all events are disabled for this operation ! */
   206         SDL_DFB_CHECKERR(windata->
   207                          window->DisableEvents(windata->window, DWET_ALL));
   208 
   209         SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &cw, &ch));
   210         if (cw != window->w || ch != window->h)
   211             SDL_DFB_CHECKERR(windata->
   212                              window->Resize(windata->window, window->w,
   213                                             window->h));
   214         SDL_DFB_CHECKERR(windata->
   215                          window->EnableEvents(windata->window, DWET_ALL));
   216 
   217 #else
   218         SDL_DFB_CHECKERR(windata->
   219                          window->Resize(windata->window, window->w,
   220                                         window->h));
   221 #endif
   222         SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h));    /* if a window manager should have decided otherwise */
   223 
   224         SDL_OnWindowResized(window);
   225     }
   226     return;
   227   error:
   228     windata->window->EnableEvents(windata->window, DWET_ALL);
   229     return;
   230 }
   231 
   232 void
   233 DirectFB_ShowWindow(_THIS, SDL_Window * window)
   234 {
   235     SDL_DFB_WINDOWDATA(window);
   236 
   237     windata->window->SetOpacity(windata->window, windata->opacity);
   238 
   239 }
   240 
   241 void
   242 DirectFB_HideWindow(_THIS, SDL_Window * window)
   243 {
   244     SDL_DFB_WINDOWDATA(window);
   245 
   246     windata->window->GetOpacity(windata->window, &windata->opacity);
   247     windata->window->SetOpacity(windata->window, 0);
   248 }
   249 
   250 void
   251 DirectFB_RaiseWindow(_THIS, SDL_Window * window)
   252 {
   253     SDL_DFB_WINDOWDATA(window);
   254 
   255     windata->window->RaiseToTop(windata->window);
   256     windata->window->RequestFocus(windata->window);
   257 }
   258 
   259 void
   260 DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
   261 {
   262     /* FIXME: Size to Desktop ? */
   263 
   264     SDL_Unsupported();
   265 }
   266 
   267 void
   268 DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
   269 {
   270     /* FIXME: Size to 32x32 ? */
   271 
   272     SDL_Unsupported();
   273 }
   274 
   275 void
   276 DirectFB_RestoreWindow(_THIS, SDL_Window * window)
   277 {
   278     SDL_Unsupported();
   279 }
   280 
   281 void
   282 DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
   283 {
   284     SDL_DFB_WINDOWDATA(window);
   285 
   286     if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
   287         (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   288         windata->window->GrabPointer(windata->window);
   289         windata->window->GrabKeyboard(windata->window);
   290     } else {
   291         windata->window->UngrabPointer(windata->window);
   292         windata->window->UngrabKeyboard(windata->window);
   293     }
   294 }
   295 
   296 void
   297 DirectFB_DestroyWindow(_THIS, SDL_Window * window)
   298 {
   299     SDL_DFB_DEVICEDATA(_this);
   300     SDL_DFB_WINDOWDATA(window);
   301     DFB_WindowData *p;
   302 
   303     SDL_DFB_DEBUG("Trace\n");
   304 
   305     SDL_DFB_RELEASE(windata->eventbuffer);
   306     SDL_DFB_RELEASE(windata->surface);
   307     SDL_DFB_RELEASE(windata->window);
   308 
   309     /* Remove from list ... */
   310 
   311     p = devdata->firstwin;
   312     while (p && p->next != windata)
   313         p = p->next;
   314     if (p)
   315         p->next = windata->next;
   316     else
   317         devdata->firstwin = windata->next;
   318     SDL_free(windata);
   319     return;
   320 }
   321 
   322 SDL_bool
   323 DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
   324                          struct SDL_SysWMinfo * info)
   325 {
   326     SDL_Unsupported();
   327     return SDL_FALSE;
   328 }