|
@@ -73,6 +73,7 @@ static bool LoadDBUSSyms(void)
|
|
|
SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *, int), connection_read_write);
|
|
SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *, int), connection_read_write);
|
|
|
SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *, int), connection_read_write_dispatch);
|
|
SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *, int), connection_read_write_dispatch);
|
|
|
SDL_DBUS_SYM(DBusDispatchStatus (*)(DBusConnection *), connection_dispatch);
|
|
SDL_DBUS_SYM(DBusDispatchStatus (*)(DBusConnection *), connection_dispatch);
|
|
|
|
|
+ SDL_DBUS_SYM(dbus_bool_t (*)(int), type_is_fixed);
|
|
|
SDL_DBUS_SYM(dbus_bool_t (*)(DBusMessage *, const char *, const char *), message_is_signal);
|
|
SDL_DBUS_SYM(dbus_bool_t (*)(DBusMessage *, const char *, const char *), message_is_signal);
|
|
|
SDL_DBUS_SYM(dbus_bool_t (*)(DBusMessage *, const char *), message_has_path);
|
|
SDL_DBUS_SYM(dbus_bool_t (*)(DBusMessage *, const char *), message_has_path);
|
|
|
SDL_DBUS_SYM(DBusMessage *(*)(const char *, const char *, const char *, const char *), message_new_method_call);
|
|
SDL_DBUS_SYM(DBusMessage *(*)(const char *, const char *, const char *, const char *), message_new_method_call);
|
|
@@ -229,7 +230,7 @@ SDL_DBusContext *SDL_DBus_GetContext(void)
|
|
|
return (dbus_handle && dbus.session_conn) ? &dbus : NULL;
|
|
return (dbus_handle && dbus.session_conn) ? &dbus : NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
|
|
|
|
|
|
|
+static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *method, va_list ap)
|
|
|
{
|
|
{
|
|
|
bool result = false;
|
|
bool result = false;
|
|
|
|
|
|
|
@@ -261,7 +262,11 @@ static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node,
|
|
|
if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_get_args_valist(reply, NULL, firstarg, ap_reply)) {
|
|
if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_get_args_valist(reply, NULL, firstarg, ap_reply)) {
|
|
|
result = true;
|
|
result = true;
|
|
|
}
|
|
}
|
|
|
- dbus.message_unref(reply);
|
|
|
|
|
|
|
+ if (save_reply) {
|
|
|
|
|
+ *save_reply = reply;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dbus.message_unref(reply);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
va_end(ap_reply);
|
|
va_end(ap_reply);
|
|
@@ -272,22 +277,22 @@ static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node,
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool SDL_DBus_CallMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
|
|
|
|
+bool SDL_DBus_CallMethodOnConnection(DBusConnection *conn, DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
{
|
|
{
|
|
|
bool result;
|
|
bool result;
|
|
|
va_list ap;
|
|
va_list ap;
|
|
|
va_start(ap, method);
|
|
va_start(ap, method);
|
|
|
- result = SDL_DBus_CallMethodInternal(conn, node, path, interface, method, ap);
|
|
|
|
|
|
|
+ result = SDL_DBus_CallMethodInternal(conn, save_reply, node, path, interface, method, ap);
|
|
|
va_end(ap);
|
|
va_end(ap);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool SDL_DBus_CallMethod(const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
|
|
|
|
+bool SDL_DBus_CallMethod(DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
{
|
|
{
|
|
|
bool result;
|
|
bool result;
|
|
|
va_list ap;
|
|
va_list ap;
|
|
|
va_start(ap, method);
|
|
va_start(ap, method);
|
|
|
- result = SDL_DBus_CallMethodInternal(dbus.session_conn, node, path, interface, method, ap);
|
|
|
|
|
|
|
+ result = SDL_DBus_CallMethodInternal(dbus.session_conn, save_reply, node, path, interface, method, ap);
|
|
|
va_end(ap);
|
|
va_end(ap);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -314,10 +319,34 @@ static bool SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *no
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static bool SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage *msg, const int expectedtype, void *result)
|
|
|
|
|
|
|
+bool SDL_DBus_CallVoidMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
|
|
+{
|
|
|
|
|
+ bool result;
|
|
|
|
|
+ va_list ap;
|
|
|
|
|
+ va_start(ap, method);
|
|
|
|
|
+ result = SDL_DBus_CallVoidMethodInternal(conn, node, path, interface, method, ap);
|
|
|
|
|
+ va_end(ap);
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool SDL_DBus_CallVoidMethod(const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
|
|
+{
|
|
|
|
|
+ bool result;
|
|
|
|
|
+ va_list ap;
|
|
|
|
|
+ va_start(ap, method);
|
|
|
|
|
+ result = SDL_DBus_CallVoidMethodInternal(dbus.session_conn, node, path, interface, method, ap);
|
|
|
|
|
+ va_end(ap);
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static bool SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage **save_reply, DBusMessage *msg, const int expectedtype, void *result)
|
|
|
{
|
|
{
|
|
|
bool retval = false;
|
|
bool retval = false;
|
|
|
|
|
|
|
|
|
|
+ // Make sure we're not looking up strings here, otherwise we'd have to save and return the reply
|
|
|
|
|
+ SDL_assert(save_reply == NULL || *save_reply == NULL);
|
|
|
|
|
+ SDL_assert(save_reply != NULL || dbus.type_is_fixed(expectedtype));
|
|
|
|
|
+
|
|
|
DBusMessage *reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
|
|
DBusMessage *reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
|
|
|
if (reply) {
|
|
if (reply) {
|
|
|
DBusMessageIter iter, actual_iter;
|
|
DBusMessageIter iter, actual_iter;
|
|
@@ -333,33 +362,17 @@ static bool SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage *msg,
|
|
|
retval = true;
|
|
retval = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- dbus.message_unref(reply);
|
|
|
|
|
|
|
+ if (save_reply) {
|
|
|
|
|
+ *save_reply = reply;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dbus.message_unref(reply);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
return retval;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool SDL_DBus_CallVoidMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
|
|
-{
|
|
|
|
|
- bool result;
|
|
|
|
|
- va_list ap;
|
|
|
|
|
- va_start(ap, method);
|
|
|
|
|
- result = SDL_DBus_CallVoidMethodInternal(conn, node, path, interface, method, ap);
|
|
|
|
|
- va_end(ap);
|
|
|
|
|
- return result;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-bool SDL_DBus_CallVoidMethod(const char *node, const char *path, const char *interface, const char *method, ...)
|
|
|
|
|
-{
|
|
|
|
|
- bool result;
|
|
|
|
|
- va_list ap;
|
|
|
|
|
- va_start(ap, method);
|
|
|
|
|
- result = SDL_DBus_CallVoidMethodInternal(dbus.session_conn, node, path, interface, method, ap);
|
|
|
|
|
- va_end(ap);
|
|
|
|
|
- return result;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result)
|
|
|
|
|
|
|
+bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result)
|
|
|
{
|
|
{
|
|
|
bool retval = false;
|
|
bool retval = false;
|
|
|
|
|
|
|
@@ -367,7 +380,7 @@ bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node,
|
|
|
DBusMessage *msg = dbus.message_new_method_call(node, path, "org.freedesktop.DBus.Properties", "Get");
|
|
DBusMessage *msg = dbus.message_new_method_call(node, path, "org.freedesktop.DBus.Properties", "Get");
|
|
|
if (msg) {
|
|
if (msg) {
|
|
|
if (dbus.message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID)) {
|
|
if (dbus.message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID)) {
|
|
|
- retval = SDL_DBus_CallWithBasicReply(conn, msg, expectedtype, result);
|
|
|
|
|
|
|
+ retval = SDL_DBus_CallWithBasicReply(conn, save_reply, msg, expectedtype, result);
|
|
|
}
|
|
}
|
|
|
dbus.message_unref(msg);
|
|
dbus.message_unref(msg);
|
|
|
}
|
|
}
|
|
@@ -376,9 +389,18 @@ bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node,
|
|
|
return retval;
|
|
return retval;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool SDL_DBus_QueryProperty(const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result)
|
|
|
|
|
|
|
+bool SDL_DBus_QueryProperty(DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result)
|
|
|
{
|
|
{
|
|
|
- return SDL_DBus_QueryPropertyOnConnection(dbus.session_conn, node, path, interface, property, expectedtype, result);
|
|
|
|
|
|
|
+ return SDL_DBus_QueryPropertyOnConnection(dbus.session_conn, save_reply, node, path, interface, property, expectedtype, result);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void SDL_DBus_FreeReply(DBusMessage **saved_reply)
|
|
|
|
|
+{
|
|
|
|
|
+ DBusMessage *reply = *saved_reply;
|
|
|
|
|
+ if (reply) {
|
|
|
|
|
+ dbus.message_unref(reply);
|
|
|
|
|
+ *saved_reply = NULL;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SDL_DBus_ScreensaverTickle(void)
|
|
void SDL_DBus_ScreensaverTickle(void)
|
|
@@ -473,7 +495,7 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit)
|
|
|
DBusMessage *msg;
|
|
DBusMessage *msg;
|
|
|
bool result = false;
|
|
bool result = false;
|
|
|
const char *key = "reason";
|
|
const char *key = "reason";
|
|
|
- const char *reply = NULL;
|
|
|
|
|
|
|
+ const char *reply_path = NULL;
|
|
|
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
|
|
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
|
|
|
if (!reason || !reason[0]) {
|
|
if (!reason || !reason[0]) {
|
|
|
reason = default_inhibit_reason;
|
|
reason = default_inhibit_reason;
|
|
@@ -497,11 +519,12 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit)
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (SDL_DBus_CallWithBasicReply(dbus.session_conn, msg, DBUS_TYPE_OBJECT_PATH, &reply)) {
|
|
|
|
|
- inhibit_handle = SDL_strdup(reply);
|
|
|
|
|
|
|
+ DBusMessage *reply = NULL;
|
|
|
|
|
+ if (SDL_DBus_CallWithBasicReply(dbus.session_conn, &reply, msg, DBUS_TYPE_OBJECT_PATH, &reply_path)) {
|
|
|
|
|
+ inhibit_handle = SDL_strdup(reply_path);
|
|
|
result = true;
|
|
result = true;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ SDL_DBus_FreeReply(&reply);
|
|
|
dbus.message_unref(msg);
|
|
dbus.message_unref(msg);
|
|
|
return result;
|
|
return result;
|
|
|
} else {
|
|
} else {
|
|
@@ -523,7 +546,7 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit)
|
|
|
reason = default_inhibit_reason;
|
|
reason = default_inhibit_reason;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!SDL_DBus_CallMethod(bus_name, path, interface, "Inhibit",
|
|
|
|
|
|
|
+ if (!SDL_DBus_CallMethod(NULL, bus_name, path, interface, "Inhibit",
|
|
|
DBUS_TYPE_STRING, &app, DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID,
|
|
DBUS_TYPE_STRING, &app, DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID,
|
|
|
DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {
|
|
DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {
|
|
|
return false;
|
|
return false;
|