From 1ce3b1233506f2a577397f2eeaf01fe47cb63c60 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 23 Mar 2017 19:59:11 +0100 Subject: [PATCH] Split up xinerama functions into separate files --- Makefile.common | 1 + gfx/common/x11_common.c | 99 ----------------------- gfx/common/x11_common.h | 14 ---- gfx/common/xinerama_common.c | 141 +++++++++++++++++++++++++++++++++ gfx/common/xinerama_common.h | 37 +++++++++ gfx/drivers_context/x_ctx.c | 1 + gfx/drivers_context/xegl_ctx.c | 1 + griffin/griffin.c | 1 + 8 files changed, 182 insertions(+), 113 deletions(-) create mode 100644 gfx/common/xinerama_common.c create mode 100644 gfx/common/xinerama_common.h diff --git a/Makefile.common b/Makefile.common index 6d06ca008a..71a3fd46cd 100644 --- a/Makefile.common +++ b/Makefile.common @@ -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) diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c index a37b92240d..25ff5ebe69 100644 --- a/gfx/common/x11_common.c +++ b/gfx/common/x11_common.c @@ -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); diff --git a/gfx/common/x11_common.h b/gfx/common/x11_common.h index 2d7d6a2da8..cd02554efb 100644 --- a/gfx/common/x11_common.h +++ b/gfx/common/x11_common.h @@ -27,10 +27,6 @@ #include #include -#ifdef HAVE_XINERAMA -#include -#endif - #include #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); diff --git a/gfx/common/xinerama_common.c b/gfx/common/xinerama_common.c new file mode 100644 index 0000000000..331ab7cf84 --- /dev/null +++ b/gfx/common/xinerama_common.c @@ -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 . + */ + +#include +#include + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + +#include + +#ifdef HAVE_XINERAMA +#include +#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 +} diff --git a/gfx/common/xinerama_common.h b/gfx/common/xinerama_common.h new file mode 100644 index 0000000000..bed750930a --- /dev/null +++ b/gfx/common/xinerama_common.h @@ -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 . + */ + +#ifndef XINERAMA_COMMON_H__ +#define XINERAMA_COMMON_H__ + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + +#include + +#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 + diff --git a/gfx/drivers_context/x_ctx.c b/gfx/drivers_context/x_ctx.c index 413ef4f2d6..48f34b0d37 100644 --- a/gfx/drivers_context/x_ctx.c +++ b/gfx/drivers_context/x_ctx.c @@ -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" diff --git a/gfx/drivers_context/xegl_ctx.c b/gfx/drivers_context/xegl_ctx.c index 32fe49315c..b07c13bc2d 100644 --- a/gfx/drivers_context/xegl_ctx.c +++ b/gfx/drivers_context/xegl_ctx.c @@ -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 diff --git a/griffin/griffin.c b/griffin/griffin.c index e882bfc4e1..6cdaa868fb 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -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"