git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@604 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
Nishi 2025-11-05 04:29:01 +00:00
commit b34054e916
13 changed files with 90 additions and 47 deletions

35
src/abstract/time.c Normal file
View file

@ -0,0 +1,35 @@
/* $Id$ */
#include <Mw/Milsko.h>
#ifdef _WIN32
#include <windows.h>
long MwTimeGetTick(void) {
return GetTickCount();
}
void MwTimeSleep(int ms) {
Sleep(ms);
}
#else
long MwTimeGetTick(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;
}
void MwTimeSleep(int ms) {
struct timespec ts;
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000 * 1000;
nanosleep(&ts, NULL);
}
#endif

View file

@ -1,6 +1,8 @@
/* $Id$ */
#include <Mw/Milsko.h>
#include <windows.h>
typedef struct userdata {
MwLL ll;
POINT min;
@ -201,7 +203,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
} else if(msg == WM_SETCURSOR) {
if(LOWORD(lp) != HTCLIENT) return DefWindowProc(hWnd, msg, wp, lp);
if(u->ll->cursor != NULL) SetCursor(u->ll->cursor);
}else if(msg == WM_USER){
} else if(msg == WM_USER) {
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
} else {
@ -390,10 +392,6 @@ void MwLLNextEvent(MwLL handle) {
}
}
void MwLLSleep(int ms) {
Sleep(ms);
}
MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int height) {
MwLLPixmap r = malloc(sizeof(*r));
HDC dc = GetDC(handle->hWnd);
@ -628,10 +626,6 @@ 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();
}
void MwLLFocus(MwLL handle) {
SetFocus(handle->hWnd);
}

View file

@ -417,15 +417,6 @@ void MwLLNextEvent(MwLL handle) {
}
}
void MwLLSleep(int ms) {
struct timespec ts;
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000 * 1000;
nanosleep(&ts, NULL);
}
void MwLLSetTitle(MwLL handle, const char* title) {
XSetStandardProperties(handle->display, handle->window, title, title, None, (char**)NULL, 0, NULL);
}
@ -757,18 +748,6 @@ void MwLLMakeBorderless(MwLL handle, int toggle) {
wait_map(handle);
}
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;
}
void MwLLFocus(MwLL handle) {
XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime);
}

View file

@ -293,9 +293,9 @@ int MwPending(MwWidget handle) {
}
void MwLoop(MwWidget handle) {
long tick = MwLLGetTick();
long tick = MwTimeGetTick();
int i;
long wait = MwGetInteger(handle, MwNwaitMS);
long wait = MwGetInteger(handle, MwNwaitMS);
long over = 0;
if(wait == MwDEFAULT) wait = MwWaitMS;
while(!handle->close) {
@ -313,10 +313,10 @@ void MwLoop(MwWidget handle) {
}
more = over % (wait / 2);
t = (tick + wait - more) - (t2 = MwLLGetTick());
t = (tick + wait - more) - (t2 = MwTimeGetTick());
if(t > 0) {
MwLLSleep(t);
tick = MwLLGetTick();
MwTimeSleep(t);
tick = MwTimeGetTick();
over -= more;
} else {
tick = t2;

View file

@ -135,7 +135,7 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) {
lb->selected = st + i;
if(((t = MwLLGetTick()) - lb->click_time) < 250 && old == st + i) {
if(((t = MwTimeGetTick()) - lb->click_time) < 250 && old == st + i) {
MwDispatchUserHandler(handle->parent, MwNactivateHandler, &lb->selected);
}