Пример #1
0
        private void spawnNearWindow()
        {
            Win32.GUITHREADINFO gui = new Win32.GUITHREADINFO();
            gui.cbSize = Marshal.SizeOf(gui);
            bool success = Win32.GetGUIThreadInfo(0, ref gui);

            if (success)
            {
                if (gui.hwndActive != IntPtr.Zero)
                {
                    Win32.RECT windowRect = new Win32.RECT();
                    bool       success2   = Win32.GetWindowRect(gui.hwndActive, ref windowRect);
                    if (success2)
                    {
                        var windowPlacement        = ((App)Application.Current).Preferences.windowPlacement;
                        var insideOutsidePlacement = ((App)Application.Current).Preferences.insideOutsidePlacement;
                        WindowUtils.PutWindowNear(this, windowRect.asRect(), windowPlacement, insideOutsidePlacement);
                    }
                }
                else
                {
                    // No active window -- spawn somewhere in the active monitor instead
                    spawnInMonitor();
                }
            }
            else
            {
                // TODO: log these, don't crash
                throw new Win32Exception();
            }
        }
Пример #2
0
        private void spawnInMonitor()
        {
            Rect rect = Rect.Empty;

            // Use the active window to determine the active monitor
            Win32.GUITHREADINFO gui = new Win32.GUITHREADINFO();
            gui.cbSize = Marshal.SizeOf(gui);
            bool success = Win32.GetGUIThreadInfo(0, ref gui);

            if (success)
            {
                if (gui.hwndActive != IntPtr.Zero)
                {
                    Win32.RECT windowRect = new Win32.RECT();
                    bool       success2   = Win32.GetWindowRect(gui.hwndActive, ref windowRect);
                    if (success2)
                    {
                        rect = windowRect.asRect();
                    }
                }
            }

            // If that fails, use the cursor to determine the active monitor
            if (rect.IsEmpty)
            {
                int left = System.Windows.Forms.Cursor.Position.X;
                int top  = System.Windows.Forms.Cursor.Position.Y;
                rect = new Rect(left, top, 0, 0);
            }

            PlacementSide monitorPlacement = ((App)Application.Current).Preferences.monitorPlacement;

            WindowUtils.PutWindowNear(this, WindowUtils.MonitorWorkAreaFromRect(rect), monitorPlacement, PlacementInOut.INSIDE);
        }
Пример #3
0
        private void spawnNearCursor()
        {
            int left = System.Windows.Forms.Cursor.Position.X;
            int top  = System.Windows.Forms.Cursor.Position.Y;

            WindowUtils.PutWindowNear(this, new Rect(left, top, 0, 0), PlacementSide.CENTER, PlacementInOut.INSIDE);
        }
Пример #4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            int left = System.Windows.Forms.Cursor.Position.X;
            int top  = System.Windows.Forms.Cursor.Position.Y;

            UpdateLayout();
            WindowUtils.PutWindowNear(this, new Rect(left, top, 0, 0), PlacementSide.CENTER, PlacementInOut.INSIDE);
        }
Пример #5
0
        private bool putNearTextCaret()
        {
            Win32.GUITHREADINFO gui = new Win32.GUITHREADINFO();
            gui.cbSize = Marshal.SizeOf(gui);
            bool success = Win32.GetGUIThreadInfo(0, ref gui);

            if (success)
            {
                if (gui.hwndCaret == IntPtr.Zero)
                {
                    /* The focused application has no caret information, so
                     * gracefully degrade to some alternative method. */
                    return(false);
                }
                else
                {
                    /* The GUI's caret position is relative to its control,
                     * so get the control's position and add the two. */
                    Win32.RECT windowRect = new Win32.RECT();
                    bool       success2   = Win32.GetWindowRect(gui.hwndCaret, ref windowRect);
                    if (success2)
                    {
                        Rect caretRect = gui.rcCaret.asRect();
                        caretRect.X += windowRect.left;
                        caretRect.Y += windowRect.top;
                        WindowUtils.PutWindowNear(this, caretRect, PlacementSide.BOTTOM_LEFT, PlacementInOut.OUTSIDE);
                        return(true);
                    }
                    else
                    {
                        /* TODO: before production release, handle these
                         * exceptions and always fall back to cursor pos */
                        throw new Win32Exception();
                    }
                }
            }
            else
            {
                // TODO: see above
                throw new Win32Exception();
            }
        }