|
@@ -56,7 +56,9 @@ LoadDBUSSyms(void)
|
|
|
SDL_DBUS_SYM(message_is_signal);
|
|
|
SDL_DBUS_SYM(message_new_method_call);
|
|
|
SDL_DBUS_SYM(message_append_args);
|
|
|
+ SDL_DBUS_SYM(message_append_args_valist);
|
|
|
SDL_DBUS_SYM(message_get_args);
|
|
|
+ SDL_DBUS_SYM(message_get_args_valist);
|
|
|
SDL_DBUS_SYM(message_iter_init);
|
|
|
SDL_DBUS_SYM(message_iter_next);
|
|
|
SDL_DBUS_SYM(message_iter_get_basic);
|
|
@@ -157,91 +159,170 @@ SDL_DBus_GetContext(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void
|
|
|
-SDL_DBus_ScreensaverTickle(void)
|
|
|
+static SDL_bool
|
|
|
+SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
|
|
|
{
|
|
|
- DBusConnection *conn = dbus.session_conn;
|
|
|
- if (conn != NULL) {
|
|
|
- DBusMessage *msg = dbus.message_new_method_call("org.gnome.ScreenSaver",
|
|
|
- "/org/gnome/ScreenSaver",
|
|
|
- "org.gnome.ScreenSaver",
|
|
|
- "SimulateUserActivity");
|
|
|
- if (msg != NULL) {
|
|
|
- if (dbus.connection_send(conn, msg, NULL)) {
|
|
|
- dbus.connection_flush(conn);
|
|
|
+ SDL_bool retval = SDL_FALSE;
|
|
|
+
|
|
|
+ if (conn) {
|
|
|
+ DBusMessage *msg = dbus.message_new_method_call(node, path, interface, method);
|
|
|
+ if (msg) {
|
|
|
+ int firstarg = va_arg(ap, int);
|
|
|
+ if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_append_args_valist(msg, firstarg, ap)) {
|
|
|
+ DBusMessage *reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
|
|
|
+ if (reply) {
|
|
|
+ firstarg = va_arg(ap, int);
|
|
|
+ if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_get_args_valist(reply, NULL, firstarg, ap)) {
|
|
|
+ retval = SDL_TRUE;
|
|
|
+ }
|
|
|
+ dbus.message_unref(reply);
|
|
|
+ }
|
|
|
}
|
|
|
dbus.message_unref(msg);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return retval;
|
|
|
}
|
|
|
|
|
|
SDL_bool
|
|
|
-SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
|
|
+SDL_DBus_CallMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
{
|
|
|
- DBusConnection *conn = dbus.session_conn;
|
|
|
+ SDL_bool retval;
|
|
|
+ va_list ap;
|
|
|
+ va_start(ap, method);
|
|
|
+ retval = SDL_DBus_CallMethodInternal(conn, node, path, interface, method, ap);
|
|
|
+ va_end(ap);
|
|
|
+ return retval;
|
|
|
+}
|
|
|
|
|
|
- if (conn == NULL)
|
|
|
- return SDL_FALSE;
|
|
|
+SDL_bool
|
|
|
+SDL_DBus_CallMethod(const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
+{
|
|
|
+ SDL_bool retval;
|
|
|
+ va_list ap;
|
|
|
+ va_start(ap, method);
|
|
|
+ retval = SDL_DBus_CallMethodInternal(dbus.session_conn, node, path, interface, method, ap);
|
|
|
+ va_end(ap);
|
|
|
+ return retval;
|
|
|
+}
|
|
|
|
|
|
- if (inhibit &&
|
|
|
- screensaver_cookie != 0)
|
|
|
- return SDL_TRUE;
|
|
|
- if (!inhibit &&
|
|
|
- screensaver_cookie == 0)
|
|
|
- return SDL_TRUE;
|
|
|
+static SDL_bool
|
|
|
+SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
|
|
|
+{
|
|
|
+ SDL_bool retval = SDL_FALSE;
|
|
|
|
|
|
- if (inhibit) {
|
|
|
- const char *app = "My SDL application";
|
|
|
- const char *reason = "Playing a game";
|
|
|
-
|
|
|
- DBusMessage *msg = dbus.message_new_method_call("org.freedesktop.ScreenSaver",
|
|
|
- "/org/freedesktop/ScreenSaver",
|
|
|
- "org.freedesktop.ScreenSaver",
|
|
|
- "Inhibit");
|
|
|
- if (msg != NULL) {
|
|
|
- dbus.message_append_args (msg,
|
|
|
- DBUS_TYPE_STRING, &app,
|
|
|
- DBUS_TYPE_STRING, &reason,
|
|
|
- DBUS_TYPE_INVALID);
|
|
|
+ if (conn) {
|
|
|
+ DBusMessage *msg = dbus.message_new_method_call(node, path, interface, method);
|
|
|
+ if (msg) {
|
|
|
+ int firstarg = va_arg(ap, int);
|
|
|
+ if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_append_args_valist(msg, firstarg, ap)) {
|
|
|
+ if (dbus.connection_send(conn, msg, NULL)) {
|
|
|
+ dbus.connection_flush(conn);
|
|
|
+ retval = SDL_TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dbus.message_unref(msg);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (msg != NULL) {
|
|
|
- DBusMessage *reply;
|
|
|
+ return retval;
|
|
|
+}
|
|
|
|
|
|
- reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
|
|
|
- if (reply) {
|
|
|
- if (!dbus.message_get_args(reply, NULL,
|
|
|
- DBUS_TYPE_UINT32, &screensaver_cookie,
|
|
|
- DBUS_TYPE_INVALID))
|
|
|
- screensaver_cookie = 0;
|
|
|
- dbus.message_unref(reply);
|
|
|
- }
|
|
|
+SDL_bool
|
|
|
+SDL_DBus_CallVoidMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
+{
|
|
|
+ SDL_bool retval;
|
|
|
+ va_list ap;
|
|
|
+ va_start(ap, method);
|
|
|
+ retval = SDL_DBus_CallVoidMethodInternal(conn, node, path, interface, method, ap);
|
|
|
+ va_end(ap);
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
+SDL_bool
|
|
|
+SDL_DBus_CallVoidMethod(const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
+{
|
|
|
+ SDL_bool retval;
|
|
|
+ va_list ap;
|
|
|
+ va_start(ap, method);
|
|
|
+ retval = SDL_DBus_CallVoidMethodInternal(dbus.session_conn, node, path, interface, method, ap);
|
|
|
+ va_end(ap);
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
+SDL_bool
|
|
|
+SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *property, const int expectedtype, void *result)
|
|
|
+{
|
|
|
+ SDL_bool retval = SDL_FALSE;
|
|
|
|
|
|
+ if (conn) {
|
|
|
+ DBusMessage *msg = dbus.message_new_method_call(node, path, "org.freedesktop.DBus.Properties", "Get");
|
|
|
+ if (msg) {
|
|
|
+ if (dbus.message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID)) {
|
|
|
+ DBusMessage *reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
|
|
|
+ if (reply) {
|
|
|
+ DBusMessageIter iter, sub;
|
|
|
+ dbus.message_iter_init(reply, &iter);
|
|
|
+ if (dbus.message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) {
|
|
|
+ dbus.message_iter_recurse(&iter, &sub);
|
|
|
+ if (dbus.message_iter_get_arg_type(&sub) == expectedtype) {
|
|
|
+ dbus.message_iter_get_basic(&sub, result);
|
|
|
+ retval = SDL_TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dbus.message_unref(reply);
|
|
|
+ }
|
|
|
+ }
|
|
|
dbus.message_unref(msg);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (screensaver_cookie == 0) {
|
|
|
- return SDL_FALSE;
|
|
|
- }
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
+SDL_bool
|
|
|
+SDL_DBus_QueryProperty(const char *node, const char *path, const char *interface, const char *property, const int expectedtype, void *result)
|
|
|
+{
|
|
|
+ return SDL_DBus_QueryPropertyOnConnection(dbus.session_conn, node, path, interface, property, expectedtype, result);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void
|
|
|
+SDL_DBus_ScreensaverTickle(void)
|
|
|
+{
|
|
|
+ SDL_DBus_CallVoidMethod("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", "org.gnome.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID);
|
|
|
+}
|
|
|
+
|
|
|
+SDL_bool
|
|
|
+SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
|
|
+{
|
|
|
+ if ( (inhibit && (screensaver_cookie != 0)) || (!inhibit && (screensaver_cookie == 0)) ) {
|
|
|
return SDL_TRUE;
|
|
|
} else {
|
|
|
- DBusMessage *msg = dbus.message_new_method_call("org.freedesktop.ScreenSaver",
|
|
|
- "/org/freedesktop/ScreenSaver",
|
|
|
- "org.freedesktop.ScreenSaver",
|
|
|
- "UnInhibit");
|
|
|
- dbus.message_append_args (msg,
|
|
|
- DBUS_TYPE_UINT32, &screensaver_cookie,
|
|
|
- DBUS_TYPE_INVALID);
|
|
|
- if (msg != NULL) {
|
|
|
- if (dbus.connection_send(conn, msg, NULL)) {
|
|
|
- dbus.connection_flush(conn);
|
|
|
+ const char *node = "org.freedesktop.ScreenSaver";
|
|
|
+ const char *path = "/org/freedesktop/ScreenSaver";
|
|
|
+ const char *interface = "org.freedesktop.ScreenSaver";
|
|
|
+
|
|
|
+ if (inhibit) {
|
|
|
+ const char *app = "My SDL application";
|
|
|
+ const char *reason = "Playing a game";
|
|
|
+ if (!SDL_DBus_CallMethod(node, path, interface, "Inhibit",
|
|
|
+ DBUS_TYPE_STRING, &app, DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID,
|
|
|
+ DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {
|
|
|
+ return SDL_FALSE;
|
|
|
}
|
|
|
- dbus.message_unref(msg);
|
|
|
+ return (screensaver_cookie != 0) ? SDL_TRUE : SDL_FALSE;
|
|
|
+ } else {
|
|
|
+ if (!SDL_DBus_CallVoidMethod(node, path, interface, "UnInhibit", DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {
|
|
|
+ return SDL_FALSE;
|
|
|
+ }
|
|
|
+ screensaver_cookie = 0;
|
|
|
}
|
|
|
-
|
|
|
- screensaver_cookie = 0;
|
|
|
- return SDL_TRUE;
|
|
|
}
|
|
|
+
|
|
|
+ return SDL_TRUE;
|
|
|
}
|
|
|
#endif
|
|
|
|