fix tick things

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@307 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
Nishi 2025-10-13 12:39:37 +00:00
commit 116b57cff0
6 changed files with 25 additions and 3 deletions

View file

@ -38,7 +38,7 @@
#define MwDispatch3(x, y, z) \ #define MwDispatch3(x, y, z) \
if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x, 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 #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -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 MwLLSetSizeHints(MwLL handle, int minx, int miny, int maxx, int maxy);
MWDECL void MwLLMakeBorderless(MwLL handle, int toggle); MWDECL void MwLLMakeBorderless(MwLL handle, int toggle);
MWDECL long MwLLGetTick(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -15,6 +15,7 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <ctype.h> #include <ctype.h>
#include <time.h>
#ifndef _WIN32 #ifndef _WIN32
#include <unistd.h> #include <unistd.h>
#include <sys/ipc.h> #include <sys/ipc.h>

View file

@ -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); SetWindowPos(handle->hWnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
} }
long MwLLGetTick(void) {
return GetTickCount();
}

View file

@ -603,3 +603,15 @@ void MwLLMakeBorderless(MwLL handle, int toggle) {
XMapWindow(handle->display, handle->window); XMapWindow(handle->display, handle->window);
XMoveWindow(handle->display, handle->window, x, y); 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;
}

View file

@ -230,11 +230,14 @@ int MwPending(MwWidget handle) {
} }
void MwLoop(MwWidget handle) { void MwLoop(MwWidget handle) {
long tick = MwLLGetTick();
while(!handle->close) { while(!handle->close) {
MwStep(handle); while(MwPending(handle)) MwStep(handle);
MwDispatchUserHandler(handle, MwNtickHandler, NULL); MwDispatchUserHandler(handle, MwNtickHandler, NULL);
MwLLSleep(MwWaitMS); tick = MwWaitMS - (MwLLGetTick() - tick);
if(tick > 0) MwLLSleep(tick);
tick = MwLLGetTick();
} }
} }