Navigation Menu

Skip to content

Commit

Permalink
More hacks for focusing on putty.
Browse files Browse the repository at this point in the history
Another hack for my quest to have the putty window properly focused.
This deals with when you maximize/restore and minimize & restore.
Previously, the putty window will lose focus. Not anymore!
  • Loading branch information
peaches committed May 15, 2012
1 parent 04fcc34 commit 30d1913
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
25 changes: 25 additions & 0 deletions SuperPutty/Classes/RestoreFromMinimizedTracker.cs
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SuperPutty.Classes
{
class RestoreFromMinimizedTracker : WindowEventHandler
{
const int EVENT_SYSTEM_MINIMIZEEND = 23;

public RestoreFromMinimizedTracker(frmSuperPutty form) : base(form)
{
HookEvent(EVENT_SYSTEM_MINIMIZEEND);
}

protected override void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
if (hwnd == this.m_form.Handle)
{
this.m_form.FocusCurrentTab();
}
}
}
}
1 change: 1 addition & 0 deletions SuperPutty/SuperPutty.csproj
Expand Up @@ -100,6 +100,7 @@
<Compile Include="Classes\Database.cs" />
<Compile Include="Classes\GlobalHotkeys.cs" />
<Compile Include="Classes\KeyboardListener.cs" />
<Compile Include="Classes\RestoreFromMinimizedTracker.cs" />
<Compile Include="Classes\WindowEventHandler.cs" />
<Compile Include="Classes\WindowTitleTracker.cs" />
<Compile Include="ctlApplicationPanel.cs">
Expand Down
22 changes: 20 additions & 2 deletions SuperPutty/frmSuperPutty.cs
Expand Up @@ -97,6 +97,7 @@ public frmSuperPutty(string[] args)
m_hotkeys = new GlobalHotkeys();
m_keyboard = new KeyboardListener(this, m_hotkeys);
m_titleTracker = new WindowTitleTracker(this);
registerHotkeys();

// Check SQLite Database
openOrCreateSQLiteDatabase();
Expand Down Expand Up @@ -186,7 +187,6 @@ public frmSuperPutty(string[] args)
// Set window state and size
setWindowStateAndSize();

registerHotkeys();

focusHacks();
}
Expand Down Expand Up @@ -589,7 +589,7 @@ private void selectTab(GlobalHotkeys.Purpose tabPosition)

private void selectTab(int index)
{
if (this.children.Count > 1)
if (this.children.Count > 1 && this.children.Count > (index + 1))
{
this.dockPanel1.ActiveContent.DockHandler.SetActiveTab(index);
}
Expand Down Expand Up @@ -895,6 +895,7 @@ private void quickConnectToolStripMenuItem_Click(object sender, EventArgs e)
private DateTime m_lastMouseDownOnTitleBar = DateTime.Now;
private TimeSpan m_delayUntilMouseMove = new TimeSpan(0, 0, 0, 0, 200); // 200ms
private Point m_mouseDownLocation = new Point(0, 0);
private RestoreFromMinimizedTracker m_restoreFromMinimized;

private int GET_X_LPARAM(int lParam)
{
Expand All @@ -911,6 +912,11 @@ private bool WndProcForFocus(ref Message m)
const int WM_NCLBUTTONDOWN = 0x00A1;
const int WM_NCMOUSEMOVE = 0x00A0;
const int WM_NCACTIVATE = 0x0086;
const int WM_SYSCOMMAND = 0x0112;

const int SC_MINIMIZE = 0xF030;
const int SC_RESTORE = 0xF120;
const int SC_DRAGMOVE = 0xF012;

switch (m.Msg)
{
Expand All @@ -937,6 +943,17 @@ private bool WndProcForFocus(ref Message m)
DefWindowProc(this.Handle, m.Msg, (IntPtr)1, m.LParam);
m.Result = (IntPtr)1;
return false;
case WM_SYSCOMMAND:
// Removing the last 4 bits. This is necessary because
// maximizing by double click gives you 0xF032, not 0xF030.
switch ((int)m.WParam & 0xFFF0)
{
case SC_MINIMIZE:
case SC_RESTORE:
FocusCurrentTab();
break;
}
break;
default:
if (m.Msg == m_shellHookNotify)
{
Expand Down Expand Up @@ -973,6 +990,7 @@ private void focusHacks()
this.ResizeEnd += HandleResizeEnd;
m_shellHookNotify = RegisterWindowMessage("SHELLHOOK");
RegisterShellHookWindow(this.Handle);
m_restoreFromMinimized = new RestoreFromMinimizedTracker(this);
}

// Handle various events to keep the child window focused
Expand Down

0 comments on commit 30d1913

Please sign in to comment.