mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-08-07 21:58:30 +02:00
Add initial screensaver inhibiting code
This commit is contained in:
@@ -187,3 +187,68 @@ void game_mode_context_loop(GameModeContext *context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to inhibit the screensaver
|
||||
* Uses the "org.freedesktop.ScreenSaver" interface
|
||||
*/
|
||||
static unsigned int screensaver_inhibit_cookie = 0;
|
||||
int game_mode_inhibit_screensaver(bool inhibit)
|
||||
{
|
||||
const char *service = "org.freedesktop.ScreenSaver";
|
||||
const char *object_path = "/org/freedesktop/ScreenSaver";
|
||||
const char *interface = service;
|
||||
const char *function = inhibit ? "Inhibit" : "UnInhibit";
|
||||
|
||||
sd_bus_message *msg = NULL;
|
||||
sd_bus *bus = NULL;
|
||||
|
||||
int result = -1;
|
||||
|
||||
// Open the user bus
|
||||
int ret = sd_bus_open_user(&bus);
|
||||
if (ret < 0) {
|
||||
LOG_ERROR("Could not connect to user bus: %s\n", strerror(-ret));
|
||||
} else {
|
||||
if (inhibit) {
|
||||
ret = sd_bus_call_method(bus,
|
||||
service,
|
||||
object_path,
|
||||
interface,
|
||||
function,
|
||||
NULL,
|
||||
&msg,
|
||||
"s",
|
||||
"GameMode",
|
||||
"s",
|
||||
"GameMode Activated",
|
||||
"u",
|
||||
&screensaver_inhibit_cookie);
|
||||
|
||||
} else {
|
||||
ret = sd_bus_call_method(bus,
|
||||
service,
|
||||
object_path,
|
||||
interface,
|
||||
function,
|
||||
NULL,
|
||||
&msg,
|
||||
"u",
|
||||
screensaver_inhibit_cookie);
|
||||
}
|
||||
if (ret < 0) {
|
||||
LOG_ERROR("Could not call %s on %s: %s\n", function, service, strerror(-ret));
|
||||
} else {
|
||||
// Read the reply
|
||||
ret = sd_bus_message_read(msg, "i", &result);
|
||||
if (ret < 0) {
|
||||
LOG_ERROR("Failure to parse response from %s on %s: %s\n",
|
||||
function,
|
||||
service,
|
||||
strerror(-ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user