diff --git a/include/Mw/Core.h b/include/Mw/Core.h index 9a23821..f9d0d4c 100644 --- a/include/Mw/Core.h +++ b/include/Mw/Core.h @@ -38,7 +38,7 @@ #define MwDispatch3(x, y, z) \ if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x, z) -#define MwWaitMS 5 +#define MwWaitMS 10 #ifdef __cplusplus extern "C" { diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index 6007d69..a20f67c 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -112,6 +112,8 @@ MWDECL void MwLLMakePopup(MwLL handle, MwLL parent); MWDECL void MwLLSetSizeHints(MwLL handle, int minx, int miny, int maxx, int maxy); MWDECL void MwLLMakeBorderless(MwLL handle, int toggle); +MWDECL long MwLLGetTick(void); + #ifdef __cplusplus } #endif diff --git a/include/Mw/MachDep.h b/include/Mw/MachDep.h index fa143a9..7c086b4 100644 --- a/include/Mw/MachDep.h +++ b/include/Mw/MachDep.h @@ -15,6 +15,7 @@ #include #include #include +#include #ifndef _WIN32 #include #include diff --git a/src/backend/gdi.c b/src/backend/gdi.c index ebaaed7..84d0dc6 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -502,3 +502,7 @@ void MwLLMakeBorderless(MwLL handle, int toggle) { SetWindowPos(handle->hWnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); } + +long MwLLGetTick(void) { + return GetTickCount(); +} diff --git a/src/backend/x11.c b/src/backend/x11.c index adcf28c..6155901 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -603,3 +603,15 @@ void MwLLMakeBorderless(MwLL handle, int toggle) { XMapWindow(handle->display, handle->window); XMoveWindow(handle->display, handle->window, x, y); } + +long MwLLGetTick(void) { + struct timespec ts; + long n = 0; + + clock_gettime(CLOCK_MONOTONIC, &ts); + + n += ts.tv_nsec / 1000 / 1000; + n += ts.tv_sec * 1000; + + return n; +} diff --git a/src/core.c b/src/core.c index 3853527..db616ce 100644 --- a/src/core.c +++ b/src/core.c @@ -230,11 +230,14 @@ int MwPending(MwWidget handle) { } void MwLoop(MwWidget handle) { + long tick = MwLLGetTick(); while(!handle->close) { - MwStep(handle); + while(MwPending(handle)) MwStep(handle); MwDispatchUserHandler(handle, MwNtickHandler, NULL); - MwLLSleep(MwWaitMS); + tick = MwWaitMS - (MwLLGetTick() - tick); + if(tick > 0) MwLLSleep(tick); + tick = MwLLGetTick(); } }