mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-27 19:19:41 +08:00
dbus: Return false if the screensaver inhibitor interface is unavailable
Returning true with an unavailable interface in no-op cases can prevent fallback to other inhibition methods. If the inhibitor interface was previously tried and marked as unavailable, just return false.
This commit is contained in:
@@ -612,8 +612,14 @@ done:
|
|||||||
|
|
||||||
bool SDL_DBus_ScreensaverInhibit(bool inhibit)
|
bool SDL_DBus_ScreensaverInhibit(bool inhibit)
|
||||||
{
|
{
|
||||||
|
static bool interface_unavailable = false;
|
||||||
const char *default_inhibit_reason = "Playing a game";
|
const char *default_inhibit_reason = "Playing a game";
|
||||||
|
|
||||||
|
// If the interface was previously queried and is unavailable, return false.
|
||||||
|
if (interface_unavailable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ((inhibit && (screensaver_cookie != 0 || inhibit_handle)) || (!inhibit && (screensaver_cookie == 0 && !inhibit_handle))) {
|
if ((inhibit && (screensaver_cookie != 0 || inhibit_handle)) || (!inhibit && (screensaver_cookie == 0 && !inhibit_handle))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -664,6 +670,8 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit)
|
|||||||
if (SDL_DBus_CallWithBasicReply(dbus.session_conn, &reply, msg, DBUS_TYPE_OBJECT_PATH, &reply_path)) {
|
if (SDL_DBus_CallWithBasicReply(dbus.session_conn, &reply, msg, DBUS_TYPE_OBJECT_PATH, &reply_path)) {
|
||||||
inhibit_handle = SDL_strdup(reply_path);
|
inhibit_handle = SDL_strdup(reply_path);
|
||||||
result = true;
|
result = true;
|
||||||
|
} else {
|
||||||
|
interface_unavailable = true;
|
||||||
}
|
}
|
||||||
SDL_DBus_FreeReply(&reply);
|
SDL_DBus_FreeReply(&reply);
|
||||||
dbus.message_unref(msg);
|
dbus.message_unref(msg);
|
||||||
@@ -690,6 +698,7 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit)
|
|||||||
if (!SDL_DBus_CallMethod(NULL, 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)) {
|
||||||
|
interface_unavailable = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (screensaver_cookie != 0);
|
return (screensaver_cookie != 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user