Split up xinerama functions into separate files

This commit is contained in:
twinaphex 2017-03-23 19:59:11 +01:00
parent 09e7186a4e
commit 1ce3b12335
8 changed files with 182 additions and 113 deletions

View File

@ -670,6 +670,7 @@ ifeq ($(HAVE_X11), 1)
OBJ += input/common/input_x11_common.o \
input/drivers/x11_input.o \
gfx/common/x11_common.o \
gfx/common/xinerama_common.o \
input/drivers_keyboard/keyboard_event_x11.o
LIBS += $(X11_LIBS) $(XEXT_LIBS) $(XF86VM_LIBS) $(XINERAMA_LIBS)

View File

@ -395,105 +395,6 @@ void x11_exit_fullscreen(Display *dpy, XF86VidModeModeInfo *desktop_mode)
XF86VidModeSetViewPort(dpy, DefaultScreen(dpy), 0, 0);
}
#ifdef HAVE_XINERAMA
static XineramaScreenInfo *xinerama_query_screens(Display *dpy, int *num_screens)
{
int major, minor;
if (!XineramaQueryExtension(dpy, &major, &minor))
return NULL;
XineramaQueryVersion(dpy, &major, &minor);
RARCH_LOG("[X11]: Xinerama version: %d.%d.\n", major, minor);
if (!XineramaIsActive(dpy))
return NULL;
return XineramaQueryScreens(dpy, num_screens);
}
bool xinerama_get_coord(Display *dpy, int screen,
int *x, int *y, unsigned *w, unsigned *h)
{
int i, num_screens = 0;
bool ret = false;
XineramaScreenInfo *info = xinerama_query_screens(dpy, &num_screens);
RARCH_LOG("[X11]: Xinerama screens: %d.\n", num_screens);
for (i = 0; i < num_screens; i++)
{
if (info[i].screen_number != screen)
continue;
*x = info[i].x_org;
*y = info[i].y_org;
*w = info[i].width;
*h = info[i].height;
ret = true;
break;
}
XFree(info);
return ret;
}
unsigned xinerama_get_monitor(Display *dpy, int x, int y,
int w, int h)
{
int i, num_screens = 0;
unsigned monitor = 0;
int largest_area = 0;
XineramaScreenInfo *info = xinerama_query_screens(dpy, &num_screens);
RARCH_LOG("[X11]: Xinerama screens: %d.\n", num_screens);
for (i = 0; i < num_screens; i++)
{
int area;
int max_lx = MAX(x, info[i].x_org);
int min_rx = MIN(x + w, info[i].x_org + info[i].width);
int max_ty = MAX(y, info[i].y_org);
int min_by = MIN(y + h, info[i].y_org + info[i].height);
int len_x = min_rx - max_lx;
int len_y = min_by - max_ty;
/* The whole window is outside the screen. */
if (len_x < 0 || len_y < 0)
continue;
area = len_x * len_y;
if (area > largest_area)
{
monitor = i;
largest_area = area;
}
}
XFree(info);
return monitor;
}
void xinerama_save_last_used_monitor(Window win)
{
XWindowAttributes target;
Window child;
int x = 0, y = 0;
XGetWindowAttributes(g_x11_dpy, g_x11_win, &target);
XTranslateCoordinates(g_x11_dpy, g_x11_win,
DefaultRootWindow(g_x11_dpy),
target.x, target.y, &x, &y, &child);
g_x11_screen = xinerama_get_monitor(g_x11_dpy, x, y,
target.width, target.height);
RARCH_LOG("[X11]: Saved monitor #%u.\n", g_x11_screen);
}
#endif
bool x11_create_input_context(Display *dpy, Window win, XIM *xim, XIC *xic)
{
x11_destroy_input_context(xim, xic);

View File

@ -27,10 +27,6 @@
#include <X11/Xutil.h>
#include <X11/extensions/xf86vmode.h>
#ifdef HAVE_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#include <boolean.h>
#include "../video_driver.h"
@ -55,16 +51,6 @@ void x11_move_window(Display *dpy, Window win,
/* Set icon, class, default stuff. */
void x11_set_window_attr(Display *dpy, Window win);
#ifdef HAVE_XINERAMA
void xinerama_save_last_used_monitor(Window win);
bool xinerama_get_coord(Display *dpy, int screen,
int *x, int *y, unsigned *w, unsigned *h);
unsigned xinerama_get_monitor(Display *dpy,
int x, int y, int w, int h);
#endif
bool x11_create_input_context(Display *dpy, Window win, XIM *xim, XIC *xic);
void x11_destroy_input_context(XIM *xim, XIC *xic);
void x11_handle_key_event(XEvent *event, XIC ic, bool filter);

View File

@ -0,0 +1,141 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* 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/>.
*/
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include <retro_miscellaneous.h>
#ifdef HAVE_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#include "xinerama_common.h"
#include "../../verbosity.h"
static XineramaScreenInfo *xinerama_query_screens(Display *dpy, int *num_screens)
{
#ifdef HAVE_XINERAMA
int major, minor;
if (!XineramaQueryExtension(dpy, &major, &minor))
return NULL;
XineramaQueryVersion(dpy, &major, &minor);
RARCH_LOG("[X11]: Xinerama version: %d.%d.\n", major, minor);
if (XineramaIsActive(dpy))
return XineramaQueryScreens(dpy, num_screens);
#endif
return NULL;
}
bool xinerama_get_coord(Display *dpy, int screen,
int *x, int *y, unsigned *w, unsigned *h)
{
#ifdef HAVE_XINERAMA
int i, num_screens = 0;
XineramaScreenInfo *info = xinerama_query_screens(dpy, &num_screens);
RARCH_LOG("[X11]: Xinerama screens: %d.\n", num_screens);
for (i = 0; i < num_screens; i++)
{
if (info[i].screen_number != screen)
continue;
*x = info[i].x_org;
*y = info[i].y_org;
*w = info[i].width;
*h = info[i].height;
XFree(info);
return true;
}
XFree(info);
#endif
return false;
}
unsigned xinerama_get_monitor(Display *dpy, int x, int y,
int w, int h)
{
#ifdef HAVE_XINERAMA
int i, num_screens = 0;
unsigned monitor = 0;
int largest_area = 0;
XineramaScreenInfo *info = xinerama_query_screens(dpy, &num_screens);
RARCH_LOG("[X11]: Xinerama screens: %d.\n", num_screens);
for (i = 0; i < num_screens; i++)
{
int area;
int max_lx = MAX(x, info[i].x_org);
int min_rx = MIN(x + w, info[i].x_org + info[i].width);
int max_ty = MAX(y, info[i].y_org);
int min_by = MIN(y + h, info[i].y_org + info[i].height);
int len_x = min_rx - max_lx;
int len_y = min_by - max_ty;
/* The whole window is outside the screen. */
if (len_x < 0 || len_y < 0)
continue;
area = len_x * len_y;
if (area > largest_area)
{
monitor = i;
largest_area = area;
}
}
XFree(info);
if (monitor > 0)
return monitor;
#endif
return 0;
}
void xinerama_save_last_used_monitor(Window win)
{
#ifdef HAVE_XINERAMA
XWindowAttributes target;
Window child;
int x = 0, y = 0;
XGetWindowAttributes(g_x11_dpy, g_x11_win, &target);
XTranslateCoordinates(g_x11_dpy, g_x11_win,
DefaultRootWindow(g_x11_dpy),
target.x, target.y, &x, &y, &child);
g_x11_screen = xinerama_get_monitor(g_x11_dpy, x, y,
target.width, target.height);
RARCH_LOG("[X11]: Saved monitor #%u.\n", g_x11_screen);
#endif
}

View File

@ -0,0 +1,37 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* 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/>.
*/
#ifndef XINERAMA_COMMON_H__
#define XINERAMA_COMMON_H__
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include <boolean.h>
#include "x11_common.h"
void xinerama_save_last_used_monitor(Window win);
bool xinerama_get_coord(Display *dpy, int screen,
int *x, int *y, unsigned *w, unsigned *h);
unsigned xinerama_get_monitor(Display *dpy,
int x, int y, int w, int h);
#endif

View File

@ -39,6 +39,7 @@
#include "../../frontend/frontend_driver.h"
#include "../common/gl_common.h"
#include "../common/x11_common.h"
#include "../common/xinerama_common.h"
#ifdef HAVE_VULKAN
#include "../common/vulkan_common.h"

View File

@ -28,6 +28,7 @@
#include "../common/egl_common.h"
#include "../common/gl_common.h"
#include "../common/x11_common.h"
#include "../common/xinerama_common.h"
#ifndef EGL_OPENGL_ES3_BIT_KHR
#define EGL_OPENGL_ES3_BIT_KHR 0x0040

View File

@ -209,6 +209,7 @@ VIDEO CONTEXT
#if defined(HAVE_X11)
#include "../gfx/common/x11_common.c"
#include "../gfx/common/xinerama_common.c"
#ifndef HAVE_OPENGLES
#include "../gfx/drivers_context/x_ctx.c"