-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2d3802
commit 26943e4
Showing
7 changed files
with
59 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
#define None XNone | ||
#define Window XWindow | ||
#include <X11/Xlib.h> | ||
#include <dbus/dbus.h> | ||
#undef None | ||
#undef Window | ||
|
||
struct LibXtst : public library { | ||
function<int (Display*, unsigned int, Bool, unsigned long)> XTestFakeKeyEvent; | ||
static void log(DBusError &error) { | ||
fprintf(stderr, "DBus error: %s\n", error.name); | ||
fprintf(stderr, "Message: %s\n", error.message); | ||
} | ||
|
||
void Application::App::inhibitScreenSaver() { | ||
DBusError error; | ||
dbus_error_init(&error); | ||
|
||
LibXtst() { | ||
if(open("Xtst")) { | ||
XTestFakeKeyEvent = sym("XTestFakeKeyEvent"); | ||
} | ||
DBusConnection *connection = dbus_bus_get(DBUS_BUS_SESSION, &error); | ||
if (connection == nullptr) { | ||
log(error); | ||
return; | ||
} | ||
} libXtst; | ||
|
||
void supressScreenSaver() { | ||
if(!libXtst.XTestFakeKeyEvent) return; | ||
DBusMessage *message = dbus_message_new_method_call( | ||
"org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver", | ||
"org.freedesktop.ScreenSaver", "Inhibit"); | ||
|
||
//XSetScreenSaver(timeout = 0) does not work | ||
//XResetScreenSaver() does not work | ||
//XScreenSaverSuspend() does not work | ||
//DPMSDisable() does not work | ||
//XSendEvent(KeyPressMask) does not work | ||
//use XTest extension to send fake keypress every ~20 seconds. | ||
//keycode of 255 does not map to any actual key, | ||
//but it will block screensaver and power management. | ||
Display *display = XOpenDisplay(0); | ||
libXtst.XTestFakeKeyEvent(display, 255, True, 0); | ||
libXtst.XTestFakeKeyEvent(display, 255, False, 0); | ||
XCloseDisplay(display); | ||
} | ||
const char *app = "org.bsnes.bsnes-plus"; | ||
const char *reason = tr("Playing a game").toLocal8Bit().data(); | ||
if (!dbus_message_append_args(message, DBUS_TYPE_STRING, &app, | ||
DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID)) { | ||
dbus_connection_unref(connection); | ||
fputs("Failed to append arguments to DBus call\n", stderr); | ||
return; | ||
} | ||
|
||
DBusMessage *reply = dbus_connection_send_with_reply_and_block( | ||
connection, message, DBUS_TIMEOUT_USE_DEFAULT, &error); | ||
dbus_connection_unref(connection); | ||
dbus_message_unref(message); | ||
if (reply == nullptr) { | ||
log(error); | ||
return; | ||
} | ||
dbus_message_unref(reply); | ||
} |