RetroArch/gfx/display_servers/dispserv_x11.c

783 lines
24 KiB
C
Raw Normal View History

2018-05-25 10:56:22 +01:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2019 - Brad Parker
2018-05-25 10:56:22 +01:00
*
* 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-
* 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;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* 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.
* If not, see <http://www.gnu.org/licenses/>.
*/
/* We are targeting XRandR 1.2 here. */
2019-06-17 21:07:16 +02:00
#include <math.h>
#include <compat/strl.h>
2020-09-14 12:54:15 +02:00
#include <string/stdstring.h>
#include <sys/types.h>
#include <unistd.h>
2019-01-30 22:46:29 +00:00
#include <X11/Xlib.h>
2018-05-25 10:56:22 +01:00
2019-05-22 14:07:56 -04:00
#ifdef HAVE_CONFIG_H
#include "../../config.h"
2019-05-22 14:07:56 -04:00
#endif
#ifdef HAVE_XRANDR
#include <X11/extensions/Xrandr.h>
#include <X11/extensions/randr.h>
#include <X11/extensions/Xrender.h>
#endif
2018-05-25 10:56:22 +01:00
#include "../video_display_server.h"
#include "../common/x11_common.h"
#include "../../retroarch.h"
2018-05-25 10:56:22 +01:00
#include "../video_crt_switch.h" /* needed to set aspect for low res in linux */
typedef struct
{
#ifdef HAVE_XRANDR
XRRModeInfo crt_rrmode;
#endif
int crt_name_id;
int monitor_index;
2018-05-25 10:56:22 +01:00
unsigned opacity;
char crt_name[16];
char new_mode[256];
char old_mode[256];
char orig_output[256];
bool using_global_dpy;
bool crt_en;
2018-05-25 10:56:22 +01:00
bool decorations;
} dispserv_x11_t;
2019-03-14 16:10:53 +00:00
#ifdef HAVE_XRANDR
static Display* x11_display_server_open_display(dispserv_x11_t *dispserv)
{
2020-09-20 17:50:06 +02:00
Display *dpy = g_x11_dpy;
if (!dispserv)
return NULL;
dispserv->using_global_dpy = (dpy != NULL);
2020-09-20 17:50:06 +02:00
/* SDL might use X11 but doesn't use g_x11_dpy, so open it manually */
if (!dpy)
dpy = XOpenDisplay(0);
return dpy;
}
static void x11_display_server_close_display(dispserv_x11_t *dispserv,
Display *dpy)
{
if (!dpy || !dispserv || dispserv->using_global_dpy || dpy == g_x11_dpy)
return;
XCloseDisplay(dpy);
}
2018-05-25 10:56:22 +01:00
2018-09-17 03:40:17 +02:00
static bool x11_display_server_set_resolution(void *data,
2020-09-20 17:50:06 +02:00
unsigned width, unsigned height, int int_hz, float hz,
int center, int monitor_index, int xoffset, int padjust)
2018-05-25 10:56:22 +01:00
{
int m, screen;
Window window;
2020-09-14 12:53:49 +02:00
XRRScreenResources
*resources = NULL;
2019-01-31 15:13:36 +01:00
XRRScreenResources *res = NULL;
Display *dpy = NULL;
2019-01-31 15:13:36 +01:00
int i = 0;
int hfp = 0;
int hsp = 0;
int hbp = 0;
int vfp = 0;
int vsp = 0;
int vbp = 0;
int hmax = 0;
int vmax = 0;
int x_offset = center;
2019-01-31 15:13:36 +01:00
int pdefault = 8;
int pwidth = 0;
float roundw = 0.0f;
float pixel_clock = 0;
2020-09-11 15:57:56 +01:00
int crt_mode_flag = 0;
bool crt_exists = false;
2020-09-14 12:53:49 +02:00
XRRModeInfo *swmode = NULL;
dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
dispserv->monitor_index = monitor_index;
dispserv->crt_en = true;
dispserv->crt_name_id += 1;
snprintf(dispserv->crt_name, sizeof(dispserv->crt_name),
"CRT%d", dispserv->crt_name_id);
2020-09-20 18:16:02 +02:00
strlcpy(dispserv->old_mode, dispserv->new_mode,
sizeof(dispserv->old_mode));
2020-09-14 12:53:49 +02:00
dpy = XOpenDisplay(0);
screen = DefaultScreen(dpy);
window = RootWindow(dpy, screen);
2018-10-02 16:56:28 -04:00
2018-05-25 10:56:22 +01:00
/* set core refresh from hz */
2018-10-02 16:56:28 -04:00
video_monitor_set_refresh_rate(hz);
2018-11-24 19:38:01 +01:00
/* following code is the mode line generator */
if (width < 700)
{
hfp = (width * 1.033)+(padjust*2);
hbp = (width * 1.225)+(padjust*2);
2020-09-14 12:59:32 +02:00
}
else
{
hfp = ((width * 1.033) + (width / 112))+(padjust*4);
hbp = ((width * 1.225) + (width /58))+(padjust*4);
xoffset = xoffset*2;
}
2020-09-14 12:53:49 +02:00
hsp = (width * 1.117) - (xoffset*4);
hmax = hbp;
2018-10-02 16:56:28 -04:00
2018-05-25 10:56:22 +01:00
if (height < 241)
vmax = 261;
2018-05-25 10:56:22 +01:00
if (height < 241 && hz > 56 && hz < 58)
vmax = 280;
2018-10-02 16:56:28 -04:00
if (height < 241 && hz < 55)
vmax = 313;
2018-05-25 10:56:22 +01:00
if (height > 250 && height < 260 && hz > 54)
vmax = 296;
2018-05-25 10:56:22 +01:00
if (height > 250 && height < 260 && hz > 52 && hz < 54)
vmax = 285;
2018-05-25 10:56:22 +01:00
if (height > 250 && height < 260 && hz < 52)
vmax = 313;
2018-05-25 10:56:22 +01:00
if (height > 260 && height < 300)
vmax = 318;
2018-05-25 10:56:22 +01:00
if (height > 400 && hz > 56)
vmax = 533;
2018-05-25 10:56:22 +01:00
if (height > 520 && hz < 57)
vmax = 580;
2018-05-25 10:56:22 +01:00
if (height > 300 && hz < 56)
vmax = 615;
if (height > 500 && hz < 56)
vmax = 624;
2018-10-02 16:56:28 -04:00
if (height > 300)
pdefault = pdefault * 2;
2018-05-25 10:56:22 +01:00
vfp = height + ((vmax - height) / 2) - pdefault;
2018-05-25 10:56:22 +01:00
if (height < 300)
vsp = vfp + 3; /* needs to be 3 for progressive */
if (height > 300)
vsp = vfp + 6; /* needs to be 6 for interlaced */
2018-10-02 16:56:28 -04:00
vbp = vmax;
2018-05-25 10:56:22 +01:00
if (height < 300)
pixel_clock = (hmax * vmax * hz) ;
2018-05-25 10:56:22 +01:00
if (height > 300)
pixel_clock = (hmax * vmax * hz) / 2;
2018-11-24 19:38:01 +01:00
/* above code is the modeline generator */
2018-05-25 10:56:22 +01:00
2018-09-10 18:12:44 +01:00
/* create interlaced newmode from modline variables */
if (height < 300)
crt_mode_flag = 10;
2018-05-25 10:56:22 +01:00
/* create interlaced newmode from modline variables */
if (height > 300)
crt_mode_flag = 26;
strlcpy(dispserv->old_mode, dispserv->new_mode, sizeof(dispserv->old_mode));
2018-10-02 16:56:28 -04:00
/* variable for new mode */
strlcpy(dispserv->new_mode, dispserv->crt_name, sizeof(dispserv->new_mode));
2018-10-02 16:56:28 -04:00
2019-02-03 15:49:35 -08:00
/* need to run loops for DVI0 - DVI-2 and VGA0 - VGA-2 outputs to
2018-11-24 19:38:01 +01:00
* add and delete modes */
dispserv->crt_rrmode.name = dispserv->new_mode;
dispserv->crt_rrmode.nameLength = strlen(dispserv->crt_name);
dispserv->crt_rrmode.dotClock = pixel_clock;
dispserv->crt_rrmode.width = width;
dispserv->crt_rrmode.hSyncStart = hfp;
dispserv->crt_rrmode.hSyncEnd = hsp;
dispserv->crt_rrmode.hTotal = hmax;
dispserv->crt_rrmode.height = height;
dispserv->crt_rrmode.vSyncStart = vfp;
dispserv->crt_rrmode.vSyncEnd = vsp;
dispserv->crt_rrmode.vTotal = vbp;
dispserv->crt_rrmode.modeFlags = crt_mode_flag; /* 10 for -hsync -vsync. 26 for -hsync -vsync interlaced */
dispserv->crt_rrmode.hSkew = 0;
res = XRRGetScreenResources(dpy, window);
XSync(dpy, False);
resources = XRRGetScreenResourcesCurrent(dpy, window);
2020-09-14 12:53:49 +02:00
for (m = 0; m < resources->nmode; m++)
{
if (string_is_equal(resources->modes[m].name, dispserv->new_mode))
{
crt_exists = true;
break;
}
}
XRRFreeScreenResources(resources);
2020-09-14 12:53:49 +02:00
if (!crt_exists)
XRRCreateMode(dpy, window, &dispserv->crt_rrmode);
2020-09-14 12:53:49 +02:00
resources = XRRGetScreenResourcesCurrent(dpy, window);
2020-09-14 12:53:49 +02:00
for (m = 0; m < resources->nmode; m++)
{
if (string_is_equal(resources->modes[m].name, dispserv->new_mode))
{
swmode = &resources->modes[m];
break;
}
}
2020-09-14 12:53:49 +02:00
if (dispserv->monitor_index == 20)
2018-10-02 16:56:28 -04:00
{
2019-02-06 09:16:26 -08:00
for (i = 0; i < res->noutput; i++)
2019-02-03 15:49:35 -08:00
{
XRROutputInfo *outputs = XRRGetOutputInfo(dpy, res, res->outputs[i]);
2019-01-30 21:55:33 +00:00
if (outputs->connection == RR_Connected)
{
2020-09-14 12:53:49 +02:00
XRRCrtcInfo *crtc = NULL;
XRRAddOutputMode(dpy, res->outputs[i], swmode->id);
XSync(dpy, False);
strlcpy(dispserv->orig_output, outputs->name,
sizeof(dispserv->orig_output));
2020-09-14 12:53:49 +02:00
crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
crtc->mode = swmode->id;
crtc->width = swmode->width;
crtc->height = swmode->height;
2020-09-14 12:53:49 +02:00
XRRSetCrtcConfig(dpy, res,res->crtcs[i], CurrentTime,
0, 0, None, RR_Rotate_0, NULL, 0);
XSync(dpy, False);
2021-04-19 07:38:38 -07:00
XRRSetScreenSize(dpy, window, width, height, (int) ((25.4 * width) / 96.0), (int) ((25.4 * height) / 96.0));
XSync(dpy, False);
2020-09-14 12:53:49 +02:00
XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime,
crtc->x, crtc->y, crtc->mode, crtc->rotation,
crtc->outputs, crtc->noutput);
XSync(dpy, False);
2020-09-14 12:53:49 +02:00
2021-04-19 07:38:38 -07:00
2020-09-11 17:31:17 +01:00
XRRFreeCrtcInfo(crtc);
2020-09-14 12:53:49 +02:00
2019-01-30 21:55:33 +00:00
}
2020-09-14 12:53:49 +02:00
XRRFreeOutputInfo(outputs);
2019-01-30 21:55:33 +00:00
}
2019-02-22 10:11:06 -05:00
}
2020-09-20 03:06:23 +02:00
else
2019-02-22 10:11:06 -05:00
{
XRROutputInfo *outputs = XRRGetOutputInfo(dpy, res, res->outputs[monitor_index]);
2019-02-22 10:11:06 -05:00
if (outputs->connection == RR_Connected)
{
2020-09-14 12:53:49 +02:00
XRRCrtcInfo *crtc = NULL;
XRRAddOutputMode(dpy, res->outputs[monitor_index], swmode->id);
XSync(dpy, False);
strlcpy(dispserv->orig_output, outputs->name,
sizeof(dispserv->orig_output));
2020-09-14 12:53:49 +02:00
crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
crtc->mode = swmode->id;
crtc->width = swmode->width;
crtc->height = swmode->height;
2020-09-14 12:53:49 +02:00
XRRSetCrtcConfig(dpy, res,res->crtcs[monitor_index], CurrentTime,
0, 0, None, RR_Rotate_0, NULL, 0);
XSync(dpy, False);
2021-04-19 07:38:38 -07:00
XRRSetScreenSize(dpy, window, width, height, (int) ((25.4 * width) / 96.0), (int) ((25.4 * height) / 96.0));
XSync(dpy, False);
2020-09-14 12:53:49 +02:00
XRRSetCrtcConfig(dpy, res, res->crtcs[monitor_index], CurrentTime,
crtc->x, crtc->y, crtc->mode, crtc->rotation,
crtc->outputs, crtc->noutput);
XSync(dpy, False);
2020-09-14 12:53:49 +02:00
XRRFreeCrtcInfo(crtc);
2019-02-22 10:11:06 -05:00
}
2020-09-11 17:31:17 +01:00
XRRFreeOutputInfo(outputs);
2019-02-22 10:11:06 -05:00
}
2020-09-20 03:06:23 +02:00
XRRFreeScreenResources(resources);
XCloseDisplay(dpy);
2018-10-02 16:56:28 -04:00
return true;
2018-05-25 10:56:22 +01:00
}
2020-09-20 17:50:06 +02:00
static void x11_display_server_set_screen_orientation(void *data,
enum rotation rotation)
{
int i, j;
2020-09-14 12:53:49 +02:00
XRRScreenResources *screen = NULL;
/* switched to using XOpenDisplay() due to deinit order issue with g_x11_dpy when restoring original rotation on exit */
2020-09-14 12:53:49 +02:00
Display *dpy = XOpenDisplay(0);
XRRScreenConfiguration *config = XRRGetScreenInfo(dpy, DefaultRootWindow(dpy));
double dpi = (25.4 * DisplayHeight(dpy, DefaultScreen(dpy))) / DisplayHeightMM(dpy, DefaultScreen(dpy));
XGrabServer(dpy);
screen = XRRGetScreenResources(dpy, DefaultRootWindow(dpy));
for (i = 0; i < screen->noutput; i++)
{
XRROutputInfo *info = XRRGetOutputInfo(dpy, screen, screen->outputs[i]);
if (info->connection != RR_Connected)
{
XRRFreeOutputInfo(info);
continue;
}
for (j = 0; j < info->ncrtc; j++)
{
XRRCrtcInfo *crtc = XRRGetCrtcInfo(dpy, screen, screen->crtcs[j]);
Rotation new_rotation = RR_Rotate_0;
if (crtc->width == 0 || crtc->height == 0)
{
XRRFreeCrtcInfo(crtc);
continue;
}
switch (rotation)
{
case ORIENTATION_NORMAL:
default:
if (crtc->rotations & RR_Rotate_0)
new_rotation = RR_Rotate_0;
break;
case ORIENTATION_VERTICAL:
if (crtc->rotations & RR_Rotate_270)
new_rotation = RR_Rotate_270;
break;
case ORIENTATION_FLIPPED:
if (crtc->rotations & RR_Rotate_180)
new_rotation = RR_Rotate_180;
break;
case ORIENTATION_FLIPPED_ROTATED:
if (crtc->rotations & RR_Rotate_90)
new_rotation = RR_Rotate_90;
break;
}
2020-09-14 12:53:49 +02:00
XRRSetCrtcConfig(dpy, screen, screen->crtcs[j], CurrentTime,
0, 0, None, RR_Rotate_0, NULL, 0);
if ((crtc->rotation & RR_Rotate_0 || crtc->rotation & RR_Rotate_180) && (rotation == ORIENTATION_VERTICAL || rotation == ORIENTATION_FLIPPED_ROTATED))
{
unsigned width = crtc->width;
crtc->width = crtc->height;
crtc->height = width;
}
else if ((crtc->rotation & RR_Rotate_90 || crtc->rotation & RR_Rotate_270) && (rotation == ORIENTATION_NORMAL || rotation == ORIENTATION_FLIPPED))
{
unsigned width = crtc->width;
2020-09-14 12:53:49 +02:00
crtc->width = crtc->height;
crtc->height = width;
}
crtc->rotation = new_rotation;
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);
XRRFreeCrtcInfo(crtc);
}
XRRFreeOutputInfo(info);
}
XRRFreeScreenResources(screen);
XUngrabServer(dpy);
XSync(dpy, False);
XRRFreeScreenConfigInfo(config);
XCloseDisplay(dpy);
}
2020-09-20 17:50:06 +02:00
static enum rotation x11_display_server_get_screen_orientation(void *data)
{
int i, j;
2020-05-24 06:54:42 +02:00
XRRScreenConfiguration *config = NULL;
enum rotation rotation = ORIENTATION_NORMAL;
dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
Display *dpy = x11_display_server_open_display(dispserv);
XRRScreenResources *screen = XRRGetScreenResources(dpy, DefaultRootWindow(dpy));
if (!screen)
return ORIENTATION_NORMAL;
config = XRRGetScreenInfo(dpy, DefaultRootWindow(dpy));
for (i = 0; i < screen->noutput; i++)
{
XRROutputInfo *info = XRRGetOutputInfo(dpy, screen, screen->outputs[i]);
if (info->connection != RR_Connected)
{
XRRFreeOutputInfo(info);
continue;
}
for (j = 0; j < info->ncrtc; j++)
{
XRRCrtcInfo *crtc = XRRGetCrtcInfo(dpy, screen, screen->crtcs[j]);
if (crtc->width == 0 || crtc->height == 0)
{
XRRFreeCrtcInfo(crtc);
continue;
}
switch (crtc->rotation)
{
case RR_Rotate_0:
default:
rotation = ORIENTATION_NORMAL;
break;
case RR_Rotate_270:
rotation = ORIENTATION_VERTICAL;
break;
case RR_Rotate_180:
rotation = ORIENTATION_FLIPPED;
break;
case RR_Rotate_90:
rotation = ORIENTATION_FLIPPED_ROTATED;
break;
}
XRRFreeCrtcInfo(crtc);
}
XRRFreeOutputInfo(info);
}
XRRFreeScreenResources(screen);
XRRFreeScreenConfigInfo(config);
x11_display_server_close_display(dispserv, dpy);
return rotation;
}
#endif
2020-08-04 03:15:09 +02:00
static void* x11_display_server_init(void)
{
dispserv_x11_t *dispserv = (dispserv_x11_t*)calloc(1, sizeof(*dispserv));
if (!dispserv)
return NULL;
return dispserv;
}
static void x11_display_server_destroy(void *data)
{
#ifdef HAVE_XRANDR
int m, j, i;
#endif
2020-08-04 03:15:09 +02:00
dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
if (!dispserv)
return;
#ifdef HAVE_XRANDR
if (dispserv->crt_en)
2020-08-04 03:15:09 +02:00
{
2020-09-14 12:53:49 +02:00
XRRModeInfo *swoldmode = NULL;
XRRModeInfo *swdeskmode = NULL;
XRRScreenResources
*resources = NULL;
XRRScreenResources *res = NULL;
2020-09-14 12:53:49 +02:00
Display *dpy = XOpenDisplay(0);
int screen = DefaultScreen(dpy);
Window window = RootWindow(dpy, screen);
bool crt_exists = false;
2020-09-14 12:53:49 +02:00
char dmode[25] = {0};
strlcpy(dmode, "d_mo", sizeof(dmode));
dispserv->crt_rrmode.name = dmode;
dispserv->crt_rrmode.nameLength = strlen(dispserv->crt_name);
dispserv->crt_rrmode.dotClock = 13849698;
dispserv->crt_rrmode.width = 700;
dispserv->crt_rrmode.hSyncStart = 742;
dispserv->crt_rrmode.hSyncEnd = 801;
dispserv->crt_rrmode.hTotal = 867;
dispserv->crt_rrmode.height = 480;
dispserv->crt_rrmode.vSyncStart = 490;
dispserv->crt_rrmode.vSyncEnd = 496;
dispserv->crt_rrmode.vTotal = 533;
dispserv->crt_rrmode.modeFlags = 26;
/* 10 for -hsync -vsync. ?? for -hsync -vsync interlaced */
dispserv->crt_rrmode.hSkew = 0;
2020-09-14 12:53:49 +02:00
res = XRRGetScreenResources(dpy, window);
resources = XRRGetScreenResourcesCurrent(dpy, window);
XSync(dpy, False);
resources = XRRGetScreenResourcesCurrent(dpy, window);
2020-09-14 12:53:49 +02:00
for (m = 0; m < resources->nmode; m++)
{
2020-09-14 12:53:49 +02:00
if (string_is_equal(resources->modes[m].name, dmode))
{
crt_exists = true;
break;
}
}
XRRFreeScreenResources(resources);
2020-09-14 12:53:49 +02:00
if (!crt_exists)
XRRCreateMode(dpy, window, &dispserv->crt_rrmode);
resources = XRRGetScreenResourcesCurrent(dpy, window);
2020-09-14 12:53:49 +02:00
for (m = 0; m < resources->nmode; m++)
{
2020-09-14 12:53:49 +02:00
if (string_is_equal(resources->modes[m].name, dmode))
{
swdeskmode = &resources->modes[m];
break;
}
}
if (dispserv->monitor_index == 20)
{
2020-09-14 12:53:49 +02:00
for (i = 0; i < res->noutput; i++)
{
2020-09-14 12:53:49 +02:00
XRROutputInfo *outputs =
XRRGetOutputInfo(dpy, res, res->outputs[i]);
if (outputs->connection == RR_Connected)
{
2020-09-14 12:53:49 +02:00
XRRCrtcInfo *crtc;
XRRAddOutputMode(dpy, res->outputs[i], swdeskmode->id);
XSync(dpy, False);
strlcpy(dispserv->orig_output, outputs->name,
sizeof(dispserv->orig_output));
2020-09-14 12:53:49 +02:00
crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
crtc->mode = swdeskmode->id;
crtc->width = swdeskmode->width;
crtc->height = swdeskmode->height;
2020-09-14 12:53:49 +02:00
XRRSetCrtcConfig(dpy, res,res->crtcs[i],
CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0);
XSync(dpy, False);
XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime,
crtc->x, crtc->y, crtc->mode, crtc->rotation,
crtc->outputs, crtc->noutput);
XSync(dpy, False);
XRRFreeCrtcInfo(crtc);
}
2020-09-14 12:53:49 +02:00
XRRFreeOutputInfo(outputs);
}
for (m = 0; m < resources->nmode; m++)
{
for (j = 0; j < res->noutput; j++)
{
for (i = 1 ; i <= dispserv->crt_name_id; i++ )
{
XRROutputInfo *outputs = XRRGetOutputInfo(dpy, res, res->outputs[j]);
if (outputs->connection == RR_Connected)
{
snprintf(dispserv->old_mode, sizeof(dispserv->old_mode),
"CRT%d", i);
if (string_is_equal(resources->modes[m].name,
dispserv->old_mode))
{
swoldmode = &resources->modes[m];
XRRDeleteOutputMode(dpy, res->outputs[j], swoldmode->id);
XRRDestroyMode(dpy, swoldmode->id);
XSync(dpy, False);
}
}
}
}
}
}
2020-09-20 03:06:23 +02:00
else
{
2020-09-14 12:53:49 +02:00
XRROutputInfo *outputs = XRRGetOutputInfo(dpy, res,
res->outputs[dispserv->monitor_index]);
if (outputs->connection == RR_Connected)
{
2020-09-14 13:25:18 +02:00
XRRCrtcInfo *crtc = NULL;
2020-09-14 12:53:49 +02:00
XRRAddOutputMode(dpy,
res->outputs[dispserv->monitor_index], swdeskmode->id);
XSync(dpy, False);
strlcpy(dispserv->orig_output, outputs->name,
sizeof(dispserv->orig_output));
2020-09-14 13:25:18 +02:00
crtc = XRRGetCrtcInfo(dpy, resources, outputs->crtc);
crtc->mode = swdeskmode->id;
crtc->width = swdeskmode->width;
crtc->height = swdeskmode->height;
2020-09-14 12:53:49 +02:00
XRRSetCrtcConfig(dpy, res,
res->crtcs[dispserv->monitor_index],
2020-09-14 12:53:49 +02:00
CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0);
XSync(dpy, False);
2020-09-14 12:53:49 +02:00
XRRSetCrtcConfig(dpy, res,
res->crtcs[dispserv->monitor_index],
2020-09-14 12:53:49 +02:00
CurrentTime, crtc->x, crtc->y,
crtc->mode, crtc->rotation,
crtc->outputs, crtc->noutput);
XSync(dpy, False);
2020-09-14 12:53:49 +02:00
XRRFreeCrtcInfo(crtc);
}
2020-09-14 12:53:49 +02:00
XRRFreeOutputInfo(outputs);
for (m = 0; m < resources->nmode; m++)
{
for (i = 1 ; i <= dispserv->crt_name_id; i++ )
{
XRROutputInfo *outputs = XRRGetOutputInfo(dpy, res, res->outputs[dispserv->monitor_index]);
if (outputs->connection == RR_Connected)
{
snprintf(dispserv->old_mode, sizeof(dispserv->old_mode),
"CRT%d", i);
if (string_is_equal(resources->modes[m].name,
dispserv->old_mode))
{
swoldmode = &resources->modes[m];
XRRDeleteOutputMode(dpy, res->outputs[dispserv->monitor_index], swoldmode->id);
XRRDestroyMode(dpy, swoldmode->id);
XSync(dpy, False);
}
}
}
}
}
2020-09-11 16:30:43 +01:00
XRRFreeScreenResources(resources);
XRRFreeScreenResources(res);
2020-09-11 16:30:43 +01:00
XCloseDisplay(dpy);
2020-08-04 03:15:09 +02:00
}
2020-08-04 03:15:09 +02:00
#endif
if (dispserv)
free(dispserv);
}
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);
2020-08-04 03:15:09 +02:00
Atom cardinal = XInternAtom(g_x11_dpy, "CARDINAL", False);
serv->opacity = opacity;
opacity = opacity * ((unsigned)-1 / 100.0);
if (opacity == (unsigned)-1)
XDeleteProperty(g_x11_dpy, g_x11_win, net_wm_opacity);
else
XChangeProperty(g_x11_dpy, g_x11_win, net_wm_opacity, cardinal,
32, PropModeReplace, (const unsigned char*)&opacity, 1);
return true;
}
static bool x11_display_server_set_window_decorations(void *data, bool on)
{
dispserv_x11_t *serv = (dispserv_x11_t*)data;
if (serv)
serv->decorations = on;
/* menu_setting performs a reinit instead to properly apply
* decoration changes */
return true;
}
const char *x11_display_server_get_output_options(void *data)
{
#ifdef HAVE_XRANDR
2022-08-08 22:41:32 +02:00
int i;
2020-08-04 03:15:09 +02:00
Display *dpy;
XRRScreenResources *res;
XRROutputInfo *info;
Window root;
2020-08-04 03:15:09 +02:00
static char s[PATH_MAX_LENGTH];
if (!(dpy = XOpenDisplay(0)))
return NULL;
root = RootWindow(dpy, DefaultScreen(dpy));
if (!(res = XRRGetScreenResources(dpy, root)))
return NULL;
for (i = 0; i < res->noutput; i++)
{
2022-08-08 22:41:32 +02:00
size_t _len;
2020-08-04 03:15:09 +02:00
if (!(info = XRRGetOutputInfo(dpy, res, res->outputs[i])))
return NULL;
2022-08-08 22:41:32 +02:00
_len = strlcat(s, info->name, sizeof(s));
2020-08-04 03:15:09 +02:00
if ((i+1) < res->noutput)
2022-08-08 22:41:32 +02:00
{
s[_len ] = '|';
s[_len+1] = '\0';
}
2020-08-04 03:15:09 +02:00
}
return s;
#else
/* TODO/FIXME - hardcoded for now; list should be built up dynamically later */
return "HDMI-0|HDMI-1|HDMI-2|HDMI-3|DVI-0|DVI-1|DVI-2|DVI-3|VGA-0|VGA-1|VGA-2|VGA-3|Config";
#endif
}
static uint32_t x11_display_server_get_flags(void *data)
{
uint32_t flags = 0;
#ifdef HAVE_XRANDR
BIT32_SET(flags, DISPSERV_CTX_CRT_SWITCHRES);
#endif
return flags;
}
2018-05-25 10:56:22 +01:00
const video_display_server_t dispserv_x11 = {
x11_display_server_init,
x11_display_server_destroy,
2018-09-17 03:40:17 +02:00
x11_display_server_set_window_opacity,
2018-11-24 02:47:22 +01:00
NULL, /* set_window_progress */
2018-09-17 03:40:17 +02:00
x11_display_server_set_window_decorations,
#ifdef HAVE_XRANDR
2018-09-17 03:40:17 +02:00
x11_display_server_set_resolution,
#else
NULL, /* set_resolution */
#endif
2018-11-24 02:47:22 +01:00
NULL, /* get_resolution_list */
2018-09-17 03:40:17 +02:00
x11_display_server_get_output_options,
#ifdef HAVE_XRANDR
x11_display_server_set_screen_orientation,
x11_display_server_get_screen_orientation,
#else
NULL, /* set_screen_orientation */
NULL, /* get_screen_orientation */
#endif
x11_display_server_get_flags,
2018-05-25 10:56:22 +01:00
"x11"
};