forked from pyrite-dev/milsko
introduce MwWidget->berserk
This commit is contained in:
parent
8d86f185f2
commit
5413332506
4 changed files with 43 additions and 9 deletions
|
|
@ -104,6 +104,8 @@ struct _MwWidget {
|
||||||
|
|
||||||
void* root_font;
|
void* root_font;
|
||||||
void* root_boldfont;
|
void* root_boldfont;
|
||||||
|
|
||||||
|
int berserk;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,16 +46,11 @@ long MwTimeGetTick(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwTimeSleep(int ms) {
|
void MwTimeSleep(int ms) {
|
||||||
#ifdef __NetBSD__
|
|
||||||
usleep(ms * 100);
|
|
||||||
#else
|
|
||||||
/* i don't know why this method does not work well on netbsd */
|
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|
||||||
ts.tv_sec = ms / 1000;
|
ts.tv_sec = ms / 1000;
|
||||||
ts.tv_nsec = (ms % 1000) * 1000000;
|
ts.tv_nsec = (ms % 1000) * 1000000;
|
||||||
|
|
||||||
nanosleep(&ts, NULL);
|
nanosleep(&ts, NULL);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
|
||||||
h->destroyed = 0;
|
h->destroyed = 0;
|
||||||
h->dark_theme = 0;
|
h->dark_theme = 0;
|
||||||
h->bgcolor = NULL;
|
h->bgcolor = NULL;
|
||||||
|
h->berserk = 0;
|
||||||
|
|
||||||
if(parent == NULL) arrput(h->tick_list, h);
|
if(parent == NULL) arrput(h->tick_list, h);
|
||||||
|
|
||||||
|
|
@ -392,7 +393,7 @@ void MwLoop(MwWidget handle) {
|
||||||
more = over % (wait / 2);
|
more = over % (wait / 2);
|
||||||
t = (tick + wait - more) - (t2 = MwTimeGetTick());
|
t = (tick + wait - more) - (t2 = MwTimeGetTick());
|
||||||
if(t > 0) {
|
if(t > 0) {
|
||||||
MwTimeSleep(t);
|
if(!handle->berserk) MwTimeSleep(t);
|
||||||
tick = MwTimeGetTick();
|
tick = MwTimeGetTick();
|
||||||
over -= more;
|
over -= more;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,9 @@ typedef struct waylandopengl {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int create(MwWidget handle) {
|
static int create(MwWidget handle) {
|
||||||
void* r = NULL;
|
void* r = NULL;
|
||||||
|
MwWidget w = handle;
|
||||||
|
|
||||||
#ifdef USE_GDI
|
#ifdef USE_GDI
|
||||||
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
||||||
PIXELFORMATDESCRIPTOR pfd;
|
PIXELFORMATDESCRIPTOR pfd;
|
||||||
|
|
@ -210,10 +212,16 @@ static int create(MwWidget handle) {
|
||||||
|
|
||||||
MwSetDefault(handle);
|
MwSetDefault(handle);
|
||||||
|
|
||||||
|
while(w->parent != NULL) w = w->parent;
|
||||||
|
|
||||||
|
w->berserk++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy(MwWidget handle) {
|
static void destroy(MwWidget handle) {
|
||||||
|
MwWidget w = handle;
|
||||||
|
|
||||||
#ifdef USE_GDI
|
#ifdef USE_GDI
|
||||||
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
||||||
gdiopengl_t* o = handle->internal;
|
gdiopengl_t* o = handle->internal;
|
||||||
|
|
@ -241,22 +249,48 @@ static void destroy(MwWidget handle) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
while(w->parent != NULL) w = w->parent;
|
||||||
|
|
||||||
|
w->berserk++;
|
||||||
|
|
||||||
free(handle->internal);
|
free(handle->internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
|
static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
|
||||||
|
/* these swap interval functions belonging here actually stink! */
|
||||||
|
|
||||||
#ifdef USE_GDI
|
#ifdef USE_GDI
|
||||||
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
||||||
gdiopengl_t* o = handle->internal;
|
gdiopengl_t* o = handle->internal;
|
||||||
|
void (*swap_interval_ext)(int) = NULL;
|
||||||
|
|
||||||
o->wglMakeCurrent(o->dc, o->gl);
|
o->wglMakeCurrent(o->dc, o->gl);
|
||||||
|
|
||||||
|
if((swap_interval_ext = MwOpenGLGetProcAddress(handle, "wglSwapIntervalEXT")) != NULL) {
|
||||||
|
swap_interval_ext(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_X11
|
#ifdef USE_X11
|
||||||
if(handle->lowlevel->common.type == MwLLBackendX11) {
|
if(handle->lowlevel->common.type == MwLLBackendX11) {
|
||||||
x11opengl_t* o = handle->internal;
|
x11opengl_t* o = handle->internal;
|
||||||
|
void (*swap_interval_ext)(Display*, GLXDrawable, int) = NULL;
|
||||||
|
void (*swap_interval_mesa)(unsigned int) = NULL;
|
||||||
|
void (*swap_interval_sgi)(int) = NULL;
|
||||||
|
|
||||||
o->glXMakeCurrent(handle->lowlevel->x11.display, handle->lowlevel->x11.window, o->gl);
|
o->glXMakeCurrent(handle->lowlevel->x11.display, handle->lowlevel->x11.window, o->gl);
|
||||||
|
|
||||||
|
if((swap_interval_ext = MwOpenGLGetProcAddress(handle, "glXSwapIntervalEXT")) != NULL) {
|
||||||
|
swap_interval_ext(handle->lowlevel->x11.display, handle->lowlevel->x11.window, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((swap_interval_mesa = MwOpenGLGetProcAddress(handle, "glXSwapIntervalMESA")) != NULL) {
|
||||||
|
swap_interval_mesa(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((swap_interval_sgi = MwOpenGLGetProcAddress(handle, "glXSwapIntervalSGI")) != NULL) {
|
||||||
|
swap_interval_sgi(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_WAYLAND
|
#ifdef USE_WAYLAND
|
||||||
|
|
@ -266,6 +300,8 @@ static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
|
||||||
if(!eglMakeCurrent(o->egl_display, o->egl_surface, o->egl_surface, o->egl_context)) {
|
if(!eglMakeCurrent(o->egl_display, o->egl_surface, o->egl_surface, o->egl_context)) {
|
||||||
printf("ERROR: eglMakeCurrent, %0X\n", eglGetError());
|
printf("ERROR: eglMakeCurrent, %0X\n", eglGetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eglSwapInterval(o->egl_display, 1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue