(Multi-Monitor)Can Choose Which Monitor to Use

-Adds option in the "VIDEO" menu for "display index" that lets you specify which monitor you would like to use.
This commit is contained in:
Spirrwell 2019-06-16 00:50:15 -04:00
parent 1f1a45a562
commit f6a9690a36
3 changed files with 94 additions and 1 deletions

View file

@ -32,6 +32,7 @@
extern void M_ForceMenuOff(void);
static cvar_t *r_mode;
static cvar_t *vid_displayindex;
static cvar_t *r_hudscale;
static cvar_t *r_consolescale;
static cvar_t *r_menuscale;
@ -49,6 +50,7 @@ static menuframework_s s_opengl_menu;
static menulist_s s_renderer_list;
static menulist_s s_mode_list;
static menulist_s s_display_list;
static menulist_s s_uiscale_list;
static menuslider_s s_brightness_slider;
static menuslider_s s_fov_slider;
@ -190,6 +192,12 @@ ApplyChanges(void *unused)
Cvar_SetValue("r_mode", s_mode_list.curvalue);
}
if (s_display_list.curvalue != GLimp_GetWindowDisplayIndex() )
{
Cvar_SetValue( "vid_displayindex", s_display_list.curvalue );
restart = true;
}
/* UI scaling */
if (s_uiscale_list.curvalue == 0)
{
@ -333,6 +341,11 @@ VID_MenuInit(void)
r_mode = Cvar_Get("r_mode", "4", 0);
}
if (!vid_displayindex)
{
vid_displayindex = Cvar_Get("vid_displayindex", "0", CVAR_ARCHIVE);
}
if (!r_hudscale)
{
r_hudscale = Cvar_Get("r_hudscale", "-1", CVAR_ARCHIVE);
@ -414,6 +427,13 @@ VID_MenuInit(void)
s_mode_list.curvalue = GetCustomValue(&s_mode_list);
}
s_display_list.generic.type = MTYPE_SPINCONTROL;
s_display_list.generic.name = "display index";
s_display_list.generic.x = 0;
s_display_list.generic.y = (y += 10);
s_display_list.itemnames = GLimp_GetDisplayIndices();
s_display_list.curvalue = GLimp_GetWindowDisplayIndex();
s_brightness_slider.generic.type = MTYPE_SLIDER;
s_brightness_slider.generic.name = "brightness";
s_brightness_slider.generic.x = 0;
@ -519,6 +539,7 @@ VID_MenuInit(void)
Menu_AddItem(&s_opengl_menu, (void *)&s_renderer_list);
Menu_AddItem(&s_opengl_menu, (void *)&s_mode_list);
Menu_AddItem(&s_opengl_menu, (void *)&s_display_list);
Menu_AddItem(&s_opengl_menu, (void *)&s_brightness_slider);
Menu_AddItem(&s_opengl_menu, (void *)&s_fov_slider);
Menu_AddItem(&s_opengl_menu, (void *)&s_uiscale_list);

View file

@ -34,6 +34,7 @@
#include <SDL2/SDL_video.h>
cvar_t *vid_displayrefreshrate;
static cvar_t *vid_displayindex;
int glimp_refreshRate = -1;
static int last_flags = 0;
@ -42,14 +43,77 @@ static int last_position_x = SDL_WINDOWPOS_UNDEFINED;
static int last_position_y = SDL_WINDOWPOS_UNDEFINED;
static SDL_Window* window = NULL;
static qboolean initSuccessful = false;
static char **displayindices = NULL;
static int num_displays = 0;
const char**
GLimp_GetDisplayIndices(void)
{
return (const char**)displayindices;
}
int
GLimp_GetWindowDisplayIndex(void)
{
return last_display;
}
int
GLimp_GetNumVideoDisplays(void)
{
return num_displays;
}
static void
ClearDisplayIndices(void)
{
if ( displayindices )
{
for ( int i = 0; i < num_displays; i++ )
free( displayindices[ i ] );
free( displayindices );
displayindices = NULL;
}
}
static void
InitDisplayIndices(qboolean ClearExisting)
{
if ( ClearExisting )
ClearDisplayIndices();
displayindices = malloc( ( num_displays + 1 ) * sizeof( char* ) );
for ( int i = 0; i < num_displays; i++ )
{
displayindices[ i ] = malloc( 11 * sizeof( char ) ); // There are a maximum of 10 digits in 32 bit int + 1 for the NULL terminator
snprintf( displayindices[ i ], 11, "%d", i );
}
// The last entry is NULL to indicate the list of strings ends
displayindices[ num_displays ] = 0;
}
// --------
static qboolean
CreateSDLWindow(int flags, int w, int h)
{
num_displays = SDL_GetNumVideoDisplays();
int displayindex = 0;
if ( vid_displayindex->value < 0 || vid_displayindex->value >= num_displays)
Cvar_SetValue( "vid_displayindex", 0 );
else
{
displayindex = vid_displayindex->value;
}
// last_position_x and last_position_y aren't really used...
const int windowpos = SDL_WINDOWPOS_UNDEFINED_DISPLAY( displayindex );
window = SDL_CreateWindow("Yamagi Quake II",
last_position_x, last_position_y,
windowpos, windowpos,
w, h, flags);
if (window)
{
@ -57,6 +121,8 @@ CreateSDLWindow(int flags, int w, int h)
last_display = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowPosition(window,
&last_position_x, &last_position_y);
InitDisplayIndices( true );
}
return window != NULL;
@ -157,6 +223,8 @@ ShutdownGraphics(void)
window = NULL;
}
ClearDisplayIndices();
// make sure that after vid_restart the refreshrate will be queried from SDL2 again.
glimp_refreshRate = -1;
@ -172,6 +240,7 @@ qboolean
GLimp_Init(void)
{
vid_displayrefreshrate = Cvar_Get("vid_displayrefreshrate", "-1", CVAR_ARCHIVE);
vid_displayindex = Cvar_Get("vid_displayindex", "0", CVAR_ARCHIVE);
if (!SDL_WasInit(SDL_INIT_VIDEO))
{

View file

@ -55,6 +55,9 @@ const char *VID_MenuKey(int);
// Stuff provided by platform backend.
extern int glimp_refreshRate;
const char **GLimp_GetDisplayIndices(void);
int GLimp_GetWindowDisplayIndex(void);
int GLimp_GetNumVideoDisplays(void);
qboolean GLimp_Init(void);
void GLimp_Shutdown(void);
qboolean GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight);