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 int opengl_pause();
|
||||||
extern void opengl_close();
|
extern void opengl_close();
|
||||||
extern void opengl_set_fs(int fs);
|
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*/
|
#endif /*!WIN_OPENGL_H*/
|
||||||
@@ -102,7 +102,7 @@ static const struct {
|
|||||||
} vid_apis[RENDERERS_NUM] = {
|
} vid_apis[RENDERERS_NUM] = {
|
||||||
{ "SDL_Software", 1, (int(*)(void*))sdl_inits, sdl_close, NULL, sdl_pause, sdl_enable, sdl_set_fs },
|
{ "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_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
|
#ifdef USE_VNC
|
||||||
,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL, NULL }
|
,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL, NULL }
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -71,11 +71,6 @@ static SDL_SysWMinfo wmi = {};
|
|||||||
*/
|
*/
|
||||||
static HWND parent = NULL;
|
static HWND parent = NULL;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Keeps track of parent window size.
|
|
||||||
*/
|
|
||||||
static RECT last_rect = {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Events listened in OpenGL thread.
|
* @brief Events listened in OpenGL thread.
|
||||||
*/
|
*/
|
||||||
@@ -103,6 +98,14 @@ static volatile struct
|
|||||||
int x, y, y1, y2, w, h, resized;
|
int x, y, y1, y2, w, h, resized;
|
||||||
} blit_info = {};
|
} blit_info = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resize event parameters.
|
||||||
|
*/
|
||||||
|
static volatile struct
|
||||||
|
{
|
||||||
|
int width, height;
|
||||||
|
} resize_info = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Identifiers to OpenGL object used.
|
* @brief Identifiers to OpenGL object used.
|
||||||
*/
|
*/
|
||||||
@@ -189,7 +192,8 @@ static GLuint LoadShaders()
|
|||||||
/**
|
/**
|
||||||
* @brief Set or unset OpenGL context window as a child window.
|
* @brief Set or unset OpenGL context window as a child window.
|
||||||
*
|
*
|
||||||
* Modifies the window style and sets the parent 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)
|
static void SetParentBinding(int enable)
|
||||||
{
|
{
|
||||||
@@ -197,13 +201,21 @@ static void SetParentBinding(int enable)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
long style = GetWindowLong(wmi.info.win.window, GWL_STYLE);
|
long style = GetWindowLong(wmi.info.win.window, GWL_STYLE);
|
||||||
|
long ex_style = GetWindowLong(wmi.info.win.window, GWL_EXSTYLE);
|
||||||
|
|
||||||
if (enable)
|
if (enable)
|
||||||
|
{
|
||||||
style |= WS_CHILD;
|
style |= WS_CHILD;
|
||||||
|
ex_style |= WS_EX_NOACTIVATE;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
style &= ~WS_CHILD;
|
style &= ~WS_CHILD;
|
||||||
|
ex_style &= ~WS_EX_NOACTIVATE;
|
||||||
|
}
|
||||||
|
|
||||||
SetWindowLong(wmi.info.win.window, GWL_STYLE, style);
|
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);
|
SetParent(wmi.info.win.window, enable ? parent : NULL);
|
||||||
}
|
}
|
||||||
@@ -277,13 +289,9 @@ static void finalize_glcontext(gl_objects obj)
|
|||||||
*/
|
*/
|
||||||
static void opengl_main()
|
static void opengl_main()
|
||||||
{
|
{
|
||||||
RECT rect;
|
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); /* Is this actually doing anything...? */
|
||||||
GetWindowRect(parent, &rect);
|
|
||||||
CopyRect(&last_rect, &rect);
|
|
||||||
|
|
||||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
window = SDL_CreateWindow("86Box OpenGL Renderer", 0, 0, resize_info.width, resize_info.height, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
|
||||||
|
|
||||||
window = SDL_CreateWindow("86Box OpenGL Renderer", 0, 0, rect.right - rect.left, rect.bottom - rect.top, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
|
|
||||||
|
|
||||||
SDL_VERSION(&wmi.version);
|
SDL_VERSION(&wmi.version);
|
||||||
SDL_GetWindowWMInfo(window, &wmi);
|
SDL_GetWindowWMInfo(window, &wmi);
|
||||||
@@ -313,13 +321,11 @@ static void opengl_main()
|
|||||||
/* Handle SDL_Window events */
|
/* Handle SDL_Window events */
|
||||||
while (SDL_PollEvent(&event))
|
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 */
|
/* 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);
|
plat_mouse_capture(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for synchronized events for 1ms before going back to window events */
|
/* Wait for synchronized events for 1ms before going back to window events */
|
||||||
@@ -350,11 +356,9 @@ static void opengl_main()
|
|||||||
/* Detach from parent while resizing */
|
/* Detach from parent while resizing */
|
||||||
SetParentBinding(0);
|
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, resize_info.width, resize_info.height);
|
||||||
|
|
||||||
glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top);
|
|
||||||
|
|
||||||
SetParentBinding(1);
|
SetParentBinding(1);
|
||||||
|
|
||||||
@@ -403,6 +407,13 @@ int opengl_init(HWND hwnd)
|
|||||||
blit_done = CreateEvent(NULL, FALSE, FALSE, NULL);
|
blit_done = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||||
|
|
||||||
parent = 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);
|
thread = thread_create(opengl_main, (void*)NULL);
|
||||||
|
|
||||||
@@ -440,6 +451,8 @@ void opengl_close()
|
|||||||
CloseHandle(sync_objects.asArray[i]);
|
CloseHandle(sync_objects.asArray[i]);
|
||||||
sync_objects.asArray[i] = (HANDLE)NULL;
|
sync_objects.asArray[i] = (HANDLE)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parent = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void opengl_set_fs(int fs)
|
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)
|
resize_info.width = w;
|
||||||
return;
|
resize_info.height = h;
|
||||||
|
|
||||||
RECT rect;
|
SetEvent(sync_objects.resize);
|
||||||
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);
|
|
||||||
|
|
||||||
SetEvent(sync_objects.resize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user