mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-21 06:48:13 +00:00
[client] ds: refactor app and cursor state into app.c and core.c
This commit is contained in:
@@ -30,6 +30,12 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
#define RESIZE_TIMEOUT (10 * 1000) // 10ms
|
||||
|
||||
bool core_inputEnabled(void)
|
||||
{
|
||||
return g_params.useSpiceInput && !g_state.ignoreInput &&
|
||||
((g_cursor.grab && g_params.captureInputOnly) || !g_params.captureInputOnly);
|
||||
}
|
||||
|
||||
void core_setCursorInView(bool enable)
|
||||
{
|
||||
// if the state has not changed, don't do anything else
|
||||
@@ -291,3 +297,172 @@ void core_stopFrameThread(void)
|
||||
|
||||
g_state.frameThread = NULL;
|
||||
}
|
||||
|
||||
void core_handleMouseGrabbed(double ex, double ey)
|
||||
{
|
||||
if (!core_inputEnabled())
|
||||
return;
|
||||
|
||||
int x, y;
|
||||
if (g_params.rawMouse && !g_cursor.sens)
|
||||
{
|
||||
/* raw unscaled input are always round numbers */
|
||||
x = floor(ex);
|
||||
y = floor(ey);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* apply sensitivity */
|
||||
ex = (ex / 10.0) * (g_cursor.sens + 10);
|
||||
ey = (ey / 10.0) * (g_cursor.sens + 10);
|
||||
util_cursorToInt(ex, ey, &x, &y);
|
||||
}
|
||||
|
||||
if (x == 0 && y == 0)
|
||||
return;
|
||||
|
||||
if (!spice_mouse_motion(x, y))
|
||||
DEBUG_ERROR("failed to send mouse motion message");
|
||||
}
|
||||
|
||||
void core_handleMouseNormal(double ex, double ey)
|
||||
{
|
||||
// prevent cursor handling outside of capture if the position is not known
|
||||
if (!g_cursor.guest.valid)
|
||||
return;
|
||||
|
||||
if (!core_inputEnabled())
|
||||
return;
|
||||
|
||||
/* scale the movement to the guest */
|
||||
if (g_cursor.useScale && g_params.scaleMouseInput)
|
||||
{
|
||||
ex *= g_cursor.scale.x / g_cursor.dpiScale;
|
||||
ey *= g_cursor.scale.y / g_cursor.dpiScale;
|
||||
}
|
||||
|
||||
bool testExit = true;
|
||||
if (!g_cursor.inView)
|
||||
{
|
||||
const bool inView =
|
||||
g_cursor.pos.x >= g_state.dstRect.x &&
|
||||
g_cursor.pos.x < g_state.dstRect.x + g_state.dstRect.w &&
|
||||
g_cursor.pos.y >= g_state.dstRect.y &&
|
||||
g_cursor.pos.y < g_state.dstRect.y + g_state.dstRect.h;
|
||||
|
||||
core_setCursorInView(inView);
|
||||
if (inView)
|
||||
g_cursor.realign = true;
|
||||
}
|
||||
|
||||
/* nothing to do if we are outside the viewport */
|
||||
if (!g_cursor.inView)
|
||||
return;
|
||||
|
||||
/*
|
||||
* do not pass mouse events to the guest if we do not have focus, this must be
|
||||
* done after the inView test has been performed so that when focus is gained
|
||||
* we know if we should be drawing the cursor.
|
||||
*/
|
||||
if (!g_state.focused)
|
||||
return;
|
||||
|
||||
/* if we have been instructed to realign */
|
||||
if (g_cursor.realign)
|
||||
{
|
||||
g_cursor.realign = false;
|
||||
|
||||
struct DoublePoint guest;
|
||||
util_localCurToGuest(&guest);
|
||||
|
||||
/* add the difference to the offset */
|
||||
ex += guest.x - (g_cursor.guest.x + g_cursor.guest.hx);
|
||||
ey += guest.y - (g_cursor.guest.y + g_cursor.guest.hy);
|
||||
|
||||
/* don't test for an exit as we just entered, we can get into a enter/exit
|
||||
* loop otherwise */
|
||||
testExit = false;
|
||||
}
|
||||
|
||||
/* if we are in "autoCapture" and the delta was large don't test for exit */
|
||||
if (g_params.autoCapture &&
|
||||
(fabs(ex) > 100.0 / g_cursor.scale.x || fabs(ey) > 100.0 / g_cursor.scale.y))
|
||||
testExit = false;
|
||||
|
||||
/* if any buttons are held we should not allow exit to happen */
|
||||
if (g_cursor.buttons)
|
||||
testExit = false;
|
||||
|
||||
if (testExit)
|
||||
{
|
||||
/* translate the move to the guests orientation */
|
||||
struct DoublePoint move = {.x = ex, .y = ey};
|
||||
util_rotatePoint(&move);
|
||||
|
||||
/* translate the guests position to our coordinate space */
|
||||
struct DoublePoint local;
|
||||
util_guestCurToLocal(&local);
|
||||
|
||||
/* check if the move would push the cursor outside the guest's viewport */
|
||||
if (
|
||||
local.x + move.x < g_state.dstRect.x ||
|
||||
local.y + move.y < g_state.dstRect.y ||
|
||||
local.x + move.x >= g_state.dstRect.x + g_state.dstRect.w ||
|
||||
local.y + move.y >= g_state.dstRect.y + g_state.dstRect.h)
|
||||
{
|
||||
local.x += move.x;
|
||||
local.y += move.y;
|
||||
const int tx = (local.x <= 0.0) ? floor(local.x) : ceil(local.x);
|
||||
const int ty = (local.y <= 0.0) ? floor(local.y) : ceil(local.y);
|
||||
|
||||
if (core_isValidPointerPos(
|
||||
g_state.windowPos.x + g_state.border.left + tx,
|
||||
g_state.windowPos.y + g_state.border.top + ty))
|
||||
{
|
||||
core_setCursorInView(false);
|
||||
|
||||
/* preempt the window leave flag if the warp will leave our window */
|
||||
if (tx < 0 || ty < 0 || tx > g_state.windowW || ty > g_state.windowH)
|
||||
g_cursor.inWindow = false;
|
||||
|
||||
/* ungrab the pointer and move the local cursor to the exit point */
|
||||
g_state.ds->ungrabPointer();
|
||||
core_warpPointer(tx, ty, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int x, y;
|
||||
util_cursorToInt(ex, ey, &x, &y);
|
||||
|
||||
if (x == 0 && y == 0)
|
||||
return;
|
||||
|
||||
if (g_params.autoCapture)
|
||||
{
|
||||
g_cursor.delta.x += x;
|
||||
g_cursor.delta.y += y;
|
||||
|
||||
if (fabs(g_cursor.delta.x) > 50.0 || fabs(g_cursor.delta.y) > 50.0)
|
||||
{
|
||||
g_cursor.delta.x = 0;
|
||||
g_cursor.delta.y = 0;
|
||||
core_warpPointer(g_state.windowCX, g_state.windowCY, false);
|
||||
}
|
||||
|
||||
g_cursor.guest.x = g_state.srcSize.x / 2;
|
||||
g_cursor.guest.y = g_state.srcSize.y / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* assume the mouse will move to the location we attempt to move it to so we
|
||||
* avoid warp out of window issues. The cursorThread will correct this if
|
||||
* wrong after the movement has ocurred on the guest */
|
||||
g_cursor.guest.x += x;
|
||||
g_cursor.guest.y += y;
|
||||
}
|
||||
|
||||
if (!spice_mouse_motion(x, y))
|
||||
DEBUG_ERROR("failed to send mouse motion message");
|
||||
}
|
||||
|
Reference in New Issue
Block a user