Skip to content

Commit

Permalink
optimize foreground change performance
Browse files Browse the repository at this point in the history
  • Loading branch information
TransposonY committed Apr 5, 2015
1 parent 68cf3c1 commit c302bf7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions GestureSign.Common/Applications/ApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public bool IsSystemWindowMatch(SystemWindow Window)

break;
case MatchUsing.ExecutableFilename:
windowMatchString = Window.Process.MainModule.ModuleName;//System.IO.Path.GetFileName(.FileName;
windowMatchString = Window.ProcessName;//.MainModule.ModuleName;//System.IO.Path.GetFileName(.FileName;

break;
case MatchUsing.All:
return true;
}

return IsRegEx ? Regex.IsMatch(windowMatchString, compareMatchString, RegexOptions.Singleline | RegexOptions.IgnoreCase) : windowMatchString.Trim().ToLower() == compareMatchString.Trim().ToLower();
return IsRegEx ? Regex.IsMatch(windowMatchString, compareMatchString, RegexOptions.Singleline | RegexOptions.IgnoreCase) : String.Equals(windowMatchString.Trim(), compareMatchString.Trim(), StringComparison.CurrentCultureIgnoreCase);
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion GestureSignDaemon/Input/InitializationRatio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void MessageWindow_PointsIntercepted(object sender, GestureSign.Common.In
MessageProcessor.OnGotTouchPoint -= MessageProcessor_OnGotTouchPoint;
messageWindow.PointsIntercepted -= MessageWindow_PointsIntercepted;
messageWindow.PointerIntercepted -= MessageWindow_PointerIntercepted;

messageWindow.Unregister();
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions GestureSignDaemon/Input/MessageWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const int
public bool IsRegistered
{
get { return isRegistered; }
set
private set
{
if (value)
{
Expand Down Expand Up @@ -220,7 +220,11 @@ private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int
{
if (OnForegroundChange != null) OnForegroundChange(this, hwnd);
}

public void Unregister()
{
if (IsRegistered)
Invoke(new Action(() => IsRegistered = false));
}
public void ToggleRegister(object sender, bool e)
{
if (e && !AppConfig.InterceptTouchInput) return;
Expand Down
2 changes: 1 addition & 1 deletion GestureSignDaemon/Input/TouchCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected TouchCapture()

void messageWindow_OnForegroundChange(object sender, IntPtr e)
{
if (e.Equals(IntPtr.Zero) || Application.OpenForms.Count != 0 && e.Equals(Application.OpenForms[0].Handle))
if (State != CaptureState.Ready || e.Equals(IntPtr.Zero) || Application.OpenForms.Count != 0 && e.Equals(Application.OpenForms[0].Handle))
return;

bool flag =
Expand Down
12 changes: 11 additions & 1 deletion ManagedWinapi/SystemWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,19 +816,29 @@ public bool IsDescendantOf(SystemWindow ancestor)
return IsChild(ancestor._hwnd, _hwnd);
}

private Process _process;
/// <summary>
/// The process which created this window.
/// </summary>
public Process Process
{
get
{
if (_process != null) return _process;
int pid;
GetWindowThreadProcessId(HWnd, out pid);
return Process.GetProcessById(pid);
_process = Process.GetProcessById(pid);
return _process;
}
}

private string _processName;

public string ProcessName
{
get { return _processName ?? (_processName = Process.ProcessName + ".exe"); }
}

/// <summary>
/// The Thread which created this window.
/// </summary>
Expand Down

0 comments on commit c302bf7

Please sign in to comment.