This commit is contained in:
alphanu1 2018-05-11 22:21:52 +01:00 committed by GitHub
parent 06d411d6e7
commit dcc87f4557
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 306 additions and 358 deletions

View File

@ -1,358 +1,306 @@
/* RetroArch - A frontend for libretro. /* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Brad Parker * Copyright (C) 2016-2017 - Brad Parker
* *
* RetroArch is free software: you can redistribute it and/or modify it under the terms * RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found- * of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version. * ation, either version 3 of the License, or (at your option) any later version.
* *
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details. * PURPOSE. See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with RetroArch. * You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../video_display_server.h" #include "../video_display_server.h"
#include "../common/x11_common.h" #include "../common/x11_common.h"
#include "../../configuration.h" #include "../../configuration.h"
#include "../video_driver.h" /* needed to set refresh rate in set resolution */ #include "../video_driver.h" /* needed to set refresh rate in set resolution */
#include "../video_crt_switch.h" /* needed to set aspect for low res in linux */ #include "../video_crt_switch.h" /* needed to set aspect for low res in linux */
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
static unsigned orig_width = 0; static unsigned orig_width = 0;
static unsigned orig_height = 0; static unsigned orig_height = 0;
static char orig_res[50]; static char old_mode[150];
static char old_mode[150]; static char new_mode[150];
static char new_mode[150]; static char xrandr[250];
static char output[450]; static char fbset[150];
static bool crt_en = false; static char output[150];
static FILE *res; static bool crt_en = false;
typedef struct typedef struct
{ {
unsigned opacity; unsigned opacity;
bool decorations; bool decorations;
} dispserv_x11_t; } dispserv_x11_t;
static void* x11_display_server_init(void) static void* x11_display_server_init(void)
{ {
dispserv_x11_t *dispserv = (dispserv_x11_t*)calloc(1, sizeof(*dispserv)); dispserv_x11_t *dispserv = (dispserv_x11_t*)calloc(1, sizeof(*dispserv));
if (!dispserv) if (!dispserv)
return NULL; return NULL;
return dispserv; return dispserv;
} }
static void x11_display_server_destroy(void *data) static void x11_display_server_destroy(void *data)
{ {
dispserv_x11_t *dispserv = (dispserv_x11_t*)data; dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
int i = 0; int i = 0;
if (crt_en == true)
if (crt_en == true) {
{ sprintf(output,"xrandr -s %dx%d", orig_width, orig_height);
sprintf(orig_res, "xrandr -s %dx%d", orig_width, orig_height); system(output);
system(orig_res); }
for (i =0; i < 3; i++)
res= fopen ("res.sh", "w"); {
for (i =0; i < 3; i++) sprintf(output,"xrandr --delmode %s%d %s", "VGA",i ,old_mode);
{ system(output);
fprintf(res, "if (xrandr | grep \"VGA-%d connected\" )" sprintf(output,"xrandr --delmode %s-%d %s", "VGA",i ,old_mode);
"\nthen" system(output);
"\n xrandr --delmode VGA-%d %s"
"\n exit" sprintf(output,"xrandr --delmode %s%d %s", "DVI",i ,old_mode);
"\n fi \n\n" system(output);
"if (xrandr | grep \"VGA%d connected\" )" sprintf(output,"xrandr --delmode %s-%d %s", "DVI",i ,old_mode);
"\nthen" system(output);
"\n xrandr --delmode VGA%d %s"
"\n exit" }
"\n fi \n\n" sprintf(output,"xrandr --rmmode %s", old_mode);
"if (xrandr | grep \"DVI-%d connected\" )" system(output);
"\nthen"
"\n xrandr --delmode VGA-%d %s" if (dispserv)
"\n exit" free(dispserv);
"\n fi \n\n" }
"if (xrandr | grep \"DVI%d connected\" )"
"\nthen" static bool x11_set_window_opacity(void *data, unsigned opacity)
"\n xrandr --delmode DVI%d %s" {
"\n exit" dispserv_x11_t *serv = (dispserv_x11_t*)data;
"\n fi \n\n" Atom net_wm_opacity = XInternAtom(g_x11_dpy, "_NET_WM_WINDOW_OPACITY", False);
"\nexit" Atom cardinal = XInternAtom(g_x11_dpy, "CARDINAL", False);
,i, i ,old_mode serv->opacity = opacity;
,i, i ,old_mode
,i, i ,old_mode opacity = opacity * ((unsigned)-1 / 100.0);
,i, i ,old_mode);
} if (opacity == (unsigned)-1)
fclose(res); XDeleteProperty(g_x11_dpy, g_x11_win, net_wm_opacity);
system("bash res.sh"); else
sprintf(output,"xrandr --rmmode %s", old_mode); XChangeProperty(g_x11_dpy, g_x11_win, net_wm_opacity, cardinal, 32, PropModeReplace, (const unsigned char*)&opacity, 1);
system(output);
return true;
} }
if (dispserv) static bool x11_set_window_decorations(void *data, bool on)
free(dispserv); {
} dispserv_x11_t *serv = (dispserv_x11_t*)data;
static bool x11_set_window_opacity(void *data, unsigned opacity) serv->decorations = on;
{
dispserv_x11_t *serv = (dispserv_x11_t*)data; /* menu_setting performs a reinit instead to properly apply decoration changes */
Atom net_wm_opacity = XInternAtom(g_x11_dpy, "_NET_WM_WINDOW_OPACITY", False);
Atom cardinal = XInternAtom(g_x11_dpy, "CARDINAL", False); return true;
}
serv->opacity = opacity;
static bool x11_set_resolution(void *data,
opacity = opacity * ((unsigned)-1 / 100.0); unsigned width, unsigned height, int int_hz, float hz)
{
if (opacity == (unsigned)-1) int i = 0;
XDeleteProperty(g_x11_dpy, g_x11_win, net_wm_opacity); int hfp = 0;
else int hsp = 0;
XChangeProperty(g_x11_dpy, g_x11_win, net_wm_opacity, cardinal, 32, PropModeReplace, (const unsigned char*)&opacity, 1); int hbp = 0;
int vfp = 0;
return true; int vsp = 0;
} int vbp = 0;
int hmax = 0;
static bool x11_set_window_decorations(void *data, bool on) int vmax = 0;
{ float pixel_clock = 0;
dispserv_x11_t *serv = (dispserv_x11_t*)data;
Display* disp = XOpenDisplay(NULL);
serv->decorations = on; Screen* scrn = DefaultScreenOfDisplay(disp);
/* menu_setting performs a reinit instead to properly apply decoration changes */ if (orig_height == 0 && orig_width == 0)
{
return true; orig_width = scrn->width;
} orig_height = scrn->height;
}
static bool x11_set_resolution(void *data,
unsigned width, unsigned height, int int_hz, float hz) crt_en = true;
{
int i = 0; hsp = width*1.10;
int hfp = 0;
int hsp = 0; /* set core refresh from hz */
int hbp = 0; video_monitor_set_refresh_rate(hz);
int vfp = 0;
int vsp = 0; /* following code is the mode line genorator */
int vbp = 0;
int hmax = 0; hfp = width+8;
int vmax = 0; hbp = width*1.23;
float pixel_clock = 0; hmax = hbp;
char xrandr[250];
char fbset[150]; if (height < 241)
{
Display* disp = XOpenDisplay(NULL); vmax = 261;
Screen* scrn = DefaultScreenOfDisplay(disp); }
if (height < 241 && hz > 56 && hz < 58)
crt_en = true; {
vmax = 280;
if (orig_width == 0) }
orig_width = scrn->width; if (height < 241 && hz < 55)
{
if (orig_height == 0) vmax = 313;
orig_height = scrn->height; }
if (height > 250 && height < 260 && hz > 54)
hsp = width*1.12; {
vmax = 296;
/* set core refresh from hz */ }
video_monitor_set_refresh_rate(hz); if (height > 250 && height < 260 && hz > 52 && hz < 54)
{
/* following code is the mode line genorator */ vmax = 285;
}
hfp = width+12; if (height > 240 && height < 260 && hz < 52)
hbp = width*1.22; {
hmax = hbp; vmax = 265;
}
if (height < 241) if (height > 250 && height < 260 && hz < 52)
{ {
vmax = 261; vmax = 313;
} }
if (height < 241 && hz > 56 && hz < 58) if (height > 260 && height < 300)
{ {
vmax = 280; vmax = 313;
} }
if (height < 241 && hz < 55)
{ if (height > 400 && hz > 56)
vmax = 313; {
} vmax = 523;
if (height > 250 && height < 260 && hz > 54) }
{ if (height > 520 && hz < 57)
vmax = 296; {
} vmax = 580;
if (height > 250 && height < 260 && hz > 52 && hz < 54) }
{
vmax = 285; if (height > 300 && hz < 56)
} {
if (height > 240 && height < 260 && hz < 52) vmax = 627;
{ }
vmax = 265;
} if (hz < 53)
if (height > 250 && height < 260 && hz < 52) {
{ vfp = height+((vmax-height)*0.20);
vmax = 313; }
}sprintf(output,"xrandr --rmmode %s", old_mode); if (hz > 56)
system(output); {
if (height > 260 && height < 300) vfp = height+((vmax-height)*0.26);
{ }
vmax = 313; if (hz > 53 && hz < 56)
} {
vfp = height+((vmax-height)*0.25);
if (height > 400 && hz > 56) }
{
vmax = 523;
} if ( vfp < 1 )
if (height > 520 && hz < 57) {
{ vfp = height+2;
vmax = 580;
} }
if (height > 300 && hz < 56) if (height < 300)
{ {
vmax = 627; vsp = vfp+3; /* needs to me 3 for progressive */
} } if (height > 300)
{
if (hz < 53) vsp = vfp+6; /* needs to me 6 for interlaced */
{ }
vfp = height+((vmax-height)*0.38);
} vbp = vmax;
if (hz > 56)
{ if (height < 300)
vfp = height+((vmax-height)*0.28); {
} pixel_clock = (hmax*vmax*hz)/1000000;
if (hz > 53 && hz < 56) }
{
vfp = height+((vmax-height)*0.35); if (height > 300)
} {
pixel_clock = ((hmax*vmax*hz)/1000000)/2;
}
if ( vfp < 1 ) /* above code is the modeline genorator */
{
vfp = height+2; /* create progressive newmode from modline variables */
if (height < 300)
} {
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);
if (height < 300) system(xrandr);
{
vsp = vfp+3; /* needs to me 3 for progressive */ }
} if (height > 300) /* create interlaced newmode from modline variables */
{ if (height > 300)
vsp = vfp+6; /* needs to me 6 for interlaced */ {
} 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);
vbp = vmax;
}
if (height < 300) /* variable for new mode */
{ sprintf(new_mode,"%dx%d_%0.2f", width, height, hz);
pixel_clock = (hmax*vmax*hz)/1000000;
} /* need to run loops for DVI0 - DVI-2 and VGA0 - VGA-2 outputs to add and delete modes */
for (i =0; i < 3; i++)
if (height > 300) {
{ sprintf(output,"xrandr --addmode %s%d %s", "DVI",i ,new_mode);
pixel_clock = ((hmax*vmax*hz)/1000000)/2; system(output);
} sprintf(output,"xrandr --output %s%d --mode %s", "DVI", i, new_mode);
/* above code is the modeline genorator */ system(output);
sprintf(output,"xrandr --delmode %s%d %s", "DVI",i ,old_mode);
/* create progressive newmode from modline variables */ system(output);
if (height < 300)
{ sprintf(output,"xrandr --addmode %s-%d %s", "DVI",i ,new_mode);
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(output);
system(xrandr); 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);
/* create interlaced newmode from modline variables */ system(output);
if (height > 300)
{ sprintf(output,"xrandr --addmode %s%d %s", "VGA",i ,new_mode);
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(output);
system(xrandr); 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);
/* variable for new mode */ system(output);
sprintf(new_mode,"%dx%d_%0.2f", width, height, hz);
sprintf(output,"xrandr --addmode %s-%d %s", "VGA",i ,new_mode);
res= fopen ("res.sh", "w"); system(output);
for (i =0; i < 3; i++) sprintf(output,"xrandr --output %s-%d --mode %s", "VGA", i, new_mode);
{ system(output);
fprintf(res, "if (xrandr | grep \"VGA-%d connected\" )" sprintf(output,"xrandr --delmode %s-%d %s", "VGA",i ,old_mode);
"\nthen" system(output);
"\n xrandr --addmode VGA-%d %s" }
"\n xrandr --output VGA-%d --mode %s"
"\n xrandr --delmode VGA-%d %s"
"\n exit" /* remove old mode */
"\n fi \n \n" sprintf(output,"xrandr --rmmode %s", old_mode);
"if (xrandr | grep \"VGA%d connected\" )" system(output);
"\nthen" system("xdotool windowactivate $(xdotool search --class RetroArch)"); /* needs xdotool installed. needed to recaputure window. */
"\n xrandr --addmode VGA%d %s" /* variable for old mode */
"\n xrandr --output VGA%d --mode %s" sprintf(old_mode,"%s", new_mode);
"\n xrandr --delmode VGA%d %s" system("xdotool windowactivate $(xdotool search --class RetroArch)"); /* needs xdotool installed. needed to recaputure window. */
"\n exit" /* Second run needed as some times it runs to fast to capture first time */
"\n fi \n \n"
"if (xrandr | grep \"DVI-%d connected\" )" return true;
"\nthen" }
"\n xrandr --addmode DVI-%d %s"
"\n xrandr --output DVI-%d --mode %s" const video_display_server_t dispserv_x11 = {
"\n xrandr --delmode DVI-%d %s" x11_display_server_init,
"\n exit" x11_display_server_destroy,
"\n fi \n \n" x11_set_window_opacity,
"if (xrandr | grep \"DVI%d connected\" )" NULL,
"\nthen" x11_set_window_decorations,
"\n xrandr --addmode DVI%d %s" x11_set_resolution, /* set_resolution */
"\n xrandr --output DVI%d --mode %s" "x11"
"\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 */
system("bash res.sh");
/* remove 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 */
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 */
return true;
}
const video_display_server_t dispserv_x11 = {
x11_display_server_init,
x11_display_server_destroy,
x11_set_window_opacity,
NULL,
x11_set_window_decorations,
x11_set_resolution, /* set_resolution */
"x11"
};