From 3a88173f529cfda03601caa3e659698341dc217d Mon Sep 17 00:00:00 2001 From: Lorenz Cuno Klopfenstein Date: Sun, 8 Nov 2009 16:08:01 +0000 Subject: [PATCH] Fullscreen mode fixes (correct window selection and restoring). Window selection menu improved (click on main window menuitem). --- OnTopReplica/AspectRatioForm.cs | 2 +- OnTopReplica/CloseRequestEventArgs.cs | 8 +- OnTopReplica/FullscreenForm.cs | 220 +++++++++++++----------- OnTopReplica/MainForm.cs | 15 +- OnTopReplica/OnTopReplica.csproj | 4 +- OnTopReplica/Properties/AssemblyInfo.cs | 4 +- OnTopReplica/WindowListHelper.cs | 26 +-- 7 files changed, 150 insertions(+), 129 deletions(-) diff --git a/OnTopReplica/AspectRatioForm.cs b/OnTopReplica/AspectRatioForm.cs index d71c537..b5c0801 100644 --- a/OnTopReplica/AspectRatioForm.cs +++ b/OnTopReplica/AspectRatioForm.cs @@ -9,7 +9,7 @@ using System.Drawing; namespace OnTopReplica { /// - /// Form that automatically keeps a certain aspect ratio and resizes withour flickering. + /// Form that automatically keeps a certain aspect ratio and resizes without flickering. /// public class AspectRatioForm : GlassForm { diff --git a/OnTopReplica/CloseRequestEventArgs.cs b/OnTopReplica/CloseRequestEventArgs.cs index 3fb018c..c9d031e 100644 --- a/OnTopReplica/CloseRequestEventArgs.cs +++ b/OnTopReplica/CloseRequestEventArgs.cs @@ -1,15 +1,13 @@ using System; using System.Collections.Generic; using System.Text; +using System.Drawing; namespace OnTopReplica { public class CloseRequestEventArgs : EventArgs { - public CloseRequestEventArgs(WindowHandle lastHandle) { - CurrentWindowHandle = lastHandle; - } - - public WindowHandle CurrentWindowHandle { get; set; } + public WindowHandle LastWindowHandle { get; set; } + public Rectangle? LastRegion { get; set; } } } diff --git a/OnTopReplica/FullscreenForm.cs b/OnTopReplica/FullscreenForm.cs index 02fec99..2e451b8 100644 --- a/OnTopReplica/FullscreenForm.cs +++ b/OnTopReplica/FullscreenForm.cs @@ -5,74 +5,78 @@ using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; +using VistaControls.TaskDialog; namespace OnTopReplica { - public partial class FullscreenForm : Form { + public partial class FullscreenForm : Form { - public FullscreenForm() { - InitializeComponent(); + public FullscreenForm() { + InitializeComponent(); - _thumbnail.GlassMode = true; + _thumbnail.GlassMode = true; - //Set native renderer on context menu - Asztal.Szótár.NativeToolStripRenderer.SetToolStripRenderer(new Control[] { + //Set native renderer on context menu + Asztal.Szótár.NativeToolStripRenderer.SetToolStripRenderer(new Control[] { menuContext, menuWindows }); - _cursorTimer = new Timer(); + /*_cursorTimer = new Timer(); _cursorTimer.Interval = 1000; - _cursorTimer.Tick += new EventHandler(_cursorTimer_Tick); - } + _cursorTimer.Tick += new EventHandler(_cursorTimer_Tick);*/ + } - Timer _cursorTimer; + //Timer _cursorTimer; - WindowHandle _lastHandle; - WindowManager _manager = new WindowManager(WindowManager.EnumerationMode.TaskWindows); + WindowHandle _lastHandle; + WindowManager _manager = new WindowManager(WindowManager.EnumerationMode.TaskWindows); - public void DisplayFullscreen(Screen screen, WindowHandle window) { - _lastHandle = window; + public void DisplayFullscreen(Screen screen, WindowHandle window) { + _lastHandle = window; - //Init thumbnail - _thumbnail.SetThumbnailHandle(window); + //Init thumbnail + _thumbnail.SetThumbnailHandle(window); - //Form setup - this.Location = screen.WorkingArea.Location; - this.Size = screen.WorkingArea.Size; - } + //Form setup + this.Location = screen.WorkingArea.Location; + this.Size = screen.WorkingArea.Size; + } - public void CloseFullscreen() { - this.Visible = false; + public void CloseFullscreen() { + this.Visible = false; - _thumbnail.UnsetThumbnail(); - } + _thumbnail.UnsetThumbnail(); + } - public Rectangle ShownRegion { - get { - return _thumbnail.ShownRegion; - } - set { - _thumbnail.ShownRegion = value; - } - } + public Rectangle ShownRegion { + get { + return _thumbnail.ShownRegion; + } + set { + _thumbnail.ShownRegion = value; + } + } - public bool ShowRegion { - get { - return _thumbnail.ShowRegion; - } - set { - _thumbnail.ShowRegion = value; - } - } + public bool ShowRegion { + get { + return _thumbnail.ShowRegion; + } + set { + _thumbnail.ShowRegion = value; + } + } - public event EventHandler CloseRequest; + public event EventHandler CloseRequest; - protected virtual void OnCloseRequest() { - if (CloseRequest != null) - CloseRequest(this, new CloseRequestEventArgs(_lastHandle)); - } + protected virtual void OnCloseRequest() { + if (CloseRequest != null) + CloseRequest(this, new CloseRequestEventArgs { + LastWindowHandle = _lastHandle, + LastRegion = (_thumbnail.ShowRegion) ? (Rectangle?)_thumbnail.ShownRegion : null + }); + } - protected override void OnActivated(EventArgs e) { + /*protected override void OnActivated(EventArgs e) { _cursorTimer.Start(); base.OnActivated(e); @@ -107,84 +111,94 @@ namespace OnTopReplica { void _cursorTimer_Tick(object sender, EventArgs e) { Cursor.Hide(); _cursorTimer.Stop(); + }*/ + + protected override void OnDoubleClick(EventArgs e) { + OnCloseRequest(); + + base.OnDoubleClick(e); } - protected override void OnDoubleClick(EventArgs e) { - OnCloseRequest(); - - base.OnDoubleClick(e); - } - - protected override void OnKeyUp(KeyEventArgs e) { - if (e.KeyCode == Keys.Escape) { - e.Handled = true; - OnCloseRequest(); - } + protected override void OnKeyUp(KeyEventArgs e) { + if (e.KeyCode == Keys.Escape) { + e.Handled = true; + OnCloseRequest(); + } else if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Alt) { e.Handled = true; OnCloseRequest(); } - base.OnKeyUp(e); - } + base.OnKeyUp(e); + } - bool _clickThrough = false; + bool _clickThrough = false; - public bool ClickThrough { - get { - return _clickThrough; - } - set { - _clickThrough = value; + public bool ClickThrough { + get { + return _clickThrough; + } + set { + _clickThrough = value; - this.TransparencyKey = (value) ? Color.Black : Color.White; - this.Invalidate(); - } - } + this.TransparencyKey = (value) ? Color.Black : Color.White; + this.Invalidate(); + } + } - const int WM_NCHITTEST = 0x0084; - const int HTTRANSPARENT = -1; + const int WM_NCHITTEST = 0x0084; + const int HTTRANSPARENT = -1; - protected override void WndProc(ref Message m) { - if (_clickThrough && m.Msg == WM_NCHITTEST) { - m.Result = new IntPtr(HTTRANSPARENT); - return; - } + protected override void WndProc(ref Message m) { + if (_clickThrough && m.Msg == WM_NCHITTEST) { + m.Result = new IntPtr(HTTRANSPARENT); + return; + } - base.WndProc(ref m); - } + base.WndProc(ref m); + } - private void Menu_Quit_click(object sender, EventArgs e) { - OnCloseRequest(); - } + private void Menu_Quit_click(object sender, EventArgs e) { + OnCloseRequest(); + } - private void Menu_Windows_opening(object sender, EventArgs e) { - _manager.Refresh(WindowManager.EnumerationMode.TaskWindows); + private void Menu_Windows_opening(object sender, EventArgs e) { + _manager.Refresh(WindowManager.EnumerationMode.TaskWindows); - WindowListHelper.PopulateMenu(_manager, menuWindows, _lastHandle, new EventHandler(Menu_Window_click)); - } + WindowListHelper.PopulateMenu(this, _manager, menuWindows, _lastHandle, new EventHandler(Menu_Window_click)); + } - void Menu_Window_click(object sender, EventArgs e) { - //Get clicked item and window index from tag - ToolStripItem tsi = (ToolStripItem)sender; + void Menu_Window_click(object sender, EventArgs e) { + //Ensure menu is closed + menuContext.Close(); - //Handle -none- selection - if (tsi.Tag == null) { - OnCloseRequest(); - return; - } + //Get clicked item and window index from tag + ToolStripItem tsi = (ToolStripItem)sender; - int index = (int)tsi.Tag; + var windowData = tsi.Tag as WindowListHelper.WindowSelectionData; - if (index >= _manager.Windows.Count) - return; + //Handle "-none-" window request + if (windowData == null) { + OnCloseRequest(); + return; + } - var handle = _manager.Windows[index]; + try { + _thumbnail.SetThumbnailHandle(windowData.Handle); + if (windowData.Region != null) { + _thumbnail.ShownRegion = windowData.Region.Rect; + _thumbnail.ShowRegion = true; + } + else { + _thumbnail.ShowRegion = false; + } + _lastHandle = windowData.Handle; + } + catch (Exception) { + OnCloseRequest(); + } + } - _thumbnail.SetThumbnailHandle(handle); - _lastHandle = handle; - } - - } + } } diff --git a/OnTopReplica/MainForm.cs b/OnTopReplica/MainForm.cs index c72f073..2af8efb 100644 --- a/OnTopReplica/MainForm.cs +++ b/OnTopReplica/MainForm.cs @@ -76,11 +76,11 @@ namespace OnTopReplica void FullscreenForm_CloseRequest(object sender, CloseRequestEventArgs e) { if (_isFullscreen) { - //Update handle to match the one selected in fullscreen mode - if (_lastWindowHandle != e.CurrentWindowHandle) { - _lastWindowHandle = e.CurrentWindowHandle; - _thumbnailPanel.SetThumbnailHandle(e.CurrentWindowHandle); - } + var regionContainer = (e.LastRegion != null) ? + new StoredRegion { Rect = e.LastRegion.Value } : null; + + //Update handle to match the one selected in fullscreen mode + ThumbnailSet(e.LastWindowHandle, regionContainer); ToggleFullscreen(); } @@ -439,6 +439,9 @@ namespace OnTopReplica } void Menu_Windows_itemclick(object sender, EventArgs e) { + //Insure the menu is closed + menuContext.Close(); + //Get clicked item and window index from tag ToolStripItem tsi = (ToolStripItem)sender; @@ -629,7 +632,7 @@ namespace OnTopReplica //Refresh window list _windowManager.Refresh(WindowManager.EnumerationMode.TaskWindows); - WindowListHelper.PopulateMenu(_windowManager, menuWindows, _lastWindowHandle, new EventHandler(Menu_Windows_itemclick)); + WindowListHelper.PopulateMenu(this, _windowManager, menuWindows, _lastWindowHandle, new EventHandler(Menu_Windows_itemclick)); } private void Menu_Chrome_click(object sender, EventArgs e) { diff --git a/OnTopReplica/OnTopReplica.csproj b/OnTopReplica/OnTopReplica.csproj index 50b23f1..0be85c8 100644 --- a/OnTopReplica/OnTopReplica.csproj +++ b/OnTopReplica/OnTopReplica.csproj @@ -49,8 +49,8 @@ true publish.htm false - 2 - 2.8.0.%2a + 1 + 2.8.1.%2a false true true diff --git a/OnTopReplica/Properties/AssemblyInfo.cs b/OnTopReplica/Properties/AssemblyInfo.cs index 364d0ef..fce3f03 100644 --- a/OnTopReplica/Properties/AssemblyInfo.cs +++ b/OnTopReplica/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.8.0.0")] -[assembly: AssemblyFileVersion("2.8.0.0")] +[assembly: AssemblyVersion("2.8.1.0")] +[assembly: AssemblyFileVersion("2.8.1.0")] diff --git a/OnTopReplica/WindowListHelper.cs b/OnTopReplica/WindowListHelper.cs index e1306b4..dbec10f 100644 --- a/OnTopReplica/WindowListHelper.cs +++ b/OnTopReplica/WindowListHelper.cs @@ -14,7 +14,7 @@ namespace OnTopReplica { const int cMaxWindowTitleLength = 55; - public static void PopulateMenu(WindowManager windowManager, ToolStrip menu, + public static void PopulateMenu(Form ownerForm, WindowManager windowManager, ToolStrip menu, WindowHandle currentHandle, EventHandler clickHandler) { var regions = Settings.Default.SavedRegions; @@ -30,8 +30,13 @@ namespace OnTopReplica { //Add an item for each window foreach (WindowHandle h in windowManager.Windows) { + //Skip if in the same process + if (h.Handle.Equals(ownerForm.Handle)) + continue; + var tsi = new ToolStripMenuItem(); + //Window title if (h.Title.Length > cMaxWindowTitleLength) { tsi.Text = h.Title.Substring(0, cMaxWindowTitleLength) + "..."; tsi.ToolTipText = h.Title; @@ -39,12 +44,21 @@ namespace OnTopReplica { else tsi.Text = h.Title; - //tsi.Click += clickHandler; + //Icon if (h.Icon != null) { tsi.Image = h.Icon.ToBitmap(); } + + //Check if this is the currently displayed window tsi.Checked = h.Equals(currentHandle); + //Add direct click if no stored regions + tsi.Tag = new WindowSelectionData { + Handle = h, + Region = null + }; + tsi.Click += clickHandler; + if (regions != null && regions.Count > 0) { //Add subitem for no region var nullRegionItem = new ToolStripMenuItem(Strings.MenuWindowsWholeRegion); @@ -68,14 +82,6 @@ namespace OnTopReplica { tsi.DropDownItems.Add(regionItem); } } - else { - //Add direct click if no stored regions - tsi.Tag = new WindowSelectionData { - Handle = h, - Region = null - }; - tsi.Click += clickHandler; - } menu.Items.Add(tsi); }