]> git.mxchange.org Git - flightgear.git/commitdiff
Disable screensaver: initial Linux-only implementation
authorRebecca Palmer <R.Palmer@bham.ac.uk>
Mon, 9 Dec 2013 00:13:44 +0000 (00:13 +0000)
committerJames Turner <zakalawe@mac.com>
Sun, 15 Dec 2013 21:18:22 +0000 (21:18 +0000)
Add a function fgOSDisableScreensaver() that attempts to disable the
screensaver (currently only succeeding on Linux), and call it on startup.

CMake option USE_DBUS (on by default), requires libdbus-1

Motivation: most screensavers do not monitor the joystick
https://bugs.launchpad.net/ubuntu/+source/flightgear/+bug/793599

Discussion: http://sourceforge.net/p/flightgear/mailman/message/31717061/

CMakeLists.txt
src/Include/config_cmake.h.in
src/Main/CMakeLists.txt
src/Main/main.cxx
src/Main/screensaver_control.cxx [new file with mode: 0644]
src/Main/screensaver_control.hxx [new file with mode: 0644]

index 3806ea09b47cdbe5d9e2a83cfd3e168a3cb7f8c6..f3540fbb6632d255afefe19c43e14169df930478 100644 (file)
@@ -110,6 +110,7 @@ IF(APPLE)
     list(APPEND PLATFORM_LIBS ${COCOA_LIBRARY} ${CORESERVICES_LIBRARY})
 
 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
+    set(USE_DBUS_DEFAULT 1)
     find_package(UDev)
 
     if(UDEV_FOUND)
