Index: libs/libmyth/screensaver-osx.cpp
===================================================================
--- libs/libmyth/screensaver-osx.cpp	(revision 10054)
+++ libs/libmyth/screensaver-osx.cpp	(working copy)
@@ -61,3 +61,8 @@
     ScreenSaverOSXPrivate::timerCallback(NULL, NULL);
 }
 
+bool ScreenSaverOSX::Asleep(void)
+{
+    return 0;
+}
+
Index: libs/libmyth/screensaver-x11.cpp
===================================================================
--- libs/libmyth/screensaver-x11.cpp	(revision 10054)
+++ libs/libmyth/screensaver-x11.cpp	(working copy)
@@ -20,8 +20,10 @@
         int interval;
         int preferblank;
         int allowexposure;
-        bool dpmsdisabled;
         bool xscreensaverRunning;
+        BOOL dpmsaware;
+        BOOL dpmsenabled;
+        bool dpmsdeactivated;
     } state;
 
     QTimer *resetTimer;
@@ -44,10 +46,40 @@
         d->timeoutInterval = -1;
         VERBOSE(VB_GENERAL, "XScreenSaver support enabled");
     }
+
+    int dummy;
+    if ((d->state.dpmsaware = DPMSQueryExtension(qt_xdisplay(),&dummy,&dummy)))
+    {
+        CARD16 power_level;
+
+	    /* If someone runs into X server weirdness that goes away when
+	    * they externally disable DPMS, then the 'dpmsenabled' test should
+	    * be short circuited by a call to 'DPMSCapable()'. Be sure to
+	    * manually initialize dpmsenabled to false.
+	    */
+
+        DPMSInfo(qt_xdisplay(), &power_level, &(d->state.dpmsenabled));
+
+        if (d->state.dpmsenabled)
+            VERBOSE(VB_GENERAL, "DPMS is active.");
+        else
+            VERBOSE(VB_GENERAL, "DPMS is disabled.");
+
+    } else {
+        d->state.dpmsenabled = false;
+        VERBOSE(VB_GENERAL, "DPMS is not supported.");
+    }
+
+    d->state.dpmsdeactivated = false;
+
 }
 
 ScreenSaverX11::~ScreenSaverX11() 
 {
+    /* Ensure DPMS gets left as it was found. */
+    if (d->state.dpmsdeactivated)
+        Restore();
+
     delete d;
 }
 
@@ -65,20 +97,11 @@
     XResetScreenSaver(qt_xdisplay());
     XSetScreenSaver(qt_xdisplay(), 0, 0, 0, 0);
 
-    int nothing;
-
-    if (DPMSQueryExtension(qt_xdisplay(), &nothing, &nothing))
+    if (d->state.dpmsenabled)
     {
-        BOOL on;
-        CARD16 power_level;
-
-        DPMSInfo(qt_xdisplay(), &power_level, &on);
-        if (on)
-        {
-            d->state.dpmsdisabled = true;
-            DPMSDisable(qt_xdisplay());       // monitor powersave off
-            VERBOSE(VB_GENERAL, "Disable DPMS");
-        }
+        d->state.dpmsdeactivated = true;
+        DPMSDisable(qt_xdisplay());
+        VERBOSE(VB_GENERAL, "DPMS Deactivated ");
     }
 
     if (d->state.xscreensaverRunning)
@@ -109,15 +132,11 @@
                     d->state.allowexposure);
     d->state.saved = false;
 
-    if (d->state.dpmsdisabled)
+    if (d->state.dpmsdeactivated)
     {
-        int nothing;
-        d->state.dpmsdisabled = false;
-        if (DPMSQueryExtension(qt_xdisplay(), &nothing, &nothing))
-        {
-            DPMSEnable(qt_xdisplay());
-            VERBOSE(VB_GENERAL, "Enable DPMS");
-        }
+        d->state.dpmsdeactivated = false;
+        DPMSEnable(qt_xdisplay());
+        VERBOSE(VB_GENERAL, "DPMS Reactivated.");
     }
 
     if (d->state.xscreensaverRunning && d->resetTimer)
@@ -130,20 +149,31 @@
     if (d->state.xscreensaverRunning)
         resetSlot();
 
-    int nothing;
-    if (DPMSQueryExtension(qt_xdisplay(), &nothing, &nothing))
+    if (Asleep())
     {
-        BOOL on;
-        CARD16 power_level;
-        if (!d->state.dpmsdisabled) 
-        {
-            DPMSInfo(qt_xdisplay(), &power_level, &on);
-            if (power_level != DPMSModeOn)
-                DPMSForceLevel(qt_xdisplay(), DPMSModeOn);
-        }
+        DPMSForceLevel(qt_xdisplay(), DPMSModeOn);
+	// Calling XSync is necessary for the case when Myth executes
+	// another application before the event loop regains control
+        XSync(qt_xdisplay(), false);
     }
 }
 
