mirror of
https://github.com/libretro/RetroArch
synced 2025-02-11 15:40:28 +00:00
(dispserv_x11.c) Cleanups
This commit is contained in:
parent
5640a5b512
commit
e27b314afb
@ -89,12 +89,15 @@ static void x11_display_server_close_display(Display *dpy)
|
||||
}
|
||||
|
||||
static bool x11_display_server_set_resolution(void *data,
|
||||
unsigned width, unsigned height, int int_hz, float hz, int center, int monitor_index, int xoffset, int padjust)
|
||||
unsigned width, unsigned height, int int_hz,
|
||||
float hz, int center, int monitor_index,
|
||||
int xoffset, int padjust)
|
||||
{
|
||||
int screen;
|
||||
Window window;
|
||||
int m;
|
||||
XRRScreenResources *resources;
|
||||
XRRModeInfo *swmode = NULL;
|
||||
XRRModeInfo *crt_xrrmode = NULL;
|
||||
XRRScreenResources *res = NULL;
|
||||
Display *dpy = NULL;
|
||||
int i = 0;
|
||||
int hfp = 0;
|
||||
int hsp = 0;
|
||||
@ -111,20 +114,17 @@ static bool x11_display_server_set_resolution(void *data,
|
||||
float pixel_clock = 0;
|
||||
int crt_mode_flag = 0;
|
||||
bool crt_exists = false;
|
||||
Display *dpy = XOpenDisplay(0);
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window window = RootWindow(dpy, screen);
|
||||
|
||||
g_monitor_index = monitor_index;
|
||||
|
||||
XRRScreenResources *resources;
|
||||
|
||||
crt_en = true;
|
||||
crt_name_id += 1;
|
||||
|
||||
snprintf(crt_name, sizeof(crt_name), "CRT%d", crt_name_id);
|
||||
|
||||
|
||||
dpy = XOpenDisplay(0);
|
||||
screen = DefaultScreen(dpy);
|
||||
window = RootWindow(dpy, screen);
|
||||
|
||||
/* set core refresh from hz */
|
||||
video_monitor_set_refresh_rate(hz);
|
||||
|
||||
@ -133,7 +133,9 @@ static bool x11_display_server_set_resolution(void *data,
|
||||
{
|
||||
hfp = (width * 1.033)+(padjust*2);
|
||||
hbp = (width * 1.225)+(padjust*2);
|
||||
}else {
|
||||
}
|
||||
else
|
||||
{
|
||||
hfp = ((width * 1.033) + (width / 112))+(padjust*4);
|
||||
hbp = ((width * 1.225) + (width /58))+(padjust*4);
|
||||
xoffset = xoffset*2;
|
||||
@ -185,18 +187,13 @@ static bool x11_display_server_set_resolution(void *data,
|
||||
|
||||
/* create interlaced newmode from modline variables */
|
||||
if (height < 300)
|
||||
{
|
||||
crt_mode_flag = 10;
|
||||
}
|
||||
|
||||
/* create interlaced newmode from modline variables */
|
||||
if (height > 300)
|
||||
{
|
||||
crt_mode_flag = 26;
|
||||
}
|
||||
snprintf(old_mode, sizeof(old_mode), "%s", new_mode);
|
||||
strlcpy(old_mode, new_mode, sizeof(old_mode));
|
||||
/* variable for new mode */
|
||||
snprintf(new_mode, sizeof(new_mode), "%s", crt_name);
|
||||
strlcpy(new_mode, crt_name, sizeof(new_mode));
|
||||
|
||||
/* need to run loops for DVI0 - DVI-2 and VGA0 - VGA-2 outputs to
|
||||
* add and delete modes */
|
||||
@ -212,18 +209,19 @@ static bool x11_display_server_set_resolution(void *data,
|
||||
crt_rrmode.vSyncStart = vfp;
|
||||
crt_rrmode.vSyncEnd = vsp;
|
||||
crt_rrmode.vTotal = vbp;
|
||||
crt_rrmode.modeFlags = crt_mode_flag; /* 10 for -hsync -vsync. 26 for -hsync -vsync interlaced */
|
||||
crt_rrmode.modeFlags = crt_mode_flag;
|
||||
/* 10 for -hsync -vsync. 26 for -hsync -vsync interlaced */
|
||||
crt_rrmode.hSkew = 0;
|
||||
|
||||
XRRModeInfo *crt_xrrmode = &crt_rrmode;
|
||||
crt_xrrmode = &crt_rrmode;
|
||||
res = XRRGetScreenResources(dpy, window);
|
||||
XSync(dpy, False);
|
||||
|
||||
resources = XRRGetScreenResourcesCurrent(dpy, window);
|
||||
|
||||
for (int m = 0; m < resources->nmode; m++)
|
||||
for (m = 0; m < resources->nmode; m++)
|
||||
{
|
||||
if (strcmp(resources->modes[m].name, new_mode) == 0)
|
||||
if (string_is_equal(resources->modes[m].name, new_mode))
|
||||
{
|
||||
|
||||
crt_exists = true;
|
||||
@ -234,19 +232,15 @@ static bool x11_display_server_set_resolution(void *data,
|
||||
XRRFreeScreenResources(resources);
|
||||
|
||||
|
||||
if (crt_exists == false)
|
||||
{
|
||||
RRMode wMode = XRRCreateMode(dpy, window, &crt_rrmode);
|
||||
}
|
||||
if (!crt_exists)
|
||||
XRRCreateMode(dpy, window, &crt_rrmode);
|
||||
|
||||
XRRModeInfo *swmode = NULL;
|
||||
resources = XRRGetScreenResourcesCurrent(dpy, window);
|
||||
|
||||
for (int m = 0; m < resources->nmode; m++)
|
||||
for (m = 0; m < resources->nmode; m++)
|
||||
{
|
||||
if (strcmp(resources->modes[m].name, new_mode) == 0)
|
||||
if (string_is_equal(resources->modes[m].name, new_mode))
|
||||
{
|
||||
|
||||
swmode = &resources->modes[m];
|
||||
break;
|
||||
}
|
||||
@ -258,26 +252,29 @@ static bool x11_display_server_set_resolution(void *data,
|
||||
{
|
||||
XRROutputInfo *outputs = XRRGetOutputInfo(dpy, res, res->outputs[i]);
|
||||
|
||||
|
||||
if (outputs->connection == RR_Connected)
|
||||
{
|
||||
|
||||
XRRAddOutputMode(dpy, res->outputs[i], swmode->id);
|
||||
XSync(dpy, False);
|
||||
snprintf(orig_output, sizeof(orig_output), "%s", outputs->name);
|
||||
strlcpy(orig_output, outputs->name, sizeof(orig_output));
|
||||
XRRCrtcInfo *crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
|
||||
crtc->mode = swmode->id;
|
||||
crtc->width = swmode->width;
|
||||
crtc->height = swmode->height;
|
||||
XRRSetCrtcConfig(dpy, res,res->crtcs[i], CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0);
|
||||
XRRSetCrtcConfig(dpy, res,res->crtcs[i],
|
||||
CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0);
|
||||
XSync(dpy, False);
|
||||
XRRSetScreenSize(dpy, window, width, height, (int) ((25.4 * width) / 96.0), (int) ((25.4 * height) / 96.0));
|
||||
XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput);
|
||||
XRRSetScreenSize(dpy, window, width, height,
|
||||
(int)((25.4 * width) / 96.0),
|
||||
(int)((25.4 * height) / 96.0));
|
||||
XRRSetCrtcConfig(dpy, res, res->crtcs[i],
|
||||
CurrentTime, crtc->x, crtc->y, crtc->mode,
|
||||
crtc->rotation, crtc->outputs, crtc->noutput);
|
||||
XSync(dpy, False);
|
||||
|
||||
XRRFreeCrtcInfo(crtc);
|
||||
XRRFreeOutputInfo(outputs);
|
||||
|
||||
}
|
||||
}
|
||||
XRRFreeScreenResources(resources);
|
||||
@ -290,17 +287,23 @@ static bool x11_display_server_set_resolution(void *data,
|
||||
|
||||
if (outputs->connection == RR_Connected)
|
||||
{
|
||||
XRRCrtcInfo *crtc;
|
||||
|
||||
XRRAddOutputMode(dpy, res->outputs[monitor_index], swmode->id);
|
||||
XSync(dpy, False);
|
||||
snprintf(orig_output, sizeof(orig_output), "%s", outputs->name);
|
||||
XRRCrtcInfo *crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
|
||||
strlcpy(orig_output, outputs->name, sizeof(orig_output));
|
||||
crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
|
||||
crtc->mode = swmode->id;
|
||||
crtc->width = swmode->width;
|
||||
crtc->height = swmode->height;
|
||||
XRRSetCrtcConfig(dpy, res,res->crtcs[monitor_index], CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0);
|
||||
XSync(dpy, False);
|
||||
XRRSetScreenSize(dpy, window, width, height, (int) ((25.4 * width) / 96.0), (int) ((25.4 * height) / 96.0));
|
||||
XRRSetCrtcConfig(dpy, res, res->crtcs[monitor_index], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput);
|
||||
XRRSetScreenSize(dpy, window, width, height,
|
||||
(int)((25.4 * width) / 96.0),
|
||||
(int)((25.4 * height) / 96.0));
|
||||
XRRSetCrtcConfig(dpy, res, res->crtcs[monitor_index],
|
||||
CurrentTime, crtc->x, crtc->y, crtc->mode,
|
||||
crtc->rotation, crtc->outputs, crtc->noutput);
|
||||
XSync(dpy, False);
|
||||
|
||||
XRRFreeCrtcInfo(crtc);
|
||||
@ -385,9 +388,13 @@ static void x11_display_server_set_screen_orientation(enum rotation rotation)
|
||||
|
||||
crtc->rotation = new_rotation;
|
||||
|
||||
XRRSetScreenSize(dpy, DefaultRootWindow(dpy), crtc->width, crtc->height, (25.4 * crtc->width) / dpi, (25.4 * crtc->height) / dpi);
|
||||
XRRSetScreenSize(dpy, DefaultRootWindow(dpy), crtc->width,
|
||||
crtc->height, (25.4 * crtc->width) / dpi,
|
||||
(25.4 * crtc->height) / dpi);
|
||||
|
||||
XRRSetCrtcConfig(dpy, screen, screen->crtcs[j], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput);
|
||||
XRRSetCrtcConfig(dpy, screen, screen->crtcs[j], CurrentTime,
|
||||
crtc->x, crtc->y, crtc->mode, crtc->rotation,
|
||||
crtc->outputs, crtc->noutput);
|
||||
|
||||
XRRFreeCrtcInfo(crtc);
|
||||
}
|
||||
@ -409,10 +416,12 @@ static enum rotation x11_display_server_get_screen_orientation(void)
|
||||
XRRScreenConfiguration *config = NULL;
|
||||
enum rotation rotation = ORIENTATION_NORMAL;
|
||||
Display *dpy = x11_display_server_open_display();
|
||||
XRRScreenResources *screen = XRRGetScreenResources(dpy, DefaultRootWindow(dpy));
|
||||
XRRScreenResources *screen = XRRGetScreenResources(dpy,
|
||||
DefaultRootWindow(dpy));
|
||||
if (!screen)
|
||||
return ORIENTATION_NORMAL;
|
||||
config = XRRGetScreenInfo(dpy, DefaultRootWindow(dpy));
|
||||
config = XRRGetScreenInfo(dpy,
|
||||
DefaultRootWindow(dpy));
|
||||
|
||||
for (i = 0; i < screen->noutput; i++)
|
||||
{
|
||||
@ -480,19 +489,18 @@ static void x11_display_server_destroy(void *data)
|
||||
{
|
||||
dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
|
||||
#ifdef HAVE_XRANDR
|
||||
int screen;
|
||||
Window window;
|
||||
XRRScreenResources *res = NULL;
|
||||
Display *dpy = NULL;
|
||||
XRRScreenResources *resources;
|
||||
dpy = XOpenDisplay(0);
|
||||
screen = DefaultScreen(dpy);
|
||||
window = RootWindow(dpy, screen);
|
||||
int m;
|
||||
XRRModeInfo *swoldmode = NULL;
|
||||
XRRModeInfo *swdeskmode = NULL;
|
||||
XRRScreenResources *resources = NULL;
|
||||
Display *dpy = XOpenDisplay(0);
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window window = RootWindow(dpy, screen);
|
||||
bool crt_exists = false;
|
||||
char dmode[25] ={};
|
||||
char dmode[25] = {0};
|
||||
XRRScreenResources *res = XRRGetScreenResources(dpy, window);
|
||||
|
||||
|
||||
snprintf(dmode, sizeof(dmode), "%s", "d_mo");
|
||||
strlcpy(dmode, "d_mo", sizeof(dmode));
|
||||
|
||||
crt_rrmode.name = dmode;
|
||||
crt_rrmode.nameLength = strlen(crt_name);
|
||||
@ -505,23 +513,19 @@ static void x11_display_server_destroy(void *data)
|
||||
crt_rrmode.vSyncStart = 490;
|
||||
crt_rrmode.vSyncEnd = 496;
|
||||
crt_rrmode.vTotal = 533;
|
||||
crt_rrmode.modeFlags = 26; /* 10 for -hsync -vsync. ?? for -hsync -vsync interlaced */
|
||||
crt_rrmode.modeFlags = 26;
|
||||
/* 10 for -hsync -vsync. ?? for -hsync -vsync interlaced */
|
||||
crt_rrmode.hSkew = 0;
|
||||
|
||||
|
||||
res = XRRGetScreenResources(dpy, window);
|
||||
resources = XRRGetScreenResourcesCurrent(dpy, window);
|
||||
XRRModeInfo *swoldmode = NULL;
|
||||
XRRModeInfo *swdeskmode = NULL;
|
||||
XSync(dpy, False);
|
||||
|
||||
resources = XRRGetScreenResourcesCurrent(dpy, window);
|
||||
|
||||
for (int m = 0; m < resources->nmode; m++)
|
||||
for (m = 0; m < resources->nmode; m++)
|
||||
{
|
||||
if (strcmp(resources->modes[m].name, dmode) == 0)
|
||||
if (string_is_equal(resources->modes[m].name, dmode))
|
||||
{
|
||||
|
||||
crt_exists = true;
|
||||
break;
|
||||
}
|
||||
@ -529,20 +533,15 @@ static void x11_display_server_destroy(void *data)
|
||||
|
||||
XRRFreeScreenResources(resources);
|
||||
|
||||
|
||||
if (crt_exists == false)
|
||||
{
|
||||
RRMode wMode = XRRCreateMode(dpy, window, &crt_rrmode);
|
||||
}
|
||||
|
||||
if (!crt_exists)
|
||||
XRRCreateMode(dpy, window, &crt_rrmode);
|
||||
|
||||
resources = XRRGetScreenResourcesCurrent(dpy, window);
|
||||
|
||||
for (int m = 0; m < resources->nmode; m++)
|
||||
for (m = 0; m < resources->nmode; m++)
|
||||
{
|
||||
if (strcmp(resources->modes[m].name, dmode) == 0)
|
||||
if (string_is_equal(resources->modes[m].name, dmode))
|
||||
{
|
||||
|
||||
swdeskmode = &resources->modes[m];
|
||||
break;
|
||||
}
|
||||
@ -552,45 +551,53 @@ static void x11_display_server_destroy(void *data)
|
||||
{
|
||||
if (g_monitor_index == 20)
|
||||
{
|
||||
for (int i = 0; i < res->noutput; i++)
|
||||
int i;
|
||||
for (i = 0; i < res->noutput; i++)
|
||||
{
|
||||
XRROutputInfo *outputs = XRRGetOutputInfo(dpy, res, res->outputs[i]);
|
||||
|
||||
XRROutputInfo *outputs = XRRGetOutputInfo(
|
||||
dpy, res, res->outputs[i]);
|
||||
|
||||
if (outputs->connection == RR_Connected)
|
||||
{
|
||||
XRRCrtcInfo *crtc;
|
||||
|
||||
XRRAddOutputMode(dpy, res->outputs[i], swdeskmode->id);
|
||||
XSync(dpy, False);
|
||||
snprintf(orig_output, sizeof(orig_output), "%s", outputs->name);
|
||||
XRRCrtcInfo *crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
|
||||
strlcpy(orig_output, outputs->name, sizeof(orig_output));
|
||||
crtc = XRRGetCrtcInfo(dpy, resources,
|
||||
outputs->crtc);
|
||||
crtc->mode = swdeskmode->id;
|
||||
crtc->width = swdeskmode->width;
|
||||
crtc->height = swdeskmode->height;
|
||||
XRRSetCrtcConfig(dpy, res,res->crtcs[i], CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0);
|
||||
XSync(dpy, False);
|
||||
XRRSetScreenSize(dpy, window, crt_rrmode.width, crt_rrmode.height, (int) ((25.4 * crt_rrmode.width) / 96.0), (int) ((25.4 * crt_rrmode.height) / 96.0));
|
||||
XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput);
|
||||
XRRSetScreenSize(dpy, window,
|
||||
crt_rrmode.width,
|
||||
crt_rrmode.height,
|
||||
(int) ((25.4 * crt_rrmode.width) / 96.0),
|
||||
(int) ((25.4 * crt_rrmode.height) / 96.0));
|
||||
XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime,
|
||||
crtc->x, crtc->y, crtc->mode,
|
||||
crtc->rotation, crtc->outputs, crtc->noutput);
|
||||
XSync(dpy, False);
|
||||
|
||||
XRRFreeCrtcInfo(crtc);
|
||||
XRRFreeOutputInfo(outputs);
|
||||
|
||||
}
|
||||
}
|
||||
XRRFreeScreenResources(resources);
|
||||
}
|
||||
else if (g_monitor_index != 20)
|
||||
{
|
||||
|
||||
XRROutputInfo *outputs = XRRGetOutputInfo(dpy, res, res->outputs[g_monitor_index]);
|
||||
|
||||
if (outputs->connection == RR_Connected)
|
||||
{
|
||||
XRRCrtcInfo *crtc;
|
||||
XRRAddOutputMode(dpy, res->outputs[g_monitor_index], swdeskmode->id);
|
||||
XSync(dpy, False);
|
||||
snprintf(orig_output, sizeof(orig_output), "%s", outputs->name);
|
||||
XRRCrtcInfo *crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
|
||||
strlcpy(orig_output, outputs->name, sizeof(orig_output));
|
||||
crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
|
||||
crtc->mode = swdeskmode->id;
|
||||
crtc->width = swdeskmode->width;
|
||||
crtc->height = swdeskmode->height;
|
||||
@ -603,20 +610,21 @@ static void x11_display_server_destroy(void *data)
|
||||
XRRFreeCrtcInfo(crtc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int m = 0; m < resources->nmode; m++)
|
||||
for (m = 0; m < resources->nmode; m++)
|
||||
{
|
||||
for (int j = 0; j < res->noutput; j++)
|
||||
int j, i;
|
||||
|
||||
for (j = 0; j < res->noutput; j++)
|
||||
{
|
||||
for (int i = 1 ; i <= crt_name_id; i++ )
|
||||
for (i = 1 ; i <= crt_name_id; i++ )
|
||||
{
|
||||
XRROutputInfo *outputs = XRRGetOutputInfo(dpy, res, res->outputs[j]);
|
||||
if (outputs->connection == RR_Connected)
|
||||
{
|
||||
snprintf(old_mode, sizeof(old_mode), "CRT%d", i);
|
||||
if (strcmp(resources->modes[m].name, old_mode) == 0)
|
||||
if (string_is_equal(resources->modes[m].name, old_mode))
|
||||
{
|
||||
swoldmode = &resources->modes[m];
|
||||
XRRDeleteOutputMode(dpy, res->outputs[j], swoldmode->id);
|
||||
@ -627,8 +635,6 @@ static void x11_display_server_destroy(void *data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
if (dispserv)
|
||||
@ -638,7 +644,8 @@ static void x11_display_server_destroy(void *data)
|
||||
static bool x11_display_server_set_window_opacity(void *data, unsigned opacity)
|
||||
{
|
||||
dispserv_x11_t *serv = (dispserv_x11_t*)data;
|
||||
Atom net_wm_opacity = XInternAtom(g_x11_dpy, "_NET_WM_WINDOW_OPACITY", False);
|
||||
Atom net_wm_opacity = XInternAtom(g_x11_dpy, "_NET_WM_WINDOW_OPACITY",
|
||||
False);
|
||||
Atom cardinal = XInternAtom(g_x11_dpy, "CARDINAL", False);
|
||||
|
||||
serv->opacity = opacity;
|
||||
|
Loading…
x
Reference in New Issue
Block a user