banshee r3795 - in trunk/banshee: . src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying



Author: abock
Date: Sat Apr 19 02:14:31 2008
New Revision: 3795
URL: http://svn.gnome.org/viewvc/banshee?rev=3795&view=rev

Log:
2008-04-18  Aaron Bockover  <abock gnome org>

    * src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/FullscreenWindow.cs:
    Hide the cursor if it hasn't moved in 2.5 seconds, allow 150px of movement
    before showing it again if it was hidden already



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/FullscreenWindow.cs

Modified: trunk/banshee/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/FullscreenWindow.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/FullscreenWindow.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/FullscreenWindow.cs	Sat Apr 19 02:14:31 2008
@@ -2,9 +2,9 @@
 // FullScreenWindow.cs
 //
 // Authors:
+//   Aaron Bockover <abockover novell com>
 //   Larry Ewing <lewing novell com>
 //   Gabriel Burt <gburt novell com>
-//   Aaron Bockover <abockover novell com>
 //
 // Copyright (C) 2008 Novell, Inc.
 //
@@ -34,7 +34,7 @@
 namespace Banshee.NowPlaying
 {
     public class FullscreenWindow : Window
-    {
+    {    
         public FullscreenWindow (Window parent) : base ("Banshee")
         {
             Gdk.Screen screen = Screen;
@@ -46,6 +46,18 @@
             Decorated = false;
         }
         
+        protected override void OnRealized ()
+        {
+            Events |= Gdk.EventMask.PointerMotionMask | Gdk.EventMask.PointerMotionHintMask;
+            base.OnRealized ();
+        }
+        
+        protected override void OnShown ()
+        {
+            base.OnShown ();
+            OnHideCursorTimeout ();
+        }
+        
         protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
         {
             switch (evnt.Key) {
@@ -57,5 +69,93 @@
             
             return base.OnKeyPressEvent (evnt);
         }
+        
+#region Mouse Cursor Polish
+
+        private const int CursorUpdatePositionDelay = 500;   // How long (ms) before the cursor position is updated
+        private const int CursorHideDelay = 2500;            // How long (ms) to remain stationary before it hides
+        private const int CursorShowMovementThreshold = 150; // How far (px) to move before it shows again
+        
+        private uint hide_cursor_timeout_id;
+        private uint cursor_update_position_timeout_id;
+        private int hide_cursor_x;
+        private int hide_cursor_y;
+        private bool cursor_is_hidden = false;
+        
+        protected override bool OnMotionNotifyEvent (Gdk.EventMotion evnt)
+        {
+            if (cursor_is_hidden) {
+                if (Math.Abs (hide_cursor_x - evnt.X) > CursorShowMovementThreshold || 
+                    Math.Abs (hide_cursor_y - evnt.Y) > CursorShowMovementThreshold) {
+                    ShowCursor ();
+                } else {
+                    if (cursor_update_position_timeout_id > 0) {
+                        GLib.Source.Remove (cursor_update_position_timeout_id);
+                    }
+                    
+                    cursor_update_position_timeout_id = GLib.Timeout.Add (CursorUpdatePositionDelay, 
+                        OnCursorUpdatePositionTimeout);
+                }        
+            } else {
+                if (hide_cursor_timeout_id > 0) {
+                    GLib.Source.Remove (hide_cursor_timeout_id);
+                }
+                
+                hide_cursor_timeout_id = GLib.Timeout.Add (CursorHideDelay, OnHideCursorTimeout);
+            }
+            
+            return base.OnMotionNotifyEvent (evnt);
+        }
+        
+        private bool OnCursorUpdatePositionTimeout ()
+        {
+            UpdateHiddenCursorPosition ();
+            cursor_update_position_timeout_id = 0;
+            return false;
+        }
+        
+        private bool OnHideCursorTimeout ()
+        {
+            HideCursor ();
+            hide_cursor_timeout_id = 0;
+            return false;
+        }
+        
+        private void UpdateHiddenCursorPosition ()
+        {
+            Screen.Display.GetPointer (out hide_cursor_x, out hide_cursor_y);
+        }
+        
+        private void ShowCursor ()
+        {
+            cursor_is_hidden = false;
+            GdkWindow.Cursor = null;
+        }
+        
+        private void HideCursor ()
+        {
+            if (GdkWindow == null) {
+                return;
+            }
+            
+            Gdk.Pixmap pixmap = Gdk.Pixmap.CreateBitmapFromData (GdkWindow, "0x0", 1, 1);
+            if (pixmap == null) {
+                return;
+            }
+            
+            UpdateHiddenCursorPosition ();
+            cursor_is_hidden = true;
+            
+            Gdk.Color color = new Gdk.Color (0, 0, 0);
+            Gdk.Cursor cursor = new Gdk.Cursor (pixmap, pixmap, color, color, 0, 0);
+            
+            GdkWindow.Cursor = cursor;
+            
+            pixmap.Dispose ();
+            cursor.Dispose ();  
+        }
+        
+#endregion
+
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]