FlightGear next
screensaver_control.cxx
Go to the documentation of this file.
1// screensaver_control.cxx -- disable the screensaver
2//
3// Written by Rebecca Palmer, December 2013.
4//
5// Copyright (C) 2013 Rebecca Palmer
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License as
9// published by the Free Software Foundation; either version 2 of the
10// License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15// General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20//
21// $Id$
22
23#include <config.h>
24#include <simgear/compiler.h>
25
26#ifdef HAVE_DBUS
27#include <dbus/dbus.h>//Uses the low-level libdbus rather than GDBus/QtDBus to avoid adding more dependencies than necessary. http://dbus.freedesktop.org/doc/api/html/index.html
28#endif
40{
41#if defined(HAVE_DBUS) && defined(SG_UNIX) && !defined(SG_MAC)
42 DBusConnection *dbus_connection;
43 DBusMessage *dbus_inhibit_screenlock;
44 unsigned int window_id=1000;//fake-it doesn't seem to care
45 unsigned int inhibit_idle=8;//8=idle inhibit flag
46 const char *app_name="org.flightgear";
47 const char *inhibit_reason="Uses joystick input";
48
49 // REVIEW: Memory Leak - 2,056 bytes in 1 blocks are still reachable
50 dbus_connection=dbus_bus_get(DBUS_BUS_SESSION,NULL);
51 dbus_connection_set_exit_on_disconnect(dbus_connection,FALSE);//Don't close us if we lose the DBus connection
52
53 //Two possible interfaces; we send on both, as that is easier than trying to determine which will work
54 //GNOME: https://people.gnome.org/~mccann/gnome-session/docs/gnome-session.html
55 dbus_inhibit_screenlock=dbus_message_new_method_call("org.gnome.SessionManager","/org/gnome/SessionManager","org.gnome.SessionManager","Inhibit");
56 // REVIEW: Memory Leak - 352 bytes in 1 blocks are indirectly lost
57 dbus_message_append_args(dbus_inhibit_screenlock,DBUS_TYPE_STRING,&app_name,DBUS_TYPE_UINT32,&window_id,DBUS_TYPE_STRING,&inhibit_reason,DBUS_TYPE_UINT32,&inhibit_idle,DBUS_TYPE_INVALID);
58 dbus_connection_send(dbus_connection,dbus_inhibit_screenlock,NULL);
59
60 //KDE, GNOME 3.6+: http://standards.freedesktop.org/idle-inhibit-spec/0.1/re01.html
61 dbus_inhibit_screenlock=dbus_message_new_method_call("org.freedesktop.ScreenSaver","/ScreenSaver","org.freedesktop.ScreenSaver","Inhibit");
62 // REVIEW: Memory Leak - 320 bytes in 1 blocks are still reachable
63 dbus_message_append_args(dbus_inhibit_screenlock,DBUS_TYPE_STRING,&app_name,DBUS_TYPE_STRING,&inhibit_reason,DBUS_TYPE_INVALID);
64 dbus_connection_send(dbus_connection,dbus_inhibit_screenlock,NULL);
65 dbus_connection_flush(dbus_connection);
66 //Currently ignores the reply; it would need to read it if we wanted to determine whether we've succeeded and/or allow explicitly re-enabling the screensaver
67 //Don't disconnect, that ends the inhibition
68#endif
69}
void fgOSDisableScreensaver()
Attempt to disable the screensaver.