Permalink
Browse files

Guard against missing scrnsaver.h file

The scrnsaver.h header is not available on all systems. Therefore code
depending on it is left out when the check fails.
In addition compiledWithXScreenSaver is set to False.
  • Loading branch information...
1 parent e45ac8d commit ac3933e46e52fe10d875d673be5d7aec46f6de65 @jotrk jotrk committed Sep 10, 2012
Showing with 51 additions and 3 deletions.
  1. +8 −0 Graphics/X11/Types.hsc
  2. +11 −0 Graphics/X11/XScreenSaver.hsc
  3. +8 −0 Graphics/X11/Xlib/Extras.hsc
  4. +18 −3 configure.ac
  5. +3 −0 include/HsXlib.h
  6. +3 −0 include/XlibExtras.h
View
@@ -434,8 +434,10 @@ module Graphics.X11.Types
rrCrtcChangeNotifyMask,
rrOutputChangeNotifyMask,
rrOutputPropertyNotifyMask,
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
screenSaverCycleMask,
screenSaverNotifyMask,
+#endif
-- ** Event types
EventType,
@@ -478,7 +480,9 @@ module Graphics.X11.Types
rrNotifyOutputChange,
rrNotifyOutputProperty,
lASTEvent,
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
screenSaverNotify,
+#endif
-- ** Modifiers
Modifier,
@@ -1288,8 +1292,10 @@ type EventMask = Mask
, rrCrtcChangeNotifyMask = RRCrtcChangeNotifyMask
, rrOutputChangeNotifyMask = RROutputChangeNotifyMask
, rrOutputPropertyNotifyMask = RROutputPropertyNotifyMask
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
, screenSaverCycleMask = ScreenSaverCycleMask
, screenSaverNotifyMask = ScreenSaverNotifyMask
+#endif
}
type EventType = Word32
@@ -1333,7 +1339,9 @@ type EventType = Word32
, rrNotifyOutputChange = RRNotify_OutputChange
, rrNotifyOutputProperty=RRNotify_OutputProperty
, lASTEvent = LASTEvent
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
, screenSaverNotify = ScreenSaverNotify
+#endif
}
type Modifier = CUInt
@@ -15,6 +15,10 @@
-- Interface to XScreenSaver API
--
+#include <HsX11Config.h>
+
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
+
module Graphics.X11.XScreenSaver (
getXIdleTime,
XScreenSaverState(..),
@@ -423,3 +427,10 @@ foreign import ccall "XScreenSaverSuspend"
foreign import ccall "XFree"
cXFree :: Ptr a -> IO CInt
+
+#else
+module Graphics.X11.XScreenSaver where
+
+compiledWithXScreenSaver :: Bool
+compiledWithXScreenSaver = False
+#endif
@@ -16,7 +16,9 @@ module Graphics.X11.Xlib.Extras where
import Data.Maybe
import Data.Typeable ( Typeable )
import Graphics.X11.Xrandr
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
import Graphics.X11.XScreenSaver
+#endif
import Graphics.X11.Xlib
import Graphics.X11.Xlib.Types
import Foreign (Storable, Ptr, peek, poke, peekElemOff, pokeElemOff, peekByteOff, pokeByteOff, peekArray, throwIfNull, nullPtr, sizeOf, alignment, alloca, with, throwIf, Word8, Word16, Word64, Int32, plusPtr, castPtr, withArrayLen, setBit, testBit, allocaBytes, FunPtr)
@@ -282,6 +284,7 @@ data Event
, ev_timestamp :: !Time
, ev_rr_state :: !CInt
}
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
| ScreenSaverNotifyEvent
{ ev_event_type :: !EventType
, ev_serial :: !CULong
@@ -294,6 +297,7 @@ data Event
, ev_forced :: !Bool
, ev_time :: !Time
}
+#endif
deriving ( Show, Typeable )
eventTable :: [(EventType, String)]
@@ -332,7 +336,9 @@ eventTable =
, (clientMessage , "ClientMessage")
, (mappingNotify , "MappingNotify")
, (lASTEvent , "LASTEvent")
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
, (screenSaverNotify , "ScreenSaverNotify")
+#endif
]
eventName :: Event -> String
@@ -817,6 +823,7 @@ getEvent p = do
, ev_subtype = subtype
}
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
-----------------
-- ScreenSaverNotifyEvent:
-----------------
@@ -828,6 +835,7 @@ getEvent p = do
`ap` (#{peek XScreenSaverNotifyEvent, kind } p )
`ap` (#{peek XScreenSaverNotifyEvent, forced } p )
`ap` (#{peek XScreenSaverNotifyEvent, time } p )
+#endif
-- We don't handle this event specifically, so return the generic
-- AnyEvent.
View
@@ -78,9 +78,24 @@ if ! test "$have_xrandr" = yes; then
AC_MSG_ERROR([X11/extensions/Xrandr.h (from libXrandr) is required])
fi
-AC_CHECK_HEADERS([X11/extensions/scrnsaver.h], [have_xrandr=yes])
-if ! test "$have_xrandr" = yes; then
- AC_MSG_ERROR([X11/extensions/scrnsaver.h (XScreenSaver) is required])
+AC_MSG_CHECKING([whether to build XScreenSaver])
+AC_ARG_WITH(xscreensaver,
+ AS_HELP_STRING([--without-xscreensaver], [do not build XScreenSaver support]),
+ [],
+ [with_xscreensaver=yes])
+AC_MSG_RESULT([$with_xscreensaver])
+
+if test "$with_xscreensaver" = yes; then
+ AC_CHECK_HEADERS([X11/extensions/scrnsaver.h], [have_xscreensaver=yes])
+ if test "$have_xscreensaver" = yes; then
+ EXTRA_LIBRARIES="extra-libraries: Xss"
+ else
+ EXTRA_LIBRARIES=""
+ echo "WARNING: XScreenSaver headers not found. Building without XScreenSaver support"
+ fi
+else
+ EXTRA_LIBRARIES=""
+ echo "WARNING: Building without XScreenSaver support per user request"
fi
AC_MSG_CHECKING([whether to include X.org keysyms])
View
@@ -19,7 +19,10 @@
#include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
+
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
#include <X11/extensions/scrnsaver.h>
+#endif
/* Xutil.h overrides some functions with macros.
* In recent versions of X this can be turned off with
View
@@ -18,7 +18,10 @@
#include <X11/Xproto.h>
#include <X11/extensions/Xrandr.h>
+
+#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
#include <X11/extensions/scrnsaver.h>
+#endif
/* Xutil.h overrides some functions with macros.
* In recent versions of X this can be turned off with

0 comments on commit ac3933e

Please sign in to comment.