@@ -141,6 +142,7 @@ option(ENABLE_PROFILE    "Set to ON to build FlightGear with gperftools profilin
 option(JPEG_FACTORY      "Set to ON to build FlightGear with JPEG-factory support" OFF)
 option(SYSTEM_SQLITE     "Set to ON to build FlightGear with the system's SQLite3 library" OFF)
 option(ENABLE_IAX        "Set to ON to build FlightGear with IAXClient/fgcom built-in (default)" ON)
+option(USE_DBUS          "Set to ON to build FlightGear with DBus screensaver interaction (default on Linux)" ${USE_DBUS_DEFAULT})
 
 # additional utilities
 option(ENABLE_FGADMIN    "Set to ON to build the FGADMIN application (default)" ON)
@@ -239,6 +241,27 @@ endif (SYSTEM_SQLITE)
 # Sqlite always depends on the threading lib
 list(APPEND SQLITE3_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
 
+##############################################################################
+## DBus setup
+
+if (USE_DBUS)
+    include(FindPkgConfig)
+    if (PKG_CONFIG_FOUND)
+        pkg_check_modules(DBUS dbus-1)
+    endif (PKG_CONFIG_FOUND) #if we don't have pkg-config, assume we don't have libdbus-1-dev either http://packages.debian.org/sid/libdbus-1-dev
+    if (DBUS_FOUND)
+        set(HAVE_DBUS 1)
+        message(STATUS "Using DBus")
+        include_directories( ${DBUS_INCLUDE_DIRS})
+    else()
+        message(STATUS "DBus not found, screensaver control disabled")
+    endif (DBUS_FOUND)
+else()
+endif (USE_DBUS)
+
+# Sqlite always depends on the threading lib
+list(APPEND SQLITE3_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
+
 ##############################################################################
 
 find_package(PLIB REQUIRED puaux pu js fnt)
index 7f3ee6a04a8e959877e4f7532bfe17eeabaef4fa..1485016ce32f34139935a9954b6eb19ea40f7902 100644 (file)
@@ -40,3 +40,5 @@
 #cmakedefine SYSTEM_SQLITE
 
 #cmakedefine ENABLE_IAX
+
+#cmakedefine HAVE_DBUS
index aeade6aa0e271e60095e44b0494dfa81d263b2d0..9167ec960d99d744b4ad6082e42a93cdbfc4253a 100644 (file)
@@ -19,6 +19,7 @@ set(SOURCES
        util.cxx
     positioninit.cxx
     subsystemFactory.cxx
+    screensaver_control.cxx
        ${RESOURCE_FILE}
        )
 
@@ -37,6 +38,7 @@ set(HEADERS
     positioninit.hxx
     subsystemFactory.hxx
     AircraftDirVisitorBase.hxx
+    screensaver_control.hxx
        )
 
 get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES)
@@ -90,6 +92,9 @@ endif()
 if(ENABLE_IAX)
     target_link_libraries(fgfs iaxclient_lib ${OPENAL_LIBRARY})
 endif()
+if(USE_DBUS)
+    target_link_libraries(fgfs ${DBUS_LIBRARIES})
+endif()
 if(FG_HAVE_GPERFTOOLS)
     include_directories(${GooglePerfTools_INCLUDE_DIR})
     target_link_libraries(fgfs ${GooglePerfTools_LIBRARIES})
index f64e0d38a19de57af3a45638115f7ed9f06f61f1..40af6e292fb89605037f9107e61fc3c3fe366490 100644 (file)
 #include "fg_os.hxx"
 #include "fg_props.hxx"
 #include "positioninit.hxx"
+#include "screensaver_control.hxx"
 #include "subsystemFactory.hxx"
 #include "options.hxx"
 
+
 using namespace flightgear;
 
 using std::cerr;
@@ -429,6 +431,9 @@ int fgMainInit( int argc, char **argv ) {
     
     fgOutputSettings();
     
+    //try to disable the screensaver
+    fgOSDisableScreensaver();
+    
     // pass control off to the master event handler
     int result = fgOSMainLoop();
     frame_signal.clear();
diff --git a/src/Main/screensaver_control.cxx b/src/Main/screensaver_control.cxx
new file mode 100644 (file)
index 0000000..0af20eb
--- /dev/null
@@ -0,0 +1,66 @@
+// screensaver_control.cxx -- disable the screensaver
+//
+// Written by Rebecca Palmer, December 2013.
+//
+// Copyright (C) 2013 Rebecca Palmer
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//
+// $Id$
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#ifdef HAVE_DBUS
+#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
+#endif
+/** Attempt to disable the screensaver.
+* 
+* Screensavers/powersavers often do not monitor the joystick, and it is hence advisable to disable them while FlightGear is running.
+* This function always exists, but currently only actually does anything on Linux, where it will disable gnome-screensaver/kscreensaver until FlightGear exits.
+*
+* The following might be useful to anyone wishing to add Windows support:
+* http://msdn.microsoft.com/en-us/library/windows/desktop/aa373233%28v=vs.85%29.aspx
+* http://msdn.microsoft.com/en-us/library/windows/desktop/aa373208%28v=vs.85%29.aspx (While this documentation says it only disables powersave, it is elsewhere reported to also disable screensaver)
+* http://msdn.microsoft.com/en-us/library/windows/desktop/dd405534%28v=vs.85%29.aspx
+*/
+void fgOSDisableScreensaver()
+{
+#ifdef HAVE_DBUS
+    DBusConnection *dbus_connection;
+    DBusMessage *dbus_inhibit_screenlock;
+    unsigned int window_id=1000;//fake-it doesn't seem to care
+    unsigned int inhibit_idle=8;//8=idle inhibit flag
+    const char *app_name="org.flightgear";
+    const char *inhibit_reason="Uses joystick input";
+    
+    dbus_connection=dbus_bus_get(DBUS_BUS_SESSION,NULL);
+    dbus_connection_set_exit_on_disconnect(dbus_connection,FALSE);//Don't close us if we lose the DBus connection
+    
+    //Two possible interfaces; we send on both, as that is easier than trying to determine which will work
+    //GNOME: https://people.gnome.org/~mccann/gnome-session/docs/gnome-session.html
+    dbus_inhibit_screenlock=dbus_message_new_method_call("org.gnome.SessionManager","/org/gnome/SessionManager","org.gnome.SessionManager","Inhibit");
+    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);
+    dbus_connection_send(dbus_connection,dbus_inhibit_screenlock,NULL);
+    
+    //KDE, GNOME 3.6+: http://standards.freedesktop.org/idle-inhibit-spec/0.1/re01.html
+    dbus_inhibit_screenlock=dbus_message_new_method_call("org.freedesktop.ScreenSaver","/ScreenSaver","org.freedesktop.ScreenSaver","Inhibit");
+    dbus_message_append_args(dbus_inhibit_screenlock,DBUS_TYPE_STRING,&app_name,DBUS_TYPE_STRING,&inhibit_reason,DBUS_TYPE_INVALID);
+    dbus_connection_send(dbus_connection,dbus_inhibit_screenlock,NULL);
+    dbus_connection_flush(dbus_connection);
+    //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
+    //Don't disconnect, that ends the inhibition
+#endif
+}
diff --git a/src/Main/screensaver_control.hxx b/src/Main/screensaver_control.hxx
new file mode 100644 (file)
index 0000000..5f68145
--- /dev/null
@@ -0,0 +1,24 @@
+// screensaver_control.hxx -- disable the screensaver
+//
+// Written by Rebecca Palmer, December 2013.
+//
+// Copyright (C) 2013 Rebecca Palmer
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//
+// $Id$
+
+
+void fgOSDisableScreensaver();