bugfix with show frames

refactor/clean up
This commit is contained in:
Ulf
2013-06-14 20:46:54 +02:00
parent df11dfec82
commit c39fa0282d
6 changed files with 94 additions and 99 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

View File

@@ -38,14 +38,14 @@ namespace PreviewToy
base.OnResize(e); base.OnResize(e);
if (has_been_set_up) if (has_been_set_up)
{ {
this.spawner.set_sync_size(this.Size); this.spawner.syncronize_preview_size(this.Size);
} }
} }
protected override void OnMove(EventArgs e) protected override void OnMove(EventArgs e)
{ {
base.OnMove(e); base.OnMove(e);
this.spawner.set_preview_position(this.Handle, this.Location); this.spawner.register_preview_position(this.Handle, this.Location);
} }
protected void RefreshPreview() protected void RefreshPreview()

View File

@@ -14,10 +14,10 @@ namespace PreviewToy
{ {
public partial class PreviewToyHandler : Form public partial class PreviewToyHandler : Form
{ {
private Dictionary<IntPtr, Preview> thumbnails; private Dictionary<IntPtr, Preview> previews;
private DispatcherTimer dispatcherTimer; private DispatcherTimer dispatcherTimer;
private IntPtr last_known_active_window_; private IntPtr active_client;
private Dictionary<IntPtr, Dictionary<IntPtr, Point>> layouts; private Dictionary<IntPtr, Dictionary<IntPtr, Point>> layouts;
@@ -30,11 +30,12 @@ namespace PreviewToy
{ {
is_initialized = false; is_initialized = false;
thumbnails = new Dictionary<IntPtr, Preview>(); previews = new Dictionary<IntPtr, Preview>();
layouts = new Dictionary<IntPtr, Dictionary<IntPtr, Point>>(); layouts = new Dictionary<IntPtr, Dictionary<IntPtr, Point>>();
ignoring_size_sync = new Stopwatch(); ignoring_size_sync = new Stopwatch();
ignoring_size_sync.Start();
InitializeComponent(); InitializeComponent();
init_options(); init_options();
@@ -45,8 +46,6 @@ namespace PreviewToy
dispatcherTimer.Interval = new TimeSpan(0, 0, 1); dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start(); dispatcherTimer.Start();
is_initialized = true; is_initialized = true;
} }
@@ -85,20 +84,20 @@ namespace PreviewToy
sync_size.Width = (int)Properties.Settings.Default.sync_resize_x; sync_size.Width = (int)Properties.Settings.Default.sync_resize_x;
sync_size.Height = (int)Properties.Settings.Default.sync_resize_y; sync_size.Height = (int)Properties.Settings.Default.sync_resize_y;
if (!thumbnails.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != "") if (!previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != "")
{ {
thumbnails[process.MainWindowHandle] = new Preview(process.MainWindowHandle, "...", this, sync_size); previews[process.MainWindowHandle] = new Preview(process.MainWindowHandle, "...", this, sync_size);
thumbnails[process.MainWindowHandle].set_render_area_size(sync_size); previews[process.MainWindowHandle].set_render_area_size(sync_size);
// apply more thumbnail specific options // apply more thumbnail specific options
thumbnails[process.MainWindowHandle].TopMost = Properties.Settings.Default.always_on_top; previews[process.MainWindowHandle].TopMost = Properties.Settings.Default.always_on_top;
set_thumbnail_frame_style(thumbnails[process.MainWindowHandle], Properties.Settings.Default.show_thumb_frames); set_thumbnail_frame_style(previews[process.MainWindowHandle], Properties.Settings.Default.show_thumb_frames);
} }
else if (thumbnails.ContainsKey(process.MainWindowHandle)) //or update the preview titles else if (previews.ContainsKey(process.MainWindowHandle)) //or update the preview titles
{ {
thumbnails[process.MainWindowHandle].Text = "-> " + process.MainWindowTitle + " <-"; previews[process.MainWindowHandle].Text = "-> " + process.MainWindowTitle + " <-";
} }
} }
@@ -107,7 +106,7 @@ namespace PreviewToy
// clean up old previews // clean up old previews
List<IntPtr> to_be_pruned = new List<IntPtr>(); List<IntPtr> to_be_pruned = new List<IntPtr>();
foreach (IntPtr processHandle in thumbnails.Keys) foreach (IntPtr processHandle in previews.Keys)
{ {
if (!(processHandles.Contains(processHandle))) if (!(processHandles.Contains(processHandle)))
{ {
@@ -117,8 +116,8 @@ namespace PreviewToy
foreach (IntPtr processHandle in to_be_pruned) foreach (IntPtr processHandle in to_be_pruned)
{ {
thumbnails[processHandle].Close(); previews[processHandle].Close();
thumbnails.Remove(processHandle); previews.Remove(processHandle);
layouts.Remove(processHandle); layouts.Remove(processHandle);
} }
} }
@@ -147,39 +146,12 @@ namespace PreviewToy
} }
} }
private bool window_is_preview_or_client(IntPtr window)
private void hide_show_move_thumbnails(IntPtr last_known_active_window, IntPtr sys_activeWindow, bool active_window_is_right_type)
{ {
// hide, show, resize and move
foreach (KeyValuePair<IntPtr, Preview> entry in thumbnails)
{
if (!active_window_is_right_type && option_hide_all_if_not_right_type.Checked)
{
entry.Value.Hide();
}
else if (entry.Key == last_known_active_window && option_hide_active.Checked)
{
entry.Value.Hide();
}
else
{
entry.Value.Show();
if (option_unique_layout.Checked)
{
handle_unique_layout(entry.Value, last_known_active_window);
}
}
}
}
private bool is_active_window_right_type(IntPtr sys_activeWindow)
{
// is the active window an eve window?
bool active_window_is_right_type = false; bool active_window_is_right_type = false;
foreach (KeyValuePair<IntPtr, Preview> entry in thumbnails) foreach (KeyValuePair<IntPtr, Preview> entry in previews)
{ {
if (entry.Key == sys_activeWindow || entry.Value.Handle == sys_activeWindow || this.Handle == sys_activeWindow) if (entry.Key == window || entry.Value.Handle == window || this.Handle == window)
{ {
active_window_is_right_type = true; active_window_is_right_type = true;
} }
@@ -190,34 +162,51 @@ namespace PreviewToy
private void refresh_thumbnails() private void refresh_thumbnails()
{ {
spawn_and_kill_previews();
IntPtr sys_activeWindow = DwmApi.GetForegroundWindow(); IntPtr active_window = DwmApi.GetForegroundWindow();
Preview poo; Preview poo;
if( thumbnails.TryGetValue(sys_activeWindow, out poo) ) if (previews.TryGetValue(active_window, out poo)){
active_client = active_window;}
// hide, show, resize and move
foreach (KeyValuePair<IntPtr, Preview> entry in previews)
{ {
last_known_active_window_ = sys_activeWindow; if (!window_is_preview_or_client(active_window) && Properties.Settings.Default.hide_all)
{
entry.Value.Hide();
} }
else if (entry.Key == active_client && Properties.Settings.Default.hide_active)
{
entry.Value.Hide();
}
else
{
entry.Value.Show();
bool active_window_is_right_type = is_active_window_right_type(sys_activeWindow); if (Properties.Settings.Default.unique_layout)
hide_show_move_thumbnails(last_known_active_window_, sys_activeWindow, active_window_is_right_type); {
handle_unique_layout(entry.Value, active_client);
if (ignoring_size_sync.ElapsedMilliseconds > 500) { ignoring_size_sync.Stop(); }; }
}
}
} }
public void set_sync_size(Size sync_size) public void syncronize_preview_size(Size sync_size)
{ {
if (!is_initialized) { return; } if (!is_initialized) { return; }
if (option_sync_size.Checked && option_show_thumbnail_frames.Checked && ignoring_size_sync.ElapsedMilliseconds > 500) if (Properties.Settings.Default.sync_resize &&
Properties.Settings.Default.show_thumb_frames &&
ignoring_size_sync.ElapsedMilliseconds > 500)
{ {
ignoring_size_sync.Stop(); ignoring_size_sync.Stop();
option_sync_size_x.Text = sync_size.Width.ToString(); option_sync_size_x.Text = sync_size.Width.ToString();
option_sync_size_y.Text = sync_size.Height.ToString(); option_sync_size_y.Text = sync_size.Height.ToString();
foreach (KeyValuePair<IntPtr, Preview> entry in thumbnails) foreach (KeyValuePair<IntPtr, Preview> entry in previews)
{ {
if (entry.Value.Handle != DwmApi.GetForegroundWindow()) if (entry.Value.Handle != DwmApi.GetForegroundWindow())
{ {
@@ -230,23 +219,26 @@ namespace PreviewToy
} }
public void set_preview_position(IntPtr preview_handle, Point position) public void register_preview_position(IntPtr preview_handle, Point position)
{ {
Dictionary<IntPtr, Point> layout; Dictionary<IntPtr, Point> layout;
if (layouts.TryGetValue(last_known_active_window_, out layout)) if (layouts.TryGetValue(active_client, out layout))
{ {
layout[preview_handle] = position; layout[preview_handle] = position;
} }
else if ((int)last_known_active_window_ != 0) else if ((int)active_client != 0)
{ {
layouts[last_known_active_window_] = new Dictionary<IntPtr, Point>(); layouts[active_client] = new Dictionary<IntPtr, Point>();
layouts[last_known_active_window_][preview_handle] = position; layouts[active_client][preview_handle] = position;
} }
} }
private void dispatcherTimer_Tick(object sender, EventArgs e) private void dispatcherTimer_Tick(object sender, EventArgs e)
{ {
spawn_and_kill_previews();
refresh_thumbnails(); refresh_thumbnails();
if (ignoring_size_sync.ElapsedMilliseconds > 500) { ignoring_size_sync.Stop(); };
} }
@@ -281,9 +273,8 @@ namespace PreviewToy
refresh_thumbnails(); refresh_thumbnails();
} }
private bool try_save_size_xy()
{ private void parse_size_entry()
if (Properties.Settings.Default.sync_resize)
{ {
UInt32 x = 0, y = 0; UInt32 x = 0, y = 0;
@@ -292,35 +283,34 @@ namespace PreviewToy
y = Convert.ToUInt32(option_sync_size_y.Text); y = Convert.ToUInt32(option_sync_size_y.Text);
x = Convert.ToUInt32(option_sync_size_x.Text); x = Convert.ToUInt32(option_sync_size_x.Text);
} }
catch (System.FormatException) catch (System.FormatException) {
{ return;
return false;
} }
if (y < 64 || x < 64) if (x < 64 || y < 64)
{ {
return false; return;
} }
Properties.Settings.Default.sync_resize_y = y; Properties.Settings.Default.sync_resize_y = y;
Properties.Settings.Default.sync_resize_x = x; Properties.Settings.Default.sync_resize_x = x;
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
set_sync_size(new Size((int)x, (int)y)); // resize
} syncronize_preview_size(new Size((int)Properties.Settings.Default.sync_resize_x,
return true; (int)Properties.Settings.Default.sync_resize_y));
} }
private void option_sync_size_x_TextChanged(object sender, EventArgs e) private void option_sync_size_x_TextChanged(object sender, EventArgs e)
{ {
if (try_save_size_xy()) { } parse_size_entry();
} }
private void option_sync_size_y_TextChanged(object sender, EventArgs e) private void option_sync_size_y_TextChanged(object sender, EventArgs e)
{ {
if (try_save_size_xy()) { } parse_size_entry();
} }
@@ -328,21 +318,18 @@ namespace PreviewToy
{ {
Properties.Settings.Default.always_on_top = option_always_on_top.Checked; Properties.Settings.Default.always_on_top = option_always_on_top.Checked;
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
foreach (var thumbnail in thumbnails) foreach (var thumbnail in previews)
{ {
thumbnail.Value.TopMost = Properties.Settings.Default.always_on_top; thumbnail.Value.TopMost = Properties.Settings.Default.always_on_top;
} }
} }
private void set_thumbnail_frame_style(Preview preview, bool show_frames) void set_thumbnail_frame_style(Preview preview, bool show_frames)
{ {
if (show_frames) if (show_frames)
{ {
preview.FormBorderStyle = FormBorderStyle.SizableToolWindow; preview.FormBorderStyle = FormBorderStyle.SizableToolWindow;
ignoring_size_sync.Stop();
ignoring_size_sync.Reset();
ignoring_size_sync.Start();
} }
else else
{ {
@@ -350,15 +337,23 @@ namespace PreviewToy
} }
} }
private void option_show_thumbnail_frames_CheckedChanged(object sender, EventArgs e) private void option_show_thumbnail_frames_CheckedChanged(object sender, EventArgs e)
{ {
Properties.Settings.Default.show_thumb_frames = option_show_thumbnail_frames.Checked; Properties.Settings.Default.show_thumb_frames = option_show_thumbnail_frames.Checked;
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
foreach (var thumbnail in thumbnails)
if (Properties.Settings.Default.show_thumb_frames)
{
ignoring_size_sync.Stop();
ignoring_size_sync.Reset();
ignoring_size_sync.Start();
}
foreach (var thumbnail in previews)
{ {
set_thumbnail_frame_style(thumbnail.Value, Properties.Settings.Default.show_thumb_frames); set_thumbnail_frame_style(thumbnail.Value, Properties.Settings.Default.show_thumb_frames);
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.