Merge pull request #83 from alphanu1/alphanu1-patch-77

snprintf broke switching
This commit is contained in:
alphanu1 2018-09-09 11:52:36 +01:00 committed by GitHub
commit 557fe10bac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,8 +25,8 @@
static unsigned orig_width = 0;
static unsigned orig_height = 0;
static char old_mode[150];
static char new_mode[150];
static char old_mode[250];
static char new_mode[250];
static char xrandr[250];
static char fbset[150];
static char output[250];
@ -234,58 +234,74 @@ static bool x11_set_resolution(void *data,
/* create progressive newmode from modline variables */
if (height < 300)
{
snprintf(xrandr, sizeof(xrandr), "xrandr --newmode \"%dx%d_%0.2f\" %lf %d %d %d %d %d %d %d %d -hsync -vsync", width, height, hz, pixel_clock, width, hfp, hsp, hbp, height, vfp, vsp, vbp);
sprintf(xrandr,"xrandr --newmode \"%dx%d_%0.2f\" %lf %d %d %d %d %d %d %d %d -hsync -vsync", width, height, hz, pixel_clock, width, hfp, hsp, hbp, height, vfp, vsp, vbp);
system(xrandr);
}
/* create interlaced newmode from modline variables */
if (height > 300)
{
snprintf(xrandr, sizeof(xrandr), "xrandr --newmode \"%dx%d_%0.2f\" %lf %d %d %d %d %d %d %d %d interlace -hsync -vsync", width, height, hz, pixel_clock, width, hfp, hsp, hbp, height, vfp, vsp, vbp);
sprintf(xrandr,"xrandr --newmode \"%dx%d_%0.2f\" %lf %d %d %d %d %d %d %d %d interlace -hsync -vsync", width, height, hz, pixel_clock, width, hfp, hsp, hbp, height, vfp, vsp, vbp);
system(xrandr);
}
/* variable for new mode */
snprintf(new_mode, sizeof(new_mode), "%dx%d_%0.2f", width, height, hz);
sprintf(new_mode,"%dx%d_%0.2f", width, height, hz);
/* need to run loops for DVI0 - DVI-2 and VGA0 - VGA-2 outputs to add and delete modes */
for (i =0; i < 3; i++)
{
snprintf(output, sizeof(output), "xrandr --addmode %s%d %s", "DVI",i ,new_mode);
sprintf(output,"xrandr --addmode %s%d %s", "HDMI",i ,new_mode);
system(output);
snprintf(output, sizeof(output), "xrandr --delmode %s%d %s", "DVI",i ,old_mode);
sprintf(output,"xrandr --output %s%d --mode %s", "HDMI", i, new_mode);
system(output);
sprintf(output,"xrandr --delmode %s%d %s", "HDMI",i ,old_mode);
system(output);
}
for (i =0; i < 3; i++)
{
snprintf(output, sizeof(output), "xrandr --addmode %s-%d %s", "DVI",i ,new_mode);
system(output);
snprintf(output, sizeof(output), "xrandr --delmode %s-%d %s", "DVI",i ,old_mode);
sprintf(output,"xrandr --addmode %s-%d %s", "HDMI",i ,new_mode);
system(output);
}
for (i =0; i < 3; i++)
{
snprintf(output, sizeof(output), "xrandr --addmode %s%d %s", "VGA",i ,new_mode);
system(output);
snprintf(output, sizeof(output), "xrandr --delmode %s%d %s", "VGA",i ,old_mode);
sprintf(output,"xrandr --output %s-%d --mode %s", "HDMI", i, new_mode);
system(output);
sprintf(output,"xrandr --delmode %s-%d %s", "HDMI",i ,old_mode);
system(output);
sprintf(output,"xrandr --addmode %s%d %s", "DVI",i ,new_mode);
system(output);
}
for (i =0; i < 3; i++)
{
snprintf(output, sizeof(output), "xrandr --addmode %s-%d %s", "VGA",i ,new_mode);
sprintf(output,"xrandr --output %s%d --mode %s", "DVI", i, new_mode);
system(output);
sprintf(output,"xrandr --delmode %s%d %s", "DVI",i ,old_mode);
system(output);
snprintf(output, sizeof(output), "xrandr --delmode %s-%d %s", "VGA",i ,old_mode);
sprintf(output,"xrandr --addmode %s-%d %s", "DVI",i ,new_mode);
system(output);
sprintf(output,"xrandr --output %s-%d --mode %s", "DVI", i, new_mode);
system(output);
sprintf(output,"xrandr --delmode %s-%d %s", "DVI",i ,old_mode);
system(output);
sprintf(output,"xrandr --addmode %s%d %s", "VGA",i ,new_mode);
system(output);
sprintf(output,"xrandr --output %s%d --mode %s", "VGA", i, new_mode);
system(output);
sprintf(output,"xrandr --delmode %s%d %s", "VGA",i ,old_mode);
system(output);
sprintf(output,"xrandr --addmode %s-%d %s", "VGA",i ,new_mode);
system(output);
sprintf(output,"xrandr --output %s-%d --mode %s", "VGA", i, new_mode);
system(output);
sprintf(output,"xrandr --delmode %s-%d %s", "VGA",i ,old_mode);
system(output);
}
snprintf(output, sizeof(output), "xrandr -s %s", new_mode);
system(output);
/* remove old mode */
snprintf(output, sizeof(output), "xrandr --rmmode %s", old_mode);
sprintf(output,"xrandr --rmmode %s", old_mode);
system(output);
system("xdotool windowactivate $(xdotool search --class RetroArch)"); /* needs xdotool installed. needed to recaputure window. */
/* variable for old mode */
snprintf(old_mode, sizeof(old_mode), "%s", new_mode);
sprintf(old_mode,"%s", new_mode);
system("xdotool windowactivate $(xdotool search --class RetroArch)"); /* needs xdotool installed. needed to recaputure window. */
/* Second run needed as some times it runs to fast to capture first time */