(dispserv_x11) Cleanups

This commit is contained in:
twinaphex 2020-08-04 03:15:09 +02:00
parent 379cc9ca4a
commit c68cd7851a

View File

@ -76,9 +76,7 @@ static Display* x11_display_server_open_display(void)
return dpy;
}
#endif
#ifdef HAVE_XRANDR
static void x11_display_server_close_display(Display *dpy)
{
if (!dpy || x11_display_server_using_global_dpy || dpy == g_x11_dpy)
@ -86,84 +84,7 @@ static void x11_display_server_close_display(Display *dpy)
XCloseDisplay(dpy);
}
#endif
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)
{
dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
#ifdef HAVE_XRANDR
if (crt_en)
{
snprintf(xrandr, sizeof(xrandr),
"xrandr --newmode 700x480_59.94 13.849698 700 742 801 867 480 490 496 533 interlace -hsync -vsync");
system(xrandr);
snprintf(xrandr, sizeof(xrandr),
"xrandr --addmode \"%s\" 700x480_59.94",
orig_output);
system(xrandr);
snprintf(xrandr, sizeof(xrandr),
"xrandr --output \"%s\" --mode 700x480_59.94",
orig_output);
system(xrandr);
snprintf(xrandr, sizeof(xrandr),
"xrandr --delmode \"%s\" \"%s\"",
orig_output, old_mode);
system(xrandr);
snprintf(xrandr, sizeof(xrandr),
"xrandr --rmmode \"%s\"",
old_mode);
system(xrandr);
}
#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);
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;
}
#ifdef HAVE_XRANDR
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)
{
@ -350,44 +271,7 @@ static bool x11_display_server_set_resolution(void *data,
}
return true;
}
#endif
const char *x11_display_server_get_output_options(void *data)
{
#ifdef HAVE_XRANDR
Display *dpy;
XRRScreenResources *res;
XRROutputInfo *info;
Window root;
int i;
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++)
{
if (!(info = XRRGetOutputInfo(dpy, res, res->outputs[i])))
return NULL;
strlcat(s, info->name, sizeof(s));
if ((i+1) < res->noutput)
strlcat(s, "|", sizeof(s));
}
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
}
#ifdef HAVE_XRANDR
static void x11_display_server_set_screen_orientation(enum rotation rotation)
{
int i, j;
@ -541,6 +425,117 @@ static enum rotation x11_display_server_get_screen_orientation(void)
}
#endif
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)
{
dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
#ifdef HAVE_XRANDR
if (crt_en)
{
snprintf(xrandr, sizeof(xrandr),
"xrandr --newmode 700x480_59.94 13.849698 700 742 801 867 480 490 496 533 interlace -hsync -vsync");
system(xrandr);
snprintf(xrandr, sizeof(xrandr),
"xrandr --addmode \"%s\" 700x480_59.94",
orig_output);
system(xrandr);
snprintf(xrandr, sizeof(xrandr),
"xrandr --output \"%s\" --mode 700x480_59.94",
orig_output);
system(xrandr);
snprintf(xrandr, sizeof(xrandr),
"xrandr --delmode \"%s\" \"%s\"",
orig_output, old_mode);
system(xrandr);
snprintf(xrandr, sizeof(xrandr),
"xrandr --rmmode \"%s\"",
old_mode);
system(xrandr);
}
#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);
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
Display *dpy;
XRRScreenResources *res;
XRROutputInfo *info;
Window root;
int i;
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++)
{
if (!(info = XRRGetOutputInfo(dpy, res, res->outputs[i])))
return NULL;
strlcat(s, info->name, sizeof(s));
if ((i+1) < res->noutput)
strlcat(s, "|", sizeof(s));
}
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;