Clients/Idle/FormClientIdle.cs
changeset 197 c66ec88ed19d
parent 196 0fb548a75849
child 225 6ccaa430aa23
     1.1 --- a/Clients/Idle/FormClientIdle.cs	Sun Feb 07 13:29:05 2016 +0100
     1.2 +++ b/Clients/Idle/FormClientIdle.cs	Sun Feb 07 22:37:31 2016 +0100
     1.3 @@ -44,6 +44,9 @@
     1.4          Client iClient;
     1.5          ContentAlignment iAlignment;
     1.6          TextField iTextField;
     1.7 +        //Used to determine if screen saver need to kick in
     1.8 +        private PowerManager.SettingNotifier iPowerSettingNotifier;
     1.9 +        private bool MonitorPowerOn;
    1.10  
    1.11          public delegate void CloseDelegate();
    1.12          public delegate void CloseConnectionDelegate();
    1.13 @@ -75,9 +78,52 @@
    1.14              //Timer
    1.15              iTimer.Interval = IntervalToNextMinute();
    1.16              iTimer.Start();
    1.17 +
    1.18 +            //Create our power setting notifier and register the event we are interested in
    1.19 +            iPowerSettingNotifier = new PowerManager.SettingNotifier(Handle);
    1.20 +            iPowerSettingNotifier.OnMonitorPowerOn += OnMonitorPowerOn;
    1.21 +            iPowerSettingNotifier.OnMonitorPowerOff += OnMonitorPowerOff;
    1.22 +            MonitorPowerOn = true;
    1.23 +
    1.24          }
    1.25  
    1.26          /// <summary>
    1.27 +        /// Broadcast messages to subscribers.
    1.28 +        /// </summary>
    1.29 +        /// <param name="message"></param>
    1.30 +        protected override void WndProc(ref Message aMessage)
    1.31 +        {
    1.32 +            //Hook in our power manager
    1.33 +            if (iPowerSettingNotifier != null)
    1.34 +            {
    1.35 +                iPowerSettingNotifier.WndProc(ref aMessage);
    1.36 +            }
    1.37 +
    1.38 +            base.WndProc(ref aMessage);
    1.39 +        }
    1.40 +
    1.41 +
    1.42 +
    1.43 +        /// <summary>
    1.44 +        /// 
    1.45 +        /// </summary>
    1.46 +        private void OnMonitorPowerOn()
    1.47 +        {
    1.48 +            MonitorPowerOn = true;
    1.49 +            UpdateDisplay();
    1.50 +        }
    1.51 +
    1.52 +        /// <summary>
    1.53 +        /// 
    1.54 +        /// </summary>
    1.55 +        private void OnMonitorPowerOff()
    1.56 +        {
    1.57 +            MonitorPowerOn = false;
    1.58 +            UpdateDisplay();
    1.59 +        }
    1.60 +
    1.61 +
    1.62 +        /// <summary>
    1.63          /// 
    1.64          /// </summary>
    1.65          /// <returns></returns>
    1.66 @@ -190,6 +236,15 @@
    1.67              iTimer.Interval = IntervalToNextMinute();
    1.68              iTimer.Start();
    1.69  
    1.70 +            UpdateDisplay();
    1.71 +
    1.72 +        }
    1.73 +
    1.74 +        /// <summary>
    1.75 +        /// 
    1.76 +        /// </summary>
    1.77 +        private void UpdateDisplay()
    1.78 +        {
    1.79              //
    1.80              if (String.IsNullOrEmpty(iTextField.Text))
    1.81              {
    1.82 @@ -206,7 +261,8 @@
    1.83              iClient.SetField(iTextField);
    1.84  
    1.85              //Now make sure we save our screen from any running system monitor
    1.86 -            if (String.IsNullOrEmpty(iTextField.Text))
    1.87 +            //We don't go into screen saving mode if our monitor is still on
    1.88 +            if (String.IsNullOrEmpty(iTextField.Text) && !MonitorPowerOn)
    1.89              {
    1.90                  //If text it empty it means we need to cool down our display even if system monitor is running
    1.91                  iClient.SetPriority(Priorities.SystemMonitor + 1);
    1.92 @@ -218,6 +274,11 @@
    1.93              }
    1.94          }
    1.95  
    1.96 +        /// <summary>
    1.97 +        /// 
    1.98 +        /// </summary>
    1.99 +        /// <param name="sender"></param>
   1.100 +        /// <param name="e"></param>
   1.101          private void FormClientIdle_Shown(object sender, EventArgs e)
   1.102          {
   1.103              //Visible = false;