diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2011-02-08 23:42:18 +0000 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2011-02-08 23:42:18 +0000 |
commit | 3c414e7668d6db3ac738f8850b9e038495ee5e3a (patch) | |
tree | 8466e11aee8f959aeace604cf801fe85e1ef7319 /windows/gui.c | |
parent | 42990ed9ec37680791c88504595243f269f726c7 (diff) | |
download | netsurf-3c414e7668d6db3ac738f8850b9e038495ee5e3a.tar.gz netsurf-3c414e7668d6db3ac738f8850b9e038495ee5e3a.tar.bz2 |
Stop win32 frontend using 100% cpu time when idle
svn path=/trunk/netsurf/; revision=11633
Diffstat (limited to 'windows/gui.c')
-rw-r--r-- | windows/gui.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/windows/gui.c b/windows/gui.c index 18a67d355..35ab01b72 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -143,20 +143,40 @@ void gui_multitask(void) void gui_poll(bool active) { - MSG Msg; - if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) != 0) { -/* if (!((current_gui == NULL) || - (TranslateAccelerator(current_gui->main, - current_gui->acceltable, &Msg)))) { - TranslateMessage(&Msg); - } -*/ - TranslateMessage(&Msg); - DispatchMessage(&Msg); + MSG Msg; /* message from system */ + BOOL bRet; /* message fetch result */ + int timeout; /* timeout in miliseconds */ + UINT timer_id = 0; + + /* run the scheduler and discover how long to wait for the next event */ + timeout = schedule_run(); + + /* if active set timeout so message is not waited for */ + if (active) + timeout = 0; + + if (timeout == 0) { + bRet = PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE); + } else { + if (timeout > 0) { + /* set up a timer to ensure we get woken */ + timer_id = SetTimer(NULL, 0, timeout, NULL); + } + + /* wait for a message */ + bRet = GetMessage(&Msg, NULL, 0, 0); + + /* if a timer was sucessfully created remove it */ + if (timer_id != 0) { + KillTimer(NULL, timer_id); + } } - schedule_run(); + if (bRet > 0) { + TranslateMessage(&Msg); + DispatchMessage(&Msg); + } } /* obtain gui window structure from windows window handle */ |