+bool ScreenSaverX11::Asleep(void)
+{
+    if (!d->state.dpmsenabled)
+        return 0;
+
+    if (d->state.dpmsdeactivated)
+        return 0;
+
+    BOOL on;
+    CARD16 power_level;
+
+    DPMSInfo(qt_xdisplay(), &power_level, &on);
+
+    return (power_level != DPMSModeOn);
+}
+
 void ScreenSaverX11::resetSlot() 
 {
     myth_system(QString("xscreensaver-command -deactivate >&- 2>&- &")); 
Index: libs/libmyth/screensaver-null.cpp
===================================================================
--- libs/libmyth/screensaver-null.cpp	(revision 10054)
+++ libs/libmyth/screensaver-null.cpp	(working copy)
@@ -17,3 +17,8 @@
 void ScreenSaverNull::Reset(void)
 {
 }
+
+bool ScreenSaverNull::Asleep(void)
+{
+    return 0;
+}
Index: libs/libmyth/mythcontext.h
===================================================================
--- libs/libmyth/mythcontext.h	(revision 10054)
+++ libs/libmyth/mythcontext.h	(working copy)
@@ -405,6 +405,7 @@
 
     // get the current status
     bool GetScreensaverEnabled(void);
+    bool GetScreenIsAsleep(void);
 
     void addPrivRequest(MythPrivRequest::Type t, void *data);
     void waitPrivRequest() const;
Index: libs/libmyth/screensaver.h
===================================================================
--- libs/libmyth/screensaver.h	(revision 10054)
+++ libs/libmyth/screensaver.h	(working copy)
@@ -36,6 +36,8 @@
     virtual void Disable(void) = 0;
     virtual void Restore(void) = 0;
     virtual void Reset(void) = 0;
+
+    virtual bool Asleep(void) = 0;
 };
 
 #endif // MYTH_SCREENSAVER_H
Index: libs/libmyth/screensaver-null.h
===================================================================
--- libs/libmyth/screensaver-null.h	(revision 10054)
+++ libs/libmyth/screensaver-null.h	(working copy)
@@ -12,6 +12,8 @@
     void Disable(void);
     void Restore(void);
     void Reset(void);
+
+    bool Asleep(void);
 };
 
 #endif // MYTH_SCREENSAVER_NULL_H
Index: libs/libmyth/mythcontext.cpp
===================================================================
--- libs/libmyth/mythcontext.cpp	(revision 10054)
+++ libs/libmyth/mythcontext.cpp	(working copy)
@@ -2852,4 +2852,11 @@
     return currentLocation.last();
 }
 
+bool MythContext::GetScreenIsAsleep(void)
+{
+    if (!d->screensaver)
+        return false;
+    return d->screensaver->Asleep();
+}
+
 /* vim: set expandtab tabstop=4 shiftwidth=4: */
Index: libs/libmyth/screensaver-osx.h
===================================================================
--- libs/libmyth/screensaver-osx.h	(revision 10054)
+++ libs/libmyth/screensaver-osx.h	(working copy)
@@ -13,6 +13,8 @@
     void Restore(void);
     void Reset(void);
 
+    bool Asleep(void);
+
 protected:
     class ScreenSaverOSXPrivate *d;
 };
Index: libs/libmyth/screensaver-x11.h
===================================================================
--- libs/libmyth/screensaver-x11.h	(revision 10054)
+++ libs/libmyth/screensaver-x11.h	(working copy)
@@ -17,6 +17,8 @@
     void Restore(void);
     void Reset(void);
 
+    bool Asleep(void);
+
   public slots:
     void resetSlot();
 
Index: libs/libmythui/mythmainwindow.cpp
===================================================================
--- libs/libmythui/mythmainwindow.cpp	(revision 10054)
+++ libs/libmythui/mythmainwindow.cpp	(working copy)
@@ -1186,6 +1188,8 @@
         if (keycode) 
         {
             gContext->ResetScreensaver();
+            if (gContext->GetScreenIsAsleep())
+                return;
 
             int mod = keycode & MODIFIER_MASK;
             int k = keycode & ~MODIFIER_MASK; /* trim off the mod */
@@ -1235,6 +1239,8 @@
         if (keycode)
         {
             gContext->ResetScreensaver();
+            if (gContext->GetScreenIsAsleep())
+                return;
 
             int mod = keycode & MODIFIER_MASK;
             int k = keycode & ~MODIFIER_MASK; /* trim off the mod */
