mirror of
https://github.com/libretro/RetroArch
synced 2025-02-22 03:40:43 +00:00
Split up dbus functions into separate file
This commit is contained in:
parent
22672af217
commit
62aa0c4415
@ -669,6 +669,7 @@ endif
|
|||||||
ifeq ($(HAVE_X11), 1)
|
ifeq ($(HAVE_X11), 1)
|
||||||
OBJ += input/common/input_x11_common.o \
|
OBJ += input/common/input_x11_common.o \
|
||||||
input/drivers/x11_input.o \
|
input/drivers/x11_input.o \
|
||||||
|
gfx/common/dbus_common.o \
|
||||||
gfx/common/x11_common.o \
|
gfx/common/x11_common.o \
|
||||||
gfx/common/xinerama_common.o \
|
gfx/common/xinerama_common.o \
|
||||||
input/drivers_keyboard/keyboard_event_x11.o
|
input/drivers_keyboard/keyboard_event_x11.o
|
||||||
|
163
gfx/common/dbus_common.c
Normal file
163
gfx/common/dbus_common.c
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
/* RetroArch - A frontend for libretro.
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "../../config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_DBUS
|
||||||
|
#include <dbus/dbus.h>
|
||||||
|
static DBusConnection* dbus_connection = NULL;
|
||||||
|
static unsigned int dbus_screensaver_cookie = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../../verbosity.h"
|
||||||
|
|
||||||
|
void dbus_ensure_connection(void)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_DBUS
|
||||||
|
DBusError err;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
dbus_error_init(&err);
|
||||||
|
|
||||||
|
dbus_connection = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
|
||||||
|
|
||||||
|
if (dbus_error_is_set(&err))
|
||||||
|
{
|
||||||
|
RARCH_LOG("[DBus]: Failed to get DBus connection. Screensaver will not be suspended via DBus.\n");
|
||||||
|
dbus_error_free(&err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dbus_connection)
|
||||||
|
dbus_connection_set_exit_on_disconnect(dbus_connection, true);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbus_close_connection(void)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_DBUS
|
||||||
|
if (!dbus_connection)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dbus_connection_close(dbus_connection);
|
||||||
|
dbus_connection_unref(dbus_connection);
|
||||||
|
dbus_connection = NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dbus_screensaver_inhibit(void)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
#ifdef HAVE_DBUS
|
||||||
|
const char *app = "RetroArch";
|
||||||
|
const char *reason = "Playing a game";
|
||||||
|
DBusMessage *msg = NULL;
|
||||||
|
DBusMessage *reply = NULL;
|
||||||
|
|
||||||
|
if (!dbus_connection)
|
||||||
|
return false; /* DBus connection was not obtained */
|
||||||
|
|
||||||
|
if (dbus_screensaver_cookie > 0)
|
||||||
|
return true; /* Already inhibited */
|
||||||
|
|
||||||
|
msg = dbus_message_new_method_call("org.freedesktop.ScreenSaver",
|
||||||
|
"/org/freedesktop/ScreenSaver",
|
||||||
|
"org.freedesktop.ScreenSaver",
|
||||||
|
"Inhibit");
|
||||||
|
|
||||||
|
if (!msg)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!dbus_message_append_args(msg,
|
||||||
|
DBUS_TYPE_STRING, &app,
|
||||||
|
DBUS_TYPE_STRING, &reason,
|
||||||
|
DBUS_TYPE_INVALID))
|
||||||
|
{
|
||||||
|
dbus_message_unref(msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
reply = dbus_connection_send_with_reply_and_block(dbus_connection,
|
||||||
|
msg, 300, NULL);
|
||||||
|
|
||||||
|
if (reply != NULL)
|
||||||
|
{
|
||||||
|
if (!dbus_message_get_args(reply, NULL,
|
||||||
|
DBUS_TYPE_UINT32, &dbus_screensaver_cookie,
|
||||||
|
DBUS_TYPE_INVALID))
|
||||||
|
dbus_screensaver_cookie = 0;
|
||||||
|
else
|
||||||
|
ret = true;
|
||||||
|
|
||||||
|
dbus_message_unref(reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbus_message_unref(msg);
|
||||||
|
|
||||||
|
if (dbus_screensaver_cookie == 0)
|
||||||
|
{
|
||||||
|
RARCH_ERR("[DBus]: Failed to suspend screensaver via DBus.\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RARCH_LOG("[DBus]: Suspended screensaver via DBus.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbus_screensaver_uninhibit(void)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_DBUS
|
||||||
|
DBusMessage *msg = NULL;
|
||||||
|
|
||||||
|
if (!dbus_connection)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (dbus_screensaver_cookie == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
msg = dbus_message_new_method_call("org.freedesktop.ScreenSaver",
|
||||||
|
"/org/freedesktop/ScreenSaver",
|
||||||
|
"org.freedesktop.ScreenSaver",
|
||||||
|
"UnInhibit");
|
||||||
|
if (!msg)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dbus_message_append_args(msg,
|
||||||
|
DBUS_TYPE_UINT32, &dbus_screensaver_cookie,
|
||||||
|
DBUS_TYPE_INVALID);
|
||||||
|
|
||||||
|
if (dbus_connection_send(dbus_connection, msg, NULL))
|
||||||
|
dbus_connection_flush(dbus_connection);
|
||||||
|
dbus_message_unref(msg);
|
||||||
|
|
||||||
|
dbus_screensaver_cookie = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns false when fallback should be attempted */
|
||||||
|
bool dbus_suspend_screensaver(bool enable)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_DBUS
|
||||||
|
if (enable)
|
||||||
|
return dbus_screensaver_inhibit();
|
||||||
|
dbus_screensaver_uninhibit();
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
31
gfx/common/dbus_common.h
Normal file
31
gfx/common/dbus_common.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* RetroArch - A frontend for libretro.
|
||||||
|
* 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 DBUS_COMMON_H__
|
||||||
|
#define DBUS_COMMON_H__
|
||||||
|
|
||||||
|
#include <boolean.h>
|
||||||
|
|
||||||
|
void dbus_ensure_connection(void);
|
||||||
|
|
||||||
|
void dbus_close_connection(void);
|
||||||
|
|
||||||
|
bool dbus_screensaver_inhibit(void);
|
||||||
|
|
||||||
|
void dbus_screensaver_uninhibit(void);
|
||||||
|
|
||||||
|
bool dbus_suspend_screensaver(bool enable);
|
||||||
|
|
||||||
|
#endif
|
@ -40,11 +40,6 @@
|
|||||||
#define MOVERESIZE_X_SHIFT 8
|
#define MOVERESIZE_X_SHIFT 8
|
||||||
#define MOVERESIZE_Y_SHIFT 9
|
#define MOVERESIZE_Y_SHIFT 9
|
||||||
|
|
||||||
#ifdef HAVE_DBUS
|
|
||||||
#include <dbus/dbus.h>
|
|
||||||
static DBusConnection* dbus_connection = NULL;
|
|
||||||
static unsigned int dbus_screensaver_cookie = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static XF86VidModeModeInfo desktop_mode;
|
static XF86VidModeModeInfo desktop_mode;
|
||||||
static bool xdg_screensaver_available = true;
|
static bool xdg_screensaver_available = true;
|
||||||
@ -66,133 +61,6 @@ static Atom g_x11_quit_atom;
|
|||||||
static XIM g_x11_xim;
|
static XIM g_x11_xim;
|
||||||
static XIC g_x11_xic;
|
static XIC g_x11_xic;
|
||||||
|
|
||||||
#ifdef HAVE_DBUS
|
|
||||||
static void dbus_ensure_connection(void)
|
|
||||||
{
|
|
||||||
DBusError err;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
dbus_error_init(&err);
|
|
||||||
|
|
||||||
dbus_connection = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
|
|
||||||
|
|
||||||
if (dbus_error_is_set(&err))
|
|
||||||
{
|
|
||||||
RARCH_LOG("[DBus]: Failed to get DBus connection. Screensaver will not be suspended via DBus.\n");
|
|
||||||
dbus_error_free(&err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dbus_connection)
|
|
||||||
dbus_connection_set_exit_on_disconnect(dbus_connection, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dbus_close_connection(void)
|
|
||||||
{
|
|
||||||
if (!dbus_connection)
|
|
||||||
return;
|
|
||||||
|
|
||||||
dbus_connection_close(dbus_connection);
|
|
||||||
dbus_connection_unref(dbus_connection);
|
|
||||||
dbus_connection = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool dbus_screensaver_inhibit(void)
|
|
||||||
{
|
|
||||||
const char *app = "RetroArch";
|
|
||||||
const char *reason = "Playing a game";
|
|
||||||
DBusMessage *msg = NULL;
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
if (!dbus_connection)
|
|
||||||
return false; /* DBus connection was not obtained */
|
|
||||||
|
|
||||||
if (dbus_screensaver_cookie > 0)
|
|
||||||
return true; /* Already inhibited */
|
|
||||||
|
|
||||||
msg = dbus_message_new_method_call("org.freedesktop.ScreenSaver",
|
|
||||||
"/org/freedesktop/ScreenSaver",
|
|
||||||
"org.freedesktop.ScreenSaver",
|
|
||||||
"Inhibit");
|
|
||||||
|
|
||||||
if (!msg)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!dbus_message_append_args(msg,
|
|
||||||
DBUS_TYPE_STRING, &app,
|
|
||||||
DBUS_TYPE_STRING, &reason,
|
|
||||||
DBUS_TYPE_INVALID))
|
|
||||||
{
|
|
||||||
dbus_message_unref(msg);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
reply = dbus_connection_send_with_reply_and_block(dbus_connection,
|
|
||||||
msg, 300, NULL);
|
|
||||||
|
|
||||||
if (reply != NULL)
|
|
||||||
{
|
|
||||||
if (!dbus_message_get_args(reply, NULL,
|
|
||||||
DBUS_TYPE_UINT32, &dbus_screensaver_cookie,
|
|
||||||
DBUS_TYPE_INVALID))
|
|
||||||
dbus_screensaver_cookie = 0;
|
|
||||||
else
|
|
||||||
ret = true;
|
|
||||||
|
|
||||||
dbus_message_unref(reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_unref(msg);
|
|
||||||
|
|
||||||
if (dbus_screensaver_cookie == 0)
|
|
||||||
{
|
|
||||||
RARCH_ERR("[DBus]: Failed to suspend screensaver via DBus.\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RARCH_LOG("[DBus]: Suspended screensaver via DBus.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dbus_screensaver_uninhibit(void)
|
|
||||||
{
|
|
||||||
DBusMessage *msg = NULL;
|
|
||||||
|
|
||||||
if (!dbus_connection)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (dbus_screensaver_cookie == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
msg = dbus_message_new_method_call("org.freedesktop.ScreenSaver",
|
|
||||||
"/org/freedesktop/ScreenSaver",
|
|
||||||
"org.freedesktop.ScreenSaver",
|
|
||||||
"UnInhibit");
|
|
||||||
if (!msg)
|
|
||||||
return;
|
|
||||||
|
|
||||||
dbus_message_append_args(msg,
|
|
||||||
DBUS_TYPE_UINT32, &dbus_screensaver_cookie,
|
|
||||||
DBUS_TYPE_INVALID);
|
|
||||||
|
|
||||||
if (dbus_connection_send(dbus_connection, msg, NULL))
|
|
||||||
dbus_connection_flush(dbus_connection);
|
|
||||||
dbus_message_unref(msg);
|
|
||||||
|
|
||||||
dbus_screensaver_cookie = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns false when fallback should be attempted */
|
|
||||||
bool x11_suspend_screensaver_dbus(bool enable)
|
|
||||||
{
|
|
||||||
if (enable) return dbus_screensaver_inhibit();
|
|
||||||
dbus_screensaver_uninhibit();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void x11_hide_mouse(Display *dpy, Window win)
|
static void x11_hide_mouse(Display *dpy, Window win)
|
||||||
{
|
{
|
||||||
static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
@ -319,7 +187,7 @@ void x11_suspend_screensaver_xdg_screensaver(Window wnd, bool enable)
|
|||||||
void x11_suspend_screensaver(Window wnd, bool enable)
|
void x11_suspend_screensaver(Window wnd, bool enable)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
if (x11_suspend_screensaver_dbus(enable))
|
if (dbus_suspend_screensaver(enable))
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
x11_suspend_screensaver_xdg_screensaver(wnd, enable);
|
x11_suspend_screensaver_xdg_screensaver(wnd, enable);
|
||||||
@ -628,10 +496,7 @@ bool x11_connect(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DBUS
|
|
||||||
dbus_ensure_connection();
|
dbus_ensure_connection();
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,6 @@
|
|||||||
#ifndef X11_COMMON_H__
|
#ifndef X11_COMMON_H__
|
||||||
#define X11_COMMON_H__
|
#define X11_COMMON_H__
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include "../../config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
@ -209,6 +209,7 @@ VIDEO CONTEXT
|
|||||||
|
|
||||||
#if defined(HAVE_X11)
|
#if defined(HAVE_X11)
|
||||||
#include "../gfx/common/x11_common.c"
|
#include "../gfx/common/x11_common.c"
|
||||||
|
#include "../gfx/common/dbus_common.c"
|
||||||
#include "../gfx/common/xinerama_common.c"
|
#include "../gfx/common/xinerama_common.c"
|
||||||
|
|
||||||
#ifndef HAVE_OPENGLES
|
#ifndef HAVE_OPENGLES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user