Merge pull request #66 from alphanu1/alphanu1-patch-63

changes to switching method
This commit is contained in:
alphanu1 2018-05-08 15:17:30 +01:00 committed by GitHub
commit 61f445b159
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,10 +23,16 @@
#include <sys/types.h>
#include <unistd.h>
#include <X11/Xlib.h>
static unsigned orig_width = 0;
static unsigned orig_height = 0;
static char orig_res[50];
static char old_mode[150];
static char new_mode[150];
static bool crt_en = false;
static char output[450];
static bool crt_en = false;
static FILE *res;
typedef struct
{
@ -47,9 +53,49 @@ static void* x11_display_server_init(void)
static void x11_display_server_destroy(void *data)
{
dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
int i = 0;
if (crt_en == true)
system("xrandr -s 704x480");
{
sprintf(orig_res, "xrandr -s %dx%d", orig_width, orig_height);
system(orig_res);
res= fopen ("res.sh", "w");
for (i =0; i < 3; i++)
{
fprintf(res, "if (xrandr | grep \"VGA-%d connected\" )"
"\nthen"
"\n xrandr --delmode VGA-%d %s"
"\n exit"
"\n fi \n\n"
"if (xrandr | grep \"VGA%d connected\" )"
"\nthen"
"\n xrandr --delmode VGA%d %s"
"\n exit"
"\n fi \n\n"
"if (xrandr | grep \"DVI-%d connected\" )"
"\nthen"
"\n xrandr --delmode VGA-%d %s"
"\n exit"
"\n fi \n\n"
"if (xrandr | grep \"DVI%d connected\" )"
"\nthen"
"\n xrandr --delmode DVI%d %s"
"\n exit"
"\n fi \n\n"
"\nexit"
,i, i ,old_mode
,i, i ,old_mode
,i, i ,old_mode
,i, i ,old_mode);
}
fclose(res);
system("bash res.sh");
sprintf(output,"xrandr --rmmode %s", old_mode);
system(output);
}
if (dispserv)
free(dispserv);
@ -99,24 +145,27 @@ static bool x11_set_resolution(void *data,
float pixel_clock = 0;
char xrandr[250];
char fbset[150];
char output[150];
Display* disp = XOpenDisplay(NULL);
Screen* scrn = DefaultScreenOfDisplay(disp);
crt_en = true;
hsp = width*1.14;
if (orig_width == 0)
orig_width = scrn->width;
if (orig_height == 0)
orig_height = scrn->height;
hsp = width*1.15;
/* set core refresh from hz */
video_monitor_set_refresh_rate(hz);
/* following code is the mode line genorator */
if (width < 300)
{
width = width*2;
crt_aspect_ratio_switch(width, height);
}
hfp = width+16;
hbp = width*1.22;
hbp = width*1.26;
hmax = hbp;
if (height < 241)
@ -146,7 +195,8 @@ static bool x11_set_resolution(void *data,
if (height > 250 && height < 260 && hz < 52)
{
vmax = 313;
}
}sprintf(output,"xrandr --rmmode %s", old_mode);
system(output);
if (height > 260 && height < 300)
{
vmax = 313;
@ -172,7 +222,7 @@ static bool x11_set_resolution(void *data,
}
if (hz > 56)
{
vfp = height+((vmax-height)*0.15);
vfp = height+((vmax-height)*0.28);
}
if (hz > 53 && hz < 56)
{
@ -223,39 +273,67 @@ static bool x11_set_resolution(void *data,
}
/* variable for new mode */
sprintf(new_mode,"%dx%d_%0.2f", width, height, hz);
res= fopen ("res.sh", "w");
for (i =0; i < 3; i++)
{
fprintf(res, "if (xrandr | grep \"VGA-%d connected\" )"
"\nthen"
"\n xrandr --addmode VGA-%d %s"
"\n xrandr --output VGA-%d --mode %s"
"\n xrandr --delmode VGA-%d %s"
"\n exit"
"\n fi \n \n"
"if (xrandr | grep \"VGA%d connected\" )"
"\nthen"
"\n xrandr --addmode VGA%d %s"
"\n xrandr --output VGA%d --mode %s"
"\n xrandr --delmode VGA%d %s"
"\n exit"
"\n fi \n \n"
"if (xrandr | grep \"DVI-%d connected\" )"
"\nthen"
"\n xrandr --addmode DVI-%d %s"
"\n xrandr --output DVI-%d --mode %s"
"\n xrandr --delmode DVI-%d %s"
"\n exit"
"\n fi \n \n"
"if (xrandr | grep \"DVI%d connected\" )"
"\nthen"
"\n xrandr --addmode DVI%d %s"
"\n xrandr --output DVI%d --mode %s"
"\n xrandr --delmode DVI%d %s"
"\n exit"
"\n fi \n \n"
"if (xrandr | grep \"HDMI-%d connected\" )"
"\nthen"
"\n xrandr --addmode HDMI-%d %s"
"\n xrandr --output HDMI-%d --mode %s"
"\n xrandr --delmode HDMI-%d %s"
"\n exit"
"\n fi \n \n"
"if (xrandr | grep \"HDMI%d connected\" )"
"\nthen"
"\n xrandr --addmode HDMI%d %s"
"\n xrandr --output HDMI%d --mode %s"
"\n xrandr --delmode HMDI%d %s"
"\n exit"
"\n fi \n \n"
"\nexit"
,i ,i ,new_mode,i , new_mode, i ,old_mode
,i ,i ,new_mode,i , new_mode, i ,old_mode
,i ,i ,new_mode,i , new_mode, i ,old_mode
,i ,i ,new_mode,i , new_mode, i ,old_mode
,i ,i ,new_mode,i , new_mode, i ,old_mode
,i ,i ,new_mode,i , new_mode, i ,old_mode);
}
fclose(res);
/* need to run loops for DVI0 - DVI-2 and VGA0 - VGA-2 outputs to add and delete modes */
for (i =0; i < 3; i++)
{
sprintf(output,"xrandr --addmode %s%d %s", "DVI",i ,new_mode);
system(output);
sprintf(output,"xrandr --delmode %s%d %s", "DVI",i ,old_mode);
system(output);
}
for (i =0; i < 3; i++)
{
sprintf(output,"xrandr --addmode %s-%d %s", "DVI",i ,new_mode);
system(output);
sprintf(output,"xrandr --delmode %s-%d %s", "DVI",i ,old_mode);
system(output);
}
for (i =0; i < 3; i++)
{
sprintf(output,"xrandr --addmode %s%d %s", "VGA",i ,new_mode);
system(output);
sprintf(output,"xrandr --delmode %s%d %s", "VGA",i ,old_mode);
system(output);
}
for (i =0; i < 3; i++)
{
sprintf(output,"xrandr --addmode %s-%d %s", "VGA",i ,new_mode);
system(output);
sprintf(output,"xrandr --delmode %s-%d %s", "VGA",i ,old_mode);
system(output);
}
sprintf(output,"xrandr -s %s", new_mode);
system(output);
system("bash res.sh");
/* remove old mode */
sprintf(output,"xrandr --rmmode %s", old_mode);
system(output);