mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-24 12:42:32 +00:00
[win] Communicate application focus to the client
This fixes the weird slug when running nq on windows. It turns out it was the "friendly neighbor" sleep code activating due to bitrot. In addition, there are cvars for enabling unfocused sleep (defaults off) and disabling minimized sleep (defaults on).
This commit is contained in:
parent
9a01e71f67
commit
4eef0889ee
4 changed files with 36 additions and 35 deletions
|
@ -38,10 +38,11 @@ extern HDC win_maindc;
|
|||
extern HCURSOR win_arrow;
|
||||
extern bool win_cursor_visible;
|
||||
extern int win_palettized;
|
||||
extern int win_canalttab;
|
||||
extern bool win_canalttab;
|
||||
extern DEVMODE win_gdevmode;
|
||||
extern struct sw_ctx_s *win_sw_context;
|
||||
extern int win_minimized;
|
||||
extern bool win_minimized;
|
||||
extern bool win_focused;
|
||||
extern int vid_ddraw;
|
||||
extern int win_center_x, win_center_y;
|
||||
extern RECT win_rect;
|
||||
|
|
|
@ -50,8 +50,9 @@ HDC win_maindc;
|
|||
HCURSOR win_arrow;
|
||||
bool win_cursor_visible;
|
||||
int win_palettized;
|
||||
int win_minimized;
|
||||
int win_canalttab = 0;
|
||||
bool win_minimized;
|
||||
bool win_focused;
|
||||
bool win_canalttab;
|
||||
sw_ctx_t *win_sw_context;
|
||||
|
||||
#define MODE_WINDOWED 0
|
||||
|
|
|
@ -666,6 +666,7 @@ event_leave (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
static LONG
|
||||
event_focusin (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
win_focused = true;
|
||||
in_win_send_focus_event (1);
|
||||
return 0;
|
||||
}
|
||||
|
@ -673,9 +674,7 @@ event_focusin (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
static LONG
|
||||
event_focusout (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (modestate == MS_FULLDIB) {
|
||||
ShowWindow (win_mainwindow, SW_SHOWMINNOACTIVE);
|
||||
}
|
||||
win_focused = false;
|
||||
in_win_send_focus_event (0);
|
||||
return 0;
|
||||
}
|
||||
|
@ -829,7 +828,7 @@ IN_Win_Preinit (void)
|
|||
Win_AddEvent (WM_MOUSELEAVE, event_leave);
|
||||
|
||||
Win_AddEvent (WM_SETFOCUS, event_focusin);
|
||||
Win_AddEvent (WM_SETFOCUS, event_focusout);
|
||||
Win_AddEvent (WM_KILLFOCUS, event_focusout);
|
||||
|
||||
Win_AddEvent (WM_KEYDOWN, event_key);
|
||||
Win_AddEvent (WM_SYSKEYDOWN, event_key);
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
#include "nq/include/client.h"
|
||||
#include "nq/include/host.h"
|
||||
|
||||
#include "context_win.h"
|
||||
|
||||
bool isDedicated = false;
|
||||
|
||||
#define MINIMUM_WIN_MEMORY 0x0880000
|
||||
|
@ -49,11 +51,26 @@ bool isDedicated = false;
|
|||
#define PAUSE_SLEEP 50 // sleep time on pause or minimization
|
||||
#define NOT_FOCUS_SLEEP 20 // sleep time when not focus
|
||||
|
||||
bool ActiveApp, Minimized;
|
||||
bool WinNT;
|
||||
static int cl_pause_sleep;
|
||||
static cvar_t cl_pause_sleep_cvar = {
|
||||
.name = "cl_pause_sleep",
|
||||
.description =
|
||||
"Control whether the client will sleep when paused",
|
||||
.default_value = "1",
|
||||
.flags = CVAR_NONE,
|
||||
.value = { .type = &cexpr_int, .value = &cl_pause_sleep },
|
||||
};
|
||||
|
||||
static int cl_unfocus_sleep;
|
||||
static cvar_t cl_unfocus_sleep_cvar = {
|
||||
.name = "cl_unfocus_sleep",
|
||||
.description =
|
||||
"Control whether the client will sleep when unfocused",
|
||||
.default_value = "0",
|
||||
.flags = CVAR_NONE,
|
||||
.value = { .type = &cexpr_int, .value = &cl_unfocus_sleep },
|
||||
};
|
||||
|
||||
static double pfreq;
|
||||
static int lowshift;
|
||||
HANDLE hinput, houtput;
|
||||
|
||||
static HANDLE tevent;
|
||||
|
@ -64,7 +81,6 @@ static void
|
|||
startup (void)
|
||||
{
|
||||
LARGE_INTEGER PerformanceFreq;
|
||||
unsigned int lowpart, highpart;
|
||||
OSVERSIONINFO vinfo;
|
||||
|
||||
Sys_MaskFPUExceptions ();
|
||||
|
@ -72,21 +88,6 @@ startup (void)
|
|||
if (!QueryPerformanceFrequency (&PerformanceFreq))
|
||||
Sys_Error ("No hardware timer available");
|
||||
|
||||
// get 32 out of the 64 time bits such that we have around
|
||||
// 1 microsecond resolution
|
||||
lowpart = (unsigned int) PerformanceFreq.LowPart;
|
||||
highpart = (unsigned int) PerformanceFreq.HighPart;
|
||||
lowshift = 0;
|
||||
|
||||
while (highpart || (lowpart > 2000000.0)) {
|
||||
lowshift++;
|
||||
lowpart >>= 1;
|
||||
lowpart |= (highpart & 1) << 31;
|
||||
highpart >>= 1;
|
||||
}
|
||||
|
||||
pfreq = 1.0 / (double) lowpart;
|
||||
|
||||
vinfo.dwOSVersionInfoSize = sizeof (vinfo);
|
||||
|
||||
if (!GetVersionEx (&vinfo))
|
||||
|
@ -96,11 +97,6 @@ startup (void)
|
|||
(vinfo.dwPlatformId == VER_PLATFORM_WIN32s)) {
|
||||
Sys_Error ("WinQuake requires at least Win95 or NT 4.0");
|
||||
}
|
||||
|
||||
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
||||
WinNT = true;
|
||||
else
|
||||
WinNT = false;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -211,15 +207,19 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
|||
|
||||
Host_Init ();
|
||||
|
||||
Cvar_Register (&cl_pause_sleep_cvar, 0, 0);
|
||||
Cvar_Register (&cl_unfocus_sleep_cvar, 0, 0);
|
||||
|
||||
oldtime = Sys_DoubleTime () - 0.1;
|
||||
while (1) { // Main message loop
|
||||
if (!isDedicated) {
|
||||
// yield the CPU for a little while when paused, minimized, or
|
||||
// not the focus
|
||||
if ((cl.paused && !ActiveApp) || Minimized) {
|
||||
if (cl_pause_sleep
|
||||
&& ((cl.paused && !win_focused) || win_minimized)) {
|
||||
SleepUntilInput (PAUSE_SLEEP);
|
||||
scr_skipupdate = 1; // no point in bothering to draw
|
||||
} else if (!ActiveApp) {
|
||||
} else if (cl_unfocus_sleep && !win_focused) {
|
||||
SleepUntilInput (NOT_FOCUS_SLEEP);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue