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
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;
}

View File

@ -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 */

View File

@ -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;

View File

@ -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;
};

View File

@ -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;
}
}

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_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);