From bf583290a4f2685d048e47a822fc1fe8de10d4bb Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 25 Jan 2021 19:58:36 +1100 Subject: [PATCH] [client/common] restructure project in prep for full SDL removal --- client/CMakeLists.txt | 5 +- client/displayservers/SDL/sdl.c | 4 +- client/displayservers/X11/x11.c | 4 +- client/include/app.h | 4 +- client/include/interface/displayserver.h | 8 +- client/include/util.h | 37 + client/renderers/EGL/egl.c | 2 +- client/renderers/EGL/fps.c | 1 - client/renderers/EGL/model.c | 3 +- client/renderers/EGL/shader.c | 8 +- client/renderers/EGL/splash.c | 1 - client/renderers/EGL/texture.c | 1 - client/src/app.c | 537 +++++++- client/src/clipboard.c | 116 ++ .../lg-decoders.h => src/clipboard.h} | 22 +- client/src/config.c | 132 +- client/src/core.c | 262 ++++ client/{include/utils.h => src/core.h} | 17 +- client/src/kb.c | 148 +++ client/src/kb.h | 126 +- client/src/main.c | 1145 +---------------- client/src/main.h | 14 +- client/src/util.c | 222 ++++ client/src/utils.c | 70 - common/include/common/KVMFR.h | 46 +- common/include/common/crash.h | 7 +- common/include/common/debug.h | 5 + common/include/common/dpi.h | 5 + common/include/common/event.h | 7 +- common/include/common/framebuffer.h | 7 +- common/include/common/ivshmem.h | 7 +- common/include/common/locking.h | 8 +- common/include/common/memcpySSE.h | 135 -- common/include/common/option.h | 13 +- common/include/common/stringlist.h | 7 +- common/include/common/stringutils.h | 9 +- common/include/common/sysinfo.h | 7 +- common/include/common/thread.h | 10 +- common/include/common/types.h | 58 + common/include/common/version.h | 24 + common/include/common/windebug.h | 9 +- common/src/memcpySSE.asm | 237 ---- 42 files changed, 1668 insertions(+), 1822 deletions(-) create mode 100644 client/include/util.h create mode 100644 client/src/clipboard.c rename client/{include/lg-decoders.h => src/clipboard.h} (62%) create mode 100644 client/src/core.c rename client/{include/utils.h => src/core.h} (70%) create mode 100644 client/src/kb.c create mode 100644 client/src/util.c delete mode 100644 client/src/utils.c delete mode 100644 common/include/common/memcpySSE.h create mode 100644 common/include/common/types.h delete mode 100644 common/src/memcpySSE.asm diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index bc13a44a..a1ad3ba0 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -99,11 +99,14 @@ link_libraries( set(SOURCES ${CMAKE_BINARY_DIR}/version.c src/main.c + src/core.c src/app.c src/config.c src/lg-renderer.c src/ll.c - src/utils.c + src/util.c + src/clipboard.c + src/kb.c ) add_subdirectory("${PROJECT_TOP}/common" "${CMAKE_BINARY_DIR}/common" ) diff --git a/client/displayservers/SDL/sdl.c b/client/displayservers/SDL/sdl.c index 67816966..71766519 100644 --- a/client/displayservers/SDL/sdl.c +++ b/client/displayservers/SDL/sdl.c @@ -128,12 +128,12 @@ static bool sdlEventFilter(SDL_Event * event) switch(event->window.event) { case SDL_WINDOWEVENT_ENTER: - app_handleWindowEnter(); + app_handleEnterEvent(true); return true; case SDL_WINDOWEVENT_LEAVE: sdl.exiting = false; - app_handleWindowLeave(); + app_handleEnterEvent(false); return true; case SDL_WINDOWEVENT_FOCUS_GAINED: diff --git a/client/displayservers/X11/x11.c b/client/displayservers/X11/x11.c index e069659d..74b595dd 100644 --- a/client/displayservers/X11/x11.c +++ b/client/displayservers/X11/x11.c @@ -372,7 +372,7 @@ static bool x11EventFilter(SDL_Event * event) XIEnterEvent *xie = cookie->data; app_updateCursorPos(xie->event_x, xie->event_y); - app_handleWindowEnter(); + app_handleEnterEvent(true); x11.entered = true; return true; } @@ -384,7 +384,7 @@ static bool x11EventFilter(SDL_Event * event) XILeaveEvent *xie = cookie->data; app_updateCursorPos(xie->event_x, xie->event_y); - app_handleWindowLeave(); + app_handleEnterEvent(false); x11.entered = false; return true; } diff --git a/client/include/app.h b/client/include/app.h index 2ae2ad37..9d5ea1c9 100644 --- a/client/include/app.h +++ b/client/include/app.h @@ -21,7 +21,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "interface/displayserver.h" - SDL_Window * app_getWindow(void); bool app_getProp(LG_DSProperty prop, void * ret); @@ -39,8 +38,7 @@ void app_handleButtonPress(int button); void app_handleButtonRelease(int button); void app_handleKeyPress(int scancode); void app_handleKeyRelease(int scancode); -void app_handleWindowEnter(void); -void app_handleWindowLeave(void); +void app_handleEnterEvent(bool entered); void app_handleFocusEvent(bool focused); void app_handleCloseEvent(void); diff --git a/client/include/interface/displayserver.h b/client/include/interface/displayserver.h index abb9ccf7..5ca82c4a 100644 --- a/client/include/interface/displayserver.h +++ b/client/include/interface/displayserver.h @@ -105,10 +105,10 @@ struct LG_DisplayServerOps void (*uninhibitIdle)(); /* clipboard support */ - bool (* cbInit)(void); - void (* cbNotice)(LG_ClipboardData type); - void (* cbRelease)(void); - void (* cbRequest)(LG_ClipboardData type); + bool (*cbInit)(void); + void (*cbNotice)(LG_ClipboardData type); + void (*cbRelease)(void); + void (*cbRequest)(LG_ClipboardData type); }; #endif diff --git a/client/include/util.h b/client/include/util.h new file mode 100644 index 00000000..8657d9a6 --- /dev/null +++ b/client/include/util.h @@ -0,0 +1,37 @@ +/* +Looking Glass - KVM FrameRelay (KVMFR) Client +Copyright (C) 2017-2019 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _H_LG_UTIL_ +#define _H_LG_UTIL_ + +#include +#include +#include "common/types.h" + +// reads the specified file into a new buffer +// the callee must free the buffer +bool util_fileGetContents(const char * filename, char ** buffer, size_t * length); + +void util_cursorToInt(double ex, double ey, int *x, int *y); +bool util_guestCurToLocal(struct DoublePoint *local); +void util_localCurToGuest(struct DoublePoint *guest); +void util_rotatePoint(struct DoublePoint *point); +bool util_isValidCursorLocation(int x, int y); + +#endif diff --git a/client/renderers/EGL/egl.c b/client/renderers/EGL/egl.c index b7a56448..4bb7ab2b 100644 --- a/client/renderers/EGL/egl.c +++ b/client/renderers/EGL/egl.c @@ -24,7 +24,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "common/sysinfo.h" #include "common/time.h" #include "common/locking.h" -#include "utils.h" +#include "util.h" #include "dynamic/fonts.h" #include diff --git a/client/renderers/EGL/fps.c b/client/renderers/EGL/fps.c index d3b1f8bc..8a10dc4c 100644 --- a/client/renderers/EGL/fps.c +++ b/client/renderers/EGL/fps.c @@ -19,7 +19,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "fps.h" #include "common/debug.h" -#include "utils.h" #include "texture.h" #include "shader.h" diff --git a/client/renderers/EGL/model.c b/client/renderers/EGL/model.c index 1c6a41e0..8994353d 100644 --- a/client/renderers/EGL/model.c +++ b/client/renderers/EGL/model.c @@ -22,7 +22,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "texture.h" #include "common/debug.h" -#include "utils.h" #include "ll.h" #include @@ -216,4 +215,4 @@ void update_uniform_bindings(EGL_Model * model) const int count = egl_texture_count(model->texture); egl_shader_associate_textures(model->shader, count); -} \ No newline at end of file +} diff --git a/client/renderers/EGL/shader.c b/client/renderers/EGL/shader.c index 22df986f..2ae033ff 100644 --- a/client/renderers/EGL/shader.c +++ b/client/renderers/EGL/shader.c @@ -19,7 +19,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "shader.h" #include "common/debug.h" -#include "utils.h" +#include "util.h" #include #include @@ -63,7 +63,7 @@ bool egl_shader_load(EGL_Shader * this, const char * vertex_file, const char * f char * vertex_code, * fragment_code; size_t vertex_size, fragment_size; - if (!file_get_contents(vertex_file, &vertex_code, &vertex_size)) + if (!util_fileGetContents(vertex_file, &vertex_code, &vertex_size)) { DEBUG_ERROR("Failed to read vertex shader"); return false; @@ -71,7 +71,7 @@ bool egl_shader_load(EGL_Shader * this, const char * vertex_file, const char * f DEBUG_INFO("Loaded vertex shader: %s", vertex_file); - if (!file_get_contents(fragment_file, &fragment_code, &fragment_size)) + if (!util_fileGetContents(fragment_file, &fragment_code, &fragment_size)) { DEBUG_ERROR("Failed to read fragment shader"); free(vertex_code); @@ -222,4 +222,4 @@ GLint egl_shader_get_uniform_location(EGL_Shader * this, const char * name) } return glGetUniformLocation(this->shader, name); -} \ No newline at end of file +} diff --git a/client/renderers/EGL/splash.c b/client/renderers/EGL/splash.c index eda71513..eeb81c84 100644 --- a/client/renderers/EGL/splash.c +++ b/client/renderers/EGL/splash.c @@ -19,7 +19,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "splash.h" #include "common/debug.h" -#include "utils.h" #include "draw.h" #include "texture.h" diff --git a/client/renderers/EGL/texture.c b/client/renderers/EGL/texture.c index 513fa28b..0715c9ca 100644 --- a/client/renderers/EGL/texture.c +++ b/client/renderers/EGL/texture.c @@ -21,7 +21,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "common/debug.h" #include "common/framebuffer.h" #include "dynprocs.h" -#include "utils.h" #include "egldebug.h" #include diff --git a/client/src/app.c b/client/src/app.c index 921f2b05..3901f79b 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -17,13 +17,22 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "app.h" + #include "main.h" +#include "core.h" +#include "util.h" +#include "clipboard.h" + +#include "ll.h" +#include "kb.h" + #include "common/debug.h" #include void app_alert(LG_MsgAlert type, const char * fmt, ...) { - if (!g_state.lgr || !params.showAlerts) + if (!g_state.lgr || !g_params.showAlerts) return; va_list args; @@ -73,3 +82,529 @@ void app_release_keybind(KeybindHandle * handle) free(*handle); *handle = NULL; } + +bool app_getProp(LG_DSProperty prop, void * ret) +{ + return g_state.ds->getProp(prop, ret); +} + +SDL_Window * app_getWindow(void) +{ + return g_state.window; +} + +bool app_inputEnabled(void) +{ + return g_params.useSpiceInput && !g_state.ignoreInput && + ((g_cursor.grab && g_params.captureInputOnly) || !g_params.captureInputOnly); +} + +bool app_cursorInWindow(void) +{ + return g_cursor.inWindow; +} + +bool app_cursorIsGrabbed(void) +{ + return g_cursor.grab; +} + +bool app_cursorWantsRaw(void) +{ + return g_params.rawMouse; +} + +void app_updateCursorPos(double x, double y) +{ + g_cursor.pos.x = x; + g_cursor.pos.y = y; + g_cursor.valid = true; +} + +void app_handleFocusEvent(bool focused) +{ + g_state.focused = focused; + if (!app_inputEnabled()) + return; + + if (!focused) + { + core_setGrabQuiet(false); + core_setCursorInView(false); + } + + g_cursor.realign = true; + g_state.ds->realignPointer(); +} + +void app_handleEnterEvent(bool entered) +{ + if (entered) + { + g_cursor.inWindow = true; + if (!app_inputEnabled()) + return; + + g_cursor.realign = true; + } + else + { + g_cursor.inWindow = false; + core_setCursorInView(false); + + if (!app_inputEnabled()) + return; + + if (!g_params.alwaysShowCursor) + g_cursor.draw = false; + g_cursor.redraw = true; + } +} + +void app_clipboardRelease(void) +{ + if (!g_params.clipboardToVM) + return; + + spice_clipboard_release(); +} + +void app_clipboardNotify(const LG_ClipboardData type, size_t size) +{ + if (!g_params.clipboardToVM) + return; + + if (type == LG_CLIPBOARD_DATA_NONE) + { + spice_clipboard_release(); + return; + } + + g_state.cbType = cb_lgTypeToSpiceType(type); + g_state.cbChunked = size > 0; + g_state.cbXfer = size; + + spice_clipboard_grab(g_state.cbType); + + if (size) + spice_clipboard_data_start(g_state.cbType, size); +} + +void app_clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size) +{ + if (!g_params.clipboardToVM) + return; + + if (g_state.cbChunked && size > g_state.cbXfer) + { + DEBUG_ERROR("refusing to send more then cbXfer bytes for chunked xfer"); + size = g_state.cbXfer; + } + + if (!g_state.cbChunked) + spice_clipboard_data_start(g_state.cbType, size); + + spice_clipboard_data(g_state.cbType, data, (uint32_t)size); + g_state.cbXfer -= size; +} + +void app_clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque) +{ + if (!g_params.clipboardToLocal) + return; + + struct CBRequest * cbr = (struct CBRequest *)malloc(sizeof(struct CBRequest)); + + cbr->type = g_state.cbType; + cbr->replyFn = replyFn; + cbr->opaque = opaque; + ll_push(g_state.cbRequestList, cbr); + + spice_clipboard_request(g_state.cbType); +} + +void spiceClipboardNotice(const SpiceDataType type) +{ + if (!g_params.clipboardToLocal) + return; + + if (!g_state.cbAvailable) + return; + + g_state.cbType = type; + g_state.ds->cbNotice(cb_spiceTypeToLGType(type)); +} + +void app_handleMouseGrabbed(double ex, double ey) +{ + if (!app_inputEnabled()) + return; + + int x, y; + if (g_params.rawMouse && !g_cursor.useScale) + { + /* 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 app_handleButtonPress(int button) +{ + if (!app_inputEnabled() || !g_cursor.inView) + return; + + g_cursor.buttons |= (1U << button); + + if (!spice_mouse_press(button)) + DEBUG_ERROR("SDL_MOUSEBUTTONDOWN: failed to send message"); +} + +void app_handleButtonRelease(int button) +{ + if (!app_inputEnabled()) + return; + + g_cursor.buttons &= ~(1U << button); + + if (!spice_mouse_release(button)) + DEBUG_ERROR("SDL_MOUSEBUTTONUP: failed to send message"); +} + +void app_handleKeyPress(int sc) +{ + if (sc == g_params.escapeKey && !g_state.escapeActive) + { + g_state.escapeActive = true; + g_state.escapeAction = -1; + return; + } + + if (g_state.escapeActive) + { + g_state.escapeAction = sc; + return; + } + + if (!app_inputEnabled()) + return; + + if (g_params.ignoreWindowsKeys && (sc == KEY_LEFTMETA || sc == KEY_RIGHTMETA)) + return; + + if (!g_state.keyDown[sc]) + { + uint32_t ps2 = xfree86_to_ps2[sc]; + if (!ps2) + return; + + if (spice_key_down(ps2)) + g_state.keyDown[sc] = true; + else + { + DEBUG_ERROR("SDL_KEYDOWN: failed to send message"); + return; + } + } +} + +void app_handleKeyRelease(int sc) +{ + if (g_state.escapeActive) + { + if (g_state.escapeAction == -1) + { + if (g_params.useSpiceInput) + core_setGrab(!g_cursor.grab); + } + else + { + KeybindHandle handle = g_state.bindings[sc]; + if (handle) + { + handle->callback(sc, handle->opaque); + return; + } + } + + if (sc == g_params.escapeKey) + g_state.escapeActive = false; + } + + if (!app_inputEnabled()) + return; + + // avoid sending key up events when we didn't send a down + if (!g_state.keyDown[sc]) + return; + + if (g_params.ignoreWindowsKeys && (sc == KEY_LEFTMETA || sc == KEY_RIGHTMETA)) + return; + + uint32_t ps2 = xfree86_to_ps2[sc]; + if (!ps2) + return; + + if (spice_key_up(ps2)) + g_state.keyDown[sc] = false; + else + { + DEBUG_ERROR("SDL_KEYUP: failed to send message"); + return; + } +} + +void app_handleMouseNormal(double ex, double ey) +{ + // prevent cursor handling outside of capture if the position is not known + if (!g_cursor.guest.valid) + return; + + if (!app_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 (util_isValidCursorLocation( + g_state.windowPos.x + g_state.border.x + tx, + g_state.windowPos.y + g_state.border.y + 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"); +} + + +// On some display servers normal cursor logic does not work due to the lack of +// cursor warp support. Instead, we attempt a best-effort emulation which works +// with a 1:1 mouse movement patch applied in the guest. For anything fancy, use +// capture mode. +void app_handleMouseBasic() +{ + /* do not pass mouse events to the guest if we do not have focus */ + if (!g_state.focused) + return; + + if (!app_inputEnabled()) + return; + + 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 (g_cursor.guest.dpiScale == 0) + return; + + double px = g_cursor.pos.x; + double py = g_cursor.pos.y; + + if (px < g_state.dstRect.x) + px = g_state.dstRect.x; + else if (px > g_state.dstRect.x + g_state.dstRect.w) + px = g_state.dstRect.x + g_state.dstRect.w; + + if (py < g_state.dstRect.y) + py = g_state.dstRect.y; + else if (py > g_state.dstRect.y + g_state.dstRect.h) + py = g_state.dstRect.y + g_state.dstRect.h; + + /* translate the guests position to our coordinate space */ + struct DoublePoint local; + util_guestCurToLocal(&local); + + int x = (int) round((px - local.x) / g_cursor.dpiScale); + int y = (int) round((py - local.y) / g_cursor.dpiScale); + + if (!x && !y) + return; + + g_cursor.guest.x += x; + g_cursor.guest.y += y; + + if (!spice_mouse_motion(x, y)) + DEBUG_ERROR("failed to send mouse motion message"); +} + +void app_updateWindowPos(int x, int y) +{ + g_state.windowPos.x = x; + g_state.windowPos.y = y; +} + +void app_handleResizeEvent(int w, int h) +{ + SDL_GetWindowBordersSize(g_state.window, + &g_state.border.y, + &g_state.border.x, + &g_state.border.h, + &g_state.border.w + ); + + /* don't do anything else if the window dimensions have not changed */ + if (g_state.windowW == w && g_state.windowH == h) + return; + + g_state.windowW = w; + g_state.windowH = h; + g_state.windowCX = w / 2; + g_state.windowCY = h / 2; + core_updatePositionInfo(); + + if (app_inputEnabled()) + { + /* if the window is moved/resized causing a loss of focus while grabbed, it + * makes it impossible to re-focus the window, so we quietly re-enter + * capture if we were already in it */ + if (g_cursor.grab) + { + core_setGrabQuiet(false); + core_setGrabQuiet(true); + } + core_alignToGuest(); + } +} + +void app_handleCloseEvent(void) +{ + if (!g_params.ignoreQuit || !g_cursor.inView) + g_state.state = APP_STATE_SHUTDOWN; +} diff --git a/client/src/clipboard.c b/client/src/clipboard.c new file mode 100644 index 00000000..5a4b1844 --- /dev/null +++ b/client/src/clipboard.c @@ -0,0 +1,116 @@ +/* +Looking Glass - KVM FrameRelay (KVMFR) Client +Copyright (C) 2017-2021 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "clipboard.h" + +#include "main.h" +#include "ll.h" + +#include "common/debug.h" + +LG_ClipboardData cb_spiceTypeToLGType(const SpiceDataType type) +{ + switch(type) + { + case SPICE_DATA_TEXT: return LG_CLIPBOARD_DATA_TEXT; break; + case SPICE_DATA_PNG : return LG_CLIPBOARD_DATA_PNG ; break; + case SPICE_DATA_BMP : return LG_CLIPBOARD_DATA_BMP ; break; + case SPICE_DATA_TIFF: return LG_CLIPBOARD_DATA_TIFF; break; + case SPICE_DATA_JPEG: return LG_CLIPBOARD_DATA_JPEG; break; + default: + DEBUG_ERROR("invalid spice data type"); + return LG_CLIPBOARD_DATA_NONE; + } +} + +SpiceDataType cb_lgTypeToSpiceType(const LG_ClipboardData type) +{ + switch(type) + { + case LG_CLIPBOARD_DATA_TEXT: return SPICE_DATA_TEXT; break; + case LG_CLIPBOARD_DATA_PNG : return SPICE_DATA_PNG ; break; + case LG_CLIPBOARD_DATA_BMP : return SPICE_DATA_BMP ; break; + case LG_CLIPBOARD_DATA_TIFF: return SPICE_DATA_TIFF; break; + case LG_CLIPBOARD_DATA_JPEG: return SPICE_DATA_JPEG; break; + default: + DEBUG_ERROR("invalid clipboard data type"); + return SPICE_DATA_NONE; + } +} + +void cb_spiceNotice(const SpiceDataType type) +{ + if (!g_params.clipboardToLocal) + return; + + if (!g_state.cbAvailable) + return; + + g_state.cbType = type; + g_state.ds->cbNotice(cb_spiceTypeToLGType(type)); +} + +void cb_spiceData(const SpiceDataType type, uint8_t * buffer, uint32_t size) +{ + if (!g_params.clipboardToLocal) + return; + + if (type == SPICE_DATA_TEXT) + { + // dos2unix + uint8_t * p = buffer; + uint32_t newSize = size; + for(uint32_t i = 0; i < size; ++i) + { + uint8_t c = buffer[i]; + if (c == '\r') + { + --newSize; + continue; + } + *p++ = c; + } + size = newSize; + } + + struct CBRequest * cbr; + if (ll_shift(g_state.cbRequestList, (void **)&cbr)) + { + cbr->replyFn(cbr->opaque, cb_spiceTypeToLGType(type), buffer, size); + free(cbr); + } +} + +void cb_spiceRelease(void) +{ + if (!g_params.clipboardToLocal) + return; + + if (g_state.cbAvailable) + g_state.ds->cbRelease(); +} + +void cb_spiceRequest(const SpiceDataType type) +{ + if (!g_params.clipboardToVM) + return; + + if (g_state.cbAvailable) + g_state.ds->cbRequest(cb_spiceTypeToLGType(type)); +} diff --git a/client/include/lg-decoders.h b/client/src/clipboard.h similarity index 62% rename from client/include/lg-decoders.h rename to client/src/clipboard.h index 8aec2ccf..59daffb6 100644 --- a/client/include/lg-decoders.h +++ b/client/src/clipboard.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,17 +17,13 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#pragma once -#include "interface/decoder.h" +#include "spice/spice.h" +#include "interface/displayserver.h" -extern const LG_Decoder LGD_NULL; -extern const LG_Decoder LGD_YUV420; +LG_ClipboardData cb_spiceTypeToLGType(const SpiceDataType type); +SpiceDataType cb_lgTypeToSpiceType(const LG_ClipboardData type); -const LG_Decoder * LG_Decoders[] = -{ - &LGD_NULL, - &LGD_YUV420, - NULL // end of array sentinal -}; - -#define LG_DECODER_COUNT ((sizeof(LG_Decoders) / sizeof(LG_Decoder *)) - 1) \ No newline at end of file +void cb_spiceNotice(const SpiceDataType type); +void cb_spiceData(const SpiceDataType type, uint8_t * buffer, uint32_t size); +void cb_spiceRelease(void); +void cb_spiceRequest(const SpiceDataType type); diff --git a/client/src/config.c b/client/src/config.c index c7803857..594a2d94 100644 --- a/client/src/config.c +++ b/client/src/config.c @@ -411,9 +411,9 @@ static struct Option options[] = void config_init(void) { - params.center = true; - params.w = 1024; - params.h = 768; + g_params.center = true; + g_params.w = 1024; + g_params.h = 768; option_register(options); } @@ -468,72 +468,72 @@ bool config_load(int argc, char * argv[]) } // setup the application params for the basic types - params.cursorPollInterval = option_get_int ("app", "cursorPollInterval"); - params.framePollInterval = option_get_int ("app", "framePollInterval" ); - params.allowDMA = option_get_bool ("app", "allowDMA" ); + g_params.cursorPollInterval = option_get_int ("app", "cursorPollInterval"); + g_params.framePollInterval = option_get_int ("app", "framePollInterval" ); + g_params.allowDMA = option_get_bool ("app", "allowDMA" ); - params.windowTitle = option_get_string("win", "title" ); - params.autoResize = option_get_bool ("win", "autoResize" ); - params.allowResize = option_get_bool ("win", "allowResize" ); - params.keepAspect = option_get_bool ("win", "keepAspect" ); - params.forceAspect = option_get_bool ("win", "forceAspect" ); - params.dontUpscale = option_get_bool ("win", "dontUpscale" ); - params.borderless = option_get_bool ("win", "borderless" ); - params.fullscreen = option_get_bool ("win", "fullScreen" ); - params.maximize = option_get_bool ("win", "maximize" ); - params.fpsMin = option_get_int ("win", "fpsMin" ); - params.showFPS = option_get_bool ("win", "showFPS" ); - params.ignoreQuit = option_get_bool ("win", "ignoreQuit" ); - params.noScreensaver = option_get_bool ("win", "noScreensaver"); - params.showAlerts = option_get_bool ("win", "alerts" ); - params.quickSplash = option_get_bool ("win", "quickSplash" ); + g_params.windowTitle = option_get_string("win", "title" ); + g_params.autoResize = option_get_bool ("win", "autoResize" ); + g_params.allowResize = option_get_bool ("win", "allowResize" ); + g_params.keepAspect = option_get_bool ("win", "keepAspect" ); + g_params.forceAspect = option_get_bool ("win", "forceAspect" ); + g_params.dontUpscale = option_get_bool ("win", "dontUpscale" ); + g_params.borderless = option_get_bool ("win", "borderless" ); + g_params.fullscreen = option_get_bool ("win", "fullScreen" ); + g_params.maximize = option_get_bool ("win", "maximize" ); + g_params.fpsMin = option_get_int ("win", "fpsMin" ); + g_params.showFPS = option_get_bool ("win", "showFPS" ); + g_params.ignoreQuit = option_get_bool ("win", "ignoreQuit" ); + g_params.noScreensaver = option_get_bool ("win", "noScreensaver"); + g_params.showAlerts = option_get_bool ("win", "alerts" ); + g_params.quickSplash = option_get_bool ("win", "quickSplash" ); switch(option_get_int("win", "rotate")) { - case 0 : params.winRotate = LG_ROTATE_0 ; break; - case 90 : params.winRotate = LG_ROTATE_90 ; break; - case 180: params.winRotate = LG_ROTATE_180; break; - case 270: params.winRotate = LG_ROTATE_270; break; + case 0 : g_params.winRotate = LG_ROTATE_0 ; break; + case 90 : g_params.winRotate = LG_ROTATE_90 ; break; + case 180: g_params.winRotate = LG_ROTATE_180; break; + case 270: g_params.winRotate = LG_ROTATE_270; break; } - params.grabKeyboard = option_get_bool("input", "grabKeyboard" ); - params.grabKeyboardOnFocus = option_get_bool("input", "grabKeyboardOnFocus"); - params.escapeKey = option_get_int ("input", "escapeKey" ); - params.ignoreWindowsKeys = option_get_bool("input", "ignoreWindowsKeys" ); - params.hideMouse = option_get_bool("input", "hideCursor" ); - params.mouseSens = option_get_int ("input", "mouseSens" ); - params.mouseSmoothing = option_get_bool("input", "mouseSmoothing" ); - params.rawMouse = option_get_bool("input", "rawMouse" ); - params.mouseRedraw = option_get_bool("input", "mouseRedraw" ); - params.autoCapture = option_get_bool("input", "autoCapture" ); - params.captureInputOnly = option_get_bool("input", "captureOnly" ); + g_params.grabKeyboard = option_get_bool("input", "grabKeyboard" ); + g_params.grabKeyboardOnFocus = option_get_bool("input", "grabKeyboardOnFocus"); + g_params.escapeKey = option_get_int ("input", "escapeKey" ); + g_params.ignoreWindowsKeys = option_get_bool("input", "ignoreWindowsKeys" ); + g_params.hideMouse = option_get_bool("input", "hideCursor" ); + g_params.mouseSens = option_get_int ("input", "mouseSens" ); + g_params.mouseSmoothing = option_get_bool("input", "mouseSmoothing" ); + g_params.rawMouse = option_get_bool("input", "rawMouse" ); + g_params.mouseRedraw = option_get_bool("input", "mouseRedraw" ); + g_params.autoCapture = option_get_bool("input", "autoCapture" ); + g_params.captureInputOnly = option_get_bool("input", "captureOnly" ); - params.minimizeOnFocusLoss = option_get_bool("win", "minimizeOnFocusLoss"); + g_params.minimizeOnFocusLoss = option_get_bool("win", "minimizeOnFocusLoss"); if (option_get_bool("spice", "enable")) { - params.spiceHost = option_get_string("spice", "host"); - params.spicePort = option_get_int ("spice", "port"); + g_params.spiceHost = option_get_string("spice", "host"); + g_params.spicePort = option_get_int ("spice", "port"); - params.useSpiceInput = option_get_bool("spice", "input" ); - params.useSpiceClipboard = option_get_bool("spice", "clipboard"); + g_params.useSpiceInput = option_get_bool("spice", "input" ); + g_params.useSpiceClipboard = option_get_bool("spice", "clipboard"); - if (params.useSpiceClipboard) + if (g_params.useSpiceClipboard) { - params.clipboardToVM = option_get_bool("spice", "clipboardToVM" ); - params.clipboardToLocal = option_get_bool("spice", "clipboardToLocal"); + g_params.clipboardToVM = option_get_bool("spice", "clipboardToVM" ); + g_params.clipboardToLocal = option_get_bool("spice", "clipboardToLocal"); - if (!params.clipboardToVM && !params.clipboardToLocal) - params.useSpiceClipboard = false; + if (!g_params.clipboardToVM && !g_params.clipboardToLocal) + g_params.useSpiceClipboard = false; } - params.scaleMouseInput = option_get_bool("spice", "scaleCursor"); - params.captureOnStart = option_get_bool("spice", "captureOnStart"); - params.alwaysShowCursor = option_get_bool("spice", "alwaysShowCursor"); + g_params.scaleMouseInput = option_get_bool("spice", "scaleCursor"); + g_params.captureOnStart = option_get_bool("spice", "captureOnStart"); + g_params.alwaysShowCursor = option_get_bool("spice", "alwaysShowCursor"); } //FIXME, this should be using linux keycodes - params.escapeKey = sdl_to_xfree86[params.escapeKey]; + g_params.escapeKey = sdl_to_xfree86[g_params.escapeKey]; return true; } @@ -574,15 +574,15 @@ static bool optRendererParse(struct Option * opt, const char * str) if (strcasecmp(str, "auto") == 0) { - params.forceRenderer = false; + g_params.forceRenderer = false; return true; } for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i) if (strcasecmp(str, LG_Renderers[i]->get_name()) == 0) { - params.forceRenderer = true; - params.forceRendererIndex = i; + g_params.forceRenderer = true; + g_params.forceRendererIndex = i; return true; } @@ -602,13 +602,13 @@ static StringList optRendererValues(struct Option * opt) static char * optRendererToString(struct Option * opt) { - if (!params.forceRenderer) + if (!g_params.forceRenderer) return strdup("auto"); - if (params.forceRendererIndex >= LG_RENDERER_COUNT) + if (g_params.forceRendererIndex >= LG_RENDERER_COUNT) return NULL; - return strdup(LG_Renderers[params.forceRendererIndex]->get_name()); + return strdup(LG_Renderers[g_params.forceRendererIndex]->get_name()); } static bool optPosParse(struct Option * opt, const char * str) @@ -618,13 +618,13 @@ static bool optPosParse(struct Option * opt, const char * str) if (strcmp(str, "center") == 0) { - params.center = true; + g_params.center = true; return true; } - if (sscanf(str, "%dx%d", ¶ms.x, ¶ms.y) == 2) + if (sscanf(str, "%dx%d", &g_params.x, &g_params.y) == 2) { - params.center = false; + g_params.center = false; return true; } @@ -641,12 +641,12 @@ static StringList optPosValues(struct Option * opt) static char * optPosToString(struct Option * opt) { - if (params.center) + if (g_params.center) return strdup("center"); - int len = snprintf(NULL, 0, "%dx%d", params.x, params.y); + int len = snprintf(NULL, 0, "%dx%d", g_params.x, g_params.y); char * str = malloc(len + 1); - sprintf(str, "%dx%d", params.x, params.y); + sprintf(str, "%dx%d", g_params.x, g_params.y); return str; } @@ -656,9 +656,9 @@ static bool optSizeParse(struct Option * opt, const char * str) if (!str) return false; - if (sscanf(str, "%dx%d", ¶ms.w, ¶ms.h) == 2) + if (sscanf(str, "%dx%d", &g_params.w, &g_params.h) == 2) { - if (params.w < 1 || params.h < 1) + if (g_params.w < 1 || g_params.h < 1) return false; return true; } @@ -675,9 +675,9 @@ static StringList optSizeValues(struct Option * opt) static char * optSizeToString(struct Option * opt) { - int len = snprintf(NULL, 0, "%dx%d", params.w, params.h); + int len = snprintf(NULL, 0, "%dx%d", g_params.w, g_params.h); char * str = malloc(len + 1); - sprintf(str, "%dx%d", params.w, params.h); + sprintf(str, "%dx%d", g_params.w, g_params.h); return str; } diff --git a/client/src/core.c b/client/src/core.c new file mode 100644 index 00000000..64b9c0cf --- /dev/null +++ b/client/src/core.c @@ -0,0 +1,262 @@ +/* +Looking Glass - KVM FrameRelay (KVMFR) Client +Copyright (C) 2017-2021 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "core.h" +#include "main.h" +#include "app.h" +#include "util.h" + +#include "common/time.h" + +#include + +#define RESIZE_TIMEOUT (10 * 1000) // 10ms + +void core_setCursorInView(bool enable) +{ + // if the state has not changed, don't do anything else + if (g_cursor.inView == enable) + return; + + if (enable && !g_state.focused) + return; + + // do not allow the view to become active if any mouse buttons are being held, + // this fixes issues with meta window resizing. + if (enable && g_cursor.buttons) + return; + + g_cursor.inView = enable; + g_cursor.draw = (g_params.alwaysShowCursor || g_params.captureInputOnly) + ? true : enable; + g_cursor.redraw = true; + + /* if the display server does not support warp, then we can not operate in + * always relative mode and we should not grab the pointer */ + bool warpSupport = true; + app_getProp(LG_DS_WARP_SUPPORT, &warpSupport); + + g_cursor.warpState = enable ? WARP_STATE_ON : WARP_STATE_OFF; + + if (enable) + { + if (g_params.hideMouse) + SDL_ShowCursor(SDL_DISABLE); + + if (warpSupport && !g_params.captureInputOnly) + g_state.ds->grabPointer(); + } + else + { + if (g_params.hideMouse) + SDL_ShowCursor(SDL_ENABLE); + + if (warpSupport) + g_state.ds->ungrabPointer(); + + g_state.ds->ungrabKeyboard(); + } + + g_cursor.warpState = WARP_STATE_ON; +} + +void core_setGrab(bool enable) +{ + core_setGrabQuiet(enable); + + app_alert( + g_cursor.grab ? LG_ALERT_SUCCESS : LG_ALERT_WARNING, + g_cursor.grab ? "Capture Enabled" : "Capture Disabled" + ); +} + +void core_setGrabQuiet(bool enable) +{ + /* we always do this so that at init the cursor is in the right state */ + if (g_params.captureInputOnly && g_params.hideMouse) + SDL_ShowCursor(enable ? SDL_DISABLE : SDL_ENABLE); + + if (g_cursor.grab == enable) + return; + + g_cursor.grab = enable; + g_cursor.acc.x = 0.0; + g_cursor.acc.y = 0.0; + + /* if the display server does not support warp we need to ungrab the pointer + * here instead of in the move handler */ + bool warpSupport = true; + app_getProp(LG_DS_WARP_SUPPORT, &warpSupport); + + if (enable) + { + core_setCursorInView(true); + g_state.ignoreInput = false; + + if (g_params.grabKeyboard) + g_state.ds->grabKeyboard(); + + g_state.ds->grabPointer(); + } + else + { + if (g_params.grabKeyboard) + { + if (!g_params.grabKeyboardOnFocus || + !g_state.focused || g_params.captureInputOnly) + g_state.ds->ungrabKeyboard(); + } + + if (!warpSupport || g_params.captureInputOnly || !g_state.formatValid) + g_state.ds->ungrabPointer(); + + // if exiting capture when input on capture only, we want to show the cursor + if (g_params.captureInputOnly || !g_params.hideMouse) + core_alignToGuest(); + } +} + +bool core_warpPointer(int x, int y, bool exiting) +{ + if (!g_cursor.inWindow && !exiting) + return false; + + if (g_cursor.warpState == WARP_STATE_OFF) + return false; + + if (exiting) + g_cursor.warpState = WARP_STATE_OFF; + + if (g_cursor.pos.x == x && g_cursor.pos.y == y) + return true; + + g_state.ds->warpPointer(x, y, exiting); + return true; +} + +void core_updatePositionInfo(void) +{ + if (!g_state.haveSrcSize) + goto done; + + float srcW; + float srcH; + switch(g_params.winRotate) + { + case LG_ROTATE_0: + case LG_ROTATE_180: + srcW = g_state.srcSize.x; + srcH = g_state.srcSize.y; + break; + + case LG_ROTATE_90: + case LG_ROTATE_270: + srcW = g_state.srcSize.y; + srcH = g_state.srcSize.x; + break; + + default: + assert(!"unreachable"); + } + + if (g_params.keepAspect) + { + const float srcAspect = srcH / srcW; + const float wndAspect = (float)g_state.windowH / (float)g_state.windowW; + bool force = true; + + if (g_params.dontUpscale && + srcW <= g_state.windowW && + srcH <= g_state.windowH) + { + force = false; + g_state.dstRect.w = srcW; + g_state.dstRect.h = srcH; + g_state.dstRect.x = g_state.windowCX - srcW / 2; + g_state.dstRect.y = g_state.windowCY - srcH / 2; + } + else + if ((int)(wndAspect * 1000) == (int)(srcAspect * 1000)) + { + force = false; + g_state.dstRect.w = g_state.windowW; + g_state.dstRect.h = g_state.windowH; + g_state.dstRect.x = 0; + g_state.dstRect.y = 0; + } + else + if (wndAspect < srcAspect) + { + g_state.dstRect.w = (float)g_state.windowH / srcAspect; + g_state.dstRect.h = g_state.windowH; + g_state.dstRect.x = (g_state.windowW >> 1) - (g_state.dstRect.w >> 1); + g_state.dstRect.y = 0; + } + else + { + g_state.dstRect.w = g_state.windowW; + g_state.dstRect.h = (float)g_state.windowW * srcAspect; + g_state.dstRect.x = 0; + g_state.dstRect.y = (g_state.windowH >> 1) - (g_state.dstRect.h >> 1); + } + + if (force && g_params.forceAspect) + { + g_state.resizeTimeout = microtime() + RESIZE_TIMEOUT; + g_state.resizeDone = false; + } + } + else + { + g_state.dstRect.x = 0; + g_state.dstRect.y = 0; + g_state.dstRect.w = g_state.windowW; + g_state.dstRect.h = g_state.windowH; + } + g_state.dstRect.valid = true; + + g_cursor.useScale = ( + srcH != g_state.dstRect.h || + srcW != g_state.dstRect.w || + g_cursor.guest.dpiScale != 100); + + g_cursor.scale.x = (float)srcW / (float)g_state.dstRect.w; + g_cursor.scale.y = (float)srcH / (float)g_state.dstRect.h; + g_cursor.dpiScale = g_cursor.guest.dpiScale / 100.0f; + + if (!g_state.posInfoValid) + { + g_state.posInfoValid = true; + g_state.ds->realignPointer(); + } + +done: + atomic_fetch_add(&g_state.lgrResize, 1); +} + +void core_alignToGuest(void) +{ + if (!g_cursor.guest.valid || !g_state.focused) + return; + + struct DoublePoint local; + if (util_guestCurToLocal(&local)) + if (core_warpPointer(round(local.x), round(local.y), false)) + core_setCursorInView(true); +} diff --git a/client/include/utils.h b/client/src/core.h similarity index 70% rename from client/include/utils.h rename to client/src/core.h index 66d8506b..a15c0eae 100644 --- a/client/include/utils.h +++ b/client/src/core.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,11 +17,16 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#pragma once +#ifndef _H_LG_CORE_ +#define _H_LG_CORE_ -#include #include -// reads the specified file into a new buffer -// the callee must free the buffer -bool file_get_contents(const char * filename, char ** buffer, size_t * length); +void core_setCursorInView(bool enable); +void core_setGrab(bool enable); +void core_setGrabQuiet(bool enable); +bool core_warpPointer(int x, int y, bool exiting); +void core_updatePositionInfo(void); +void core_alignToGuest(void); + +#endif diff --git a/client/src/kb.c b/client/src/kb.c new file mode 100644 index 00000000..af9e34f6 --- /dev/null +++ b/client/src/kb.c @@ -0,0 +1,148 @@ +/* +Looking Glass - KVM FrameRelay (KVMFR) Client +Copyright (C) 2017-2021 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _H_LG_KB_ +#define _H_LG_KB_ + +#include "kb.h" + +const uint32_t xfree86_to_ps2[KEY_MAX] = +{ + [KEY_RESERVED] /* = USB 0 */ = 0x000000, + [KEY_ESC] /* = USB 41 */ = 0x000001, + [KEY_1] /* = USB 30 */ = 0x000002, + [KEY_2] /* = USB 31 */ = 0x000003, + [KEY_3] /* = USB 32 */ = 0x000004, + [KEY_4] /* = USB 33 */ = 0x000005, + [KEY_5] /* = USB 34 */ = 0x000006, + [KEY_6] /* = USB 35 */ = 0x000007, + [KEY_7] /* = USB 36 */ = 0x000008, + [KEY_8] /* = USB 37 */ = 0x000009, + [KEY_9] /* = USB 38 */ = 0x00000A, + [KEY_0] /* = USB 39 */ = 0x00000B, + [KEY_MINUS] /* = USB 45 */ = 0x00000C, + [KEY_EQUAL] /* = USB 46 */ = 0x00000D, + [KEY_BACKSPACE] /* = USB 42 */ = 0x00000E, + [KEY_TAB] /* = USB 43 */ = 0x00000F, + [KEY_Q] /* = USB 20 */ = 0x000010, + [KEY_W] /* = USB 26 */ = 0x000011, + [KEY_E] /* = USB 8 */ = 0x000012, + [KEY_R] /* = USB 21 */ = 0x000013, + [KEY_T] /* = USB 23 */ = 0x000014, + [KEY_Y] /* = USB 28 */ = 0x000015, + [KEY_U] /* = USB 24 */ = 0x000016, + [KEY_I] /* = USB 12 */ = 0x000017, + [KEY_O] /* = USB 18 */ = 0x000018, + [KEY_P] /* = USB 19 */ = 0x000019, + [KEY_LEFTBRACE] /* = USB 47 */ = 0x00001A, + [KEY_RIGHTBRACE] /* = USB 48 */ = 0x00001B, + [KEY_ENTER] /* = USB 40 */ = 0x00001C, + [KEY_LEFTCTRL] /* = USB 224 */ = 0x00001D, + [KEY_A] /* = USB 4 */ = 0x00001E, + [KEY_S] /* = USB 22 */ = 0x00001F, + [KEY_D] /* = USB 7 */ = 0x000020, + [KEY_F] /* = USB 9 */ = 0x000021, + [KEY_G] /* = USB 10 */ = 0x000022, + [KEY_H] /* = USB 11 */ = 0x000023, + [KEY_J] /* = USB 13 */ = 0x000024, + [KEY_K] /* = USB 14 */ = 0x000025, + [KEY_L] /* = USB 15 */ = 0x000026, + [KEY_SEMICOLON] /* = USB 51 */ = 0x000027, + [KEY_APOSTROPHE] /* = USB 52 */ = 0x000028, + [KEY_GRAVE] /* = USB 53 */ = 0x000029, + [KEY_LEFTSHIFT] /* = USB 225 */ = 0x00002A, + [KEY_BACKSLASH] /* = USB 49 */ = 0x00002B, + [KEY_Z] /* = USB 29 */ = 0x00002C, + [KEY_X] /* = USB 27 */ = 0x00002D, + [KEY_C] /* = USB 6 */ = 0x00002E, + [KEY_V] /* = USB 25 */ = 0x00002F, + [KEY_B] /* = USB 5 */ = 0x000030, + [KEY_N] /* = USB 17 */ = 0x000031, + [KEY_M] /* = USB 16 */ = 0x000032, + [KEY_COMMA] /* = USB 54 */ = 0x000033, + [KEY_DOT] /* = USB 55 */ = 0x000034, + [KEY_SLASH] /* = USB 56 */ = 0x000035, + [KEY_RIGHTSHIFT] /* = USB 229 */ = 0x000036, + [KEY_KPASTERISK] /* = USB 85 */ = 0x000037, + [KEY_LEFTALT] /* = USB 226 */ = 0x000038, + [KEY_SPACE] /* = USB 44 */ = 0x000039, + [KEY_CAPSLOCK] /* = USB 57 */ = 0x00003A, + [KEY_F1] /* = USB 58 */ = 0x00003B, + [KEY_F2] /* = USB 59 */ = 0x00003C, + [KEY_F3] /* = USB 60 */ = 0x00003D, + [KEY_F4] /* = USB 61 */ = 0x00003E, + [KEY_F5] /* = USB 62 */ = 0x00003F, + [KEY_F6] /* = USB 63 */ = 0x000040, + [KEY_F7] /* = USB 64 */ = 0x000041, + [KEY_F8] /* = USB 65 */ = 0x000042, + [KEY_F9] /* = USB 66 */ = 0x000043, + [KEY_F10] /* = USB 67 */ = 0x000044, + [KEY_NUMLOCK] /* = USB 83 */ = 0x000045, + [KEY_SCROLLLOCK] /* = USB 71 */ = 0x000046, + [KEY_KP7] /* = USB 95 */ = 0x000047, + [KEY_KP8] /* = USB 96 */ = 0x000048, + [KEY_KP9] /* = USB 97 */ = 0x000049, + [KEY_KPMINUS] /* = USB 86 */ = 0x00004A, + [KEY_KP4] /* = USB 92 */ = 0x00004B, + [KEY_KP5] /* = USB 93 */ = 0x00004C, + [KEY_KP6] /* = USB 94 */ = 0x00004D, + [KEY_KPPLUS] /* = USB 87 */ = 0x00004E, + [KEY_KP1] /* = USB 89 */ = 0x00004F, + [KEY_KP2] /* = USB 90 */ = 0x000050, + [KEY_KP3] /* = USB 91 */ = 0x000051, + [KEY_KP0] /* = USB 98 */ = 0x000052, + [KEY_KPDOT] /* = USB 99 */ = 0x000053, + [KEY_102ND] /* = USB 100 */ = 0x000056, + [KEY_F11] /* = USB 68 */ = 0x000057, + [KEY_F12] /* = USB 69 */ = 0x000058, + [KEY_RO] /* = USB 135 */ = 0x000073, + [KEY_HENKAN] /* = USB 138 */ = 0x000079, + [KEY_KATAKANAHIRAGANA] /* = USB 136 */ = 0x000070, + [KEY_MUHENKAN] /* = USB 139 */ = 0x00007B, + [KEY_KPENTER] /* = USB 88 */ = 0x00E01C, + [KEY_RIGHTCTRL] /* = USB 228 */ = 0x00E01D, + [KEY_KPSLASH] /* = USB 84 */ = 0x00E035, + [KEY_SYSRQ] /* = USB 70 */ = 0x00E037, + [KEY_RIGHTALT] /* = USB 230 */ = 0x00E038, + [KEY_HOME] /* = USB 74 */ = 0x00E047, + [KEY_UP] /* = USB 82 */ = 0x00E048, + [KEY_PAGEUP] /* = USB 75 */ = 0x00E049, + [KEY_LEFT] /* = USB 80 */ = 0x00E04B, + [KEY_RIGHT] /* = USB 79 */ = 0x00E04D, + [KEY_END] /* = USB 77 */ = 0x00E04F, + [KEY_DOWN] /* = USB 81 */ = 0x00E050, + [KEY_PAGEDOWN] /* = USB 78 */ = 0x00E051, + [KEY_INSERT] /* = USB 73 */ = 0x00E052, + [KEY_DELETE] /* = USB 76 */ = 0x00E053, + [KEY_KPEQUAL] /* = USB 103 */ = 0x000059, + [KEY_PAUSE] /* = USB 72 */ = 0x00E046, + [KEY_KPCOMMA] /* = USB 133 */ = 0x00007E, + [KEY_HANGEUL] /* = USB 144 */ = 0x0000F2, + [KEY_HANJA] /* = USB 145 */ = 0x0000F1, + [KEY_YEN] /* = USB 137 */ = 0x00007D, + [KEY_LEFTMETA] /* = USB 227 */ = 0x00E05B, + [KEY_RIGHTMETA] /* = USB 231 */ = 0x00E05C, + [KEY_COMPOSE] /* = USB 101 */ = 0x00E05D, + [KEY_F13] /* = USB 104 */ = 0x00005D, + [KEY_F14] /* = USB 105 */ = 0x00005E, + [KEY_F15] /* = USB 106 */ = 0x00005F, + [KEY_PRINT] /* = USB 70 */ = 0x00E037, +}; + +#endif diff --git a/client/src/kb.h b/client/src/kb.h index 9161106a..a00ba2c3 100644 --- a/client/src/kb.h +++ b/client/src/kb.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -18,126 +18,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA */ #include +#include -const uint32_t xfree86_to_ps2[KEY_MAX] = -{ - [KEY_RESERVED] /* = USB 0 */ = 0x000000, - [KEY_ESC] /* = USB 41 */ = 0x000001, - [KEY_1] /* = USB 30 */ = 0x000002, - [KEY_2] /* = USB 31 */ = 0x000003, - [KEY_3] /* = USB 32 */ = 0x000004, - [KEY_4] /* = USB 33 */ = 0x000005, - [KEY_5] /* = USB 34 */ = 0x000006, - [KEY_6] /* = USB 35 */ = 0x000007, - [KEY_7] /* = USB 36 */ = 0x000008, - [KEY_8] /* = USB 37 */ = 0x000009, - [KEY_9] /* = USB 38 */ = 0x00000A, - [KEY_0] /* = USB 39 */ = 0x00000B, - [KEY_MINUS] /* = USB 45 */ = 0x00000C, - [KEY_EQUAL] /* = USB 46 */ = 0x00000D, - [KEY_BACKSPACE] /* = USB 42 */ = 0x00000E, - [KEY_TAB] /* = USB 43 */ = 0x00000F, - [KEY_Q] /* = USB 20 */ = 0x000010, - [KEY_W] /* = USB 26 */ = 0x000011, - [KEY_E] /* = USB 8 */ = 0x000012, - [KEY_R] /* = USB 21 */ = 0x000013, - [KEY_T] /* = USB 23 */ = 0x000014, - [KEY_Y] /* = USB 28 */ = 0x000015, - [KEY_U] /* = USB 24 */ = 0x000016, - [KEY_I] /* = USB 12 */ = 0x000017, - [KEY_O] /* = USB 18 */ = 0x000018, - [KEY_P] /* = USB 19 */ = 0x000019, - [KEY_LEFTBRACE] /* = USB 47 */ = 0x00001A, - [KEY_RIGHTBRACE] /* = USB 48 */ = 0x00001B, - [KEY_ENTER] /* = USB 40 */ = 0x00001C, - [KEY_LEFTCTRL] /* = USB 224 */ = 0x00001D, - [KEY_A] /* = USB 4 */ = 0x00001E, - [KEY_S] /* = USB 22 */ = 0x00001F, - [KEY_D] /* = USB 7 */ = 0x000020, - [KEY_F] /* = USB 9 */ = 0x000021, - [KEY_G] /* = USB 10 */ = 0x000022, - [KEY_H] /* = USB 11 */ = 0x000023, - [KEY_J] /* = USB 13 */ = 0x000024, - [KEY_K] /* = USB 14 */ = 0x000025, - [KEY_L] /* = USB 15 */ = 0x000026, - [KEY_SEMICOLON] /* = USB 51 */ = 0x000027, - [KEY_APOSTROPHE] /* = USB 52 */ = 0x000028, - [KEY_GRAVE] /* = USB 53 */ = 0x000029, - [KEY_LEFTSHIFT] /* = USB 225 */ = 0x00002A, - [KEY_BACKSLASH] /* = USB 49 */ = 0x00002B, - [KEY_Z] /* = USB 29 */ = 0x00002C, - [KEY_X] /* = USB 27 */ = 0x00002D, - [KEY_C] /* = USB 6 */ = 0x00002E, - [KEY_V] /* = USB 25 */ = 0x00002F, - [KEY_B] /* = USB 5 */ = 0x000030, - [KEY_N] /* = USB 17 */ = 0x000031, - [KEY_M] /* = USB 16 */ = 0x000032, - [KEY_COMMA] /* = USB 54 */ = 0x000033, - [KEY_DOT] /* = USB 55 */ = 0x000034, - [KEY_SLASH] /* = USB 56 */ = 0x000035, - [KEY_RIGHTSHIFT] /* = USB 229 */ = 0x000036, - [KEY_KPASTERISK] /* = USB 85 */ = 0x000037, - [KEY_LEFTALT] /* = USB 226 */ = 0x000038, - [KEY_SPACE] /* = USB 44 */ = 0x000039, - [KEY_CAPSLOCK] /* = USB 57 */ = 0x00003A, - [KEY_F1] /* = USB 58 */ = 0x00003B, - [KEY_F2] /* = USB 59 */ = 0x00003C, - [KEY_F3] /* = USB 60 */ = 0x00003D, - [KEY_F4] /* = USB 61 */ = 0x00003E, - [KEY_F5] /* = USB 62 */ = 0x00003F, - [KEY_F6] /* = USB 63 */ = 0x000040, - [KEY_F7] /* = USB 64 */ = 0x000041, - [KEY_F8] /* = USB 65 */ = 0x000042, - [KEY_F9] /* = USB 66 */ = 0x000043, - [KEY_F10] /* = USB 67 */ = 0x000044, - [KEY_NUMLOCK] /* = USB 83 */ = 0x000045, - [KEY_SCROLLLOCK] /* = USB 71 */ = 0x000046, - [KEY_KP7] /* = USB 95 */ = 0x000047, - [KEY_KP8] /* = USB 96 */ = 0x000048, - [KEY_KP9] /* = USB 97 */ = 0x000049, - [KEY_KPMINUS] /* = USB 86 */ = 0x00004A, - [KEY_KP4] /* = USB 92 */ = 0x00004B, - [KEY_KP5] /* = USB 93 */ = 0x00004C, - [KEY_KP6] /* = USB 94 */ = 0x00004D, - [KEY_KPPLUS] /* = USB 87 */ = 0x00004E, - [KEY_KP1] /* = USB 89 */ = 0x00004F, - [KEY_KP2] /* = USB 90 */ = 0x000050, - [KEY_KP3] /* = USB 91 */ = 0x000051, - [KEY_KP0] /* = USB 98 */ = 0x000052, - [KEY_KPDOT] /* = USB 99 */ = 0x000053, - [KEY_102ND] /* = USB 100 */ = 0x000056, - [KEY_F11] /* = USB 68 */ = 0x000057, - [KEY_F12] /* = USB 69 */ = 0x000058, - [KEY_RO] /* = USB 135 */ = 0x000073, - [KEY_HENKAN] /* = USB 138 */ = 0x000079, - [KEY_KATAKANAHIRAGANA] /* = USB 136 */ = 0x000070, - [KEY_MUHENKAN] /* = USB 139 */ = 0x00007B, - [KEY_KPENTER] /* = USB 88 */ = 0x00E01C, - [KEY_RIGHTCTRL] /* = USB 228 */ = 0x00E01D, - [KEY_KPSLASH] /* = USB 84 */ = 0x00E035, - [KEY_SYSRQ] /* = USB 70 */ = 0x00E037, - [KEY_RIGHTALT] /* = USB 230 */ = 0x00E038, - [KEY_HOME] /* = USB 74 */ = 0x00E047, - [KEY_UP] /* = USB 82 */ = 0x00E048, - [KEY_PAGEUP] /* = USB 75 */ = 0x00E049, - [KEY_LEFT] /* = USB 80 */ = 0x00E04B, - [KEY_RIGHT] /* = USB 79 */ = 0x00E04D, - [KEY_END] /* = USB 77 */ = 0x00E04F, - [KEY_DOWN] /* = USB 81 */ = 0x00E050, - [KEY_PAGEDOWN] /* = USB 78 */ = 0x00E051, - [KEY_INSERT] /* = USB 73 */ = 0x00E052, - [KEY_DELETE] /* = USB 76 */ = 0x00E053, - [KEY_KPEQUAL] /* = USB 103 */ = 0x000059, - [KEY_PAUSE] /* = USB 72 */ = 0x00E046, - [KEY_KPCOMMA] /* = USB 133 */ = 0x00007E, - [KEY_HANGEUL] /* = USB 144 */ = 0x0000F2, - [KEY_HANJA] /* = USB 145 */ = 0x0000F1, - [KEY_YEN] /* = USB 137 */ = 0x00007D, - [KEY_LEFTMETA] /* = USB 227 */ = 0x00E05B, - [KEY_RIGHTMETA] /* = USB 231 */ = 0x00E05C, - [KEY_COMPOSE] /* = USB 101 */ = 0x00E05D, - [KEY_F13] /* = USB 104 */ = 0x00005D, - [KEY_F14] /* = USB 105 */ = 0x00005E, - [KEY_F15] /* = USB 106 */ = 0x00005F, - [KEY_PRINT] /* = USB 70 */ = 0x00E037, -}; +extern const uint32_t xfree86_to_ps2[KEY_MAX]; diff --git a/client/src/main.c b/client/src/main.c index 27f5e6ad..5671962c 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -48,12 +48,12 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "common/time.h" #include "common/version.h" +#include "core.h" #include "app.h" -#include "utils.h" -#include "kb.h" +#include "util.h" +#include "clipboard.h" #include "ll.h" - -#define RESIZE_TIMEOUT (10 * 1000) // 10ms +#include "kb.h" // forwards static int cursorThread(void * unused); @@ -68,22 +68,11 @@ static LGThread *t_cursor = NULL; static LGThread *t_frame = NULL; static SDL_Cursor *cursor = NULL; -static Uint32 e_SDLEvent; // our SDL event - -enum -{ - LG_EVENT_ALIGN_TO_GUEST -}; - struct AppState g_state; struct CursorState g_cursor; // this structure is initialized in config.c -struct AppParams params = { 0 }; - -static void setGrab(bool enable); -static void setGrabQuiet(bool enable); -static void setCursorInView(bool enable); +struct AppParams g_params = { 0 }; static void lgInit(void) { @@ -92,7 +81,7 @@ static void lgInit(void) g_state.resizeDone = true; if (g_cursor.grab) - setGrab(false); + core_setGrab(false); g_cursor.useScale = false; g_cursor.scale.x = 1.0; @@ -102,185 +91,12 @@ static void lgInit(void) g_cursor.guest.valid = false; // if spice is not in use, hide the local cursor - if (!app_inputEnabled() && params.hideMouse) + if (!app_inputEnabled() && g_params.hideMouse) SDL_ShowCursor(SDL_DISABLE); else SDL_ShowCursor(SDL_ENABLE); } -bool app_getProp(LG_DSProperty prop, void * ret) -{ - return g_state.ds->getProp(prop, ret); -} - -SDL_Window * app_getWindow(void) -{ - return g_state.window; -} - -bool app_inputEnabled(void) -{ - return params.useSpiceInput && !g_state.ignoreInput && - ((g_cursor.grab && params.captureInputOnly) || !params.captureInputOnly); -} - -bool app_cursorInWindow(void) -{ - return g_cursor.inWindow; -} - -bool app_cursorIsGrabbed(void) -{ - return g_cursor.grab; -} - -bool app_cursorWantsRaw(void) -{ - return params.rawMouse; -} - -void app_updateCursorPos(double x, double y) -{ - g_cursor.pos.x = x; - g_cursor.pos.y = y; - g_cursor.valid = true; -} - -void app_handleFocusEvent(bool focused) -{ - g_state.focused = focused; - if (!app_inputEnabled()) - return; - - if (!focused) - { - setGrabQuiet(false); - setCursorInView(false); - } - - g_cursor.realign = true; - g_state.ds->realignPointer(); -} - -void app_handleCloseEvent(void) -{ - if (!params.ignoreQuit || !g_cursor.inView) - g_state.state = APP_STATE_SHUTDOWN; -} - -static void alignToGuest(void) -{ - if (SDL_HasEvent(e_SDLEvent)) - return; - - SDL_Event event; - SDL_memset(&event, 0, sizeof(event)); - event.type = e_SDLEvent; - event.user.code = LG_EVENT_ALIGN_TO_GUEST; - - SDL_PushEvent(&event); -} - -static void updatePositionInfo(void) -{ - if (!g_state.haveSrcSize) - goto done; - - float srcW; - float srcH; - switch(params.winRotate) - { - case LG_ROTATE_0: - case LG_ROTATE_180: - srcW = g_state.srcSize.x; - srcH = g_state.srcSize.y; - break; - - case LG_ROTATE_90: - case LG_ROTATE_270: - srcW = g_state.srcSize.y; - srcH = g_state.srcSize.x; - break; - - default: - assert(!"unreachable"); - } - - if (params.keepAspect) - { - const float srcAspect = srcH / srcW; - const float wndAspect = (float)g_state.windowH / (float)g_state.windowW; - bool force = true; - - if (params.dontUpscale && - srcW <= g_state.windowW && - srcH <= g_state.windowH) - { - force = false; - g_state.dstRect.w = srcW; - g_state.dstRect.h = srcH; - g_state.dstRect.x = g_state.windowCX - srcW / 2; - g_state.dstRect.y = g_state.windowCY - srcH / 2; - } - else - if ((int)(wndAspect * 1000) == (int)(srcAspect * 1000)) - { - force = false; - g_state.dstRect.w = g_state.windowW; - g_state.dstRect.h = g_state.windowH; - g_state.dstRect.x = 0; - g_state.dstRect.y = 0; - } - else - if (wndAspect < srcAspect) - { - g_state.dstRect.w = (float)g_state.windowH / srcAspect; - g_state.dstRect.h = g_state.windowH; - g_state.dstRect.x = (g_state.windowW >> 1) - (g_state.dstRect.w >> 1); - g_state.dstRect.y = 0; - } - else - { - g_state.dstRect.w = g_state.windowW; - g_state.dstRect.h = (float)g_state.windowW * srcAspect; - g_state.dstRect.x = 0; - g_state.dstRect.y = (g_state.windowH >> 1) - (g_state.dstRect.h >> 1); - } - - if (force && params.forceAspect) - { - g_state.resizeTimeout = microtime() + RESIZE_TIMEOUT; - g_state.resizeDone = false; - } - } - else - { - g_state.dstRect.x = 0; - g_state.dstRect.y = 0; - g_state.dstRect.w = g_state.windowW; - g_state.dstRect.h = g_state.windowH; - } - g_state.dstRect.valid = true; - - g_cursor.useScale = ( - srcH != g_state.dstRect.h || - srcW != g_state.dstRect.w || - g_cursor.guest.dpiScale != 100); - - g_cursor.scale.x = (float)srcW / (float)g_state.dstRect.w; - g_cursor.scale.y = (float)srcH / (float)g_state.dstRect.h; - g_cursor.dpiScale = g_cursor.guest.dpiScale / 100.0f; - - if (!g_state.posInfoValid) - { - g_state.posInfoValid = true; - g_state.ds->realignPointer(); - } - -done: - atomic_fetch_add(&g_state.lgrResize, 1); -} - static int renderThread(void * unused) { if (!g_state.lgr->render_startup(g_state.lgrData, g_state.window)) @@ -300,7 +116,7 @@ static int renderThread(void * unused) while(g_state.state != APP_STATE_SHUTDOWN) { - if (params.fpsMin != 0) + if (g_params.fpsMin != 0) { lgWaitEventAbs(e_frame, &time); clock_gettime(CLOCK_MONOTONIC, &time); @@ -312,14 +128,14 @@ static int renderThread(void * unused) { if (g_state.lgr) g_state.lgr->on_resize(g_state.lgrData, g_state.windowW, g_state.windowH, - g_state.dstRect, params.winRotate); + g_state.dstRect, g_params.winRotate); atomic_compare_exchange_weak(&g_state.lgrResize, &resize, 0); } - if (!g_state.lgr->render(g_state.lgrData, g_state.window, params.winRotate)) + if (!g_state.lgr->render(g_state.lgrData, g_state.window, g_params.winRotate)) break; - if (params.showFPS) + if (g_params.showFPS) { const uint64_t t = nanotime(); g_state.renderTime += t - g_state.lastFrameTime; @@ -406,7 +222,7 @@ static int cursorThread(void * unused) g_state.lgr->on_mouse_event ( g_state.lgrData, - g_cursor.guest.visible && (g_cursor.draw || !params.useSpiceInput), + g_cursor.guest.visible && (g_cursor.draw || !g_params.useSpiceInput), g_cursor.guest.x, g_cursor.guest.y ); @@ -417,7 +233,7 @@ static int cursorThread(void * unused) const struct timespec req = { .tv_sec = 0, - .tv_nsec = params.cursorPollInterval * 1000L + .tv_nsec = g_params.cursorPollInterval * 1000L }; struct timespec rem; @@ -487,7 +303,7 @@ static int cursorThread(void * unused) // if the state just became valid if (valid != true && app_inputEnabled()) - alignToGuest(); + core_alignToGuest(); } lgmpClientMessageDone(queue); @@ -496,12 +312,12 @@ static int cursorThread(void * unused) g_state.lgr->on_mouse_event ( g_state.lgrData, - g_cursor.guest.visible && (g_cursor.draw || !params.useSpiceInput), + g_cursor.guest.visible && (g_cursor.draw || !g_params.useSpiceInput), g_cursor.guest.x, g_cursor.guest.y ); - if (params.mouseRedraw && g_cursor.guest.visible) + if (g_params.mouseRedraw && g_cursor.guest.visible) lgSignalEvent(e_frame); } @@ -527,7 +343,7 @@ static int frameThread(void * unused) struct DMAFrameInfo dmaInfo[LGMP_Q_FRAME_LEN] = {0}; const bool useDMA = - params.allowDMA && + g_params.allowDMA && ivshmemHasDMA(&g_state.shm) && g_state.lgr->supports && g_state.lgr->supports(g_state.lgrData, LG_SUPPORTS_DMABUF); @@ -568,7 +384,7 @@ static int frameThread(void * unused) const struct timespec req = { .tv_sec = 0, - .tv_nsec = params.framePollInterval * 1000L + .tv_nsec = g_params.framePollInterval * 1000L }; struct timespec rem; @@ -660,11 +476,11 @@ static int frameThread(void * unused) g_state.srcSize.x = lgrFormat.width; g_state.srcSize.y = lgrFormat.height; g_state.haveSrcSize = true; - if (params.autoResize) + if (g_params.autoResize) SDL_SetWindowSize(g_state.window, lgrFormat.width, lgrFormat.height); g_cursor.guest.dpiScale = frame->mouseScalePercent; - updatePositionInfo(); + core_updatePositionInfo(); } if (useDMA) @@ -760,822 +576,6 @@ int spiceThread(void * arg) return 0; } -static LG_ClipboardData spice_type_to_clipboard_type(const SpiceDataType type) -{ - switch(type) - { - case SPICE_DATA_TEXT: return LG_CLIPBOARD_DATA_TEXT; break; - case SPICE_DATA_PNG : return LG_CLIPBOARD_DATA_PNG ; break; - case SPICE_DATA_BMP : return LG_CLIPBOARD_DATA_BMP ; break; - case SPICE_DATA_TIFF: return LG_CLIPBOARD_DATA_TIFF; break; - case SPICE_DATA_JPEG: return LG_CLIPBOARD_DATA_JPEG; break; - default: - DEBUG_ERROR("invalid spice data type"); - return LG_CLIPBOARD_DATA_NONE; - } -} - -static SpiceDataType clipboard_type_to_spice_type(const LG_ClipboardData type) -{ - switch(type) - { - case LG_CLIPBOARD_DATA_TEXT: return SPICE_DATA_TEXT; break; - case LG_CLIPBOARD_DATA_PNG : return SPICE_DATA_PNG ; break; - case LG_CLIPBOARD_DATA_BMP : return SPICE_DATA_BMP ; break; - case LG_CLIPBOARD_DATA_TIFF: return SPICE_DATA_TIFF; break; - case LG_CLIPBOARD_DATA_JPEG: return SPICE_DATA_JPEG; break; - default: - DEBUG_ERROR("invalid clipboard data type"); - return SPICE_DATA_NONE; - } -} - -void app_clipboardRelease(void) -{ - if (!params.clipboardToVM) - return; - - spice_clipboard_release(); -} - -void app_clipboardNotify(const LG_ClipboardData type, size_t size) -{ - if (!params.clipboardToVM) - return; - - if (type == LG_CLIPBOARD_DATA_NONE) - { - spice_clipboard_release(); - return; - } - - g_state.cbType = clipboard_type_to_spice_type(type); - g_state.cbChunked = size > 0; - g_state.cbXfer = size; - - spice_clipboard_grab(g_state.cbType); - - if (size) - spice_clipboard_data_start(g_state.cbType, size); -} - -void app_clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size) -{ - if (!params.clipboardToVM) - return; - - if (g_state.cbChunked && size > g_state.cbXfer) - { - DEBUG_ERROR("refusing to send more then cbXfer bytes for chunked xfer"); - size = g_state.cbXfer; - } - - if (!g_state.cbChunked) - spice_clipboard_data_start(g_state.cbType, size); - - spice_clipboard_data(g_state.cbType, data, (uint32_t)size); - g_state.cbXfer -= size; -} - -void app_clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque) -{ - if (!params.clipboardToLocal) - return; - - struct CBRequest * cbr = (struct CBRequest *)malloc(sizeof(struct CBRequest)); - - cbr->type = g_state.cbType; - cbr->replyFn = replyFn; - cbr->opaque = opaque; - ll_push(g_state.cbRequestList, cbr); - - spice_clipboard_request(g_state.cbType); -} - -void spiceClipboardNotice(const SpiceDataType type) -{ - if (!params.clipboardToLocal) - return; - - if (!g_state.cbAvailable) - return; - - g_state.cbType = type; - g_state.ds->cbNotice(spice_type_to_clipboard_type(type)); -} - -void spiceClipboardData(const SpiceDataType type, uint8_t * buffer, uint32_t size) -{ - if (!params.clipboardToLocal) - return; - - if (type == SPICE_DATA_TEXT) - { - // dos2unix - uint8_t * p = buffer; - uint32_t newSize = size; - for(uint32_t i = 0; i < size; ++i) - { - uint8_t c = buffer[i]; - if (c == '\r') - { - --newSize; - continue; - } - *p++ = c; - } - size = newSize; - } - - struct CBRequest * cbr; - if (ll_shift(g_state.cbRequestList, (void **)&cbr)) - { - cbr->replyFn(cbr->opaque, spice_type_to_clipboard_type(type), buffer, size); - free(cbr); - } -} - -void spiceClipboardRelease(void) -{ - if (!params.clipboardToLocal) - return; - - if (g_state.cbAvailable) - g_state.ds->cbRelease(); -} - -void spiceClipboardRequest(const SpiceDataType type) -{ - if (!params.clipboardToVM) - return; - - if (g_state.cbAvailable) - g_state.ds->cbRequest(spice_type_to_clipboard_type(type)); -} - -static bool warpPointer(int x, int y, bool exiting) -{ - if (!g_cursor.inWindow && !exiting) - return false; - - if (g_cursor.warpState == WARP_STATE_OFF) - return false; - - if (exiting) - g_cursor.warpState = WARP_STATE_OFF; - - if (g_cursor.pos.x == x && g_cursor.pos.y == y) - return true; - - g_state.ds->warpPointer(x, y, exiting); - return true; -} - -static bool isValidCursorLocation(int x, int y) -{ - const int displays = SDL_GetNumVideoDisplays(); - for(int i = 0; i < displays; ++i) - { - SDL_Rect r; - SDL_GetDisplayBounds(i, &r); - if ((x >= r.x && x < r.x + r.w) && - (y >= r.y && y < r.y + r.h)) - return true; - } - return false; -} - -static void cursorToInt(double ex, double ey, int *x, int *y) -{ - /* only smooth if enabled and not using raw mode */ - if (params.mouseSmoothing && !(g_cursor.grab && params.rawMouse)) - { - static struct DoublePoint last = { 0 }; - - /* only apply smoothing to small deltas */ - if (fabs(ex - last.x) < 5.0 && fabs(ey - last.y) < 5.0) - { - ex = last.x = (last.x + ex) / 2.0; - ey = last.y = (last.y + ey) / 2.0; - } - else - { - last.x = ex; - last.y = ey; - } - } - - /* convert to int accumulating the fractional error */ - ex += g_cursor.acc.x; - ey += g_cursor.acc.y; - g_cursor.acc.x = modf(ex, &ex); - g_cursor.acc.y = modf(ey, &ey); - - *x = (int)ex; - *y = (int)ey; -} - -static void setCursorInView(bool enable) -{ - // if the state has not changed, don't do anything else - if (g_cursor.inView == enable) - return; - - if (enable && !g_state.focused) - return; - - // do not allow the view to become active if any mouse buttons are being held, - // this fixes issues with meta window resizing. - if (enable && g_cursor.buttons) - return; - - g_cursor.inView = enable; - g_cursor.draw = (params.alwaysShowCursor || params.captureInputOnly) - ? true : enable; - g_cursor.redraw = true; - - /* if the display server does not support warp, then we can not operate in - * always relative mode and we should not grab the pointer */ - bool warpSupport = true; - app_getProp(LG_DS_WARP_SUPPORT, &warpSupport); - - g_cursor.warpState = enable ? WARP_STATE_ON : WARP_STATE_OFF; - - if (enable) - { - if (params.hideMouse) - SDL_ShowCursor(SDL_DISABLE); - - if (warpSupport && !params.captureInputOnly) - g_state.ds->grabPointer(); - - if (params.grabKeyboardOnFocus) - g_state.ds->grabKeyboard(); - } - else - { - if (params.hideMouse) - SDL_ShowCursor(SDL_ENABLE); - - if (warpSupport) - g_state.ds->ungrabPointer(); - - g_state.ds->ungrabKeyboard(); - } - - g_cursor.warpState = WARP_STATE_ON; -} - -void app_handleMouseGrabbed(double ex, double ey) -{ - if (!app_inputEnabled()) - return; - - int x, y; - if (params.rawMouse && !g_cursor.useScale) - { - /* 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); - 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 app_handleButtonPress(int button) -{ - if (!app_inputEnabled() || !g_cursor.inView) - return; - - g_cursor.buttons |= (1U << button); - - if (!spice_mouse_press(button)) - DEBUG_ERROR("SDL_MOUSEBUTTONDOWN: failed to send message"); -} - -void app_handleButtonRelease(int button) -{ - if (!app_inputEnabled()) - return; - - g_cursor.buttons &= ~(1U << button); - - if (!spice_mouse_release(button)) - DEBUG_ERROR("SDL_MOUSEBUTTONUP: failed to send message"); -} - -void app_handleKeyPress(int sc) -{ - if (sc == params.escapeKey && !g_state.escapeActive) - { - g_state.escapeActive = true; - g_state.escapeAction = -1; - return; - } - - if (g_state.escapeActive) - { - g_state.escapeAction = sc; - return; - } - - if (!app_inputEnabled()) - return; - - if (params.ignoreWindowsKeys && (sc == KEY_LEFTMETA || sc == KEY_RIGHTMETA)) - return; - - if (!g_state.keyDown[sc]) - { - uint32_t ps2 = xfree86_to_ps2[sc]; - if (!ps2) - return; - - if (spice_key_down(ps2)) - g_state.keyDown[sc] = true; - else - { - DEBUG_ERROR("SDL_KEYDOWN: failed to send message"); - return; - } - } -} - -void app_handleKeyRelease(int sc) -{ - if (g_state.escapeActive) - { - if (g_state.escapeAction == -1) - { - if (params.useSpiceInput) - setGrab(!g_cursor.grab); - } - else - { - KeybindHandle handle = g_state.bindings[sc]; - if (handle) - { - handle->callback(sc, handle->opaque); - return; - } - } - - if (sc == params.escapeKey) - g_state.escapeActive = false; - } - - if (!app_inputEnabled()) - return; - - // avoid sending key up events when we didn't send a down - if (!g_state.keyDown[sc]) - return; - - if (params.ignoreWindowsKeys && (sc == KEY_LEFTMETA || sc == KEY_RIGHTMETA)) - return; - - uint32_t ps2 = xfree86_to_ps2[sc]; - if (!ps2) - return; - - if (spice_key_up(ps2)) - g_state.keyDown[sc] = false; - else - { - DEBUG_ERROR("SDL_KEYUP: failed to send message"); - return; - } -} - -static void rotatePoint(struct DoublePoint *point) -{ - double temp; - - switch((g_state.rotate + params.winRotate) % LG_ROTATE_MAX) - { - case LG_ROTATE_0: - break; - - case LG_ROTATE_90: - temp = point->x; - point->x = point->y; - point->y = -temp; - break; - - case LG_ROTATE_180: - point->x = -point->x; - point->y = -point->y; - break; - - case LG_ROTATE_270: - temp = point->x; - point->x = -point->y; - point->y = temp; - break; - } -} - -static bool guestCurToLocal(struct DoublePoint *local) -{ - if (!g_cursor.guest.valid || !g_state.posInfoValid) - return false; - - const struct DoublePoint point = - { - .x = g_cursor.guest.x + g_cursor.guest.hx, - .y = g_cursor.guest.y + g_cursor.guest.hy - }; - - switch((g_state.rotate + params.winRotate) % LG_ROTATE_MAX) - { - case LG_ROTATE_0: - local->x = (point.x / g_cursor.scale.x) + g_state.dstRect.x; - local->y = (point.y / g_cursor.scale.y) + g_state.dstRect.y;; - break; - - case LG_ROTATE_90: - local->x = (g_state.dstRect.x + g_state.dstRect.w) - - point.y / g_cursor.scale.y; - local->y = (point.x / g_cursor.scale.x) + g_state.dstRect.y; - break; - - case LG_ROTATE_180: - local->x = (g_state.dstRect.x + g_state.dstRect.w) - - point.x / g_cursor.scale.x; - local->y = (g_state.dstRect.y + g_state.dstRect.h) - - point.y / g_cursor.scale.y; - break; - - case LG_ROTATE_270: - local->x = (point.y / g_cursor.scale.y) + g_state.dstRect.x; - local->y = (g_state.dstRect.y + g_state.dstRect.h) - - point.x / g_cursor.scale.x; - break; - } - - return true; -} - -inline static void localCurToGuest(struct DoublePoint *guest) -{ - const struct DoublePoint point = - g_cursor.pos; - - switch((g_state.rotate + params.winRotate) % LG_ROTATE_MAX) - { - case LG_ROTATE_0: - guest->x = (point.x - g_state.dstRect.x) * g_cursor.scale.x; - guest->y = (point.y - g_state.dstRect.y) * g_cursor.scale.y; - break; - - case LG_ROTATE_90: - guest->x = (point.y - g_state.dstRect.y) * g_cursor.scale.y; - guest->y = (g_state.dstRect.w - point.x + g_state.dstRect.x) - * g_cursor.scale.x; - break; - - case LG_ROTATE_180: - guest->x = (g_state.dstRect.w - point.x + g_state.dstRect.x) - * g_cursor.scale.x; - guest->y = (g_state.dstRect.h - point.y + g_state.dstRect.y) - * g_cursor.scale.y; - break; - - case LG_ROTATE_270: - guest->x = (g_state.dstRect.h - point.y + g_state.dstRect.y) - * g_cursor.scale.y; - guest->y = (point.x - g_state.dstRect.x) * g_cursor.scale.x; - break; - - default: - assert(!"unreachable"); - } -} - -void app_handleMouseNormal(double ex, double ey) -{ - // prevent cursor handling outside of capture if the position is not known - if (!g_cursor.guest.valid) - return; - - if (!app_inputEnabled()) - return; - - /* scale the movement to the guest */ - if (g_cursor.useScale && 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; - - 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; - 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 (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}; - rotatePoint(&move); - - /* translate the guests position to our coordinate space */ - struct DoublePoint local; - 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 (isValidCursorLocation( - g_state.windowPos.x + g_state.border.x + tx, - g_state.windowPos.y + g_state.border.y + ty)) - { - 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(); - warpPointer(tx, ty, true); - return; - } - } - } - - int x, y; - cursorToInt(ex, ey, &x, &y); - - if (x == 0 && y == 0) - return; - - if (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; - 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"); -} - - -// On some display servers normal cursor logic does not work due to the lack of -// cursor warp support. Instead, we attempt a best-effort emulation which works -// with a 1:1 mouse movement patch applied in the guest. For anything fancy, use -// capture mode. -void app_handleMouseBasic() -{ - /* do not pass mouse events to the guest if we do not have focus */ - if (!g_state.focused) - return; - - if (!app_inputEnabled()) - return; - - 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; - - setCursorInView(inView); - - if (g_cursor.guest.dpiScale == 0) - return; - - double px = g_cursor.pos.x; - double py = g_cursor.pos.y; - - if (px < g_state.dstRect.x) - px = g_state.dstRect.x; - else if (px > g_state.dstRect.x + g_state.dstRect.w) - px = g_state.dstRect.x + g_state.dstRect.w; - - if (py < g_state.dstRect.y) - py = g_state.dstRect.y; - else if (py > g_state.dstRect.y + g_state.dstRect.h) - py = g_state.dstRect.y + g_state.dstRect.h; - - /* translate the guests position to our coordinate space */ - struct DoublePoint local; - guestCurToLocal(&local); - - int x = (int) round((px - local.x) / g_cursor.dpiScale); - int y = (int) round((py - local.y) / g_cursor.dpiScale); - - if (!x && !y) - return; - - g_cursor.guest.x += x; - g_cursor.guest.y += y; - - if (!spice_mouse_motion(x, y)) - DEBUG_ERROR("failed to send mouse motion message"); -} - -void app_updateWindowPos(int x, int y) -{ - g_state.windowPos.x = x; - g_state.windowPos.y = y; -} - -void app_handleResizeEvent(int w, int h) -{ - SDL_GetWindowBordersSize(g_state.window, - &g_state.border.y, - &g_state.border.x, - &g_state.border.h, - &g_state.border.w - ); - - /* don't do anything else if the window dimensions have not changed */ - if (g_state.windowW == w && g_state.windowH == h) - return; - - g_state.windowW = w; - g_state.windowH = h; - g_state.windowCX = w / 2; - g_state.windowCY = h / 2; - updatePositionInfo(); - - if (app_inputEnabled()) - { - /* if the window is moved/resized causing a loss of focus while grabbed, it - * makes it impossible to re-focus the window, so we quietly re-enter - * capture if we were already in it */ - if (g_cursor.grab) - { - setGrabQuiet(false); - setGrabQuiet(true); - } - alignToGuest(); - } -} - -void app_handleWindowLeave(void) -{ - g_cursor.inWindow = false; - setCursorInView(false); - - if (!app_inputEnabled()) - return; - - if (!params.alwaysShowCursor) - g_cursor.draw = false; - g_cursor.redraw = true; -} - -void app_handleWindowEnter(void) -{ - g_cursor.inWindow = true; - if (!app_inputEnabled()) - return; - - g_cursor.realign = true; -} - -static void setGrab(bool enable) -{ - setGrabQuiet(enable); - - app_alert( - g_cursor.grab ? LG_ALERT_SUCCESS : LG_ALERT_WARNING, - g_cursor.grab ? "Capture Enabled" : "Capture Disabled" - ); -} - -static void setGrabQuiet(bool enable) -{ - /* we always do this so that at init the cursor is in the right state */ - if (params.captureInputOnly && params.hideMouse) - SDL_ShowCursor(enable ? SDL_DISABLE : SDL_ENABLE); - - if (g_cursor.grab == enable) - return; - - g_cursor.grab = enable; - g_cursor.acc.x = 0.0; - g_cursor.acc.y = 0.0; - - /* if the display server does not support warp we need to ungrab the pointer - * here instead of in the move handler */ - bool warpSupport = true; - app_getProp(LG_DS_WARP_SUPPORT, &warpSupport); - - if (enable) - { - setCursorInView(true); - g_state.ignoreInput = false; - - if (params.grabKeyboard) - g_state.ds->grabKeyboard(); - - g_state.ds->grabPointer(); - } - else - { - if (params.grabKeyboard) - { - if (!params.grabKeyboardOnFocus || !g_state.focused || params.captureInputOnly) - g_state.ds->ungrabKeyboard(); - } - - if (!warpSupport || params.captureInputOnly || !g_state.formatValid) - g_state.ds->ungrabPointer(); - - // if exiting capture when input on capture only, we want to show the cursor - if (params.captureInputOnly || !params.hideMouse) - alignToGuest(); - } -} - int eventFilter(void * userdata, SDL_Event * event) { if (g_state.ds->eventFilter(event)) @@ -1586,25 +586,6 @@ int eventFilter(void * userdata, SDL_Event * event) if (LG_DisplayServers[0]->eventFilter(event)) return 0; - if (event->type == e_SDLEvent) - { - switch(event->user.code) - { - case LG_EVENT_ALIGN_TO_GUEST: - { - if (!g_cursor.guest.valid || !g_state.focused) - break; - - struct DoublePoint local; - if (guestCurToLocal(&local)) - if (warpPointer(round(local.x), round(local.y), false)) - setCursorInView(true); - break; - } - } - return 0; - } - // consume all events return 0; } @@ -1658,8 +639,8 @@ static bool try_renderer(const int index, const LG_RendererParams lgrParams, Uin static void toggle_fullscreen(uint32_t scancode, void * opaque) { - SDL_SetWindowFullscreen(g_state.window, params.fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); - params.fullscreen = !params.fullscreen; + SDL_SetWindowFullscreen(g_state.window, g_params.fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); + g_params.fullscreen = !g_params.fullscreen; } static void toggle_video(uint32_t scancode, void * opaque) @@ -1685,11 +666,11 @@ static void toggle_video(uint32_t scancode, void * opaque) static void toggle_rotate(uint32_t scancode, void * opaque) { - if (params.winRotate == LG_ROTATE_MAX-1) - params.winRotate = 0; + if (g_params.winRotate == LG_ROTATE_MAX-1) + g_params.winRotate = 0; else - ++params.winRotate; - updatePositionInfo(); + ++g_params.winRotate; + core_updatePositionInfo(); } static void toggle_input(uint32_t scancode, void * opaque) @@ -1697,7 +678,7 @@ static void toggle_input(uint32_t scancode, void * opaque) g_state.ignoreInput = !g_state.ignoreInput; if (g_state.ignoreInput) - setCursorInView(false); + core_setCursorInView(false); else g_state.ds->realignPointer(); @@ -1769,7 +750,7 @@ static void register_key_binds(void) g_state.kbRotate = app_register_keybind(KEY_R , toggle_rotate , NULL); g_state.kbQuit = app_register_keybind(KEY_Q , quit , NULL); - if (params.useSpiceInput) + if (g_params.useSpiceInput) { g_state.kbInput = app_register_keybind(KEY_I , toggle_input , NULL); g_state.kbMouseSensInc = app_register_keybind(KEY_INSERT, mouse_sens_inc , NULL); @@ -1819,7 +800,7 @@ static int lg_run(void) { memset(&g_state, 0, sizeof(g_state)); - g_cursor.sens = params.mouseSens; + g_cursor.sens = g_params.mouseSens; if (g_cursor.sens < -9) g_cursor.sens = -9; else if (g_cursor.sens > 9) g_cursor.sens = 9; @@ -1891,15 +872,15 @@ static int lg_run(void) } // try to connect to the spice server - if (params.useSpiceInput || params.useSpiceClipboard) + if (g_params.useSpiceInput || g_params.useSpiceClipboard) { spice_set_clipboard_cb( - spiceClipboardNotice, - spiceClipboardData, - spiceClipboardRelease, - spiceClipboardRequest); + cb_spiceNotice, + cb_spiceData, + cb_spiceRelease, + cb_spiceRequest); - if (!spice_connect(params.spiceHost, params.spicePort, "")) + if (!spice_connect(g_params.spiceHost, g_params.spicePort, "")) { DEBUG_ERROR("Failed to connect to spice server"); return -1; @@ -1923,20 +904,20 @@ static int lg_run(void) // select and init a renderer LG_RendererParams lgrParams; - lgrParams.showFPS = params.showFPS; - lgrParams.quickSplash = params.quickSplash; + lgrParams.showFPS = g_params.showFPS; + lgrParams.quickSplash = g_params.quickSplash; Uint32 sdlFlags; - if (params.forceRenderer) + if (g_params.forceRenderer) { DEBUG_INFO("Trying forced renderer"); sdlFlags = 0; - if (!try_renderer(params.forceRendererIndex, lgrParams, &sdlFlags)) + if (!try_renderer(g_params.forceRendererIndex, lgrParams, &sdlFlags)) { DEBUG_ERROR("Forced renderer failed to iniailize"); return -1; } - g_state.lgr = LG_Renderers[params.forceRendererIndex]; + g_state.lgr = LG_Renderers[g_params.forceRendererIndex]; } else { @@ -1960,16 +941,16 @@ static int lg_run(void) // all our ducks are in a line, create the window g_state.window = SDL_CreateWindow( - params.windowTitle, - params.center ? SDL_WINDOWPOS_CENTERED : params.x, - params.center ? SDL_WINDOWPOS_CENTERED : params.y, - params.w, - params.h, + g_params.windowTitle, + g_params.center ? SDL_WINDOWPOS_CENTERED : g_params.x, + g_params.center ? SDL_WINDOWPOS_CENTERED : g_params.y, + g_params.w, + g_params.h, ( SDL_WINDOW_HIDDEN | - (params.allowResize ? SDL_WINDOW_RESIZABLE : 0) | - (params.borderless ? SDL_WINDOW_BORDERLESS : 0) | - (params.maximize ? SDL_WINDOW_MAXIMIZED : 0) | + (g_params.allowResize ? SDL_WINDOW_RESIZABLE : 0) | + (g_params.borderless ? SDL_WINDOW_BORDERLESS : 0) | + (g_params.maximize ? SDL_WINDOW_MAXIMIZED : 0) | sdlFlags ) ); @@ -1997,37 +978,34 @@ static int lg_run(void) SDL_ShowWindow(g_state.window); SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, - params.minimizeOnFocusLoss ? "1" : "0"); + g_params.minimizeOnFocusLoss ? "1" : "0"); - if (params.fullscreen) + if (g_params.fullscreen) SDL_SetWindowFullscreen(g_state.window, SDL_WINDOW_FULLSCREEN_DESKTOP); - if (!params.center) - SDL_SetWindowPosition(g_state.window, params.x, params.y); + if (!g_params.center) + SDL_SetWindowPosition(g_state.window, g_params.x, g_params.y); - if (params.noScreensaver) + if (g_params.noScreensaver) g_state.ds->inhibitIdle(); // ensure the initial window size is stored in the state SDL_GetWindowSize(g_state.window, &g_state.windowW, &g_state.windowH); // ensure renderer viewport is aware of the current window size - updatePositionInfo(); + core_updatePositionInfo(); - if (params.fpsMin <= 0) + if (g_params.fpsMin <= 0) { // default 30 fps g_state.frameTime = 1000000000ULL / 30ULL; } else { - DEBUG_INFO("Using the FPS minimum from args: %d", params.fpsMin); - g_state.frameTime = 1000000000ULL / (unsigned long long)params.fpsMin; + DEBUG_INFO("Using the FPS minimum from args: %d", g_params.fpsMin); + g_state.frameTime = 1000000000ULL / (unsigned long long)g_params.fpsMin; } - // create our custom event - e_SDLEvent = SDL_RegisterEvents(1); - register_key_binds(); initSDLCursor(); @@ -2083,8 +1061,8 @@ static int lg_run(void) * we start checking for a valid session */ SDL_WaitEventTimeout(NULL, 200); - if (params.captureOnStart) - setGrab(true); + if (g_params.captureOnStart) + core_setGrab(true); uint32_t udataSize; KVMFR *udata; @@ -2113,8 +1091,7 @@ restart: { DEBUG_BREAK(); DEBUG_INFO("Please check the host application is running and is the correct version"); - DEBUG_INFO("Check the host log in your guest at: " - "%%ProgramData%%\\Looking Glass (host)\\looking-glass-host.txt"); + DEBUG_INFO("Check the host log in your guest at %%TEMP%%\\looking-glass-host.txt"); DEBUG_INFO("Continuing to wait..."); } @@ -2232,7 +1209,7 @@ static void lg_shutdown(void) } // if spice is still connected send key up events for any pressed keys - if (params.useSpiceInput && spice_ready()) + if (g_params.useSpiceInput && spice_ready()) { for(uint32_t scancode = 0; scancode < KEY_MAX; ++scancode) if (g_state.keyDown[scancode]) diff --git a/client/src/main.h b/client/src/main.h index 42ce5906..d81b38b7 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -25,6 +25,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "interface/app.h" #include "dynamic/displayservers.h" #include "dynamic/renderers.h" + +#include "common/types.h" #include "common/ivshmem.h" #include "spice/spice.h" @@ -192,11 +194,6 @@ struct CursorInfo uint32_t dpiScale; }; -struct DoublePoint -{ - double x, y; -}; - struct CursorState { /* cursor is in grab mode */ @@ -252,5 +249,6 @@ struct CursorState }; // forwards -extern struct AppState g_state; -extern struct AppParams params; +extern struct AppState g_state; +extern struct CursorState g_cursor; +extern struct AppParams g_params; diff --git a/client/src/util.c b/client/src/util.c new file mode 100644 index 00000000..d8d8e00e --- /dev/null +++ b/client/src/util.c @@ -0,0 +1,222 @@ +/* +Looking Glass - KVM FrameRelay (KVMFR) Client +Copyright (C) 2017-2021 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "util.h" +#include "main.h" + +#include "common/debug.h" + +#include +#include +#include + +bool util_fileGetContents(const char * filename, char ** buffer, size_t * length) +{ + FILE * fh = fopen(filename, "r"); + if (!fh) + { + DEBUG_ERROR("Failed to open the file: %s", filename); + return false; + } + + if (fseek(fh, 0, SEEK_END) != 0) + { + DEBUG_ERROR("Failed to seek"); + fclose(fh); + return false; + } + + long fsize = ftell(fh); + if (fseek(fh, 0, SEEK_SET) != 0) + { + DEBUG_ERROR("Failed to seek"); + fclose(fh); + return false; + } + + *buffer = malloc(fsize + 1); + if (!*buffer) + { + DEBUG_ERROR("Failed to allocate buffer of %lu bytes", fsize + 1); + fclose(fh); + return false; + } + + if (fread(*buffer, 1, fsize, fh) != fsize) + { + DEBUG_ERROR("Failed to read the entire file"); + fclose(fh); + free(*buffer); + return false; + } + + fclose(fh); + buffer[fsize] = 0; + *length = fsize; + return true; +} + +void util_cursorToInt(double ex, double ey, int *x, int *y) +{ + /* only smooth if enabled and not using raw mode */ + if (g_params.mouseSmoothing && !(g_cursor.grab && g_params.rawMouse)) + { + static struct DoublePoint last = { 0 }; + + /* only apply smoothing to small deltas */ + if (fabs(ex - last.x) < 5.0 && fabs(ey - last.y) < 5.0) + { + ex = last.x = (last.x + ex) / 2.0; + ey = last.y = (last.y + ey) / 2.0; + } + else + { + last.x = ex; + last.y = ey; + } + } + + /* convert to int accumulating the fractional error */ + ex += g_cursor.acc.x; + ey += g_cursor.acc.y; + g_cursor.acc.x = modf(ex, &ex); + g_cursor.acc.y = modf(ey, &ey); + + *x = (int)ex; + *y = (int)ey; +} + +bool util_guestCurToLocal(struct DoublePoint *local) +{ + if (!g_cursor.guest.valid || !g_state.posInfoValid) + return false; + + const struct DoublePoint point = + { + .x = g_cursor.guest.x + g_cursor.guest.hx, + .y = g_cursor.guest.y + g_cursor.guest.hy + }; + + switch((g_state.rotate + g_params.winRotate) % LG_ROTATE_MAX) + { + case LG_ROTATE_0: + local->x = (point.x / g_cursor.scale.x) + g_state.dstRect.x; + local->y = (point.y / g_cursor.scale.y) + g_state.dstRect.y;; + break; + + case LG_ROTATE_90: + local->x = (g_state.dstRect.x + g_state.dstRect.w) - + point.y / g_cursor.scale.y; + local->y = (point.x / g_cursor.scale.x) + g_state.dstRect.y; + break; + + case LG_ROTATE_180: + local->x = (g_state.dstRect.x + g_state.dstRect.w) - + point.x / g_cursor.scale.x; + local->y = (g_state.dstRect.y + g_state.dstRect.h) - + point.y / g_cursor.scale.y; + break; + + case LG_ROTATE_270: + local->x = (point.y / g_cursor.scale.y) + g_state.dstRect.x; + local->y = (g_state.dstRect.y + g_state.dstRect.h) - + point.x / g_cursor.scale.x; + break; + } + + return true; +} + +void util_localCurToGuest(struct DoublePoint *guest) +{ + const struct DoublePoint point = + g_cursor.pos; + + switch((g_state.rotate + g_params.winRotate) % LG_ROTATE_MAX) + { + case LG_ROTATE_0: + guest->x = (point.x - g_state.dstRect.x) * g_cursor.scale.x; + guest->y = (point.y - g_state.dstRect.y) * g_cursor.scale.y; + break; + + case LG_ROTATE_90: + guest->x = (point.y - g_state.dstRect.y) * g_cursor.scale.y; + guest->y = (g_state.dstRect.w - point.x + g_state.dstRect.x) + * g_cursor.scale.x; + break; + + case LG_ROTATE_180: + guest->x = (g_state.dstRect.w - point.x + g_state.dstRect.x) + * g_cursor.scale.x; + guest->y = (g_state.dstRect.h - point.y + g_state.dstRect.y) + * g_cursor.scale.y; + break; + + case LG_ROTATE_270: + guest->x = (g_state.dstRect.h - point.y + g_state.dstRect.y) + * g_cursor.scale.y; + guest->y = (point.x - g_state.dstRect.x) * g_cursor.scale.x; + break; + + default: + assert(!"unreachable"); + } +} + +void util_rotatePoint(struct DoublePoint *point) +{ + double temp; + + switch((g_state.rotate + g_params.winRotate) % LG_ROTATE_MAX) + { + case LG_ROTATE_0: + break; + + case LG_ROTATE_90: + temp = point->x; + point->x = point->y; + point->y = -temp; + break; + + case LG_ROTATE_180: + point->x = -point->x; + point->y = -point->y; + break; + + case LG_ROTATE_270: + temp = point->x; + point->x = -point->y; + point->y = temp; + break; + } +} + +bool util_isValidCursorLocation(int x, int y) +{ + const int displays = SDL_GetNumVideoDisplays(); + for(int i = 0; i < displays; ++i) + { + SDL_Rect r; + SDL_GetDisplayBounds(i, &r); + if ((x >= r.x && x < r.x + r.w) && + (y >= r.y && y < r.y + r.h)) + return true; + } + return false; +} diff --git a/client/src/utils.c b/client/src/utils.c deleted file mode 100644 index a877543e..00000000 --- a/client/src/utils.c +++ /dev/null @@ -1,70 +0,0 @@ -/* -Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2019 Geoffrey McRae -https://looking-glass.hostfission.com - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; either version 2 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include "utils.h" -#include "common/debug.h" - -#include -#include - -bool file_get_contents(const char * filename, char ** buffer, size_t * length) -{ - FILE * fh = fopen(filename, "r"); - if (!fh) - { - DEBUG_ERROR("Failed to open the file: %s", filename); - return false; - } - - if (fseek(fh, 0, SEEK_END) != 0) - { - DEBUG_ERROR("Failed to seek"); - fclose(fh); - return false; - } - - long fsize = ftell(fh); - if (fseek(fh, 0, SEEK_SET) != 0) - { - DEBUG_ERROR("Failed to seek"); - fclose(fh); - return false; - } - - *buffer = malloc(fsize + 1); - if (!*buffer) - { - DEBUG_ERROR("Failed to allocate buffer of %lu bytes", fsize + 1); - fclose(fh); - return false; - } - - if (fread(*buffer, 1, fsize, fh) != fsize) - { - DEBUG_ERROR("Failed to read the entire file"); - fclose(fh); - free(*buffer); - return false; - } - - fclose(fh); - buffer[fsize] = 0; - *length = fsize; - return true; -} \ No newline at end of file diff --git a/common/include/common/KVMFR.h b/common/include/common/KVMFR.h index 00401a39..1981202a 100644 --- a/common/include/common/KVMFR.h +++ b/common/include/common/KVMFR.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -16,9 +16,17 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifndef _H_LG_COMMON_KVMFR_ +#define _H_LG_COMMON_KVMFR_ + #pragma once #include +#include "types.h" + +#define KVMFR_MAGIC "KVMFR---" +#define KVMFR_VERSION 8 #define LGMP_Q_POINTER 1 #define LGMP_Q_FRAME 2 @@ -26,47 +34,15 @@ Place, Suite 330, Boston, MA 02111-1307 USA #define LGMP_Q_FRAME_LEN 2 #define LGMP_Q_POINTER_LEN 20 -typedef enum FrameType -{ - FRAME_TYPE_INVALID , - FRAME_TYPE_BGRA , // BGRA interleaved: B,G,R,A 32bpp - FRAME_TYPE_RGBA , // RGBA interleaved: R,G,B,A 32bpp - FRAME_TYPE_RGBA10 , // RGBA interleaved: R,G,B,A 10,10,10,2 bpp - FRAME_TYPE_RGBA16F , // RGBA interleaved: R,G,B,A 16,16,16,16 bpp float - FRAME_TYPE_MAX , // sentinel value -} -FrameType; - -typedef enum FrameRotation -{ - FRAME_ROT_0, - FRAME_ROT_90, - FRAME_ROT_180, - FRAME_ROT_270 -} -FrameRotation; - -extern const char * FrameTypeStr[FRAME_TYPE_MAX]; - enum { CURSOR_FLAG_POSITION = 0x1, CURSOR_FLAG_VISIBLE = 0x2, CURSOR_FLAG_SHAPE = 0x4 }; + typedef uint32_t KVMFRCursorFlags; -typedef enum CursorType -{ - CURSOR_TYPE_COLOR , - CURSOR_TYPE_MONOCHROME , - CURSOR_TYPE_MASKED_COLOR -} -CursorType; - -#define KVMFR_MAGIC "KVMFR---" -#define KVMFR_VERSION 8 - typedef struct KVMFR { char magic[8]; @@ -99,3 +75,5 @@ typedef struct KVMFRFrame uint32_t mouseScalePercent; // movement scale factor of the mouse (relates to DPI of display, 100 = no scale) } KVMFRFrame; + +#endif diff --git a/common/include/common/crash.h b/common/include/common/crash.h index c3232421..42eff257 100644 --- a/common/include/common/crash.h +++ b/common/include/common/crash.h @@ -1,6 +1,6 @@ /* KVMGFX Client - A KVM Client for VGA Passthrough -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,7 +17,12 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef _H_LG_COMMON_CRASH_ +#define _H_LG_COMMON_CRASH_ + #include bool installCrashHandler(const char * exe); void cleanupCrashHandler(void); + +#endif diff --git a/common/include/common/debug.h b/common/include/common/debug.h index 20106184..0250362e 100644 --- a/common/include/common/debug.h +++ b/common/include/common/debug.h @@ -17,6 +17,9 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef _H_LG_COMMON_DEBUG_ +#define _H_LG_COMMON_DEBUG_ + #ifndef __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS #endif @@ -82,3 +85,5 @@ void printBacktrace(void); #else #define DEBUG_PROTO(fmt, ...) do {} while(0) #endif + +#endif diff --git a/common/include/common/dpi.h b/common/include/common/dpi.h index 10dc679b..93e77db0 100644 --- a/common/include/common/dpi.h +++ b/common/include/common/dpi.h @@ -17,9 +17,14 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef _H_LG_COMMON_DPI_ +#define _H_LG_COMMON_DPI_ + #include // At 100% scaling, Windows reports 96 DPI. #define DPI_100_PERCENT 96 UINT monitor_dpi(HMONITOR hMonitor); + +#endif diff --git a/common/include/common/event.h b/common/include/common/event.h index 2d74476f..85a2993a 100644 --- a/common/include/common/event.h +++ b/common/include/common/event.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2020 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,7 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#pragma once +#ifndef _H_LG_COMMON_EVENT_ +#define _H_LG_COMMON_EVENT_ #include #include @@ -40,3 +41,5 @@ LGEvent * lgWrapEvent(void * handle); // Posix specific, not implmented/possible in windows bool lgWaitEventAbs(LGEvent * handle, struct timespec * ts); bool lgWaitEventNS (LGEvent * handle, unsigned int timeout); + +#endif diff --git a/common/include/common/framebuffer.h b/common/include/common/framebuffer.h index aa754cbf..e61089d9 100644 --- a/common/include/common/framebuffer.h +++ b/common/include/common/framebuffer.h @@ -1,6 +1,6 @@ /* KVMGFX Client - A KVM Client for VGA Passthrough -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,7 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#pragma once +#ifndef _H_LG_COMMON_FRAMEBUFFER_ +#define _H_LG_COMMON_FRAMEBUFFER_ #include #include @@ -58,3 +59,5 @@ void framebuffer_prepare(FrameBuffer * frame); * Write data from the src buffer into the KVMFRFrame */ bool framebuffer_write(FrameBuffer * frame, const void * src, size_t size); + +#endif diff --git a/common/include/common/ivshmem.h b/common/include/common/ivshmem.h index 91b27637..9f166e00 100644 --- a/common/include/common/ivshmem.h +++ b/common/include/common/ivshmem.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2020 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,7 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#pragma once +#ifndef _H_LG_COMMON_IVSHMEM_ +#define _H_LG_COMMON_IVSHMEM_ #include #include @@ -41,3 +42,5 @@ void ivshmemFree(struct IVSHMEM * dev); /* Linux KVMFR support only for now (VM->VM) */ bool ivshmemHasDMA (struct IVSHMEM * dev); int ivshmemGetDMABuf(struct IVSHMEM * dev, uint64_t offset, uint64_t size); + +#endif diff --git a/common/include/common/locking.h b/common/include/common/locking.h index 14e086f6..b83d4a40 100644 --- a/common/include/common/locking.h +++ b/common/include/common/locking.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -16,7 +16,9 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#pragma once + +#ifndef _H_LG_COMMON_LOCKING_ +#define _H_LG_COMMON_LOCKING_ #include "time.h" @@ -38,3 +40,5 @@ typedef atomic_flag LG_Lock; LG_LOCK(lock) \ x \ LG_UNLOCK(lock) + +#endif diff --git a/common/include/common/memcpySSE.h b/common/include/common/memcpySSE.h deleted file mode 100644 index 848f5177..00000000 --- a/common/include/common/memcpySSE.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -KVMGFX Client - A KVM Client for VGA Passthrough -Copyright (C) 2017-2019 Geoffrey McRae -https://looking-glass.hostfission.com - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; either version 2 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#pragma once -#include -#include -#include -#include -#include - -#include "debug.h" - -#if defined(NATIVE_MEMCPY) - #define memcpySSE memcpy -#elif defined(_MSC_VER) - extern "C" void * memcpySSE(void *dst, const void * src, size_t length); -#elif (defined(__GNUC__) || defined(__GNUG__)) && defined(__i386__) - inline static void * memcpySSE(void *dst, const void * src, size_t length) - { - if (length == 0 || dst == src) - return; - - // copies under 1MB are faster with the inlined memcpy - // tell the dev to use that instead - if (length < 1048576) - { - static bool smallBufferWarn = false; - if (!smallBufferWarn) - { - DEBUG_WARN("Do not use memcpySSE for copies under 1MB in size!"); - smallBufferWarn = true; - } - memcpy(dst, src, length); - return; - } - - const void * end = dst + (length & ~0x7F); - const size_t off = (7 - ((length & 0x7F) >> 4)) * 9; - - __asm__ __volatile__ ( - "cmp %[dst],%[end] \n\t" - "je Remain_%= \n\t" - - // perform SIMD block copy - "loop_%=: \n\t" - "movaps 0x00(%[src]),%%xmm0 \n\t" - "movaps 0x10(%[src]),%%xmm1 \n\t" - "movaps 0x20(%[src]),%%xmm2 \n\t" - "movaps 0x30(%[src]),%%xmm3 \n\t" - "movaps 0x40(%[src]),%%xmm4 \n\t" - "movaps 0x50(%[src]),%%xmm5 \n\t" - "movaps 0x60(%[src]),%%xmm6 \n\t" - "movaps 0x70(%[src]),%%xmm7 \n\t" - "movntdq %%xmm0 ,0x00(%[dst]) \n\t" - "movntdq %%xmm1 ,0x10(%[dst]) \n\t" - "movntdq %%xmm2 ,0x20(%[dst]) \n\t" - "movntdq %%xmm3 ,0x30(%[dst]) \n\t" - "movntdq %%xmm4 ,0x40(%[dst]) \n\t" - "movntdq %%xmm5 ,0x50(%[dst]) \n\t" - "movntdq %%xmm6 ,0x60(%[dst]) \n\t" - "movntdq %%xmm7 ,0x70(%[dst]) \n\t" - "add $0x80,%[dst] \n\t" - "add $0x80,%[src] \n\t" - "cmp %[dst],%[end] \n\t" - "jne loop_%= \n\t" - - "Remain_%=: \n\t" - - // copy any remaining 16 byte blocks - "call GetPC_%=\n\t" - "Offset_%=:\n\t" - "add $(BlockTable_%= - Offset_%=), %%eax \n\t" - "add %[off],%%eax \n\t" - "jmp *%%eax \n\t" - - "GetPC_%=:\n\t" - "mov (%%esp), %%eax \n\t" - "ret \n\t" - - "BlockTable_%=:\n\t" - "movaps 0x60(%[src]),%%xmm6 \n\t" - "movntdq %%xmm6 ,0x60(%[dst]) \n\t" - "movaps 0x50(%[src]),%%xmm5 \n\t" - "movntdq %%xmm5 ,0x50(%[dst]) \n\t" - "movaps 0x40(%[src]),%%xmm4 \n\t" - "movntdq %%xmm4 ,0x40(%[dst]) \n\t" - "movaps 0x30(%[src]),%%xmm3 \n\t" - "movntdq %%xmm3 ,0x30(%[dst]) \n\t" - "movaps 0x20(%[src]),%%xmm2 \n\t" - "movntdq %%xmm2 ,0x20(%[dst]) \n\t" - "movaps 0x10(%[src]),%%xmm1 \n\t" - "movntdq %%xmm1 ,0x10(%[dst]) \n\t" - "movaps 0x00(%[src]),%%xmm0 \n\t" - "movntdq %%xmm0 ,0x00(%[dst]) \n\t" - "nop\n\t" - "nop\n\t" - - : [dst]"+r" (dst), - [src]"+r" (src) - : [off]"r" (off), - [end]"r" (end) - : "eax", - "xmm0", - "xmm1", - "xmm2", - "xmm3", - "xmm4", - "xmm5", - "xmm6", - "xmm7", - "memory" - ); - - //copy any remaining bytes - memcpy(dst, src, length & 0xF); - } -#else - #define memcpySSE memcpy -#endif diff --git a/common/include/common/option.h b/common/include/common/option.h index 093d5e6d..9ea192ee 100644 --- a/common/include/common/option.h +++ b/common/include/common/option.h @@ -17,6 +17,9 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef _H_COMMON_OPTION_ +#define _H_COMMON_OPTION_ + #include #include "common/stringlist.h" @@ -53,7 +56,7 @@ struct Option char * (*toString )(struct Option * opt); StringList (*getValues)(struct Option * opt); - void (*printHelp)(); + void (*printHelp)(void); // internal use only bool failed_set; @@ -75,10 +78,12 @@ bool option_parse(int argc, char * argv[]); bool option_load(const char * filename); // called by the main application to validate the option values -bool option_validate(); +bool option_validate(void); // print out the options, help, and their current values -void option_print(); +void option_print(void); // final cleanup -void option_free(); \ No newline at end of file +void option_free(void); + +#endif diff --git a/common/include/common/stringlist.h b/common/include/common/stringlist.h index 4b76d325..f8113668 100644 --- a/common/include/common/stringlist.h +++ b/common/include/common/stringlist.h @@ -17,6 +17,9 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef _H_LG_COMMON_STRINGLIST_ +#define _H_LG_COMMON_STRINGLIST_ + #include typedef struct StringList * StringList; @@ -25,4 +28,6 @@ StringList stringlist_new (bool owns_strings); void stringlist_free (StringList * sl); int stringlist_push (StringList sl, char * str); unsigned int stringlist_count(StringList sl); -char * stringlist_at (StringList sl, unsigned int index); \ No newline at end of file +char * stringlist_at (StringList sl, unsigned int index); + +#endif diff --git a/common/include/common/stringutils.h b/common/include/common/stringutils.h index 48274569..50eecd58 100644 --- a/common/include/common/stringutils.h +++ b/common/include/common/stringutils.h @@ -1,6 +1,6 @@ /* KVMGFX Client - A KVM Client for VGA Passthrough -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,6 +17,11 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef _H_LG_COMMON_STRINGUTILS +#define _H_LG_COMMON_STRINGUTILS + // sprintf but with buffer allocation int alloc_sprintf(char ** str, const char * format, ...) - __attribute__ ((format (printf, 2, 3))); \ No newline at end of file + __attribute__ ((format (printf, 2, 3))); + +#endif diff --git a/common/include/common/sysinfo.h b/common/include/common/sysinfo.h index d929674f..08e3aedf 100644 --- a/common/include/common/sysinfo.h +++ b/common/include/common/sysinfo.h @@ -1,6 +1,6 @@ /* KVMGFX Client - A KVM Client for VGA Passthrough -Copyright (C) 2017-2019 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,5 +17,10 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef _H_LG_COMMON_SYSUTILS +#define _H_LG_COMMON_SYSUTILS + // returns the page size long sysinfo_getPageSize(); + +#endif diff --git a/common/include/common/thread.h b/common/include/common/thread.h index 5ed03b9d..a7cc50cf 100644 --- a/common/include/common/thread.h +++ b/common/include/common/thread.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2020 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,12 +17,16 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#pragma once +#ifndef _H_LG_COMMON_THREAD_ +#define _H_LG_COMMON_THREAD_ #include typedef struct LGThread LGThread; typedef int (*LGThreadFunction)(void * opaque); -bool lgCreateThread(const char * name, LGThreadFunction function, void * opaque, LGThread ** handle); +bool lgCreateThread(const char * name, LGThreadFunction function, void * opaque, + LGThread ** handle); bool lgJoinThread (LGThread * handle, int * resultCode); + +#endif diff --git a/common/include/common/types.h b/common/include/common/types.h new file mode 100644 index 00000000..02767638 --- /dev/null +++ b/common/include/common/types.h @@ -0,0 +1,58 @@ +/* +Looking Glass - KVM FrameRelay (KVMFR) Client +Copyright (C) 2017-2021 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _LG_TYPES_H_ +#define _LG_TYPES_H_ + +struct DoublePoint +{ + double x, y; +}; + +typedef enum FrameType +{ + FRAME_TYPE_INVALID , + FRAME_TYPE_BGRA , // BGRA interleaved: B,G,R,A 32bpp + FRAME_TYPE_RGBA , // RGBA interleaved: R,G,B,A 32bpp + FRAME_TYPE_RGBA10 , // RGBA interleaved: R,G,B,A 10,10,10,2 bpp + FRAME_TYPE_RGBA16F , // RGBA interleaved: R,G,B,A 16,16,16,16 bpp float + FRAME_TYPE_MAX , // sentinel value +} +FrameType; + +typedef enum FrameRotation +{ + FRAME_ROT_0, + FRAME_ROT_90, + FRAME_ROT_180, + FRAME_ROT_270 +} +FrameRotation; + +extern const char * FrameTypeStr[FRAME_TYPE_MAX]; + +typedef enum CursorType +{ + CURSOR_TYPE_COLOR , + CURSOR_TYPE_MONOCHROME , + CURSOR_TYPE_MASKED_COLOR +} +CursorType; + +#endif diff --git a/common/include/common/version.h b/common/include/common/version.h index 88365242..da84206c 100644 --- a/common/include/common/version.h +++ b/common/include/common/version.h @@ -1 +1,25 @@ +/* +KVMGFX Client - A KVM Client for VGA Passthrough +Copyright (C) 2017-2021 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _H_LG_COMMON_VERSION_ +#define _H_LG_COMMON_VERSION_ + extern char * BUILD_VERSION; + +#endif diff --git a/common/include/common/windebug.h b/common/include/common/windebug.h index b897d697..cee26bf8 100644 --- a/common/include/common/windebug.h +++ b/common/include/common/windebug.h @@ -1,6 +1,6 @@ /* Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017-2020 Geoffrey McRae +Copyright (C) 2017-2021 Geoffrey McRae https://looking-glass.hostfission.com This program is free software; you can redistribute it and/or modify it under @@ -17,7 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#pragma once +#ifndef _H_LG_COMMON_WINDEBUG_ +#define _H_LG_COMMON_WINDEBUG_ #include "debug.h" #include @@ -35,4 +36,6 @@ bool IsWindows8(); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif + +#endif diff --git a/common/src/memcpySSE.asm b/common/src/memcpySSE.asm deleted file mode 100644 index 090435f1..00000000 --- a/common/src/memcpySSE.asm +++ /dev/null @@ -1,237 +0,0 @@ -.code -memcpySSE proc - ; dst = rcx - ; src = rdx - ; len = r8 - - mov rax, rcx - - test r8, r8 - jz @Exit - - cmp rcx, rdx - je @Exit - - sub rsp, 8 + 2*16 + 4*8 - movdqa oword ptr [rsp + 4*8 + 00 ], xmm6 - movdqa oword ptr [rsp + 4*8 + 16 ], xmm7 - - ; void * end = dst + (length & ~0x7F); - ; end = r10 - mov r9 , r8 - and r9 , 0FFFFFFFFFFFFFF80h - jz @RemainingBlocks - mov r10, rcx - add r10, r9 - - @FullLoop: - movaps xmm0 , xmmword ptr [rdx + 000h] - movaps xmm1 , xmmword ptr [rdx + 010h] - movaps xmm2 , xmmword ptr [rdx + 020h] - movaps xmm3 , xmmword ptr [rdx + 030h] - movaps xmm4 , xmmword ptr [rdx + 040h] - movaps xmm5 , xmmword ptr [rdx + 050h] - movaps xmm6 , xmmword ptr [rdx + 060h] - movaps xmm7 , xmmword ptr [rdx + 070h] - movntdq xmmword ptr [rcx + 000h], xmm0 - movntdq xmmword ptr [rcx + 010h], xmm1 - movntdq xmmword ptr [rcx + 020h], xmm2 - movntdq xmmword ptr [rcx + 030h], xmm3 - movntdq xmmword ptr [rcx + 040h], xmm4 - movntdq xmmword ptr [rcx + 050h], xmm5 - movntdq xmmword ptr [rcx + 060h], xmm6 - movntdq xmmword ptr [rcx + 070h], xmm7 - add rdx, 080h - add rcx, 080h - cmp rcx, r10 - jne @FullLoop - - @RemainingBlocks: - ; size_t rem = (length & 0x7F) >> 4); - ; rem = r11 - mov r11, r8 - and r11, 07Fh - jz @RestoreExit - shr r11, 4 - jz @FinalBytes - - mov r10, 7 - sub r10, r11 - imul r10, 9 - lea r9 , @FinalBlocks - add r9 , r10 - jmp r9 - - @RestoreExit: - movdqa xmm6 , oword ptr [rsp + 4*8 + 00] - movdqa xmm7 , oword ptr [rsp + 4*8 + 16] - add rsp, 8 + 2*16 + 4*8 - - @Exit: - ret - - @FinalBlocks: - movaps xmm6 , xmmword ptr [rdx + 060h] - movntdq xmmword ptr [rcx + 060h], xmm6 - movaps xmm5 , xmmword ptr [rdx + 050h] - movntdq xmmword ptr [rcx + 050h], xmm5 - movaps xmm4 , xmmword ptr [rdx + 040h] - movntdq xmmword ptr [rcx + 040h], xmm4 - movaps xmm3 , xmmword ptr [rdx + 030h] - movntdq xmmword ptr [rcx + 030h], xmm3 - movaps xmm2 , xmmword ptr [rdx + 020h] - movntdq xmmword ptr [rcx + 020h], xmm2 - movaps xmm1 , xmmword ptr [rdx + 010h] - movntdq xmmword ptr [rcx + 010h], xmm1 - movaps xmm0 , xmmword ptr [rdx + 000h] - movntdq xmmword ptr [rcx + 000h], xmm0 - - movdqa xmm6 , oword ptr [rsp + 4*8 + 00] - movdqa xmm7 , oword ptr [rsp + 4*8 + 16] - add rsp, 8 + 2*16 + 4*8 - sfence - - shl r11, 4 - add rdx, r11 - add rcx, r11 - - @FinalBytes: - and r8, 0Fh - jz @Exit - imul r8, 5 - lea r9, @FinalBytesTable - add r9, r8 - jmp r9 - - @FinalBytesTable: - jmp @Copy1 - jmp @Copy2 - jmp @Copy3 - jmp @Copy4 - jmp @Copy5 - jmp @Copy6 - jmp @Copy7 - jmp @Copy8 - jmp @Copy9 - jmp @Copy10 - jmp @Copy11 - jmp @Copy12 - jmp @Copy13 - jmp @Copy14 - jmp @Copy15 - - db 128 DUP(0CCh) - - ; fall through - 1 byte - @Copy1: - mov al, byte ptr [rdx] - mov byte ptr [rcx], al - ret - - @Copy2: - mov r10w, word ptr [rdx] - mov word ptr [rcx], r10w - ret - - @Copy3: - mov r10w, word ptr [rdx] - mov word ptr [rcx], r10w - mov r11b, byte ptr [rdx + 02h] - mov byte ptr [rcx + 02h], r11b - ret - - @Copy4: - mov r9d, dword ptr [rdx] - mov dword ptr [rcx], r9d - ret - - @Copy5: - mov r9d, dword ptr [rdx ] - mov r11b , byte ptr [rdx + 04h] - mov dword ptr [rcx ], r9d - mov byte ptr [rcx + 04h], r11b - ret - - @Copy6: - mov r9d , dword ptr [rdx ] - mov r10w, word ptr [rdx + 04h] - mov dword ptr [rcx ], r9d - mov word ptr [rcx + 04h], r10w - ret - - @Copy7: - mov r9d , dword ptr [rdx ] - mov r10w, word ptr [rdx + 04h] - mov r11b, byte ptr [rdx + 06h] - mov dword ptr [rcx ], r9d - mov word ptr [rcx + 04h], r10w - mov byte ptr [rcx + 06h], r11b - ret - - @Copy8: - mov r8, qword ptr [rdx] - mov qword ptr [rcx], r8 - ret - - @Copy9: - mov r8 , qword ptr [rdx ] - mov r11b, byte ptr [rdx + 08h] - mov qword ptr [rcx ], r8 - mov byte ptr [rcx + 08h], r11b - ret - - @Copy10: - mov r8 , qword ptr [rdx ] - mov r10w, word ptr [rdx + 08h] - mov qword ptr [rcx ], r8 - mov word ptr [rcx + 08h], r10w - ret - - @Copy11: - mov r8 , qword ptr [rdx ] - mov r10w, word ptr [rdx + 08h] - mov r11b, byte ptr [rdx + 0Ah] - mov qword ptr [rcx ], r8 - mov word ptr [rcx + 08h], r10w - mov byte ptr [rcx + 0Ah], r11b - ret - - @Copy12: - mov r8 , qword ptr [rdx ] - mov r9d, dword ptr [rdx + 08h] - mov qword ptr [rcx ], r8 - mov dword ptr [rcx + 08h], r9d - ret - - @Copy13: - mov r8 , qword ptr [rdx ] - mov r9d , dword ptr [rdx + 08h] - mov r11b, byte ptr [rdx + 0Ch] - mov qword ptr [rcx ], r8 - mov dword ptr [rcx + 08h], r9d - mov byte ptr [rcx + 0Ch], r11b - ret - - @Copy14: - mov r8 , qword ptr [rdx ] - mov r9d , dword ptr [rdx + 08h] - mov r10w, word ptr [rdx + 0Ch] - mov qword ptr [rcx ], r8 - mov dword ptr [rcx + 08h], r9d - mov word ptr [rcx + 0Ch], r10w - ret - - ; copy 15 - @Copy15: - mov r8 , qword ptr [rdx + 00h] - mov r9d , dword ptr [rdx + 08h] - mov r10w, word ptr [rdx + 0Ch] - mov r11b, byte ptr [rdx + 0Eh] - mov qword ptr [rcx + 00h], r8 - mov dword ptr [rcx + 08h], r9d - mov word ptr [rcx + 0Ch], r10w - mov byte ptr [rcx + 0Eh], r11b - ret - -memcpySSE endp -end \ No newline at end of file