# HG changeset patch # User Couriersud # Date 1231717763 0 # Node ID d72a0dd80e8bfbdc0c7d6ce52d23d51a58593b8b # Parent db20dde98dd3c72df267f85737b9194deb701e16 DirectFB cleanups & simple window manager - use SDL_getenv, not getenv ... - no more support for 0.9.25 - not even mentioned any longer on directfb.org - fix fullscreen issues - add a simple window manager unless the directfb team comes up with a working wm. The driver has support for a very, very basic window manager you may want to use when runnning with "wm=default". Use export SDL_DIRECTFB_WM=1 to enable basic window borders including icon support. In order to have the window title rendered, you need to have the following font installed: /usr/share/fonts/truetype/freefont/FreeSans.ttf diff -r db20dde98dd3 -r d72a0dd80e8b README.DirectFB --- a/README.DirectFB Sun Jan 11 23:39:11 2009 +0000 +++ b/README.DirectFB Sun Jan 11 23:49:23 2009 +0000 @@ -49,6 +49,19 @@ to make the YUV texture an underlay. This will make the cursor to be shown. +Simple Window Manager +===================== + +The driver has support for a very, very basic window manager you may +want to use when runnning with "wm=default". Use + +export SDL_DIRECTFB_WM=1 + +to enable basic window borders. In order to have the window title rendered, +you need to have the following font installed: + +/usr/share/fonts/truetype/freefont/FreeSans.ttf + OPENGL Support ============== diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_WM.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/directfb/SDL_DirectFB_WM.c Sun Jan 11 23:49:23 2009 +0000 @@ -0,0 +1,361 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2009 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +//#include "SDL_syswm.h" +//#include "../SDL_sysvideo.h" +//#include "../../events/SDL_keyboard_c.h" + +#include "SDL_DirectFB_video.h" + +#define COLOR_EXPAND(col) col.r, col.g, col.b, col.a + +static DFB_Theme theme_std = { + 4, 4, 8, 8, + {255, 200, 200, 200}, + 24, + {255, 0, 0, 255}, + 16, + {255, 255, 255, 255}, + "/usr/share/fonts/truetype/freefont/FreeSans.ttf", + {255, 255, 0, 0}, + {255, 255, 255, 0}, +}; + +static DFB_Theme theme_none = { + 0, 0, 0, 0, + {0, 0, 0, 0}, + 0, + {0, 0, 0, 0}, + 0, + {0, 0, 0, 0}, + NULL +}; + +static void +DrTriangle(IDirectFBSurface * s, int down, int x, int y, int w) +{ + int x1, x2, x3; + int y1, y2, y3; + + if (down) { + x1 = x + w / 2; + x2 = x; + x3 = x + w; + y1 = y + w; + y2 = y; + y3 = y; + } else { + x1 = x + w / 2; + x2 = x; + x3 = x + w; + y1 = y; + y2 = y + w; + y3 = y + w; + } + s->FillTriangle(s, x1, y1, x2, y2, x3, y3); +} + +static void +DrCaption(IDirectFBSurface * s, int x, int y, char *text) +{ + DFBSurfaceTextFlags flags; + + flags = DSTF_CENTER | DSTF_TOP; + + s->DrawString(s, text, -1, x, y, flags); +} + +void +DirectFB_WM_RedrawLayout(SDL_Window * window) +{ + SDL_DFB_WINDOWDATA(window); + IDirectFBSurface *s = windata->window_surface; + DFB_Theme *t = &windata->theme; + int i; + int d = (t->caption_size - t->font_size) / 2; + int x, y, w; + + + if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN)) + return; + + //s->SetDrawingFlags(s, DSDRAW_BLEND); + s->SetColor(s, COLOR_EXPAND(t->frame_color)); + /* top */ + for (i = 0; i < t->top_size; i++) + s->DrawLine(s, 0, i, windata->size.w, i); + /* bottom */ + for (i = windata->size.h - t->bottom_size; i < windata->size.h; i++) + s->DrawLine(s, 0, i, windata->size.w, i); + /* left */ + for (i = 0; i < t->left_size; i++) + s->DrawLine(s, i, 0, i, windata->size.h); + /* right */ + for (i = windata->size.w - t->right_size; i < windata->size.w; i++) + s->DrawLine(s, i, 0, i, windata->size.h); + /* Caption */ + s->SetColor(s, COLOR_EXPAND(t->caption_color)); + s->FillRectangle(s, t->left_size, t->top_size, windata->client.w, + t->caption_size); + /* Close Button */ + w = t->caption_size; + x = windata->size.w - t->right_size - w + d; + y = t->top_size + d; + s->SetColor(s, COLOR_EXPAND(t->close_color)); + DrTriangle(s, 1, x, y, w - 2 * d); + /* Max Button */ + s->SetColor(s, COLOR_EXPAND(t->max_color)); + DrTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w, + y, w - 2 * d); + + /* Caption */ + if (window->title) { + s->SetColor(s, COLOR_EXPAND(t->font_color)); + DrCaption(s, (x - w) / 2, t->top_size + d, window->title); + } + /* Icon */ + if (windata->icon) { + DFBRectangle dr; + + dr.x = t->left_size + d; + dr.y = t->top_size + d; + dr.w = w - 2 * d; + dr.h = w - 2 * d; + s->SetBlittingFlags(s, DSBLIT_BLEND_ALPHACHANNEL); + + s->StretchBlit(s, windata->icon, NULL, &dr); + } + windata->wm_needs_redraw = 0; +} + +DFBResult +DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch) +{ + SDL_DFB_WINDOWDATA(window); + DFBResult ret; + + ret = windata->window->GetSize(windata->window, cw, ch); + *cw -= windata->theme.left_size + windata->theme.right_size; + *ch -= + windata->theme.top_size + windata->theme.caption_size + + windata->theme.bottom_size; + return ret; +} + +void +DirectFB_WM_AdjustWindowLayout(SDL_Window * window) +{ + SDL_DFB_WINDOWDATA(window); + + if (!windata->is_managed) + windata->theme = theme_none; + else if (window->flags & SDL_WINDOW_FULLSCREEN) { + windata->theme = theme_none; + } else if (window->flags & SDL_WINDOW_MAXIMIZED) { + windata->theme = theme_std; + windata->theme.left_size = 0; + windata->theme.right_size = 0; + windata->theme.top_size = 0; + windata->theme.bottom_size = 0; + } else { + windata->theme = theme_std; + } + + windata->client.x = windata->theme.left_size; + windata->client.y = windata->theme.top_size + windata->theme.caption_size; + windata->client.w = window->w; + windata->client.h = window->h; + windata->size.w = + window->w + windata->theme.left_size + windata->theme.right_size; + windata->size.h = + window->h + windata->theme.top_size + + windata->theme.caption_size + windata->theme.bottom_size; +} + +void +DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window) +{ + SDL_DFB_WINDOWDATA(window); + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); + + windata->window->GetPosition(windata->window, + &windata->restore.x, + &windata->restore.y); + windata->window->GetSize(windata->window, &windata->restore.w, + &windata->restore.h); + + /* Do this already here */ + window->flags |= SDL_WINDOW_MAXIMIZED; + DirectFB_WM_AdjustWindowLayout(window); + + windata->window->MoveTo(windata->window, 0, 0); + windata->window->Resize(windata->window, + display->current_mode.w, + display->current_mode.h); + SDL_SendWindowEvent(windata->sdl_id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); +} + +void +DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window) +{ + SDL_DFB_WINDOWDATA(window); + + /* Do this already here */ + //window->flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED); + + DirectFB_WM_AdjustWindowLayout(window); + windata->window->MoveTo(windata->window, windata->restore.x, + windata->restore.y); + windata->window->Resize(windata->window, windata->restore.w, + windata->restore.h); + SDL_SendWindowEvent(windata->sdl_id, SDL_WINDOWEVENT_RESTORED, 0, 0); +} + +enum +{ + WM_POS_NONE = 0x00, + WM_POS_CAPTION = 0x01, + WM_POS_CLOSE = 0x02, + WM_POS_MAX = 0x04, + WM_POS_LEFT = 0x08, + WM_POS_RIGHT = 0x10, + WM_POS_TOP = 0x20, + WM_POS_BOTTOM = 0x40, +}; + +static int +WMIsClient(DFB_WindowData * p, int x, int y) +{ + x -= p->client.x; + y -= p->client.y; + if (x < 0 || y < 0) + return 0; + if (x >= p->client.w || y >= p->client.h) + return 0; + return 1; +} + +static int +WMPos(DFB_WindowData * p, int x, int y) +{ + int pos = WM_POS_NONE; + + if (!WMIsClient(p, x, y)) { + if (y < p->theme.top_size) { + pos |= WM_POS_TOP; + } else if (y < p->client.y) { + if (x < + p->size.w - p->theme.right_size - 2 * p->theme.caption_size) { + pos |= WM_POS_CAPTION; + } else if (x < + p->size.w - p->theme.right_size - + p->theme.caption_size) { + pos |= WM_POS_MAX; + } else { + pos |= WM_POS_CLOSE; + } + } else if (y >= p->size.h - p->theme.bottom_size) { + pos |= WM_POS_BOTTOM; + } + if (x < p->theme.left_size) { + pos |= WM_POS_LEFT; + } else if (x >= p->size.w - p->theme.right_size) { + pos |= WM_POS_RIGHT; + } + } + return pos; +} + +static int wm_grab; +static int wm_lastx; +static int wm_lasty; + +int +DirectFB_WM_ProcessEvent(_THIS, SDL_Window *window, DFBWindowEvent * evt) +{ + SDL_DFB_WINDOWDATA(window); + + if (!windata->is_managed) + return 0; + + switch (evt->type) { + case DWET_BUTTONDOWN: + if (evt->buttons & DIBM_LEFT) { + int pos = WMPos(windata, evt->x, evt->y); + switch (pos) { + case WM_POS_NONE: + return 0; + case WM_POS_CLOSE: + SDL_SendWindowEvent(windata->sdl_id, SDL_WINDOWEVENT_CLOSE, 0, 0); + return 1; + case WM_POS_MAX: + if (window->flags & SDL_WINDOW_MAXIMIZED) { + DirectFB_WM_RestoreWindow(_this, window); + } else { + DirectFB_WM_MaximizeWindow(_this, window); + } + return 1; + default: + wm_grab = pos; + windata->window->GrabPointer(windata->window); + wm_lastx = evt->cx; + wm_lasty = evt->cy; + } + } + return 1; + case DWET_BUTTONUP: + break; + case DWET_MOTION: + if (!wm_grab) + return 0; + if (evt->buttons & DIBM_LEFT) { + int dx = evt->cx - wm_lastx; + int dy = evt->cy - wm_lasty; + int cw, ch; + + if (wm_grab & WM_POS_CAPTION) + windata->window->Move(windata->window, dx, dy); + if (wm_grab & WM_POS_RIGHT) { + windata->window->GetSize(windata->window, &cw, &ch); + windata->window->Resize(windata->window, cw + dx, ch); + } + if (wm_grab & WM_POS_BOTTOM) { + windata->window->GetSize(windata->window, &cw, &ch); + windata->window->Resize(windata->window, cw, ch + dy); + } + wm_lastx = evt->cx; + wm_lasty = evt->cy; + return 1; + } + windata->window->UngrabPointer(windata->window); + wm_grab = WM_POS_NONE; + break; + case DWET_KEYDOWN: + break; + case DWET_KEYUP: + break; + default: + ; + } + return 0; +} diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_WM.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/directfb/SDL_DirectFB_WM.h Sun Jan 11 23:49:23 2009 +0000 @@ -0,0 +1,56 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2009 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_directfb_wm_h +#define _SDL_directfb_wm_h + +typedef struct _DFB_Theme DFB_Theme; +struct _DFB_Theme +{ + int left_size; + int right_size; + int top_size; + int bottom_size; + DFBColor frame_color; + int caption_size; + DFBColor caption_color; + int font_size; + DFBColor font_color; + char *font; + DFBColor close_color; + DFBColor max_color; +}; + +extern void DirectFB_WM_AdjustWindowLayout(SDL_Window * window); +extern void DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window); +extern void DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window); +extern void DirectFB_WM_RedrawLayout(SDL_Window * window); + +extern int DirectFB_WM_ProcessEvent(_THIS, SDL_Window *window, DFBWindowEvent * evt); + +extern DFBResult DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch); + + +#endif /* _SDL_directfb_wm_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_dyn.c --- a/src/video/directfb/SDL_DirectFB_dyn.c Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_dyn.c Sun Jan 11 23:49:23 2009 +0000 @@ -21,8 +21,8 @@ */ #include "SDL_config.h" +#include "SDL_DirectFB_video.h" #include "SDL_DirectFB_dyn.h" -#include "SDL_DirectFB_video.h" #ifdef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC #include "SDL_name.h" @@ -69,11 +69,11 @@ } } if (retval) { + const char *stemp = DirectFBCheckVersion(DIRECTFB_MAJOR_VERSION, + DIRECTFB_MINOR_VERSION, + DIRECTFB_MICRO_VERSION); /* Version Check */ - if ((*SDL_DirectFB_Symbols.directfb_major_version != - DIRECTFB_MAJOR_VERSION) - || (*SDL_DirectFB_Symbols.directfb_minor_version != - DIRECTFB_MINOR_VERSION)) { + if (stemp != NULL) { fprintf(stderr, "DirectFB Lib: Version mismatch. Compiled: %d.%d.%d Library %d.%d.%d\n", DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_dyn.h --- a/src/video/directfb/SDL_DirectFB_dyn.h Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_dyn.h Sun Jan 11 23:49:23 2009 +0000 @@ -30,8 +30,9 @@ DFB_SYM(const char *, DirectFBUsageString, ( void ), (), return) \ DFB_SYM(DFBResult, DirectFBInit, (int *argc, char *(*argv[]) ), (argc, argv), return) \ DFB_SYM(DFBResult, DirectFBSetOption, (const char *name, const char *value), (name, value), return) \ - DFB_SYM(DFBResult, DirectFBCreate, (IDirectFB **interface), (interface), return) - + DFB_SYM(DFBResult, DirectFBCreate, (IDirectFB **interface), (interface), return) \ + DFB_SYM(const char *, DirectFBCheckVersion, (unsigned int required_major, unsigned int required_minor, unsigned int required_micro), \ + (required_major, required_minor, required_micro), return) // #define SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "/usr/lib/libdirectfb-1.2.so.0" int SDL_DirectFB_LoadLibrary(void); diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_events.c --- a/src/video/directfb/SDL_DirectFB_events.c Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_events.c Sun Jan 11 23:49:23 2009 +0000 @@ -60,8 +60,8 @@ int ret; if (dispdata->vidIDinuse) - SDL_DFB_CHECKERR(dispdata->vidlayer-> - SwitchContext(dispdata->vidlayer, DFB_TRUE)); + SDL_DFB_CHECKERR(dispdata->vidlayer->SwitchContext(dispdata->vidlayer, + DFB_TRUE)); error: return; @@ -117,6 +117,254 @@ return -1; } +static int +ClientXY(DFB_WindowData * p, int *x, int *y) +{ + int cx, cy; + + cx = *x; + cy = *y; + + cx -= p->client.x; + cy -= p->client.y; + + if (cx < 0 || cy < 0) + return 0; + if (cx >= p->client.w || cy >= p->client.h) + return 0; + *x = cx; + *y = cy; + return 1; +} + +static void +ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags, + DFBWindowEvent * evt) +{ + SDL_DFB_DEVICEDATA(_this); + SDL_keysym keysym; + char text[5]; + + if (evt->clazz == DFEC_WINDOW) { + switch (evt->type) { + case DWET_BUTTONDOWN: + if (ClientXY(p, &evt->x, &evt->y)) { + if (!devdata->use_linux_input) { + SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt->x, + evt->y, 0); + SDL_SendMouseButton(devdata->mouse_id[0], + SDL_PRESSED, + DirectFB_TranslateButton + (evt->button)); + } else { + MotionAllMice(_this, evt->x, evt->y); + } + } + break; + case DWET_BUTTONUP: + if (ClientXY(p, &evt->x, &evt->y)) { + if (!devdata->use_linux_input) { + SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt->x, + evt->y, 0); + SDL_SendMouseButton(devdata->mouse_id[0], + SDL_RELEASED, + DirectFB_TranslateButton + (evt->button)); + } else { + MotionAllMice(_this, evt->x, evt->y); + } + } + break; + case DWET_MOTION: + if (ClientXY(p, &evt->x, &evt->y)) { + SDL_Window *window = SDL_GetWindowFromID(p->sdl_id); + if (!devdata->use_linux_input) { + if (!(flags & SDL_WINDOW_INPUT_GRABBED)) + SDL_SendMouseMotion(devdata->mouse_id[0], 0, + evt->x, evt->y, 0); + } else { + /* relative movements are not exact! + * This code should limit the number of events sent. + * However it kills MAME axis recognition ... */ + static int cnt = 0; + if (1 && ++cnt > 20) { + MotionAllMice(_this, evt->x, evt->y); + cnt = 0; + } + } + if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) + SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_ENTER, 0, 0); + } + break; + case DWET_KEYDOWN: + if (!devdata->use_linux_input) { + DirectFB_TranslateKey(_this, evt, &keysym); + SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode); + if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { + SDL_memcpy(text, &keysym.unicode, 4); + text[4] = 0; + if (*text) { + SDL_SendKeyboardText(0, text); + } + } + } + break; + case DWET_KEYUP: + if (!devdata->use_linux_input) { + DirectFB_TranslateKey(_this, evt, &keysym); + SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode); + } + break; + case DWET_POSITION: + if (ClientXY(p, &evt->x, &evt->y)) { + SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_MOVED, + evt->x, evt->y); + } + break; + case DWET_POSITION_SIZE: + if (ClientXY(p, &evt->x, &evt->y)) { + SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_MOVED, + evt->x, evt->y); + } + /* fall throught */ + case DWET_SIZE: + // FIXME: what about < 0 + evt->w -= (p->theme.right_size + p->theme.left_size); + evt->h -= + (p->theme.top_size + p->theme.bottom_size + + p->theme.caption_size); + SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_RESIZED, + evt->w, evt->h); + break; + case DWET_CLOSE: + SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_CLOSE, 0, 0); + break; + case DWET_GOTFOCUS: + DirectFB_SetContext(_this, p->sdl_id); + FocusAllKeyboards(_this, p->sdl_id); + SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_FOCUS_GAINED, + 0, 0); + break; + case DWET_LOSTFOCUS: + SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); + FocusAllKeyboards(_this, 0); + break; + case DWET_ENTER: + /* SDL_DirectFB_ReshowCursor(_this, 0); */ + FocusAllMice(_this, p->sdl_id); + // FIXME: when do we really enter ? + if (ClientXY(p, &evt->x, &evt->y)) + MotionAllMice(_this, evt->x, evt->y); + SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_ENTER, 0, 0); + break; + case DWET_LEAVE: + SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_LEAVE, 0, 0); + FocusAllMice(_this, 0); + /* SDL_DirectFB_ReshowCursor(_this, 1); */ + break; + default: + ; + } + } else + printf("Event Clazz %d\n", evt->clazz); +} + +static void +ProcessInputEvent(_THIS, Sint32 grabbed_window, DFBInputEvent * ievt) +{ + SDL_DFB_DEVICEDATA(_this); + SDL_keysym keysym; + int kbd_idx; + char text[5]; + + if (!devdata->use_linux_input) { + if (ievt->type == DIET_AXISMOTION) { + if ((grabbed_window >= 0) && (ievt->flags & DIEF_AXISREL)) { + if (ievt->axis == DIAI_X) + SDL_SendMouseMotion(ievt->device_id, 1, + ievt->axisrel, 0, 0); + else if (ievt->axis == DIAI_Y) + SDL_SendMouseMotion(ievt->device_id, 1, 0, + ievt->axisrel, 0); + } + } + } else { + static int last_x, last_y; + + switch (ievt->type) { + case DIET_AXISMOTION: + if (ievt->flags & DIEF_AXISABS) { + if (ievt->axis == DIAI_X) + last_x = ievt->axisabs; + else if (ievt->axis == DIAI_Y) + last_y = ievt->axisabs; + if (!(ievt->flags & DIEF_FOLLOW)) { + SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id); + SDL_Window *window = SDL_GetWindowFromID(mouse->focus); + if (window) { + DFB_WindowData *windata = + (DFB_WindowData *) window->driverdata; + int x, y; + + windata->window->GetPosition(windata->window, &x, &y); + SDL_SendMouseMotion(ievt->device_id, 0, + last_x - (x + + windata->client.x), + last_y - (y + + windata->client.y), 0); + } else { + SDL_SendMouseMotion(ievt->device_id, 0, last_x, + last_y, 0); + } + } + } else if (ievt->flags & DIEF_AXISREL) { + if (ievt->axis == DIAI_X) + SDL_SendMouseMotion(ievt->device_id, 1, + ievt->axisrel, 0, 0); + else if (ievt->axis == DIAI_Y) + SDL_SendMouseMotion(ievt->device_id, 1, 0, + ievt->axisrel, 0); + } + break; + case DIET_KEYPRESS: + kbd_idx = KbdIndex(_this, ievt->device_id); + DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym); + SDL_SendKeyboardKey(kbd_idx, SDL_PRESSED, keysym.scancode); + if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { + SDL_memcpy(text, &keysym.unicode, 4); + text[4] = 0; + if (*text) { + SDL_SendKeyboardText(kbd_idx, text); + } + } + break; + case DIET_KEYRELEASE: + kbd_idx = KbdIndex(_this, ievt->device_id); + DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym); + SDL_SendKeyboardKey(kbd_idx, SDL_RELEASED, keysym.scancode); + break; + case DIET_BUTTONPRESS: + if (ievt->buttons & DIBM_LEFT) + SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 1); + if (ievt->buttons & DIBM_MIDDLE) + SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 2); + if (ievt->buttons & DIBM_RIGHT) + SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 3); + break; + case DIET_BUTTONRELEASE: + if (!(ievt->buttons & DIBM_LEFT)) + SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 1); + if (!(ievt->buttons & DIBM_MIDDLE)) + SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 2); + if (!(ievt->buttons & DIBM_RIGHT)) + SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 3); + break; + default: + break; /* please gcc */ + } + } +} + void DirectFB_PumpEventsWindow(_THIS) { @@ -124,216 +372,28 @@ DFB_WindowData *p; DFBInputEvent ievt; Sint32 /* SDL_WindowID */ grabbed_window; - char text[5]; - int kbd_idx; grabbed_window = -1; for (p = devdata->firstwin; p != NULL; p = p->next) { DFBWindowEvent evt; - SDL_Window *w = SDL_GetWindowFromID(p->id); + SDL_Window *w = SDL_GetWindowFromID(p->sdl_id); if (w->flags & SDL_WINDOW_INPUT_GRABBED) { - grabbed_window = p->id; + grabbed_window = p->sdl_id; } while (p->eventbuffer->GetEvent(p->eventbuffer, DFB_EVENT(&evt)) == DFB_OK) { - SDL_keysym keysym; - - if (evt.clazz == DFEC_WINDOW) { - switch (evt.type) { - case DWET_BUTTONDOWN: - if (!devdata->use_linux_input) { - SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx, - evt.cy, 0); - SDL_SendMouseButton(devdata->mouse_id[0], SDL_PRESSED, - DirectFB_TranslateButton(evt. - button)); - } else { - MotionAllMice(_this, evt.x, evt.y); - } - break; - case DWET_BUTTONUP: - if (!devdata->use_linux_input) { - SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx, - evt.cy, 0); - SDL_SendMouseButton(devdata->mouse_id[0], - SDL_RELEASED, - DirectFB_TranslateButton(evt. - button)); - } else { - MotionAllMice(_this, evt.x, evt.y); - } - break; - case DWET_MOTION: - if (!devdata->use_linux_input) { - if (!(w->flags & SDL_WINDOW_INPUT_GRABBED)) - SDL_SendMouseMotion(devdata->mouse_id[0], 0, - evt.cx, evt.cy, 0); - } else { - /* relative movements are not exact! - * This code should limit the number of events sent. - * However it kills MAME axis recognition ... */ - static int cnt = 0; - if (1 && ++cnt > 20) { - MotionAllMice(_this, evt.x, evt.y); - cnt = 0; - } - } - break; - case DWET_KEYDOWN: - if (!devdata->use_linux_input) { - DirectFB_TranslateKey(_this, &evt, &keysym); - SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode); - if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { - SDL_memcpy(text, &keysym.unicode, 4); - text[4] = 0; - if (*text) { - SDL_SendKeyboardText(0, text); - } - } - } - break; - case DWET_KEYUP: - if (!devdata->use_linux_input) { - DirectFB_TranslateKey(_this, &evt, &keysym); - SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode); - } - break; - case DWET_POSITION_SIZE: - if (evt.x != w->x || evt.y != w->y) - SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, - evt.x, evt.y); - if (evt.w != w->w || evt.h != w->h) - SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, - evt.w, evt.h); - break; - case DWET_POSITION: - if (evt.x != w->x || evt.y != w->y) - SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, - evt.x, evt.y); - break; - case DWET_SIZE: - if (evt.w != w->w || evt.h != w->h) - SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, - evt.w, evt.h); - break; - case DWET_CLOSE: - SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0); - break; - case DWET_GOTFOCUS: - DirectFB_SetContext(_this, p->id); - FocusAllKeyboards(_this, p->id); - SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_GAINED, - 0, 0); - break; - case DWET_LOSTFOCUS: - SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, - 0); - FocusAllKeyboards(_this, 0); - break; - case DWET_ENTER: - /* SDL_DirectFB_ReshowCursor(_this, 0); */ - FocusAllMice(_this, p->id); - MotionAllMice(_this, evt.x, evt.y); - SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0); - break; - case DWET_LEAVE: - SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0); - FocusAllMice(_this, 0); - /* SDL_DirectFB_ReshowCursor(_this, 1); */ - break; - default: - ; - } - } else - printf("Event Clazz %d\n", evt.clazz); - + if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) + ProcessWindowEvent(_this, p, w->flags, &evt); } } /* Now get relative events in case we need them */ while (devdata->events->GetEvent(devdata->events, DFB_EVENT(&ievt)) == DFB_OK) { - SDL_keysym keysym; - - switch (ievt.type) { - case DIET_AXISMOTION: - if (!devdata->use_linux_input) { - if ((grabbed_window >= 0) && (ievt.flags & DIEF_AXISREL)) { - printf("rel devid %d\n", ievt.device_id); - if (ievt.axis == DIAI_X) - SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel, - 0, 0); - else if (ievt.axis == DIAI_Y) - SDL_SendMouseMotion(ievt.device_id, 1, 0, - ievt.axisrel, 0); - } - } - break; - } - if (devdata->use_linux_input) { - IDirectFBInputDevice *idev; - static int last_x, last_y; - - switch (ievt.type) { - case DIET_AXISMOTION: - if (ievt.flags & DIEF_AXISABS) { - if (ievt.axis == DIAI_X) - last_x = ievt.axisabs; - else if (ievt.axis == DIAI_Y) - last_y = ievt.axisabs; - if (!(ievt.flags & DIEF_FOLLOW)) - SDL_SendMouseMotion(ievt.device_id, 0, last_x, last_y, - 0); - } else if (ievt.flags & DIEF_AXISREL) { - //printf("rel %d %d\n", ievt.device_id, ievt.axisrel); - if (ievt.axis == DIAI_X) - SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel, - 0, 0); - else if (ievt.axis == DIAI_Y) - SDL_SendMouseMotion(ievt.device_id, 1, 0, - ievt.axisrel, 0); - } - break; - case DIET_KEYPRESS: - kbd_idx = KbdIndex(_this, ievt.device_id); - DirectFB_TranslateKeyInputEvent(_this, kbd_idx, &ievt, - &keysym); - SDL_SendKeyboardKey(kbd_idx, SDL_PRESSED, keysym.scancode); - if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { - SDL_memcpy(text, &keysym.unicode, 4); - text[4] = 0; - if (*text) { - SDL_SendKeyboardText(kbd_idx, text); - } - } - break; - case DIET_KEYRELEASE: - kbd_idx = KbdIndex(_this, ievt.device_id); - DirectFB_TranslateKeyInputEvent(_this, kbd_idx, &ievt, - &keysym); - SDL_SendKeyboardKey(kbd_idx, SDL_RELEASED, keysym.scancode); - break; - case DIET_BUTTONPRESS: - if (ievt.buttons & DIBM_LEFT) - SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 1); - if (ievt.buttons & DIBM_MIDDLE) - SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 2); - if (ievt.buttons & DIBM_RIGHT) - SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 3); - break; - case DIET_BUTTONRELEASE: - if (!(ievt.buttons & DIBM_LEFT)) - SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 1); - if (!(ievt.buttons & DIBM_MIDDLE)) - SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 2); - if (!(ievt.buttons & DIBM_RIGHT)) - SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 3); - break; - } - } + ProcessInputEvent(_this, grabbed_window, &ievt); } } @@ -470,14 +530,14 @@ { SDL_DFB_DEVICEDATA(_this); - if (evt->key_code >= 0 - && evt->key_code < SDL_arraysize(linux_scancode_table)) + if (evt->key_code >= 0 && + evt->key_code < SDL_arraysize(linux_scancode_table)) keysym->scancode = linux_scancode_table[evt->key_code]; else keysym->scancode = SDL_SCANCODE_UNKNOWN; - if (keysym->scancode == SDL_SCANCODE_UNKNOWN - || devdata->keyboard[0].is_generic) { + if (keysym->scancode == SDL_SCANCODE_UNKNOWN || + devdata->keyboard[0].is_generic) { if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; else @@ -486,8 +546,8 @@ keysym->unicode = (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0; - if (keysym->unicode == 0 - && (evt->key_symbol > 0 && evt->key_symbol < 255)) + if (keysym->unicode == 0 && + (evt->key_symbol > 0 && evt->key_symbol < 255)) keysym->unicode = evt->key_symbol; return keysym; @@ -499,14 +559,14 @@ { SDL_DFB_DEVICEDATA(_this); - if (evt->key_code >= 0 - && evt->key_code < SDL_arraysize(linux_scancode_table)) + if (evt->key_code >= 0 && + evt->key_code < SDL_arraysize(linux_scancode_table)) keysym->scancode = linux_scancode_table[evt->key_code]; else keysym->scancode = SDL_SCANCODE_UNKNOWN; - if (keysym->scancode == SDL_SCANCODE_UNKNOWN - || devdata->keyboard[index].is_generic) { + if (keysym->scancode == SDL_SCANCODE_UNKNOWN || + devdata->keyboard[index].is_generic) { if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; else @@ -515,12 +575,13 @@ keysym->unicode = (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0; - if (keysym->unicode == 0 - && (evt->key_symbol > 0 && evt->key_symbol < 255)) + if (keysym->unicode == 0 && + (evt->key_symbol > 0 && evt->key_symbol < 255)) keysym->unicode = evt->key_symbol; return keysym; } + static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button) { @@ -537,8 +598,8 @@ } static DFBEnumerationResult -input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, - void *callbackdata) +input_device_cb(DFBInputDeviceID device_id, + DFBInputDeviceDescription desc, void *callbackdata) { DFB_DeviceData *devdata = callbackdata; SDL_Keyboard keyboard; @@ -562,8 +623,8 @@ } static DFBEnumerationResult -EnumKeyboards(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, - void *callbackdata) +EnumKeyboards(DFBInputDeviceID device_id, + DFBInputDeviceDescription desc, void *callbackdata) { DFB_DeviceData *devdata = callbackdata; SDL_Keyboard keyboard; @@ -606,14 +667,14 @@ EnumInputDevices(devdata->dfb, EnumKeyboards, devdata)); if (devdata->num_keyboard == 0) { sys_ids = 1; - SDL_DFB_CHECK(devdata->dfb-> - EnumInputDevices(devdata->dfb, EnumKeyboards, - devdata)); + SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb, + EnumKeyboards, + devdata)); } } else { - SDL_DFB_CHECK(devdata->dfb-> - EnumInputDevices(devdata->dfb, input_device_cb, - devdata)); + SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb, + input_device_cb, + devdata)); } } @@ -649,34 +710,30 @@ switch (evt.type) { case DIET_BUTTONPRESS: - posted += SDL_PrivateMouseButton(SDL_PRESSED, - DirectFB_TranslateButton(evt. - button), - 0, 0); + posted += + SDL_PrivateMouseButton(SDL_PRESSED, + DirectFB_TranslateButton + (evt.button), 0, 0); break; case DIET_BUTTONRELEASE: - posted += SDL_PrivateMouseButton(SDL_RELEASED, - DirectFB_TranslateButton(evt. - button), - 0, 0); + posted += + SDL_PrivateMouseButton(SDL_RELEASED, + DirectFB_TranslateButton + (evt.button), 0, 0); break; case DIET_KEYPRESS: - posted += SDL_PrivateKeyboard(SDL_PRESSED, - DirectFB_TranslateKey(evt. - key_id, - evt. - key_symbol, - mod, - &keysym)); + posted += + SDL_PrivateKeyboard(SDL_PRESSED, + DirectFB_TranslateKey + (evt.key_id, evt.key_symbol, + mod, &keysym)); break; case DIET_KEYRELEASE: - posted += SDL_PrivateKeyboard(SDL_RELEASED, - DirectFB_TranslateKey(evt. - key_id, - evt. - key_symbol, - mod, - &keysym)); + posted += + SDL_PrivateKeyboard(SDL_RELEASED, + DirectFB_TranslateKey + (evt.key_id, evt.key_symbol, + mod, &keysym)); break; case DIET_AXISMOTION: if (evt.flags & DIEF_AXISREL) { diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_modes.c --- a/src/video/directfb/SDL_DirectFB_modes.c Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_modes.c Sun Jan 11 23:49:23 2009 +0000 @@ -204,8 +204,8 @@ DFBDisplayLayerConfigFlags failed; int ret; - SDL_DFB_CHECKERR(data->layer-> - SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer, + DLSCL_ADMINISTRATIVE)); config.width = mode->w; config.height = mode->h; config.pixelformat = SDLToDFBPixelFormat(mode->format); @@ -216,13 +216,13 @@ } failed = 0; data->layer->TestConfiguration(data->layer, &config, &failed); - SDL_DFB_CHECKERR(data->layer-> - SetCooperativeLevel(data->layer, DLSCL_SHARED)); + SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer, + DLSCL_SHARED)); if (failed == 0) SDL_AddDisplayMode(_this->current_display, mode); else - SDL_DFB_DEBUG("Mode %d x %d not available: %x\n", mode->w, mode->h, - failed); + SDL_DFB_DEBUG("Mode %d x %d not available: %x\n", mode->w, + mode->h, failed); return; error: @@ -235,13 +235,9 @@ SDL_DFB_DEVICEDATA(_this); IDirectFBDisplayLayer *layer = NULL; SDL_VideoDisplay display; - DFB_DisplayData *dispdata; + DFB_DisplayData *dispdata = NULL; SDL_DisplayMode mode; -#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23) - DFBCardCapabilities caps; -#else DFBGraphicsDeviceDescription caps; -#endif DFBDisplayLayerConfig dlc; struct scn_callback_t *screencbdata; @@ -259,28 +255,20 @@ screencbdata->vidlayer[i] = -1; } - SDL_DFB_CHECKERR(devdata->dfb-> - EnumScreens(devdata->dfb, &cbScreens, screencbdata)); + SDL_DFB_CHECKERR(devdata->dfb->EnumScreens(devdata->dfb, &cbScreens, + screencbdata)); for (i = 0; i < screencbdata->numscreens; i++) { IDirectFBScreen *screen; - SDL_DFB_CHECKERR(devdata->dfb-> - GetScreen(devdata->dfb, screencbdata->screenid[i], - &screen)); + SDL_DFB_CHECKERR(devdata->dfb->GetScreen(devdata->dfb, + screencbdata->screenid + [i], &screen)); screencbdata->aux = i; - SDL_DFB_CHECKERR(screen-> - EnumDisplayLayers(screen, &cbLayers, screencbdata)); -#if (DIRECTFB_MAJOR_VERSION >= 1) + SDL_DFB_CHECKERR(screen->EnumDisplayLayers(screen, &cbLayers, + screencbdata)); screen->GetSize(screen, &tcw[i], &tch[i]); -#else - /* FIXME: this is only used to center windows - * Should be done otherwise, e.g. get surface from layer - */ - tcw[i] = 800; - tch[i] = 600; -#endif screen->Release(screen); } @@ -293,12 +281,12 @@ SDL_DFB_DEBUG("Found %d screens\n", screencbdata->numscreens); for (i = 0; i < screencbdata->numscreens; i++) { - SDL_DFB_CHECKERR(devdata->dfb-> - GetDisplayLayer(devdata->dfb, - screencbdata->gralayer[i], &layer)); + SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb, + screencbdata->gralayer + [i], &layer)); - SDL_DFB_CHECKERR(layer-> - SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, + DLSCL_ADMINISTRATIVE)); layer->EnableCursor(layer, 1); SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0)); @@ -381,8 +369,8 @@ data.nummodes = 0; /* Enumerate the available fullscreen modes */ SDL_DFB_CALLOC(data.modelist, DFB_MAX_MODES, sizeof(SDL_DisplayMode)); - SDL_DFB_CHECKERR(devdata->dfb-> - EnumVideoModes(devdata->dfb, EnumModesCallback, &data)); + SDL_DFB_CHECKERR(devdata->dfb->EnumVideoModes(devdata->dfb, + EnumModesCallback, &data)); for (i = 0; i < data.nummodes; ++i) { mode = data.modelist[i]; @@ -419,8 +407,8 @@ DFBDisplayLayerConfigFlags fail = 0; DFBResult ret; - SDL_DFB_CHECKERR(data->layer-> - SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer, + DLSCL_ADMINISTRATIVE)); SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config)); config.flags = DLCONF_WIDTH | DLCONF_HEIGHT; @@ -440,8 +428,8 @@ data->layer->TestConfiguration(data->layer, &config, &fail); if (fail & - (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT | DLCONF_OPTIONS)) - { + (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT | + DLCONF_OPTIONS)) { SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h, mode->format); return -1; @@ -453,18 +441,16 @@ #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2) /* Need to call this twice ! */ SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config)); - //SDL_DFB_CHECKERR(data->layer->SetSourceRectangle(data->layer, 0, 0, config.width, config.height)); #endif /* Double check */ SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig)); - SDL_DFB_CHECKERR(data->layer-> - SetCooperativeLevel(data->layer, DLSCL_SHARED)); + SDL_DFB_CHECKERR(data-> + layer->SetCooperativeLevel(data->layer, DLSCL_SHARED)); - if ((config.width != rconfig.width) || - (config.height != rconfig.height) || - ((mode->format != SDL_PIXELFORMAT_UNKNOWN) - && (config.pixelformat != rconfig.pixelformat))) { + if ((config.width != rconfig.width) || (config.height != rconfig.height) + || ((mode->format != SDL_PIXELFORMAT_UNKNOWN) + && (config.pixelformat != rconfig.pixelformat))) { SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h, mode->format); return -1; @@ -483,7 +469,7 @@ void DirectFB_QuitModes(_THIS) { - DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata; + //DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata; SDL_DisplayMode tmode; DFBResult ret; int i; @@ -502,13 +488,14 @@ (DFB_DisplayData *) _this->displays[i].driverdata; if (dispdata->layer) { - SDL_DFB_CHECK(dispdata->layer-> - SetCooperativeLevel(dispdata->layer, - DLSCL_ADMINISTRATIVE)); - SDL_DFB_CHECK(dispdata->layer-> - SetCursorOpacity(dispdata->layer, 0x00)); - SDL_DFB_CHECK(dispdata->layer-> - SetCooperativeLevel(dispdata->layer, DLSCL_SHARED)); + SDL_DFB_CHECK(dispdata-> + layer->SetCooperativeLevel(dispdata->layer, + DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECK(dispdata-> + layer->SetCursorOpacity(dispdata->layer, 0x00)); + SDL_DFB_CHECK(dispdata-> + layer->SetCooperativeLevel(dispdata->layer, + DLSCL_SHARED)); } SDL_DFB_RELEASE(dispdata->layer); diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_mouse.c --- a/src/video/directfb/SDL_DirectFB_mouse.c Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_mouse.c Sun Jan 11 23:49:23 2009 +0000 @@ -26,8 +26,8 @@ #include "../SDL_sysvideo.h" #include "../../events/SDL_mouse_c.h" -static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, - int hot_y); +static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface, + int hot_x, int hot_y); static int DirectFB_ShowCursor(SDL_Cursor * cursor); static void DirectFB_MoveCursor(SDL_Cursor * cursor); static void DirectFB_FreeCursor(SDL_Cursor * cursor); @@ -38,8 +38,8 @@ static int id_mask; static DFBEnumerationResult -EnumMice(DFBInputDeviceID device_id, - DFBInputDeviceDescription desc, void *callbackdata) +EnumMice(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, + void *callbackdata) { DFB_DeviceData *devdata = callbackdata; @@ -132,20 +132,20 @@ dsc.height = surface->h; dsc.pixelformat = DSPF_ARGB; - SDL_DFB_CHECKERR(devdata->dfb-> - CreateSurface(devdata->dfb, &dsc, &curdata->surf)); + SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, + &curdata->surf)); curdata->hotx = hot_x; curdata->hoty = hot_y; cursor->driverdata = curdata; - SDL_DFB_CHECKERR(curdata->surf-> - Lock(curdata->surf, DSLF_WRITE, (void *) &dest, &pitch)); + SDL_DFB_CHECKERR(curdata->surf->Lock(curdata->surf, DSLF_WRITE, + (void *) &dest, &pitch)); /* Relies on the fact that this is only called with ARGB surface. */ p = surface->pixels; for (i = 0; i < surface->h; i++) - memcpy((char *) dest + i * pitch, (char *) p + i * surface->pitch, - 4 * surface->w); + memcpy((char *) dest + i * pitch, + (char *) p + i * surface->pitch, 4 * surface->w); curdata->surf->Unlock(curdata->surf); return cursor; @@ -162,7 +162,7 @@ SDL_WindowID wid; wid = SDL_GetFocusWindow(); - if (wid < 0) + if (wid <= 0) return -1; else { SDL_Window *window = SDL_GetWindowFromID(wid); @@ -179,7 +179,6 @@ curdata->surf, curdata->hotx, curdata->hoty)); - /* fprintf(stdout, "Cursor is %s\n", cursor ? "on" : "off"); */ SDL_DFB_CHECKERR(dispdata->layer-> SetCooperativeLevel(dispdata->layer, DLSCL_ADMINISTRATIVE)); @@ -227,8 +226,9 @@ int cx, cy; SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy)); - SDL_DFB_CHECKERR(dispdata->layer-> - WarpCursor(dispdata->layer, cx + x, cy + y)); + SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer, + cx + x + windata->client.x, + cy + y + windata->client.y)); error: return; diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_opengl.c --- a/src/video/directfb/SDL_DirectFB_opengl.c Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_opengl.c Sun Jan 11 23:49:23 2009 +0000 @@ -173,8 +173,8 @@ SDL_DFB_CALLOC(context, 1, sizeof(*context)); - SDL_DFB_CHECKERR(windata->surface-> - GetGL(windata->surface, &context->context)); + SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface, + &context->context)); if (!context->context) return NULL; @@ -208,16 +208,9 @@ p->context->Unlock(p->context); if (windata) { - int cw, ch; - windata->gl_context = NULL; /* Everything is unlocked, check for a resize */ - SDL_DFB_CHECKERR(windata->surface-> - GetSize(windata->surface, &cw, &ch)); - if (cw != window->w || ch != window->h) - SDL_DFB_CHECKERR(windata->window-> - ResizeSurface(windata->window, window->w, - window->h)); + DirectFB_AdjustWindowSurface(window); } if (ctx != NULL) { @@ -266,8 +259,8 @@ if (1 || windata->gl_context) { /* SDL_DFB_CHECKERR(windata->gl_context->context->Unlock(windata->gl_context->context)); */ - SDL_DFB_CHECKERR(windata->surface-> - Flip(windata->surface, ®ion, DSFLIP_ONSYNC)); + SDL_DFB_CHECKERR(windata->surface->Flip(windata->surface, ®ion, + DSFLIP_ONSYNC)); /* SDL_DFB_CHECKERR(windata->gl_context->context->Lock(windata->gl_context->context)); */ } diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_render.c --- a/src/video/directfb/SDL_DirectFB_render.c Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_render.c Sun Jan 11 23:49:23 2009 +0000 @@ -41,16 +41,16 @@ static int DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer, - SDL_Texture * texture, void **pixels, - int *pitch); + SDL_Texture * texture, + void **pixels, int *pitch); static int DirectFB_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Color * colors, int firstcolor, int ncolors); static int DirectFB_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, - SDL_Color * colors, int firstcolor, - int ncolors); + SDL_Color * colors, + int firstcolor, int ncolors); static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture); static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer, @@ -61,11 +61,12 @@ SDL_Texture * texture); static int DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); + const SDL_Rect * rect, + const void *pixels, int pitch); static int DirectFB_LockTexture(SDL_Renderer * renderer, - SDL_Texture * texture, const SDL_Rect * rect, - int markDirty, void **pixels, int *pitch); + SDL_Texture * texture, + const SDL_Rect * rect, int markDirty, + void **pixels, int *pitch); static void DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void DirectFB_DirtyTexture(SDL_Renderer * renderer, @@ -76,7 +77,8 @@ int x2, int y2); static int DirectFB_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); -static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, +static int DirectFB_RenderCopy(SDL_Renderer * renderer, + SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); static void DirectFB_RenderPresent(SDL_Renderer * renderer); @@ -94,8 +96,8 @@ SDL_RENDERER_ACCELERATED), (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), - (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | - SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), + (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND | + SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST), 14, @@ -327,7 +329,7 @@ renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER; data->isyuvdirect = 0; /* default is off! */ - p = getenv(DFBENV_USE_YUV_DIRECT); + p = SDL_getenv(DFBENV_USE_YUV_DIRECT); if (p) data->isyuvdirect = atoi(p); @@ -414,20 +416,10 @@ SDL_Window *window = SDL_GetWindowFromID(renderer->window); SDL_DFB_WINDOWDATA(window); - if (renddata->size_changed) { - int cw, ch; - int ret; - - SDL_DFB_CHECKERR(windata->surface-> - GetSize(windata->surface, &cw, &ch)); - if (cw != window->w || ch != window->h) - SDL_DFB_CHECKERR(windata->window-> - ResizeSurface(windata->window, window->w, - window->h)); + if (renddata->size_changed || windata->wm_needs_redraw) { + DirectFB_AdjustWindowSurface(window); } return 0; - error: - return -1; } static int @@ -462,22 +454,24 @@ layconf.pixelformat = SDLToDFBPixelFormat(data->format); layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE; - SDL_DFB_CHECKERR(devdata->dfb-> - GetDisplayLayer(devdata->dfb, dispdata->vidID, - &dispdata->vidlayer)); - SDL_DFB_CHECKERR(dispdata->vidlayer-> - SetCooperativeLevel(dispdata->vidlayer, - DLSCL_EXCLUSIVE)); + SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb, + dispdata->vidID, + &dispdata->vidlayer)); + SDL_DFB_CHECKERR(dispdata-> + vidlayer->SetCooperativeLevel(dispdata->vidlayer, + DLSCL_EXCLUSIVE)); if (devdata->use_yuv_underlays) { ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1); if (ret != DFB_OK) SDL_DFB_DEBUG("Underlay Setlevel not supported\n"); } - SDL_DFB_CHECKERR(dispdata->vidlayer-> - SetConfiguration(dispdata->vidlayer, &layconf)); - SDL_DFB_CHECKERR(dispdata->vidlayer-> - GetSurface(dispdata->vidlayer, &data->surface)); + SDL_DFB_CHECKERR(dispdata-> + vidlayer->SetConfiguration(dispdata->vidlayer, + &layconf)); + SDL_DFB_CHECKERR(dispdata-> + vidlayer->GetSurface(dispdata->vidlayer, + &data->surface)); dispdata->vidIDinuse = 1; data->display = display; return 0; @@ -486,9 +480,9 @@ error: if (dispdata->vidlayer) { SDL_DFB_RELEASE(data->surface); - SDL_DFB_CHECKERR(dispdata->vidlayer-> - SetCooperativeLevel(dispdata->vidlayer, - DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECKERR(dispdata-> + vidlayer->SetCooperativeLevel(dispdata->vidlayer, + DLSCL_ADMINISTRATIVE)); SDL_DFB_RELEASE(dispdata->vidlayer); } return 1; @@ -540,12 +534,12 @@ data->pixels = NULL; /* Create the surface */ - SDL_DFB_CHECKERR(devdata->dfb-> - CreateSurface(devdata->dfb, &dsc, &data->surface)); + SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, + &data->surface)); if (SDL_ISPIXELFORMAT_INDEXED(data->format) && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { - SDL_DFB_CHECKERR(data->surface-> - GetPalette(data->surface, &data->palette)); + SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, + &data->palette)); } } @@ -568,8 +562,8 @@ } static int -DirectFB_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, - void **pixels, int *pitch) +DirectFB_QueryTexturePixels(SDL_Renderer * renderer, + SDL_Texture * texture, void **pixels, int *pitch) { DirectFB_TextureData *texturedata = (DirectFB_TextureData *) texture->driverdata; @@ -584,7 +578,8 @@ } static int -DirectFB_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, +DirectFB_SetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, const SDL_Color * colors, int firstcolor, int ncolors) { @@ -602,9 +597,9 @@ entries[i].b = colors[i].b; entries[i].a = 0xFF; } - SDL_DFB_CHECKERR(data->palette-> - SetEntries(data->palette, entries, ncolors, - firstcolor)); + SDL_DFB_CHECKERR(data-> + palette->SetEntries(data->palette, entries, ncolors, + firstcolor)); return 0; } else { SDL_SetError("YUV textures don't have a palette"); @@ -615,8 +610,9 @@ } static int -DirectFB_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, - SDL_Color * colors, int firstcolor, int ncolors) +DirectFB_GetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, SDL_Color * colors, + int firstcolor, int ncolors) { DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; DFBResult ret; @@ -626,9 +622,9 @@ DFBColor entries[256]; int i; - SDL_DFB_CHECKERR(data->palette-> - GetEntries(data->palette, entries, ncolors, - firstcolor)); + SDL_DFB_CHECKERR(data-> + palette->GetEntries(data->palette, entries, ncolors, + firstcolor)); for (i = 0; i < ncolors; ++i) { colors[i].r = entries[i].r; @@ -737,8 +733,8 @@ static int DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, int markDirty, void **pixels, - int *pitch) + const SDL_Rect * rect, int markDirty, + void **pixels, int *pitch) { DirectFB_TextureData *texturedata = (DirectFB_TextureData *) texture->driverdata; @@ -807,8 +803,8 @@ a = renderer->a; SetBlendMode(data, renderer->blendMode, NULL); - SDL_DFB_CHECKERR(data->surface-> - SetDrawingFlags(data->surface, data->drawFlags)); + SDL_DFB_CHECKERR(data->surface->SetDrawingFlags(data->surface, + data->drawFlags)); switch (renderer->blendMode) { case SDL_BLENDMODE_NONE: @@ -868,9 +864,9 @@ DFBResult ret; PrepareDraw(renderer); - SDL_DFB_CHECKERR(data->surface-> - FillRectangle(data->surface, rect->x, rect->y, rect->w, - rect->h)); + SDL_DFB_CHECKERR(data-> + surface->FillRectangle(data->surface, rect->x, rect->y, + rect->w, rect->h)); return 0; error: @@ -894,15 +890,20 @@ SDL_VideoDisplay *display = texturedata->display; DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; - SDL_DFB_CHECKERR(dispdata->vidlayer-> - SetSourceRectangle(dispdata->vidlayer, srcrect->x, - srcrect->y, srcrect->w, - srcrect->h)); + SDL_DFB_CHECKERR(dispdata-> + vidlayer->SetSourceRectangle(dispdata->vidlayer, + srcrect->x, srcrect->y, + srcrect->w, + srcrect->h)); windata->window->GetPosition(windata->window, &px, &py); - SDL_DFB_CHECKERR(dispdata->vidlayer-> - SetScreenRectangle(dispdata->vidlayer, - px + dstrect->x, py + dstrect->y, - dstrect->w, dstrect->h)); + px += windata->client.x; + py += windata->client.y; + SDL_DFB_CHECKERR(dispdata-> + vidlayer->SetScreenRectangle(dispdata->vidlayer, + px + dstrect->x, + py + dstrect->y, + dstrect->w, + dstrect->h)); } else { DFBRectangle sr, dr; DFBSurfaceBlittingFlags flags = 0; @@ -928,34 +929,37 @@ SDLtoDFBRect(srcrect, &sr); SDLtoDFBRect(dstrect, &dr); - SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF, - 0xFF, 0xFF, 0xFF)); - if (texture-> - modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA)) - { + SDL_DFB_CHECKERR(data-> + surface->SetColor(data->surface, 0xFF, 0xFF, 0xFF, + 0xFF)); + if (texture->modMode & + (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA)) { if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) { alpha = texture->a; - SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF, - 0xFF, 0xFF, alpha)); + SDL_DFB_CHECKERR(data-> + surface->SetColor(data->surface, 0xFF, 0xFF, + 0xFF, alpha)); } if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { - SDL_DFB_CHECKERR(data->surface-> - SetColor(data->surface, texture->r, - texture->g, texture->b, alpha)); + SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, + texture->r, + texture->g, + texture->b, alpha)); flags |= DSBLIT_COLORIZE; } if (alpha < 0xFF) flags |= DSBLIT_SRC_PREMULTCOLOR; } else - SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF, - 0xFF, 0xFF, 0xFF)); + SDL_DFB_CHECKERR(data-> + surface->SetColor(data->surface, 0xFF, 0xFF, + 0xFF, 0xFF)); SetBlendMode(data, texture->blendMode, texturedata); - SDL_DFB_CHECKERR(data->surface-> - SetBlittingFlags(data->surface, - data->blitFlags | flags)); + SDL_DFB_CHECKERR(data->surface->SetBlittingFlags(data->surface, + data->blitFlags + | flags)); #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2) SDL_DFB_CHECKERR(data->surface->SetRenderOptions(data->surface, @@ -964,13 +968,13 @@ #endif if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { - SDL_DFB_CHECKERR(data->surface-> - Blit(data->surface, texturedata->surface, - &sr, dr.x, dr.y)); + SDL_DFB_CHECKERR(data->surface->Blit(data->surface, + texturedata->surface, + &sr, dr.x, dr.y)); } else { - SDL_DFB_CHECKERR(data->surface-> - StretchBlit(data->surface, texturedata->surface, - &sr, &dr)); + SDL_DFB_CHECKERR(data->surface->StretchBlit(data->surface, + texturedata->surface, + &sr, &dr)); } } return 0; @@ -983,6 +987,7 @@ { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_DFB_WINDOWDATA(window); DFBRectangle sr; DFBResult ret; @@ -993,12 +998,8 @@ sr.h = window->h; /* Send the data to the display */ - SDL_DFB_CHECKERR(data->surface-> - Flip(data->surface, NULL, data->flipflags)); - - return; - error: - return; + SDL_DFB_CHECK(windata->window_surface->Flip(windata->window_surface, NULL, + data->flipflags)); } static void diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_video.c --- a/src/video/directfb/SDL_DirectFB_video.c Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_video.c Sun Jan 11 23:49:23 2009 +0000 @@ -35,6 +35,7 @@ #include #include +#include #include "SDL_video.h" #include "SDL_mouse.h" @@ -55,8 +56,10 @@ static int DirectFB_Available(void); static SDL_VideoDevice *DirectFB_CreateDevice(int devindex); +#if 0 static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp); static int DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp); +#endif VideoBootStrap DirectFB_bootstrap = { "directfb", "DirectFB", @@ -111,6 +114,7 @@ device->CreateWindow = DirectFB_CreateWindow; device->CreateWindowFrom = DirectFB_CreateWindowFrom; device->SetWindowTitle = DirectFB_SetWindowTitle; + device->SetWindowIcon = DirectFB_SetWindowIcon; device->SetWindowPosition = DirectFB_SetWindowPosition; device->SetWindowSize = DirectFB_SetWindowSize; device->ShowWindow = DirectFB_ShowWindow; @@ -145,6 +149,50 @@ return (0); } +static const DirectFBSurfaceDrawingFlagsNames(drawing_flags); +static const DirectFBSurfaceBlittingFlagsNames(blitting_flags); +static const DirectFBAccelerationMaskNames(acceleration_mask); + +static void +DirectFB_DeviceInformation(IDirectFB * dfb) +{ + DFBGraphicsDeviceDescription desc; + int n; + + dfb->GetDeviceDescription(dfb, &desc); + + fprintf(LOG_CHANNEL, "DirectFB Device Information\n"); + fprintf(LOG_CHANNEL, "===========================\n"); + fprintf(LOG_CHANNEL, "Name: %s\n", desc.name); + fprintf(LOG_CHANNEL, "Vendor: %s\n", desc.vendor); + fprintf(LOG_CHANNEL, "Driver Name: %s\n", desc.driver.name); + fprintf(LOG_CHANNEL, "Driver Vendor: %s\n", desc.driver.vendor); + fprintf(LOG_CHANNEL, "Driver Version: %d.%d\n", desc.driver.major, + desc.driver.minor); + + fprintf(LOG_CHANNEL, "\nVideo memoory: %d\n", desc.video_memory); + + fprintf(LOG_CHANNEL, "\nBlitting flags:\n"); + for (n = 0; blitting_flags[n].flag; n++) { + if (desc.blitting_flags & blitting_flags[n].flag) + printf(" %s\n", blitting_flags[n].name); + } + + fprintf(LOG_CHANNEL, "\nDrawing flags:\n"); + for (n = 0; drawing_flags[n].flag; n++) { + if (desc.drawing_flags & drawing_flags[n].flag) + printf(" %s\n", drawing_flags[n].name); + } + + fprintf(LOG_CHANNEL, "\nAcceleration flags:\n"); + for (n = 0; acceleration_mask[n].mask; n++) { + if (desc.acceleration_mask & acceleration_mask[n].mask) + printf(" %s\n", acceleration_mask[n].name); + } + + +} + static int DirectFB_VideoInit(_THIS) { @@ -159,21 +207,21 @@ /* avoid switching to the framebuffer when we * are running X11 */ - stemp = getenv(DFBENV_USE_X11_CHECK); + stemp = SDL_getenv(DFBENV_USE_X11_CHECK); if (stemp) ret = atoi(stemp); else ret = 1; if (ret) { - if (getenv("DISPLAY")) + if (SDL_getenv("DISPLAY")) DirectFBSetOption("system", "x11"); else DirectFBSetOption("disable-module", "x11input"); } devdata->use_linux_input = 1; /* default: on */ - stemp = getenv(DFBENV_USE_LINUX_INPUT); + stemp = SDL_getenv(DFBENV_USE_LINUX_INPUT); if (stemp) devdata->use_linux_input = atoi(stemp); @@ -182,25 +230,34 @@ SDL_DFB_CHECKERR(DirectFBCreate(&dfb)); + DirectFB_DeviceInformation(dfb); devdata->use_yuv_underlays = 0; /* default: off */ - stemp = getenv(DFBENV_USE_YUV_UNDERLAY); + stemp = SDL_getenv(DFBENV_USE_YUV_UNDERLAY); if (stemp) devdata->use_yuv_underlays = atoi(stemp); /* Create global Eventbuffer for axis events */ if (devdata->use_linux_input) { - SDL_DFB_CHECKERR(dfb-> - CreateInputEventBuffer(dfb, DICAPS_ALL, - DFB_TRUE, &devdata->events)); + SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_ALL, + DFB_TRUE, + &devdata->events)); } else { - SDL_DFB_CHECKERR(dfb-> - CreateInputEventBuffer(dfb, - DICAPS_AXES /*DICAPS_ALL */ , - DFB_TRUE, &devdata->events)); + SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_AXES + /*DICAPS_ALL */ , + DFB_TRUE, + &devdata->events)); } devdata->initialized = 1; + + /* simple window manager support */ + stemp = SDL_getenv(DFBENV_USE_WM); + if (stemp) + devdata->has_own_wm = atoi(stemp); + else + devdata->has_own_wm = 0; + devdata->dfb = dfb; devdata->firstwin = NULL; @@ -216,7 +273,6 @@ DirectFB_InitMouse(_this); DirectFB_InitKeyboard(_this); - return 0; @@ -245,6 +301,7 @@ devdata->initialized = 0; } +#if 0 static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp) { @@ -256,3 +313,4 @@ { return -1; } +#endif diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_video.h --- a/src/video/directfb/SDL_DirectFB_video.h Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_video.h Sun Jan 11 23:49:23 2009 +0000 @@ -34,8 +34,8 @@ #define DEBUG 0 #define LOG_CHANNEL stdout -#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23) -#error "SDL_DIRECTFB: Please compile against libdirectfb version >=0.9.24" +#if (DIRECTFB_MAJOR_VERSION < 1) +#error "SDL_DIRECTFB: Please compile against libdirectfb version >= 1.0.0" #endif #if (DIRECTFB_MAJOR_VERSION >= 1) && (DIRECTFB_MINOR_VERSION >= 0) && (DIRECTFB_MICRO_VERSION >= 0 ) @@ -56,11 +56,13 @@ #include "SDL_DirectFB_mouse.h" #include "SDL_DirectFB_opengl.h" #include "SDL_DirectFB_window.h" +#include "SDL_DirectFB_WM.h" #define DFBENV_USE_YUV_UNDERLAY "SDL_DIRECTFB_YUV_UNDERLAY" /* Default: off */ #define DFBENV_USE_YUV_DIRECT "SDL_DIRECTFB_YUV_DIRECT" /* Default: off */ #define DFBENV_USE_X11_CHECK "SDL_DIRECTFB_X11_CHECK" /* Default: on */ #define DFBENV_USE_LINUX_INPUT "SDL_DIRECTFB_LINUX_INPUT" /* Default: on */ +#define DFBENV_USE_WM "SDL_DIRECTFB_WM" /* Default: off */ #define SDL_DFB_RELEASE(x) do { if ( x ) { x->Release(x); x = NULL; } } while (0) #define SDL_DFB_FREE(x) do { if ( x ) { SDL_free(x); x = NULL; } } while (0) @@ -88,6 +90,8 @@ ret = x; \ if (ret != DFB_OK) { \ fprintf(LOG_CHANNEL, "%s <%d>:\n\t", __FILE__, __LINE__ ); \ + fprintf(LOG_CHANNEL, "\t%s\n", #x ); \ + fprintf(LOG_CHANNEL, "\t%s\n", DirectFBErrorString (ret) ); \ SDL_SetError( #x, DirectFBErrorString (ret) ); \ } \ } while (0) @@ -116,7 +120,7 @@ /* Private display data */ -#define SDL_DFB_DEVICEDATA(dev) DFB_DeviceData *devdata = (DFB_DeviceData *) ((dev)->driverdata) +#define SDL_DFB_DEVICEDATA(dev) DFB_DeviceData *devdata = (dev ? (DFB_DeviceData *) ((dev)->driverdata) : NULL) #define DFB_MAX_SCREENS 10 @@ -138,6 +142,7 @@ int use_yuv_underlays; int use_linux_input; + int has_own_wm; /* OpenGL */ void (*glFinish) (void); diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_window.c --- a/src/video/directfb/SDL_DirectFB_window.c Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_window.c Sun Jan 11 23:49:23 2009 +0000 @@ -27,27 +27,27 @@ #include "SDL_DirectFB_video.h" + int DirectFB_CreateWindow(_THIS, SDL_Window * window) { SDL_DFB_DEVICEDATA(_this); SDL_DFB_DISPLAYDATA(_this, window); - DFB_WindowData *windata; + DFB_WindowData *windata = NULL; DFBWindowOptions wopts; DFBWindowDescription desc; + IDirectFBFont *font; int ret, x, y; - SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y, - window->w, window->h); - window->driverdata = NULL; SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData)); windata = (DFB_WindowData *) window->driverdata; - SDL_DFB_CHECKERR(devdata->dfb-> - SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL)); - SDL_DFB_CHECKERR(dispdata->layer-> - SetCooperativeLevel(dispdata->layer, - DLSCL_ADMINISTRATIVE)); + windata->is_managed = devdata->has_own_wm; + + SDL_DFB_CHECKERR(devdata->dfb->SetCooperativeLevel(devdata->dfb, + DFSCL_NORMAL)); + SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer, + DLSCL_ADMINISTRATIVE)); /* Fill the window description. */ if (window->x == SDL_WINDOWPOS_CENTERED) { @@ -69,76 +69,76 @@ y = 0; } - desc.flags = DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT; - /*| DWDESC_CAPS | DWDESC_SURFACE_CAPS */ + DirectFB_WM_AdjustWindowLayout(window); -#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0) - /* Needed for 1.2 */ - desc.flags |= DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS; + /* Create Window */ + desc.flags = + DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT | DWDESC_POSX + | DWDESC_POSY | DWDESC_SURFACE_CAPS; desc.posx = x; desc.posy = y; -#else - if (!(window->flags & SDL_WINDOW_FULLSCREEN) - && window->x != SDL_WINDOWPOS_UNDEFINED - && window->y != SDL_WINDOWPOS_UNDEFINED) { - desc.flags |= DWDESC_POSX | DWDESC_POSY; - desc.posx = x; - desc.posy = y; - } -#endif - - desc.width = window->w; - desc.height = window->h; + desc.width = windata->size.w; + desc.height = windata->size.h; desc.pixelformat = dispdata->pixelformat; -#if 0 - desc.caps = 0; - desc.surface_caps = - DSCAPS_DOUBLE | DSCAPS_TRIPLE | DSCAPS_PREMULTIPLIED | - DSCAPS_VIDEOONLY; -#endif desc.surface_caps = DSCAPS_PREMULTIPLIED; - /* DSCAPS_VIDEOONLY has negative impact on performance */ /* Create the window. */ - SDL_DFB_CHECKERR(dispdata->layer-> - CreateWindow(dispdata->layer, &desc, &windata->window)); + SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc, + &windata->window)); + /* Set Options */ windata->window->GetOptions(windata->window, &wopts); -#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0) if (window->flags & SDL_WINDOW_RESIZABLE) wopts |= DWOP_SCALE; else wopts |= DWOP_KEEP_SIZE; -#else - wopts |= DWOP_KEEP_SIZE; /* if not we will crash ... */ -#endif - if (window->flags & SDL_WINDOW_FULLSCREEN) + if (window->flags & SDL_WINDOW_FULLSCREEN) { wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE; + windata->window->SetStackingClass(windata->window, DWSC_UPPER); + } + windata->window->SetOptions(windata->window, wopts); - windata->window->SetOptions(windata->window, wopts); + /* See what we got */ + SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &window->w, &window->h)); + /* Get the window's surface. */ - SDL_DFB_CHECKERR(windata->window-> - GetSurface(windata->window, &windata->surface)); + SDL_DFB_CHECKERR(windata->window->GetSurface(windata->window, + &windata->window_surface)); + /* And get a subsurface for rendering */ + SDL_DFB_CHECKERR(windata->window_surface-> + GetSubSurface(windata->window_surface, &windata->client, + &windata->surface)); + windata->window->SetOpacity(windata->window, 0xFF); - SDL_DFB_CHECKERR(windata->window-> - CreateEventBuffer(windata->window, - &(windata->eventbuffer))); - SDL_DFB_CHECKERR(windata->window-> - EnableEvents(windata->window, DWET_ALL)); + + /* Create Eventbuffer */ + SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window, + &windata->eventbuffer)); + SDL_DFB_CHECKERR(windata-> + window->EnableEvents(windata->window, DWET_ALL)); - if (window->flags & SDL_WINDOW_FULLSCREEN) - windata->window->SetStackingClass(windata->window, DWSC_UPPER); + /* Create a font */ + /* FIXME: once during Video_Init */ + if (windata->is_managed) { + DFBFontDescription fdesc; + + fdesc.flags = DFDESC_HEIGHT; + fdesc.height = windata->theme.font_size; + font = NULL; + SDL_DFB_CHECK(devdata-> + dfb->CreateFont(devdata->dfb, windata->theme.font, + &fdesc, &font)); + windata->window_surface->SetFont(windata->window_surface, font); + SDL_DFB_RELEASE(font); + } + /* Make it the top most window. */ windata->window->RaiseToTop(windata->window); - windata->window->GetID(windata->window, &windata->windowID); - - windata->window->GetSize(windata->window, &window->w, &window->h); - /* remember parent */ - windata->id = window->id; + windata->sdl_id = window->id; /* Add to list ... */ @@ -146,6 +146,9 @@ windata->opacity = 0xFF; devdata->firstwin = windata; + /* Draw Frame */ + DirectFB_WM_RedrawLayout(window); + return 0; error: SDL_DFB_RELEASE(windata->window); @@ -163,7 +166,65 @@ void DirectFB_SetWindowTitle(_THIS, SDL_Window * window) { - SDL_Unsupported(); + SDL_DFB_WINDOWDATA(window); + + if (windata->is_managed) { + windata->wm_needs_redraw = 1; + } else + SDL_Unsupported(); +} + +void +DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) +{ + SDL_DFB_DEVICEDATA(_this); + SDL_DFB_WINDOWDATA(window); + SDL_Surface *surface = NULL; + DFBResult ret; + + if (icon) { + SDL_PixelFormat format; + DFBSurfaceDescription dsc; + Uint32 *dest; + Uint32 *p; + int pitch, i; + + /* Convert the icon to ARGB for modern window managers */ + SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, + 0xFF000000); + surface = SDL_ConvertSurface(icon, &format, 0); + if (!surface) { + return; + } + dsc.flags = + DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; + dsc.caps = DSCAPS_VIDEOONLY; + dsc.width = surface->w; + dsc.height = surface->h; + dsc.pixelformat = DSPF_ARGB; + + SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, + &windata->icon)); + + SDL_DFB_CHECKERR(windata->icon->Lock(windata->icon, DSLF_WRITE, + (void *) &dest, &pitch)); + + p = surface->pixels; + for (i = 0; i < surface->h; i++) + memcpy((char *) dest + i * pitch, + (char *) p + i * surface->pitch, 4 * surface->w); + + windata->icon->Unlock(windata->icon); + SDL_FreeSurface(surface); + } else { + SDL_DFB_RELEASE(windata->icon); + } + return; + error: + if (surface) + SDL_FreeSurface(surface); + SDL_DFB_RELEASE(windata->icon); + return; } void @@ -186,37 +247,39 @@ x = 0; y = 0; } - + DirectFB_WM_AdjustWindowLayout(window); windata->window->MoveTo(windata->window, x, y); } void DirectFB_SetWindowSize(_THIS, SDL_Window * window) { + SDL_DFB_DEVICEDATA(_this); + SDL_DFB_WINDOWDATA(window); int ret; - SDL_DFB_WINDOWDATA(window); if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { -#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0) int cw; int ch; /* Make sure all events are disabled for this operation ! */ - SDL_DFB_CHECKERR(windata->window-> - DisableEvents(windata->window, DWET_ALL)); + SDL_DFB_CHECKERR(windata->window->DisableEvents(windata->window, + DWET_ALL)); + + SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &cw, &ch)); + + if (cw != window->w || ch != window->h) { - SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &cw, &ch)); - if (cw != window->w || ch != window->h) - SDL_DFB_CHECKERR(windata->window-> - Resize(windata->window, window->w, window->h)); - SDL_DFB_CHECKERR(windata->window-> - EnableEvents(windata->window, DWET_ALL)); + DirectFB_WM_AdjustWindowLayout(window); + SDL_DFB_CHECKERR(windata->window->Resize(windata->window, + windata->size.w, + windata->size.h)); + } -#else - SDL_DFB_CHECKERR(windata->window-> - Resize(windata->window, window->w, window->h)); -#endif - SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h)); /* if a window manager should have decided otherwise */ + SDL_DFB_CHECKERR(windata->window->EnableEvents(windata->window, + DWET_ALL)); + + SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &window->w, &window->h)); SDL_OnWindowResized(window); } @@ -256,9 +319,12 @@ void DirectFB_MaximizeWindow(_THIS, SDL_Window * window) { - /* FIXME: Size to Desktop ? */ + SDL_DFB_WINDOWDATA(window); - SDL_Unsupported(); + if (windata->is_managed) { + DirectFB_WM_MaximizeWindow(_this, window); + } else + SDL_Unsupported(); } void @@ -272,7 +338,12 @@ void DirectFB_RestoreWindow(_THIS, SDL_Window * window) { - SDL_Unsupported(); + SDL_DFB_WINDOWDATA(window); + + if (windata->is_managed) { + DirectFB_WM_RestoreWindow(_this, window); + } else + SDL_Unsupported(); } void @@ -280,8 +351,7 @@ { SDL_DFB_WINDOWDATA(window); - if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && - (window->flags & SDL_WINDOW_INPUT_FOCUS)) { + if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) { windata->window->GrabPointer(windata->window); windata->window->GrabKeyboard(windata->window); } else { @@ -299,8 +369,16 @@ SDL_DFB_DEBUG("Trace\n"); + /* Some cleanups */ + windata->window->UngrabPointer(windata->window); + windata->window->UngrabKeyboard(windata->window); + + windata->window_surface->SetFont(windata->window_surface, NULL); + SDL_DFB_RELEASE(windata->icon); SDL_DFB_RELEASE(windata->eventbuffer); SDL_DFB_RELEASE(windata->surface); + SDL_DFB_RELEASE(windata->window_surface); + SDL_DFB_RELEASE(windata->window); /* Remove from list ... */ @@ -323,3 +401,35 @@ SDL_Unsupported(); return SDL_FALSE; } + +void +DirectFB_AdjustWindowSurface(SDL_Window * window) +{ + SDL_DFB_WINDOWDATA(window); + int adjust = windata->wm_needs_redraw; + int cw, ch; + int ret; + + DirectFB_WM_AdjustWindowLayout(window); + + SDL_DFB_CHECKERR(windata-> + window_surface->GetSize(windata->window_surface, &cw, + &ch)); + if (cw != windata->size.w || ch != windata->size.h) { + adjust = 1; + } + + if (adjust) { + SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window, + windata->size.w, + windata->size.h)); + SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface, + windata-> + window_surface, + &windata->client)); + DirectFB_WM_RedrawLayout(window); + } + error: + return; +} + diff -r db20dde98dd3 -r d72a0dd80e8b src/video/directfb/SDL_DirectFB_window.h --- a/src/video/directfb/SDL_DirectFB_window.h Sun Jan 11 23:39:11 2009 +0000 +++ b/src/video/directfb/SDL_DirectFB_window.h Sun Jan 11 23:49:23 2009 +0000 @@ -24,25 +24,38 @@ #ifndef _SDL_directfb_window_h #define _SDL_directfb_window_h +#include "SDL_DirectFB_WM.h" + #define SDL_DFB_WINDOWDATA(win) DFB_WindowData *windata = ((win) ? (DFB_WindowData *) ((win)->driverdata) : NULL) typedef struct _DFB_WindowData DFB_WindowData; struct _DFB_WindowData { IDirectFBSurface *surface; + IDirectFBSurface *window_surface; /* only used with has_own_wm */ IDirectFBWindow *window; DirectFB_GLContext *gl_context; IDirectFBEventBuffer *eventbuffer; - DFBWindowID windowID; + SDL_WindowID sdl_id; DFB_WindowData *next; Uint8 opacity; - SDL_WindowID id; + DFBRectangle client; + DFBDimension size; + /* WM extras */ + DFBRectangle restore; + int is_managed; + int wm_needs_redraw; + IDirectFBSurface *icon; + DFB_Theme theme; }; extern int DirectFB_CreateWindow(_THIS, SDL_Window * window); extern int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data); extern void DirectFB_SetWindowTitle(_THIS, SDL_Window * window); +extern void DirectFB_SetWindowIcon(_THIS, SDL_Window * window, + SDL_Surface * icon); + extern void DirectFB_SetWindowPosition(_THIS, SDL_Window * window); extern void DirectFB_SetWindowSize(_THIS, SDL_Window * window); extern void DirectFB_ShowWindow(_THIS, SDL_Window * window); @@ -56,6 +69,8 @@ extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info); +extern void DirectFB_AdjustWindowSurface(SDL_Window * window); + #endif /* _SDL_directfb_window_h */ /* vi: set ts=4 sw=4 expandtab: */