[client] core: new message event system to debounce window size events

This commit is contained in:
Geoffrey McRae 2025-04-02 13:46:55 +11:00
parent 4b11743f18
commit 852eb6bf69
4 changed files with 39 additions and 19 deletions

View File

@ -113,6 +113,7 @@ set(SOURCES
src/main.c src/main.c
src/core.c src/core.c
src/app.c src/app.c
src/message.c
src/audio.c src/audio.c
src/config.c src/config.c
src/keybind.c src/keybind.c

View File

@ -23,6 +23,8 @@
#include "app.h" #include "app.h"
#include "util.h" #include "util.h"
#include "kb.h" #include "kb.h"
#include "message.h"
#include "message.h"
#include "common/time.h" #include "common/time.h"
#include "common/debug.h" #include "common/debug.h"
@ -188,29 +190,39 @@ bool core_warpPointer(int x, int y, bool exiting)
return true; return true;
} }
void core_onWindowSizeChanged(unsigned width, unsigned height)
{
if (!g_state.pointerQueue)
return;
const KVMFRWindowSize msg =
{
.msg.type = KVMFR_MESSAGE_WINDOWSIZE,
.w = g_state.windowW,
.h = g_state.windowH
};
uint32_t serial;
LGMP_STATUS status;
if ((status = lgmpClientSendData(g_state.pointerQueue,
&msg, sizeof(msg), &serial)) != LGMP_OK)
DEBUG_WARN("Message send failed: %s", lgmpStatusString(status));
}
void core_updatePositionInfo(void) void core_updatePositionInfo(void)
{ {
if (g_state.pointerQueue && if (g_state.kvmfrFeatures & KVMFR_FEATURE_WINDOWSIZE)
g_state.kvmfrFeatures & KVMFR_FEATURE_WINDOWSIZE)
{ {
static unsigned lastW = 0, lastH = 0; LGMsg msg =
if (lastW != g_state.windowW || lastH != g_state.windowH)
{ {
lastW = g_state.windowW; .type = LG_MSG_WINDOWSIZE,
lastH = g_state.windowH; .windowSize =
{
const KVMFRWindowSize msg = { .width = g_state.windowW,
.msg.type = KVMFR_MESSAGE_WINDOWSIZE, .height = g_state.windowH
.w = g_state.windowW, }
.h = g_state.windowH };
}; lgMessage_post(&msg);
uint32_t serial;
LGMP_STATUS status;
if ((status = lgmpClientSendData(g_state.pointerQueue,
&msg, sizeof(msg), &serial)) != LGMP_OK)
DEBUG_WARN("Message send failed: %s", lgmpStatusString(status));
}
} }
if (!g_state.haveSrcSize) if (!g_state.haveSrcSize)

View File

@ -29,6 +29,7 @@ void core_setCursorInView(bool enable);
void core_setGrab(bool enable); void core_setGrab(bool enable);
void core_setGrabQuiet(bool enable); void core_setGrabQuiet(bool enable);
bool core_warpPointer(int x, int y, bool exiting); bool core_warpPointer(int x, int y, bool exiting);
void core_onWindowSizeChanged(unsigned width, unsigned height);
void core_updatePositionInfo(void); void core_updatePositionInfo(void);
void core_alignToGuest(void); void core_alignToGuest(void);
bool core_isValidPointerPos(int x, int y); bool core_isValidPointerPos(int x, int y);

View File

@ -52,6 +52,7 @@
#include "common/cpuinfo.h" #include "common/cpuinfo.h"
#include "common/ll.h" #include "common/ll.h"
#include "message.h"
#include "core.h" #include "core.h"
#include "app.h" #include "app.h"
#include "audio.h" #include "audio.h"
@ -1756,6 +1757,7 @@ restart:
g_state.state = APP_STATE_RESTART; g_state.state = APP_STATE_RESTART;
break; break;
} }
lgMessage_process();
g_state.ds->wait(100); g_state.ds->wait(100);
} }
@ -1872,6 +1874,9 @@ int main(int argc, char * argv[])
egl_dynProcsInit(); egl_dynProcsInit();
gl_dynProcsInit(); gl_dynProcsInit();
if (!lgMessage_init())
return -1;
g_state.bindings = ll_new(); g_state.bindings = ll_new();
g_state.overlays = ll_new(); g_state.overlays = ll_new();
@ -1902,6 +1907,7 @@ int main(int argc, char * argv[])
const int ret = lg_run(); const int ret = lg_run();
lg_shutdown(); lg_shutdown();
lgMessage_deinit();
config_free(); config_free();