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.
This commit is contained in:
Cameron Gutman 2021-01-26 00:05:01 -06:00
parent de85d61256
commit a1d288bea1
6 changed files with 34 additions and 36 deletions

View File

@ -287,9 +287,8 @@ WMPos(DFB_WindowData * p, int x, int y)
int int
DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt) DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
{ {
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window); 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; IDirectFBWindow *dfbwin = windata->dfbwin;
DFBWindowOptions wopts; DFBWindowOptions wopts;
@ -327,9 +326,9 @@ DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
/* fall through */ /* fall through */
default: default:
windata->wm_grab = pos; windata->wm_grab = pos;
if (gwindata != NULL) if (grabbed_window != NULL)
SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin)); DirectFB_SetWindowMouseGrab(_this, grabbed_window, SDL_FALSE);
SDL_DFB_CHECK(dfbwin->GrabPointer(dfbwin)); DirectFB_SetWindowMouseGrab(_this, window, SDL_TRUE);
windata->wm_lastx = evt->cx; windata->wm_lastx = evt->cx;
windata->wm_lasty = evt->cy; 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->Resize(dfbwin, cw + dx, ch + dy));
} }
} }
SDL_DFB_CHECK(dfbwin->UngrabPointer(dfbwin)); DirectFB_SetWindowMouseGrab(_this, window, SDL_FALSE);
if (gwindata != NULL) if (grabbed_window != NULL)
SDL_DFB_CHECK(gwindata->dfbwin->GrabPointer(gwindata->dfbwin)); DirectFB_SetWindowMouseGrab(_this, grabbed_window, SDL_TRUE);
windata->wm_grab = WM_POS_NONE; windata->wm_grab = WM_POS_NONE;
return 1; return 1;
} }

View File

@ -312,15 +312,16 @@ ProcessInputEvent(_THIS, DFBInputEvent * ievt)
int kbd_idx; int kbd_idx;
Uint32 unicode; Uint32 unicode;
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
SDL_Window* grabbed_window = SDL_GetGrabbedWindow();
if (!devdata->use_linux_input) { if (!devdata->use_linux_input) {
if (ievt->type == DIET_AXISMOTION) { 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) 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); ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y) 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); ievt->axisrel, 0);
} }
} }
@ -339,7 +340,7 @@ ProcessInputEvent(_THIS, DFBInputEvent * ievt)
SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id); SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id);
SDL_Window *window = SDL_GetWindowFromID(mouse->focus); SDL_Window *window = SDL_GetWindowFromID(mouse->focus);
#else #else
SDL_Window *window = devdata->grabbed_window; SDL_Window *window = grabbed_window;
#endif #endif
if (window) { if (window) {
DFB_WindowData *windata = DFB_WindowData *windata =
@ -359,10 +360,10 @@ ProcessInputEvent(_THIS, DFBInputEvent * ievt)
} }
} else if (ievt->flags & DIEF_AXISREL) { } else if (ievt->flags & DIEF_AXISREL) {
if (ievt->axis == DIAI_X) 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); ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y) 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); ievt->axisrel, 0);
} }
break; break;
@ -386,19 +387,19 @@ ProcessInputEvent(_THIS, DFBInputEvent * ievt)
break; break;
case DIET_BUTTONPRESS: case DIET_BUTTONPRESS:
if (ievt->buttons & DIBM_LEFT) 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) 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) 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; break;
case DIET_BUTTONRELEASE: case DIET_BUTTONRELEASE:
if (!(ievt->buttons & DIBM_LEFT)) 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)) 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)) 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; break;
default: default:
break; /* please gcc */ break; /* please gcc */

View File

@ -114,6 +114,7 @@ DirectFB_CreateDevice(int devindex)
device->MinimizeWindow = DirectFB_MinimizeWindow; device->MinimizeWindow = DirectFB_MinimizeWindow;
device->RestoreWindow = DirectFB_RestoreWindow; device->RestoreWindow = DirectFB_RestoreWindow;
device->SetWindowMouseGrab = DirectFB_SetWindowMouseGrab; device->SetWindowMouseGrab = DirectFB_SetWindowMouseGrab;
device->SetWindowKeyboardGrab = DirectFB_SetWindowKeyboardGrab;
device->DestroyWindow = DirectFB_DestroyWindow; device->DestroyWindow = DirectFB_DestroyWindow;
device->GetWindowWMInfo = DirectFB_GetWindowWMInfo; device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
@ -260,7 +261,6 @@ DirectFB_VideoInit(_THIS)
devdata->dfb = dfb; devdata->dfb = dfb;
devdata->firstwin = NULL; devdata->firstwin = NULL;
devdata->grabbed_window = NULL;
_this->driverdata = devdata; _this->driverdata = devdata;

View File

@ -153,10 +153,6 @@ struct _DFB_DeviceData
int use_linux_input; int use_linux_input;
int has_own_wm; int has_own_wm;
/* window grab */
SDL_Window *grabbed_window;
/* global events */ /* global events */
IDirectFBEventBuffer *events; IDirectFBEventBuffer *events;
}; };

View File

@ -385,23 +385,24 @@ DirectFB_RestoreWindow(_THIS, SDL_Window * window)
void void
DirectFB_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed) DirectFB_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{ {
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window); 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 (grabbed) {
if (gwindata != NULL)
{
SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
SDL_DFB_CHECK(gwindata->dfbwin->UngrabKeyboard(gwindata->dfbwin));
}
SDL_DFB_CHECK(windata->dfbwin->GrabPointer(windata->dfbwin)); SDL_DFB_CHECK(windata->dfbwin->GrabPointer(windata->dfbwin));
SDL_DFB_CHECK(windata->dfbwin->GrabKeyboard(windata->dfbwin));
devdata->grabbed_window = window;
} else { } else {
SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin)); 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)); SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
devdata->grabbed_window = NULL;
} }
} }

View File

@ -70,6 +70,7 @@ extern void DirectFB_MaximizeWindow(_THIS, SDL_Window * window);
extern void DirectFB_MinimizeWindow(_THIS, SDL_Window * window); extern void DirectFB_MinimizeWindow(_THIS, SDL_Window * window);
extern void DirectFB_RestoreWindow(_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_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 void DirectFB_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window, extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info); struct SDL_SysWMinfo *info);