X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FLibCecTray%2Fui%2FCECTray.cs;h=0b8d17c5636e0d81aa4fd9cffbfb53dfe21ce13c;hb=e9698d4a08bc15ff64f6f5ee8e0ae19f2cdb139f;hp=021eaa38e55d5d18c2bd89cdabc6036bc8ef6e90;hpb=48b0a2601fbd52ee98b65d23970f22256aade17d;p=deb_libcec.git
diff --git a/src/LibCecTray/ui/CECTray.cs b/src/LibCecTray/ui/CECTray.cs
index 021eaa3..0b8d17c 100644
--- a/src/LibCecTray/ui/CECTray.cs
+++ b/src/LibCecTray/ui/CECTray.cs
@@ -45,34 +45,6 @@ using System.Threading;
namespace LibCECTray.ui
{
- ///
- /// The tab pages in this application
- ///
- internal enum ConfigTab
- {
- Configuration,
- KeyConfiguration,
- Tester,
- Log,
- WMC,
- XBMC
- }
-
- class AsyncDisconnect
- {
- public AsyncDisconnect(CECController controller)
- {
- _controller = controller;
- }
-
- public void Process()
- {
- _controller.Close();
- }
-
- private CECController _controller;
- }
-
///
/// Main LibCecTray GUI
///
@@ -82,6 +54,13 @@ namespace LibCECTray.ui
{
Text = Resources.app_name;
InitializeComponent();
+
+ _sstimer.Interval = 5000;
+ _sstimer.Tick += ScreensaverActiveCheck;
+ _sstimer.Enabled = false;
+
+ _lastScreensaverActivated = DateTime.Now;
+
VisibleChanged += delegate
{
if (!Visible)
@@ -101,13 +80,22 @@ namespace LibCECTray.ui
#region Power state change window messages
private const int WM_POWERBROADCAST = 0x0218;
+ private const int WM_SYSCOMMAND = 0x0112;
+
private const int PBT_APMSUSPEND = 0x0004;
private const int PBT_APMRESUMESUSPEND = 0x0007;
private const int PBT_APMRESUMECRITICAL = 0x0006;
private const int PBT_APMRESUMEAUTOMATIC = 0x0012;
private const int PBT_POWERSETTINGCHANGE = 0x8013;
+
private static Guid GUID_SYSTEM_AWAYMODE = new Guid("98a7f580-01f7-48aa-9c0f-44352c29e5c0");
+ private const int SC_SCREENSAVE = 0xF140;
+ private const int SPI_GETSCREENSAVERRUNNING = 0x0072;
+
+ [DllImport("user32.dll", SetLastError = true)]
+ static extern bool SystemParametersInfo(int action, int param, ref int retval, int updini);
+
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal struct POWERBROADCAST_SETTING
{
@@ -123,7 +111,22 @@ namespace LibCECTray.ui
/// The incoming window message
protected override void WndProc(ref Message msg)
{
- if (msg.Msg == WM_POWERBROADCAST)
+ if (msg.Msg == WM_SYSCOMMAND && (msg.WParam.ToInt32() & 0xfff0) == SC_SCREENSAVE)
+ {
+ // there's no event for screensaver exit
+ if (!_sstimer.Enabled)
+ {
+ // guard against screensaver failing, and resulting in power up and down spam to the tv
+ TimeSpan diff = DateTime.Now - _lastScreensaverActivated;
+ if (diff.TotalSeconds > 60)
+ {
+ _sstimer.Enabled = true;
+ _lastScreensaverActivated = DateTime.Now;
+ Controller.CECActions.SendStandby(CecLogicalAddress.Broadcast);
+ }
+ }
+ }
+ else if (msg.Msg == WM_POWERBROADCAST)
{
switch (msg.WParam.ToInt32())
{
@@ -149,7 +152,7 @@ namespace LibCECTray.ui
//OnWake();
//return;
case 1:
- OnSleep();
+ Controller.CECActions.SendStandby(CecLogicalAddress.Broadcast);
return;
default:
break;
@@ -166,6 +169,22 @@ namespace LibCECTray.ui
base.WndProc(ref msg);
}
+ private void ScreensaverActiveCheck(object sender, EventArgs e)
+ {
+ if (!IsScreensaverActive())
+ {
+ _sstimer.Enabled = false;
+ Controller.CECActions.ActivateSource();
+ }
+ }
+
+ private bool IsScreensaverActive()
+ {
+ int active = 1;
+ SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, ref active, 0);
+ return active == 1;
+ }
+
private void OnWake()
{
Controller.Initialise();
@@ -173,7 +192,9 @@ namespace LibCECTray.ui
private void OnSleep()
{
- Controller.Close();
+ Controller.CECActions.SuppressUpdates = true;
+ AsyncDisconnect dc = new AsyncDisconnect(Controller);
+ (new Thread(dc.Process)).Start();
}
public override sealed string Text
@@ -192,9 +213,7 @@ namespace LibCECTray.ui
Hide();
if (disposing)
{
- Controller.CECActions.SuppressUpdates = true;
- AsyncDisconnect dc = new AsyncDisconnect(Controller);
- (new Thread(dc.Process)).Start();
+ OnSleep();
}
if (disposing && (components != null))
{
@@ -290,7 +309,7 @@ namespace LibCECTray.ui
private void BActivateSourceClick(object sender, EventArgs e)
{
- Controller.CECActions.ActivateSource(GetTargetDevice());
+ Controller.CECActions.SetStreamPath(GetTargetDevice());
}
private void CbCommandDestinationSelectedIndexChanged(object sender, EventArgs e)
@@ -603,6 +622,9 @@ namespace LibCECTray.ui
{
get { return GetSelectedTabName(tabPanel, tabPanel.TabPages); }
}
+
+ private System.Windows.Forms.Timer _sstimer = new System.Windows.Forms.Timer();
+ private DateTime _lastScreensaverActivated;
#endregion
private void AddNewApplicationToolStripMenuItemClick(object sender, EventArgs e)
@@ -611,4 +633,32 @@ namespace LibCECTray.ui
Controller.DisplayDialog(appConfig, false);
}
}
+
+ ///
+ /// The tab pages in this application
+ ///
+ internal enum ConfigTab
+ {
+ Configuration,
+ KeyConfiguration,
+ Tester,
+ Log,
+ WMC,
+ XBMC
+ }
+
+ class AsyncDisconnect
+ {
+ public AsyncDisconnect(CECController controller)
+ {
+ _controller = controller;
+ }
+
+ public void Process()
+ {
+ _controller.Close();
+ }
+
+ private CECController _controller;
+ }
}