public override void ForegroundChanged(IAppStateContext context, IntPtr handle, uint processId, string processPath) { if (context.ProcessPath == processPath) { // Get title string title = NativeMethods.GetWindowText(handle); // Get padded region NativeMethods.GetWindowRect(handle, out Win32Rect rect); context.WindowDimensions = new Dimensions { Left = rect.Left, Top = rect.Top, Right = rect.Right, Bottom = rect.Bottom }; // Update state context.Handle = handle; context.ProcessId = processId; context.SetCurrentState(new LockedState()); // Start hooks context.WindowHook.StartHook(handle); context.MouseHook.StartHook(context.Padding + context.WindowDimensions); context.MouseHook.RestrictMouseToRegion(); // Update UI context.SendTitleChange(title); context.SendDimensionsChange(context.WindowDimensions); context.SendForegroundChange(true); } }
public override void Lock(IAppStateContext context, string path) { var nextState = new SpecificPath.UnlockedState(); context.SetCurrentState(nextState); nextState.Lock(context, path); }
public override void Lock(IAppStateContext context, IntPtr handle) { var nextState = new SpecificWindow.UnlockedState(); context.SetCurrentState(nextState); nextState.Lock(context, handle); }
// Constructor public AppSystem(IForegroundWindowHook fgHook, IWindowUpdateHook winHook, IMouseHook msHook) { _state = new InitialState(); _stateContext = new AppStateContext { PathModeLocksToHandle = false, ForegroundHook = fgHook, WindowHook = winHook, MouseHook = msHook, SetCurrentState = (next) => SetCurrentState(next), SendLockStateChange = () => LockStateChanged.Invoke(this, new Events.LockStateChangedEventArgs { IsLocked = IsLocked }), SendPathChange = (path) => PathChanged.Invoke(this, new Events.PathChangedEventArgs { Path = path }), SendTitleChange = (title) => TitleChanged.Invoke(this, new Events.TitleChangedEventArgs { Title = title }), SendDimensionsChange = (dimensions) => DimensionsChanged.Invoke(this, new Events.DimensionsChangedEventArgs { Dimensions = dimensions }), SendForegroundChange = (inForeground) => ForegroundChanged.Invoke(this, new Events.ForegroundStateChangedEventArgs { InForeground = inForeground }) }; fgHook.ForegroundWindowChanged += ForegroundHook_ForegroundWindowChanged; winHook.WindowClosed += WindowHook_WindowClosed; winHook.DimensionsChanged += WindowHook_DimensionsChanged; winHook.TitleChanged += WindowHook_TitleChanged; }
public override void ForegroundChanged(IAppStateContext context, IntPtr handle, uint processId, string processPath) { if (context.Handle != handle || context.ProcessId != processId || context.ProcessPath != processPath) { // Release mouse context.MouseHook.UnrestrictMouse(); // If locks to handle, retain state and wait for handle if (context.PathModeLocksToHandle) { // Update state context.SetCurrentState(new WaitingHandleState()); // Update UI context.SendForegroundChange(false); } else { // Otherwise same result as closed window WindowClosed(context); } } }
private object GetServiceInstance(Type serviceType, IAppStateContext stateContext, IServiceProvider serviceProvider) { if (serviceType == typeof(IAppStateContext)) { return(stateContext); } else if (serviceType == typeof(IServiceProvider)) { return(serviceProvider); } else if (serviceType == typeof(IAppState)) { return(stateContext.State); } else if (serviceType == typeof(IAppView)) { return(stateContext.View); } else if (serviceType == typeof(IAppStateManager)) { return(stateContext.StateManager); } return(serviceProvider.GetService(serviceType)); }
public IAppStateController CreateController(Type controllerType, IAppStateContext stateContext, IServiceProvider serviceProvider) { Debug.Assert(controllerType != null); Debug.Assert(stateContext != null); Debug.Assert(serviceProvider != null); try { var constructors = controllerType.GetConstructors(BindingFlags.Instance | BindingFlags.Public); if (constructors.Length > 0) { var c = constructors[0]; var parameters = c.GetParameters(); var args = new object[parameters.Length]; for (int i = 0; i < args.Length; i++) { args[i] = GetServiceInstance(parameters[i].ParameterType, stateContext, serviceProvider); } return((IAppStateController)c.Invoke(args)); } else { return(Activator.CreateInstance(controllerType) as IAppStateController); } } catch (TargetInvocationException e) { throw e.InnerException; } }
public virtual void PaddingChanged(IAppStateContext context, Dimensions dimensions) { // Store new padding value context.Padding = dimensions; // Trigger an update using existing window dimensions WindowDimensionsChanged(context, context.WindowDimensions); }
public override void ForegroundChanged(IAppStateContext context, IntPtr handle, uint processId, string processPath) { if (context.Handle == handle && context.ProcessId == processId && context.ProcessPath == processPath) { context.MouseHook.RestrictMouseToRegion(); context.SetCurrentState(new LockedState()); context.SendForegroundChange(true); } }
public override void ForegroundChanged(IAppStateContext context, IntPtr handle, uint processId, string processPath) { if (context.Handle != handle || context.ProcessId != processId || context.ProcessPath != processPath) { context.MouseHook.UnrestrictMouse(); context.SetCurrentState(new WaitingState()); context.SendForegroundChange(false); } }
public override void WindowDimensionsChanged(IAppStateContext context, Dimensions dimensions) { // Store dimensions context.WindowDimensions = dimensions; // Create padded dimensions var paddedDimensions = context.Padding + context.WindowDimensions; // Update system and UI context.MouseHook.SetRegion(paddedDimensions); context.SendDimensionsChange(context.WindowDimensions); }
public override void Unlock(IAppStateContext context) { // Stop hooks context.ForegroundHook.StopHook(); context.WindowHook.StopHook(); context.MouseHook.StopHook(); // Update state context.Handle = default; context.ProcessId = default; context.ProcessPath = default; context.SetCurrentState(new UnlockedState()); // Update UI context.SendLockStateChange(); }
public override void WindowClosed(IAppStateContext context) { // Stop hooks context.WindowHook.StopHook(); context.MouseHook.StopHook(); // Update state context.Handle = default; context.ProcessId = default; context.SetCurrentState(new WaitingPathState()); // Update UI context.SendTitleChange("Waiting for application"); context.SendDimensionsChange(new Dimensions(0, 0, 0, 0)); context.SendForegroundChange(false); }
public override void Lock(IAppStateContext context, IntPtr handle) { // Notify client the lock request failed if (!NativeMethods.IsWindow(handle)) { context.SendLockStateChange(); return; } // Get process id _ = NativeMethods.GetWindowThreadProcessId(handle, out uint procId); // Get process path string procPath = NativeMethods.GetFullProcessName((int)procId); // Get title string title = NativeMethods.GetWindowText(handle); // Get padded region // Upper-left and lower-right corners of the window NativeMethods.GetWindowRect(handle, out Win32Rect rect); context.WindowDimensions = new Dimensions { Left = rect.Left, Top = rect.Top, Right = rect.Right, Bottom = rect.Bottom }; // Update state context.Handle = handle; context.ProcessId = procId; context.ProcessPath = procPath; context.SetCurrentState(new WaitingState()); // Start hooks context.ForegroundHook.StartHook(); context.WindowHook.StartHook(handle); context.MouseHook.StartHook(context.Padding + context.WindowDimensions); // Update UI context.SendLockStateChange(); context.SendTitleChange(title); context.SendPathChange(procPath); context.SendDimensionsChange(context.WindowDimensions); }
public override void Lock(IAppStateContext context, string path) { // Basic input checking if (string.IsNullOrWhiteSpace(path)) { return; } // Set state context.Handle = default; context.ProcessId = default; context.ProcessPath = path; context.SetCurrentState(new WaitingPathState()); // Start hooks context.ForegroundHook.StartHook(); // Update UI context.SendLockStateChange(); context.SendPathChange(path); context.SendTitleChange("Waiting for application"); }
public virtual void WindowClosed(IAppStateContext context) { }
public virtual void Lock(IAppStateContext context, IntPtr handle) { }
public virtual void WindowDimensionsChanged(IAppStateContext context, Dimensions dimensions) { }
public virtual void Lock(IAppStateContext context, string path) { }
// No op public override void WindowClosed(IAppStateContext context) { }
public virtual void WindowTitleChanged(IAppStateContext context, string title) { }
public override void WindowTitleChanged(IAppStateContext context, string title) { // Update UI context.SendTitleChange(title); }
public virtual void Unlock(IAppStateContext context) { }
public virtual void ForegroundChanged(IAppStateContext context, IntPtr handle, uint processId, string processPath) { }
public TestController_ConstructorWithMultipleArguments(IServiceProvider sp, IAppStateContext c, object o) { ServiceProvider = sp; Context = c; Obj = o; }