Fullscreen mode fixes (correct window selection and restoring).

Window selection menu improved (click on main window menuitem).
This commit is contained in:
Lorenz Cuno Klopfenstein 2009-11-08 16:08:01 +00:00
parent 636c2b6922
commit 3a88173f52
7 changed files with 150 additions and 129 deletions

View file

@ -9,7 +9,7 @@ using System.Drawing;
namespace OnTopReplica {
/// <summary>
/// Form that automatically keeps a certain aspect ratio and resizes withour flickering.
/// Form that automatically keeps a certain aspect ratio and resizes without flickering.
/// </summary>
public class AspectRatioForm : GlassForm {

View file

@ -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; }
}
}

View file

@ -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<CloseRequestEventArgs> CloseRequest;
public event EventHandler<CloseRequestEventArgs> 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;
}
}
}
}

View file

@ -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) {

View file

@ -49,8 +49,8 @@
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>2</ApplicationRevision>
<ApplicationVersion>2.8.0.%2a</ApplicationVersion>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>2.8.1.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>

View file

@ -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")]

View file

@ -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);
}