mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-01-09 13:53:58 +00:00
[client] x11: use raw keyboard and mouse button press events
This commit is contained in:
parent
b87004c597
commit
f9faa0542b
2 changed files with 52 additions and 28 deletions
|
@ -40,6 +40,8 @@ struct X11DSState
|
||||||
|
|
||||||
bool pointerGrabbed;
|
bool pointerGrabbed;
|
||||||
bool keyboardGrabbed;
|
bool keyboardGrabbed;
|
||||||
|
bool entered;
|
||||||
|
bool focused;
|
||||||
|
|
||||||
// clipboard members
|
// clipboard members
|
||||||
Atom aSelection;
|
Atom aSelection;
|
||||||
|
@ -98,7 +100,8 @@ static bool x11Init(SDL_SysWMinfo * info)
|
||||||
XQueryExtension(x11.display, "XInputExtension", &x11.xinputOp, &event, &error);
|
XQueryExtension(x11.display, "XInputExtension", &x11.xinputOp, &event, &error);
|
||||||
|
|
||||||
int num_masks;
|
int num_masks;
|
||||||
XIEventMask * mask = XIGetSelectedEvents(x11.display, x11.window, &num_masks);
|
XIEventMask * mask = XIGetSelectedEvents(x11.display,
|
||||||
|
DefaultRootWindow(x11.display), &num_masks);
|
||||||
if (!mask)
|
if (!mask)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to get the XInput event mask");
|
DEBUG_ERROR("Failed to get the XInput event mask");
|
||||||
|
@ -107,14 +110,15 @@ static bool x11Init(SDL_SysWMinfo * info)
|
||||||
|
|
||||||
for(int i = 0; i < num_masks; ++i)
|
for(int i = 0; i < num_masks; ++i)
|
||||||
{
|
{
|
||||||
XISetMask(mask[i].mask, XI_ButtonPress );
|
XISetMask(mask[i].mask, XI_RawButtonPress );
|
||||||
XISetMask(mask[i].mask, XI_ButtonRelease);
|
XISetMask(mask[i].mask, XI_RawButtonRelease);
|
||||||
XISetMask(mask[i].mask, XI_Motion );
|
XISetMask(mask[i].mask, XI_RawMotion );
|
||||||
XISetMask(mask[i].mask, XI_KeyPress );
|
XISetMask(mask[i].mask, XI_RawKeyPress );
|
||||||
XISetMask(mask[i].mask, XI_KeyRelease );
|
XISetMask(mask[i].mask, XI_RawKeyRelease );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (XISelectEvents(x11.display, x11.window, mask, num_masks) != Success)
|
if (XISelectEvents(x11.display, DefaultRootWindow(x11.display),
|
||||||
|
mask, num_masks) != Success)
|
||||||
{
|
{
|
||||||
XFree(mask);
|
XFree(mask);
|
||||||
DEBUG_ERROR("Failed to select the xinput events");
|
DEBUG_ERROR("Failed to select the xinput events");
|
||||||
|
@ -212,6 +216,8 @@ static bool x11EventFilter(SDL_Event * event)
|
||||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||||
case SDL_WINDOWEVENT_RESIZED:
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
case SDL_WINDOWEVENT_CLOSE:
|
case SDL_WINDOWEVENT_CLOSE:
|
||||||
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||||
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -254,6 +260,16 @@ static bool x11EventFilter(SDL_Event * event)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case FocusIn:
|
||||||
|
x11.focused = true;
|
||||||
|
app_handleFocusEvent(true);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case FocusOut:
|
||||||
|
x11.focused = false;
|
||||||
|
app_handleFocusEvent(false);
|
||||||
|
return true;
|
||||||
|
|
||||||
case EnterNotify:
|
case EnterNotify:
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
@ -268,6 +284,7 @@ static bool x11EventFilter(SDL_Event * event)
|
||||||
|
|
||||||
app_updateCursorPos(x, y);
|
app_updateCursorPos(x, y);
|
||||||
app_handleWindowEnter();
|
app_handleWindowEnter();
|
||||||
|
x11.entered = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,6 +304,7 @@ static bool x11EventFilter(SDL_Event * event)
|
||||||
|
|
||||||
app_updateCursorPos(x, y);
|
app_updateCursorPos(x, y);
|
||||||
app_handleWindowLeave();
|
app_handleWindowLeave();
|
||||||
|
x11.entered = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,53 +319,51 @@ static bool x11EventFilter(SDL_Event * event)
|
||||||
|
|
||||||
switch(cookie->evtype)
|
switch(cookie->evtype)
|
||||||
{
|
{
|
||||||
case XI_KeyPress:
|
case XI_RawKeyPress:
|
||||||
{
|
{
|
||||||
XIDeviceEvent *device = cookie->data;
|
if (!x11.focused)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
XIRawEvent *device = cookie->data;
|
||||||
app_handleKeyPress(device->detail - 8);
|
app_handleKeyPress(device->detail - 8);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case XI_KeyRelease:
|
case XI_RawKeyRelease:
|
||||||
{
|
{
|
||||||
XIDeviceEvent *device = cookie->data;
|
if (!x11.focused)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
XIRawEvent *device = cookie->data;
|
||||||
app_handleKeyRelease(device->detail - 8);
|
app_handleKeyRelease(device->detail - 8);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case XI_ButtonPress:
|
case XI_RawButtonPress:
|
||||||
{
|
{
|
||||||
XIDeviceEvent *device = cookie->data;
|
if (!x11.focused || !x11.entered)
|
||||||
app_updateCursorPos(device->event_x, device->event_y);
|
return true;
|
||||||
|
|
||||||
|
XIRawEvent *device = cookie->data;
|
||||||
app_handleButtonPress(
|
app_handleButtonPress(
|
||||||
device->detail > 5 ? device->detail - 2 : device->detail);
|
device->detail > 5 ? device->detail - 2 : device->detail);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case XI_ButtonRelease:
|
case XI_RawButtonRelease:
|
||||||
{
|
{
|
||||||
XIDeviceEvent *device = cookie->data;
|
if (!x11.focused || !x11.entered)
|
||||||
app_updateCursorPos(device->event_x, device->event_y);
|
return true;
|
||||||
|
|
||||||
|
XIRawEvent *device = cookie->data;
|
||||||
app_handleButtonRelease(
|
app_handleButtonRelease(
|
||||||
device->detail > 5 ? device->detail - 2 : device->detail);
|
device->detail > 5 ? device->detail - 2 : device->detail);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case XI_Motion:
|
|
||||||
{
|
|
||||||
if (!app_cursorInWindow())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
XIDeviceEvent *device = cookie->data;
|
|
||||||
app_updateCursorPos(device->event_x, device->event_y);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case XI_RawMotion:
|
case XI_RawMotion:
|
||||||
{
|
{
|
||||||
if (!app_cursorInWindow())
|
if (!x11.focused || !x11.entered)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
XIRawEvent *raw = cookie->data;
|
XIRawEvent *raw = cookie->data;
|
||||||
|
|
|
@ -71,6 +71,7 @@ struct Inst
|
||||||
EGL_Alert * alert; // the alert display
|
EGL_Alert * alert; // the alert display
|
||||||
|
|
||||||
LG_RendererFormat format;
|
LG_RendererFormat format;
|
||||||
|
bool formatValid;
|
||||||
bool start;
|
bool start;
|
||||||
uint64_t waitFadeTime;
|
uint64_t waitFadeTime;
|
||||||
bool waitDone;
|
bool waitDone;
|
||||||
|
@ -266,6 +267,9 @@ void egl_on_restart(void * opaque)
|
||||||
|
|
||||||
static void egl_calc_mouse_size(struct Inst * this)
|
static void egl_calc_mouse_size(struct Inst * this)
|
||||||
{
|
{
|
||||||
|
if (!this->formatValid)
|
||||||
|
return;
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
switch(this->format.rotate)
|
switch(this->format.rotate)
|
||||||
{
|
{
|
||||||
|
@ -308,6 +312,9 @@ static void egl_calc_mouse_size(struct Inst * this)
|
||||||
|
|
||||||
static void egl_calc_mouse_state(struct Inst * this)
|
static void egl_calc_mouse_state(struct Inst * this)
|
||||||
{
|
{
|
||||||
|
if (!this->formatValid)
|
||||||
|
return;
|
||||||
|
|
||||||
switch((this->format.rotate + this->rotate) % LG_ROTATE_MAX)
|
switch((this->format.rotate + this->rotate) % LG_ROTATE_MAX)
|
||||||
{
|
{
|
||||||
case LG_ROTATE_0:
|
case LG_ROTATE_0:
|
||||||
|
@ -395,6 +402,7 @@ bool egl_on_frame_format(void * opaque, const LG_RendererFormat format, bool use
|
||||||
{
|
{
|
||||||
struct Inst * this = (struct Inst *)opaque;
|
struct Inst * this = (struct Inst *)opaque;
|
||||||
memcpy(&this->format, &format, sizeof(LG_RendererFormat));
|
memcpy(&this->format, &format, sizeof(LG_RendererFormat));
|
||||||
|
this->formatValid = true;
|
||||||
|
|
||||||
/* this event runs in a second thread so we need to init it here */
|
/* this event runs in a second thread so we need to init it here */
|
||||||
if (!this->frameContext)
|
if (!this->frameContext)
|
||||||
|
|
Loading…
Reference in a new issue