mirror of
https://github.com/libretro/RetroArch
synced 2025-02-02 14:54:10 +00:00
Refactor out common X11 code.
This commit is contained in:
parent
df32409fb5
commit
31b12d7d00
7
Makefile
7
Makefile
@ -143,11 +143,6 @@ ifeq ($(HAVE_SDL), 1)
|
||||
DEFINES += $(SDL_CFLAGS) $(BSD_LOCAL_INC)
|
||||
LIBS += $(SDL_LIBS)
|
||||
|
||||
ifeq ($(HAVE_X11), 1)
|
||||
LIBS += $(X11_LIBS)
|
||||
DEFINES += $(X11_CFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_OPENGL), 1)
|
||||
OBJ += gfx/gl.o gfx/gfx_context.o gfx/fonts/freetype.o gfx/math/matrix.o
|
||||
|
||||
@ -202,7 +197,7 @@ ifeq ($(HAVE_XVIDEO), 1)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_X11), 1)
|
||||
OBJ += input/x11_input.o
|
||||
OBJ += input/x11_input.o gfx/context/x11_common.o
|
||||
LIBS += $(X11_LIBS) $(XEXT_LIBS)
|
||||
DEFINES += $(X11_CFLAGS) $(XEXT_CFLAGS)
|
||||
endif
|
||||
|
@ -13,13 +13,14 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Compatibility wrapper between SDL 1.2/1.3 for OpenGL.
|
||||
// Wraps functions which differ in 1.2 and 1.3.
|
||||
|
||||
#include "../gfx_context.h"
|
||||
#include "../gfx_common.h"
|
||||
#include "../../general.h"
|
||||
|
||||
#ifdef HAVE_X11
|
||||
#include "x11_common.h"
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include <OpenGL/gl.h>
|
||||
@ -161,13 +162,13 @@ static bool gfx_ctx_set_video_mode(
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
// Suspend screensaver on X11.
|
||||
#if defined(HAVE_X11) && !defined(__APPLE__)
|
||||
#if defined(HAVE_X11)
|
||||
RARCH_LOG("Suspending screensaver (X11).\n");
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
|
||||
if (SDL_GetWMInfo(&info) == 1)
|
||||
gfx_suspend_screensaver(info.info.x11.window);
|
||||
x11_suspend_screensaver(info.info.x11.window);
|
||||
else
|
||||
RARCH_ERR("Failed to get SDL WM info, cannot suspend screensaver.\n");
|
||||
#endif
|
||||
@ -192,7 +193,7 @@ static void gfx_ctx_swap_buffers(void)
|
||||
}
|
||||
|
||||
// 1.2 specific workaround for tiling WMs.
|
||||
#if defined(HAVE_X11) && !defined(__APPLE__)
|
||||
#if defined(HAVE_X11)
|
||||
// This X11 is set on OSX for some reason.
|
||||
static bool gfx_ctx_get_window_size(unsigned *width, unsigned *height)
|
||||
{
|
||||
@ -238,7 +239,7 @@ static void gfx_ctx_check_window(bool *quit,
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HAVE_X11) && !defined(__APPLE__)
|
||||
#if defined(HAVE_X11)
|
||||
if (!*resize && !g_fullscreen)
|
||||
{
|
||||
unsigned new_width, new_height;
|
||||
|
91
gfx/context/x11_common.c
Normal file
91
gfx/context/x11_common.c
Normal file
@ -0,0 +1,91 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - 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 "x11_common.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../../general.h"
|
||||
|
||||
void x11_hide_mouse(Display *dpy, Window win)
|
||||
{
|
||||
Cursor no_ptr;
|
||||
Pixmap bm_no;
|
||||
XColor black, dummy;
|
||||
Colormap colormap;
|
||||
|
||||
static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
colormap = DefaultColormap(dpy, DefaultScreen(dpy));
|
||||
if (!XAllocNamedColor(dpy, colormap, "black", &black, &dummy))
|
||||
return;
|
||||
|
||||
bm_no = XCreateBitmapFromData(dpy, win, bm_no_data, 8, 8);
|
||||
no_ptr = XCreatePixmapCursor(dpy, bm_no, bm_no, &black, &black, 0, 0);
|
||||
|
||||
XDefineCursor(dpy, win, no_ptr);
|
||||
XFreeCursor(dpy, no_ptr);
|
||||
|
||||
if (bm_no != None)
|
||||
XFreePixmap(dpy, bm_no);
|
||||
|
||||
XFreeColors(dpy, colormap, &black.pixel, 1, 0);
|
||||
}
|
||||
|
||||
static Atom XA_NET_WM_STATE;
|
||||
static Atom XA_NET_WM_STATE_FULLSCREEN;
|
||||
#define XA_INIT(x) XA##x = XInternAtom(dpy, #x, False)
|
||||
#define _NET_WM_STATE_ADD 1
|
||||
void x11_windowed_fullscreen(Display *dpy, Window win)
|
||||
{
|
||||
XA_INIT(_NET_WM_STATE);
|
||||
XA_INIT(_NET_WM_STATE_FULLSCREEN);
|
||||
|
||||
if (!XA_NET_WM_STATE || !XA_NET_WM_STATE_FULLSCREEN)
|
||||
{
|
||||
RARCH_ERR("[X/EGL]: Cannot set windowed fullscreen.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
XEvent xev;
|
||||
|
||||
xev.xclient.type = ClientMessage;
|
||||
xev.xclient.serial = 0;
|
||||
xev.xclient.send_event = True;
|
||||
xev.xclient.message_type = XA_NET_WM_STATE;
|
||||
xev.xclient.window = win;
|
||||
xev.xclient.format = 32;
|
||||
xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
|
||||
xev.xclient.data.l[1] = XA_NET_WM_STATE_FULLSCREEN;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
xev.xclient.data.l[3] = 0;
|
||||
xev.xclient.data.l[4] = 0;
|
||||
|
||||
XSendEvent(dpy, DefaultRootWindow(dpy), False,
|
||||
SubstructureRedirectMask | SubstructureNotifyMask,
|
||||
&xev);
|
||||
}
|
||||
|
||||
void x11_suspend_screensaver(Window wnd)
|
||||
{
|
||||
char cmd[64];
|
||||
snprintf(cmd, sizeof(cmd), "xdg-screensaver suspend %d", (int)wnd);
|
||||
|
||||
int ret = system(cmd);
|
||||
|
||||
if (ret != 0)
|
||||
RARCH_WARN("Could not suspend screen saver.\n");
|
||||
}
|
||||
|
28
gfx/context/x11_common.h
Normal file
28
gfx/context/x11_common.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - 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 X11_COMMON_H__
|
||||
#define X11_COMMON_H__
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
void x11_hide_mouse(Display *dpy, Window win);
|
||||
void x11_windowed_fullscreen(Display *dpy, Window win);
|
||||
void x11_suspend_screensaver(Window win);
|
||||
|
||||
#endif
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "../gfx_context.h"
|
||||
#include "../gl_common.h"
|
||||
#include "../gfx_common.h"
|
||||
#include "x11_common.h"
|
||||
#include "../../input/x11_input.h"
|
||||
|
||||
#include <signal.h>
|
||||
@ -55,65 +56,6 @@ static void sighandler(int sig)
|
||||
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height);
|
||||
static void gfx_ctx_destroy(void);
|
||||
|
||||
static void hide_mouse(void)
|
||||
{
|
||||
Cursor no_ptr;
|
||||
Pixmap bm_no;
|
||||
XColor black, dummy;
|
||||
Colormap colormap;
|
||||
|
||||
static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
colormap = DefaultColormap(g_dpy, DefaultScreen(g_dpy));
|
||||
if (!XAllocNamedColor(g_dpy, colormap, "black", &black, &dummy))
|
||||
return;
|
||||
|
||||
bm_no = XCreateBitmapFromData(g_dpy, g_win, bm_no_data, 8, 8);
|
||||
no_ptr = XCreatePixmapCursor(g_dpy, bm_no, bm_no, &black, &black, 0, 0);
|
||||
|
||||
XDefineCursor(g_dpy, g_win, no_ptr);
|
||||
XFreeCursor(g_dpy, no_ptr);
|
||||
|
||||
if (bm_no != None)
|
||||
XFreePixmap(g_dpy, bm_no);
|
||||
|
||||
XFreeColors(g_dpy, colormap, &black.pixel, 1, 0);
|
||||
}
|
||||
|
||||
static Atom XA_NET_WM_STATE;
|
||||
static Atom XA_NET_WM_STATE_FULLSCREEN;
|
||||
#define XA_INIT(x) XA##x = XInternAtom(g_dpy, #x, False)
|
||||
#define _NET_WM_STATE_ADD 1
|
||||
static void set_windowed_fullscreen(void)
|
||||
{
|
||||
XA_INIT(_NET_WM_STATE);
|
||||
XA_INIT(_NET_WM_STATE_FULLSCREEN);
|
||||
|
||||
if (!XA_NET_WM_STATE || !XA_NET_WM_STATE_FULLSCREEN)
|
||||
{
|
||||
RARCH_ERR("[X/EGL]: Cannot set windowed fullscreen.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
XEvent xev;
|
||||
|
||||
xev.xclient.type = ClientMessage;
|
||||
xev.xclient.serial = 0;
|
||||
xev.xclient.send_event = True;
|
||||
xev.xclient.message_type = XA_NET_WM_STATE;
|
||||
xev.xclient.window = g_win;
|
||||
xev.xclient.format = 32;
|
||||
xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
|
||||
xev.xclient.data.l[1] = XA_NET_WM_STATE_FULLSCREEN;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
xev.xclient.data.l[3] = 0;
|
||||
xev.xclient.data.l[4] = 0;
|
||||
|
||||
XSendEvent(g_dpy, DefaultRootWindow(g_dpy), False,
|
||||
SubstructureRedirectMask | SubstructureNotifyMask,
|
||||
&xev);
|
||||
}
|
||||
|
||||
static void gfx_ctx_swap_interval(unsigned interval)
|
||||
{
|
||||
g_interval = interval;
|
||||
@ -350,17 +292,17 @@ static bool gfx_ctx_set_video_mode(
|
||||
goto error;
|
||||
|
||||
gfx_ctx_update_window_title(true);
|
||||
hide_mouse();
|
||||
x11_hide_mouse(g_dpy, g_win);
|
||||
XMapWindow(g_dpy, g_win);
|
||||
|
||||
if (fullscreen)
|
||||
set_windowed_fullscreen();
|
||||
x11_windowed_fullscreen(g_dpy, g_win);
|
||||
|
||||
g_quit_atom = XInternAtom(g_dpy, "WM_DELETE_WINDOW", False);
|
||||
if (g_quit_atom)
|
||||
XSetWMProtocols(g_dpy, g_win, &g_quit_atom, 1);
|
||||
|
||||
gfx_suspend_screensaver(g_win);
|
||||
x11_suspend_screensaver(g_win);
|
||||
gfx_ctx_swap_interval(g_interval);
|
||||
|
||||
XFree(vi);
|
||||
|
@ -120,19 +120,6 @@ bool gfx_window_title(char *buf, size_t size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(HAVE_X11) && !defined(__APPLE__)
|
||||
void gfx_suspend_screensaver(Window wnd)
|
||||
{
|
||||
char cmd[64];
|
||||
snprintf(cmd, sizeof(cmd), "xdg-screensaver suspend %d", (int)wnd);
|
||||
|
||||
int ret = system(cmd);
|
||||
|
||||
if (ret != 0)
|
||||
RARCH_WARN("Could not suspend screen saver.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(_XBOX)
|
||||
#include <windows.h>
|
||||
#include "../dynamic.h"
|
||||
|
@ -26,11 +26,6 @@
|
||||
bool gfx_window_title(char *buf, size_t size);
|
||||
void gfx_window_title_reset(void);
|
||||
|
||||
#if defined(HAVE_X11) && !defined(__APPLE__)
|
||||
#include <X11/Xlib.h>
|
||||
void gfx_suspend_screensaver(Window wnd);
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
void gfx_set_dwm(void);
|
||||
#endif
|
||||
|
@ -23,6 +23,10 @@
|
||||
#include "gfx_common.h"
|
||||
#include "gfx_context.h"
|
||||
|
||||
#ifdef HAVE_X11
|
||||
#include "context/x11_common.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
@ -289,12 +293,12 @@ static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
#if defined(HAVE_X11) && !defined(__APPLE__)
|
||||
#if defined(HAVE_X11)
|
||||
RARCH_LOG("Suspending screensaver (X11).\n");
|
||||
SDL_SysWMinfo wm_info;
|
||||
SDL_VERSION(&wm_info.version);
|
||||
if (SDL_GetWMInfo(&wm_info) == 1)
|
||||
gfx_suspend_screensaver(wm_info.info.x11.window);
|
||||
x11_suspend_screensaver(wm_info.info.x11.window);
|
||||
else
|
||||
RARCH_ERR("Failed to suspend screensaver.\n");
|
||||
#endif
|
||||
|
@ -19,11 +19,14 @@
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <math.h>
|
||||
#include "gfx_common.h"
|
||||
#include "../input/x11_input.h"
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
#include "fonts/fonts.h"
|
||||
#endif
|
||||
#include "gfx_common.h"
|
||||
#include "../input/x11_input.h"
|
||||
|
||||
#include "context/x11_common.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
@ -529,7 +532,7 @@ static void *xv_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
xv->focus = true;
|
||||
|
||||
RARCH_LOG("Suspending screensaver (X11).\n");
|
||||
gfx_suspend_screensaver(xv->window);
|
||||
x11_suspend_screensaver(xv->window);
|
||||
|
||||
xinput = input_x.init();
|
||||
if (xinput)
|
||||
|
@ -9,6 +9,7 @@ add_define_make NOUNUSED "$HAVE_NOUNUSED"
|
||||
[ -d /opt/local/lib ] && add_library_dirs /opt/local/lib
|
||||
|
||||
if [ "$OS" = 'BSD' ]; then DYLIB=-lc; else DYLIB=-ldl; fi
|
||||
[ "$OS" = 'OSX' ] && HAVE_X11=no # X11 breaks on recent OSXes even if present.
|
||||
|
||||
[ -d /opt/vc/lib ] && add_library_dirs /opt/vc/lib
|
||||
check_lib VIDEOCORE -lbcm_host bcm_host_init "-lvcos -lvchiq_arm"
|
||||
|
Loading…
x
Reference in New Issue
Block a user