DirectFB: Split input grab handling into keyboard and mouse parts The grabbed_window field is superfluous now since SDL added the SDL_GetGrabbedWindow() function, so it can be removed. DirectFB_SetWindowMouseGrab() is also simplified because SDL handles ungrabbing any previously grabbed window prior to calling SetWindowMouseGrab() now. Compile-tested only.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
diff --git a/src/video/directfb/SDL_DirectFB_WM.c b/src/video/directfb/SDL_DirectFB_WM.c
index 46ddffd..8dd48a3 100644
--- a/src/video/directfb/SDL_DirectFB_WM.c
+++ b/src/video/directfb/SDL_DirectFB_WM.c
@@ -287,9 +287,8 @@ WMPos(DFB_WindowData * p, int x, int y)
int
DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
{
- SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
- DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
+ SDL_Window *grabbed_window = SDL_GetGrabbedWindow();
IDirectFBWindow *dfbwin = windata->dfbwin;
DFBWindowOptions wopts;
@@ -327,9 +326,9 @@ DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
/* fall through */
default:
windata->wm_grab = pos;
- if (gwindata != NULL)
- SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
- SDL_DFB_CHECK(dfbwin->GrabPointer(dfbwin));
+ if (grabbed_window != NULL)
+ DirectFB_SetWindowMouseGrab(_this, grabbed_window, SDL_FALSE);
+ DirectFB_SetWindowMouseGrab(_this, window, SDL_TRUE);
windata->wm_lastx = evt->cx;
windata->wm_lasty = evt->cy;
}
@@ -359,9 +358,9 @@ DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx, ch + dy));
}
}
- SDL_DFB_CHECK(dfbwin->UngrabPointer(dfbwin));
- if (gwindata != NULL)
- SDL_DFB_CHECK(gwindata->dfbwin->GrabPointer(gwindata->dfbwin));
+ DirectFB_SetWindowMouseGrab(_this, window, SDL_FALSE);
+ if (grabbed_window != NULL)
+ DirectFB_SetWindowMouseGrab(_this, grabbed_window, SDL_TRUE);
windata->wm_grab = WM_POS_NONE;
return 1;
}
diff --git a/src/video/directfb/SDL_DirectFB_events.c b/src/video/directfb/SDL_DirectFB_events.c
index b65ce56..1d4c199 100644
--- a/src/video/directfb/SDL_DirectFB_events.c
+++ b/src/video/directfb/SDL_DirectFB_events.c
@@ -312,15 +312,16 @@ ProcessInputEvent(_THIS, DFBInputEvent * ievt)
int kbd_idx;
Uint32 unicode;
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
+ SDL_Window* grabbed_window = SDL_GetGrabbedWindow();
if (!devdata->use_linux_input) {
if (ievt->type == DIET_AXISMOTION) {
- if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
+ if ((grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
if (ievt->axis == DIAI_X)
- SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
+ SDL_SendMouseMotion_ex(grabbed_window, ievt->device_id, 1,
ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y)
- SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
+ SDL_SendMouseMotion_ex(grabbed_window, ievt->device_id, 1, 0,
ievt->axisrel, 0);
}
}
@@ -339,7 +340,7 @@ ProcessInputEvent(_THIS, DFBInputEvent * ievt)
SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id);
SDL_Window *window = SDL_GetWindowFromID(mouse->focus);
#else
- SDL_Window *window = devdata->grabbed_window;
+ SDL_Window *window = grabbed_window;
#endif
if (window) {
DFB_WindowData *windata =
@@ -359,10 +360,10 @@ ProcessInputEvent(_THIS, DFBInputEvent * ievt)
}
} else if (ievt->flags & DIEF_AXISREL) {
if (ievt->axis == DIAI_X)
- SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
+ SDL_SendMouseMotion_ex(grabbed_window, ievt->device_id, 1,
ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y)
- SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
+ SDL_SendMouseMotion_ex(grabbed_window, ievt->device_id, 1, 0,
ievt->axisrel, 0);
}
break;
@@ -386,19 +387,19 @@ ProcessInputEvent(_THIS, DFBInputEvent * ievt)
break;
case DIET_BUTTONPRESS:
if (ievt->buttons & DIBM_LEFT)
- SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1);
+ SDL_SendMouseButton_ex(grabbed_window, ievt->device_id, SDL_PRESSED, 1);
if (ievt->buttons & DIBM_MIDDLE)
- SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 2);
+ SDL_SendMouseButton_ex(grabbed_window, ievt->device_id, SDL_PRESSED, 2);
if (ievt->buttons & DIBM_RIGHT)
- SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 3);
+ SDL_SendMouseButton_ex(grabbed_window, ievt->device_id, SDL_PRESSED, 3);
break;
case DIET_BUTTONRELEASE:
if (!(ievt->buttons & DIBM_LEFT))
- SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 1);
+ SDL_SendMouseButton_ex(grabbed_window, ievt->device_id, SDL_RELEASED, 1);
if (!(ievt->buttons & DIBM_MIDDLE))
- SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 2);
+ SDL_SendMouseButton_ex(grabbed_window, ievt->device_id, SDL_RELEASED, 2);
if (!(ievt->buttons & DIBM_RIGHT))
- SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 3);
+ SDL_SendMouseButton_ex(grabbed_window, ievt->device_id, SDL_RELEASED, 3);
break;
default:
break; /* please gcc */
diff --git a/src/video/directfb/SDL_DirectFB_video.c b/src/video/directfb/SDL_DirectFB_video.c
index 452ea60..cca2fd7 100644
--- a/src/video/directfb/SDL_DirectFB_video.c
+++ b/src/video/directfb/SDL_DirectFB_video.c
@@ -114,6 +114,7 @@ DirectFB_CreateDevice(int devindex)
device->MinimizeWindow = DirectFB_MinimizeWindow;
device->RestoreWindow = DirectFB_RestoreWindow;
device->SetWindowMouseGrab = DirectFB_SetWindowMouseGrab;
+ device->SetWindowKeyboardGrab = DirectFB_SetWindowKeyboardGrab;
device->DestroyWindow = DirectFB_DestroyWindow;
device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
@@ -260,7 +261,6 @@ DirectFB_VideoInit(_THIS)
devdata->dfb = dfb;
devdata->firstwin = NULL;
- devdata->grabbed_window = NULL;
_this->driverdata = devdata;
diff --git a/src/video/directfb/SDL_DirectFB_video.h b/src/video/directfb/SDL_DirectFB_video.h
index eff1c86..e6a840e 100644
--- a/src/video/directfb/SDL_DirectFB_video.h
+++ b/src/video/directfb/SDL_DirectFB_video.h
@@ -153,10 +153,6 @@ struct _DFB_DeviceData
int use_linux_input;
int has_own_wm;
-
- /* window grab */
- SDL_Window *grabbed_window;
-
/* global events */
IDirectFBEventBuffer *events;
};
diff --git a/src/video/directfb/SDL_DirectFB_window.c b/src/video/directfb/SDL_DirectFB_window.c
index 5cebac2..b8c78fe 100644
--- a/src/video/directfb/SDL_DirectFB_window.c
+++ b/src/video/directfb/SDL_DirectFB_window.c
@@ -385,23 +385,24 @@ DirectFB_RestoreWindow(_THIS, SDL_Window * window)
void
DirectFB_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{
- SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
- DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
- if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
- if (gwindata != NULL)
- {
- SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
- SDL_DFB_CHECK(gwindata->dfbwin->UngrabKeyboard(gwindata->dfbwin));
- }
+ if (grabbed) {
SDL_DFB_CHECK(windata->dfbwin->GrabPointer(windata->dfbwin));
- SDL_DFB_CHECK(windata->dfbwin->GrabKeyboard(windata->dfbwin));
- devdata->grabbed_window = window;
} else {
SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
+ }
+}
+
+void
+DirectFB_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+ SDL_DFB_WINDOWDATA(window);
+
+ if (grabbed) {
+ SDL_DFB_CHECK(windata->dfbwin->GrabKeyboard(windata->dfbwin));
+ } else {
SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
- devdata->grabbed_window = NULL;
}
}
diff --git a/src/video/directfb/SDL_DirectFB_window.h b/src/video/directfb/SDL_DirectFB_window.h
index 6e0c09d..e3135c5 100644
--- a/src/video/directfb/SDL_DirectFB_window.h
+++ b/src/video/directfb/SDL_DirectFB_window.h
@@ -70,6 +70,7 @@ extern void DirectFB_MaximizeWindow(_THIS, SDL_Window * window);
extern void DirectFB_MinimizeWindow(_THIS, SDL_Window * window);
extern void DirectFB_RestoreWindow(_THIS, SDL_Window * window);
extern void DirectFB_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+extern void DirectFB_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void DirectFB_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info);