private void RestoreTerminalState(TerminalWindow terminalWindow)
 {
     terminalWindow.Width  = config.Width;
     terminalWindow.Height = config.Height;
     terminalWindow.Left   = config.OffsetLeft;
     if (config.Center)
     {
         terminalWindow.CenterHorizontally();
     }
 }
        public void ResizeAndPosition()
        {
            User32.Rect rect = default;
            User32.GetWindowRect(process.MainWindowHandle, ref rect);

            var terminalWindow = new TerminalWindow(rect, GetScreenWithCursor().Bounds);

            SaveTerminalState(terminalWindow);
            if (config.Center)
            {
                terminalWindow.CenterHorizontally();
            }
            ShowTerminal(terminalWindow);
        }
        private void ShowTerminalWithEffects(TerminalWindow terminalWindow)
        {
            Console.WriteLine("Open");
            terminalWindow.Left   = config.OffsetLeft;
            terminalWindow.Width  = config.Width;
            terminalWindow.Top    = -config.Height;
            terminalWindow.Height = config.Height;
            terminalWindow.EnsureWillFitOnScreen();

            if (config.Center)
            {
                terminalWindow.CenterHorizontally();
            }

            User32.MoveWindow(
                process.MainWindowHandle,
                terminalWindow.ScreenX,
                terminalWindow.ScreenY - terminalWindow.Height,
                terminalWindow.Width,
                terminalWindow.Height,
                true
                );

            // todo - this flashes the window at it's prior position if it was minimized.
            User32.ShowWindow(process.MainWindowHandle, NCmdShow.RESTORE);

            User32.SetForegroundWindow(process.MainWindowHandle);

            var stepSize = (double)config.Height / (double)stepCount;

            for (int i = 1; i <= stepCount; i++)
            {
                User32.MoveWindow(
                    process.MainWindowHandle,
                    terminalWindow.ScreenX,
                    terminalWindow.ScreenY + (int)Math.Round(stepSize * i),
                    terminalWindow.Width,
                    terminalWindow.Height,
                    true
                    );

                Task.Delay(1).GetAwaiter().GetResult();
            }
            User32.ShowWindow(process.MainWindowHandle, NCmdShow.SHOW);
        }
        public Toggler(Process _process, Config _config)
        {
            process = _process;
            config  = _config;

            // Hide from taskbar
            User32.SetWindowLong(process.MainWindowHandle, User32.GWL_EX_STYLE, (User32.GetWindowLong(process.MainWindowHandle, User32.GWL_EX_STYLE) | User32.WS_EX_TOOLWINDOW) & ~User32.WS_EX_APPWINDOW);

            if (config.Maximize)
            {
                User32.ShowWindow(process.MainWindowHandle, NCmdShow.MAXIMIZE);
            }

            User32.Rect rect = default;
            User32.GetWindowRect(process.MainWindowHandle, ref rect);
            var terminalWindow = new TerminalWindow(rect, GetScreenWithCursor().Bounds);

            if (config.Center)
            {
                terminalWindow.CenterHorizontally();
            }
            terminalWindow.EnsureVisible();
            if (config.Width == 0 || config.Height == 0)
            {
                SaveTerminalState(terminalWindow);
            }
            else
            {
                RestoreTerminalState(terminalWindow);
            }

            User32.MoveWindow(_process.MainWindowHandle, terminalWindow.ScreenX, terminalWindow.ScreenY, terminalWindow.Width, terminalWindow.Height, true);
            User32.ShowWindow(_process.MainWindowHandle, NCmdShow.SHOW);
            User32.SetForegroundWindow(_process.MainWindowHandle);

            HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Control);
            HotKeyManager.RegisterHotKey(Keys.Q, KeyModifiers.Control);

            HotKeyManager.HotKeyPressed += handleHotKeyPressed;
        }