win_opengl: Get window size from resize instead of enable. Use noactivate window style to keep focus on parent window.
This commit is contained in:
@@ -22,6 +22,6 @@ extern int opengl_init(HWND hwnd);
|
||||
extern int opengl_pause();
|
||||
extern void opengl_close();
|
||||
extern void opengl_set_fs(int fs);
|
||||
extern void opengl_enable(int enable);
|
||||
extern void opengl_resize(int w, int h);
|
||||
|
||||
#endif /*!WIN_OPENGL_H*/
|
||||
@@ -102,7 +102,7 @@ static const struct {
|
||||
} vid_apis[RENDERERS_NUM] = {
|
||||
{ "SDL_Software", 1, (int(*)(void*))sdl_inits, sdl_close, NULL, sdl_pause, sdl_enable, sdl_set_fs },
|
||||
{ "SDL_Hardware", 1, (int(*)(void*))sdl_inith, sdl_close, NULL, sdl_pause, sdl_enable, sdl_set_fs },
|
||||
{ "SDL_OpenGL", 1, (int(*)(void*))opengl_init, opengl_close, NULL, opengl_pause, opengl_enable, opengl_set_fs }
|
||||
{ "SDL_OpenGL", 1, (int(*)(void*))opengl_init, opengl_close, opengl_resize, opengl_pause, NULL, opengl_set_fs }
|
||||
#ifdef USE_VNC
|
||||
,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL, NULL }
|
||||
#endif
|
||||
|
||||
@@ -71,11 +71,6 @@ static SDL_SysWMinfo wmi = {};
|
||||
*/
|
||||
static HWND parent = NULL;
|
||||
|
||||
/**
|
||||
* @brief Keeps track of parent window size.
|
||||
*/
|
||||
static RECT last_rect = {};
|
||||
|
||||
/**
|
||||
* @brief Events listened in OpenGL thread.
|
||||
*/
|
||||
@@ -103,6 +98,14 @@ static volatile struct
|
||||
int x, y, y1, y2, w, h, resized;
|
||||
} blit_info = {};
|
||||
|
||||
/**
|
||||
* @brief Resize event parameters.
|
||||
*/
|
||||
static volatile struct
|
||||
{
|
||||
int width, height;
|
||||
} resize_info = {};
|
||||
|
||||
/**
|
||||
* @brief Identifiers to OpenGL object used.
|
||||
*/
|
||||
@@ -190,6 +193,7 @@ static GLuint LoadShaders()
|
||||
* @brief Set or unset OpenGL context window as a child window.
|
||||
*
|
||||
* Modifies the window style and sets the parent window.
|
||||
* WS_EX_NOACTIVATE keeps the window from stealing input focus.
|
||||
*/
|
||||
static void SetParentBinding(int enable)
|
||||
{
|
||||
@@ -197,13 +201,21 @@ static void SetParentBinding(int enable)
|
||||
return;
|
||||
|
||||
long style = GetWindowLong(wmi.info.win.window, GWL_STYLE);
|
||||
long ex_style = GetWindowLong(wmi.info.win.window, GWL_EXSTYLE);
|
||||
|
||||
if (enable)
|
||||
{
|
||||
style |= WS_CHILD;
|
||||
ex_style |= WS_EX_NOACTIVATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
style &= ~WS_CHILD;
|
||||
ex_style &= ~WS_EX_NOACTIVATE;
|
||||
}
|
||||
|
||||
SetWindowLong(wmi.info.win.window, GWL_STYLE, style);
|
||||
SetWindowLong(wmi.info.win.window, GWL_EXSTYLE, ex_style);
|
||||
|
||||
SetParent(wmi.info.win.window, enable ? parent : NULL);
|
||||
}
|
||||
@@ -277,13 +289,9 @@ static void finalize_glcontext(gl_objects obj)
|
||||
*/
|
||||
static void opengl_main()
|
||||
{
|
||||
RECT rect;
|
||||
GetWindowRect(parent, &rect);
|
||||
CopyRect(&last_rect, &rect);
|
||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); /* Is this actually doing anything...? */
|
||||
|
||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
||||
|
||||
window = SDL_CreateWindow("86Box OpenGL Renderer", 0, 0, rect.right - rect.left, rect.bottom - rect.top, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
|
||||
window = SDL_CreateWindow("86Box OpenGL Renderer", 0, 0, resize_info.width, resize_info.height, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
|
||||
|
||||
SDL_VERSION(&wmi.version);
|
||||
SDL_GetWindowWMInfo(window, &wmi);
|
||||
@@ -313,14 +321,12 @@ static void opengl_main()
|
||||
/* Handle SDL_Window events */
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
/* Main window should be active to receive input */
|
||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
|
||||
SetForegroundWindow(GetParent(parent));
|
||||
|
||||
/* Start mouse capture on button down */
|
||||
else if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT)
|
||||
if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT)
|
||||
{
|
||||
plat_mouse_capture(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for synchronized events for 1ms before going back to window events */
|
||||
wait_result = WaitForMultipleObjects(sizeof(sync_objects) / sizeof(HANDLE), sync_objects.asArray, FALSE, 1);
|
||||
@@ -350,11 +356,9 @@ static void opengl_main()
|
||||
/* Detach from parent while resizing */
|
||||
SetParentBinding(0);
|
||||
|
||||
GetWindowRect(parent, &rect);
|
||||
SDL_SetWindowSize(window, resize_info.width, resize_info.height);
|
||||
|
||||
SDL_SetWindowSize(window, rect.right - rect.left, rect.bottom - rect.top);
|
||||
|
||||
glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top);
|
||||
glViewport(0, 0, resize_info.width, resize_info.height);
|
||||
|
||||
SetParentBinding(1);
|
||||
|
||||
@@ -404,6 +408,13 @@ int opengl_init(HWND hwnd)
|
||||
|
||||
parent = hwnd;
|
||||
|
||||
RECT parent_size;
|
||||
|
||||
GetWindowRect(parent, &parent_size);
|
||||
|
||||
resize_info.width = parent_size.right - parent_size.left;
|
||||
resize_info.height = parent_size.bottom - parent_size.top;
|
||||
|
||||
thread = thread_create(opengl_main, (void*)NULL);
|
||||
|
||||
atexit(opengl_close);
|
||||
@@ -440,6 +451,8 @@ void opengl_close()
|
||||
CloseHandle(sync_objects.asArray[i]);
|
||||
sync_objects.asArray[i] = (HANDLE)NULL;
|
||||
}
|
||||
|
||||
parent = NULL;
|
||||
}
|
||||
|
||||
void opengl_set_fs(int fs)
|
||||
@@ -453,20 +466,10 @@ void opengl_set_fs(int fs)
|
||||
}
|
||||
}
|
||||
|
||||
void opengl_enable(int enable)
|
||||
void opengl_resize(int w, int h)
|
||||
{
|
||||
if (enable == 0 || parent == NULL)
|
||||
return;
|
||||
|
||||
RECT rect;
|
||||
GetWindowRect(parent, &rect);
|
||||
|
||||
/* Resizing window is a common cause for enable */
|
||||
/* TODO: route the resizing event explicitly form win_ui. */
|
||||
if (!EqualRect(&rect, &last_rect))
|
||||
{
|
||||
CopyRect(&last_rect, &rect);
|
||||
resize_info.width = w;
|
||||
resize_info.height = h;
|
||||
|
||||
SetEvent(sync_objects.resize);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user