Add display_server_get_current_resolution

This commit is contained in:
twinaphex 2018-04-17 03:37:56 +02:00
parent f050104740
commit d7d5dfdc73
6 changed files with 55 additions and 34 deletions

View File

@ -50,6 +50,7 @@ const video_display_server_t dispserv_null = {
null_set_window_progress, null_set_window_progress,
NULL, NULL,
NULL, NULL,
NULL,
"null" "null"
}; };

View File

@ -67,8 +67,8 @@ be received by your application before it calls any ITaskbarList3 method.
static void* win32_display_server_init(void) static void* win32_display_server_init(void)
{ {
dispserv_win32_t *dispserv = (dispserv_win32_t*)calloc(1, sizeof(*dispserv));
HRESULT hr; HRESULT hr;
dispserv_win32_t *dispserv = (dispserv_win32_t*)calloc(1, sizeof(*dispserv));
(void)hr; (void)hr;
@ -77,11 +77,13 @@ static void* win32_display_server_init(void)
#ifdef HAS_TASKBAR_EXT #ifdef HAS_TASKBAR_EXT
#ifdef __cplusplus #ifdef __cplusplus
/* when compiling in C++ mode, GUIDs are references instead of pointers */ /* When compiling in C++ mode, GUIDs are references instead of pointers */
hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (void**)&g_taskbarList); hr = CoCreateInstance(CLSID_TaskbarList, NULL,
CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (void**)&g_taskbarList);
#else #else
/* mingw GUIDs are pointers instead of references since we're in C mode */ /* Mingw GUIDs are pointers instead of references since we're in C mode */
hr = CoCreateInstance(&CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskbarList3, (void**)&g_taskbarList); hr = CoCreateInstance(&CLSID_TaskbarList, NULL,
CLSCTX_INPROC_SERVER, &IID_ITaskbarList3, (void**)&g_taskbarList);
#endif #endif
if (!SUCCEEDED(hr)) if (!SUCCEEDED(hr))
@ -115,7 +117,8 @@ static bool win32_set_window_opacity(void *data, unsigned opacity)
HWND hwnd = win32_get_window(); HWND hwnd = win32_get_window();
dispserv_win32_t *serv = (dispserv_win32_t*)data; dispserv_win32_t *serv = (dispserv_win32_t*)data;
serv->opacity = opacity; if (serv)
serv->opacity = opacity;
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
/* Set window transparency on Windows 2000 and above */ /* Set window transparency on Windows 2000 and above */
@ -126,15 +129,14 @@ static bool win32_set_window_opacity(void *data, unsigned opacity)
GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED); GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
return SetLayeredWindowAttributes(hwnd, 0, (255 * opacity) / 100, LWA_ALPHA); return SetLayeredWindowAttributes(hwnd, 0, (255 * opacity) / 100, LWA_ALPHA);
} }
else
{ SetWindowLongPtr(hwnd,
SetWindowLongPtr(hwnd, GWL_EXSTYLE,
GWL_EXSTYLE, GetWindowLongPtr(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);
GetWindowLongPtr(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED); return true;
return true; #else
}
#endif
return false; return false;
#endif
} }
static bool win32_set_window_progress(void *data, int progress, bool finished) static bool win32_set_window_progress(void *data, int progress, bool finished)
@ -151,7 +153,8 @@ static bool win32_set_window_progress(void *data, int progress, bool finished)
if (progress == -1) if (progress == -1)
{ {
if (ITaskbarList3_SetProgressState(g_taskbarList, hwnd, TBPF_INDETERMINATE) == S_OK) if (ITaskbarList3_SetProgressState(
g_taskbarList, hwnd, TBPF_INDETERMINATE) == S_OK)
ret = true; ret = true;
if (!ret) if (!ret)
@ -159,7 +162,8 @@ static bool win32_set_window_progress(void *data, int progress, bool finished)
} }
else if (finished) else if (finished)
{ {
if (ITaskbarList3_SetProgressState(g_taskbarList, hwnd, TBPF_NOPROGRESS) == S_OK) if (ITaskbarList3_SetProgressState(
g_taskbarList, hwnd, TBPF_NOPROGRESS) == S_OK)
ret = true; ret = true;
if (!ret) if (!ret)
@ -167,13 +171,15 @@ static bool win32_set_window_progress(void *data, int progress, bool finished)
} }
else if (progress >= 0) else if (progress >= 0)
{ {
if (ITaskbarList3_SetProgressState(g_taskbarList, hwnd, TBPF_NORMAL) == S_OK) if (ITaskbarList3_SetProgressState(
g_taskbarList, hwnd, TBPF_NORMAL) == S_OK)
ret = true; ret = true;
if (!ret) if (!ret)
return false; return false;
if (ITaskbarList3_SetProgressValue(g_taskbarList, hwnd, progress, 100) == S_OK) if (ITaskbarList3_SetProgressValue(
g_taskbarList, hwnd, progress, 100) == S_OK)
ret = true; ret = true;
} }
#endif #endif
@ -202,9 +208,9 @@ static bool win32_display_server_set_resolution(void *data,
DEVMODE devmode; DEVMODE devmode;
int iModeNum; int iModeNum;
int freq = 0; int freq = 0;
DWORD flags = 0; DWORD flags = 0;
int depth = 0; int depth = 0;
dispserv_win32_t *serv = (dispserv_win32_t*)data; dispserv_win32_t *serv = (dispserv_win32_t*)data;
if (!serv) if (!serv)
@ -215,7 +221,7 @@ static bool win32_display_server_set_resolution(void *data,
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &curDevmode); EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &curDevmode);
/* used to stop superresolution bug */ /* Used to stop super resolution bug */
if (width == curDevmode.dmPelsWidth) if (width == curDevmode.dmPelsWidth)
width = 0; width = 0;
if (width == 0) if (width == 0)
@ -273,12 +279,22 @@ static bool win32_display_server_set_resolution(void *data,
return true; return true;
} }
void win32_display_server_get_current_resolution(
unsigned *width, unsigned *height)
{
if (width)
*width = GetSystemMetrics(SM_CYSCREEN);
if (height)
*height = GetSystemMetrics(SM_CXSCREEN);
}
const video_display_server_t dispserv_win32 = { const video_display_server_t dispserv_win32 = {
win32_display_server_init, win32_display_server_init,
win32_display_server_destroy, win32_display_server_destroy,
win32_set_window_opacity, win32_set_window_opacity,
win32_set_window_progress, win32_set_window_progress,
win32_set_window_decorations, win32_set_window_decorations,
win32_display_server_get_current_resolution,
win32_display_server_set_resolution, win32_display_server_set_resolution,
"win32" "win32"
}; };

View File

@ -78,6 +78,7 @@ const video_display_server_t dispserv_x11 = {
x11_set_window_opacity, x11_set_window_opacity,
NULL, NULL,
x11_set_window_decorations, x11_set_window_decorations,
NULL, /* get_current_resolution */
NULL, /* set_resolution */ NULL, /* set_resolution */
"x11" "x11"
}; };

View File

@ -20,10 +20,6 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#if defined(_WIN32) && !defined(_XBOX)
#include <windows.h>
#endif
#include "video_driver.h" #include "video_driver.h"
#include "video_crt_switch.h" #include "video_crt_switch.h"
#include "video_display_server.h" #include "video_display_server.h"
@ -47,14 +43,7 @@ static void crt_check_first_run(void)
if (!first_run) if (!first_run)
return; return;
/* TODO/FIXME - do we want to set first_run back to true video_display_server_get_current_resolution(&orig_width, &orig_height);
* at some point in time or should it stay like this? */
/* Run of first boot to get current display resolution */
#if defined(_WIN32) && !defined(_XBOX)
orig_height = GetSystemMetrics(SM_CYSCREEN);
orig_width = GetSystemMetrics(SM_CXSCREEN);
#endif
first_run = false; first_run = false;
} }

View File

@ -82,6 +82,16 @@ bool video_display_server_set_window_decorations(bool on)
return false; return false;
} }
bool video_display_server_get_current_resolution(unsigned *width, unsigned *height)
{
if (current_display_server && current_display_server->get_current_resolution)
{
current_display_server->get_current_resolution(width, height);
return true;
}
return false;
}
bool video_display_server_switch_resolution(unsigned width, unsigned height, bool video_display_server_switch_resolution(unsigned width, unsigned height,
int f_restore, int hz) int f_restore, int hz)
{ {

View File

@ -30,6 +30,7 @@ typedef struct video_display_server
bool (*set_window_opacity)(void *data, unsigned opacity); bool (*set_window_opacity)(void *data, unsigned opacity);
bool (*set_window_progress)(void *data, int progress, bool finished); bool (*set_window_progress)(void *data, int progress, bool finished);
bool (*set_window_decorations)(void *data, bool on); bool (*set_window_decorations)(void *data, bool on);
void (*get_current_resolution)(unsigned *width, unsigned *height);
bool (*switch_resolution)(void *data, unsigned width, bool (*switch_resolution)(void *data, unsigned width,
unsigned height, int f_restore, int hz); unsigned height, int f_restore, int hz);
const char *ident; const char *ident;
@ -43,6 +44,9 @@ bool video_display_server_set_window_opacity(unsigned opacity);
bool video_display_server_set_window_progress(int progress, bool finished); bool video_display_server_set_window_progress(int progress, bool finished);
bool video_display_server_get_current_resolution(
unsigned *width, unsigned *height);
bool video_display_server_set_window_decorations(bool on); bool video_display_server_set_window_decorations(bool on);
bool video_display_server_switch_resolution( bool video_display_server_switch_resolution(