Exemple #1
0
 private int SnapRight(ScreenSettings settings, int x = 0)
 {
     // Set left edge of window to to an off-screen grid cell at the right edge of screen.
     x += settings.ScreenArea.Width;
     x  = MoveLeft(settings, x);
     return(x);
 }
Exemple #2
0
 private int SnapDown(ScreenSettings settings, int y = 0)
 {
     // Set top edge of window to to an off-screen grid cell at the bottom edge of screen.
     y += settings.ScreenArea.Height;
     y  = MoveUp(settings, y);
     return(y);
 }
Exemple #3
0
 private int MoveDown(ScreenSettings settings, int y)
 {
     // Get y coordinate after moving the window one grid cell to the bottom.
     y += settings.GridCellHeight;
     // Get y coordinate of the grid cell the window should be snapped to.
     y -= settings.GridCellYOffset(y);
     return(y);
 }
Exemple #4
0
 private int MoveRight(ScreenSettings settings, int x)
 {
     // Get x coordinate after moving the window one grid cell to the right.
     x += settings.GridCellWidth;
     // Get x coordinate of the grid cell the window should be snapped to.
     x -= settings.GridCellXOffset(x);
     return(x);
 }
Exemple #5
0
 private int MoveUp(ScreenSettings settings, int y)
 {
     // If window is currently snapped to the edge of a grid cell, make sure to snap it to the
     //  adjacent grid cell on the top.
     y -= 1 + settings.GridOddRow;
     // Get y coordinate of the grid cell the window should be snapped to.
     y -= settings.GridCellYOffset(y);
     return(y);
 }
Exemple #6
0
 private int MoveLeft(ScreenSettings settings, int x)
 {
     // If window is currently snapped to the edge of a grid cell, make sure to snap it to the
     //  adjacent grid cell on the left.
     x -= 1 + settings.GridOddCol;
     // Get x coordinate of the grid cell the window should be snapped to.
     x -= settings.GridCellXOffset(x);
     return(x);
 }
Exemple #7
0
 internal ScreenSettings GetScreenSettings(Screen s)
 {
     if (!screenSettings.TryGetValue(s.DeviceName, out ScreenSettings settings))
     {
         settings = new ScreenSettings();
         screenSettings[s.DeviceName] = settings;
     }
     settings.Refresh(s);
     return(settings);
 }
Exemple #8
0
        private void ExpandDown(IntPtr window, WINDOWPLACEMENT wndPl, ref RECT rect, RECT margins, ScreenSettings settings)
        {
            int y;

            switch (wndPl.showCmd)
            {
            case SW_SHOWNORMAL:
                // Get y coordinate of bottom edge of the window, relative to the top edge of its screen.
                y = rect.bottom - margins.bottom - settings.ScreenArea.Top;
                // If window is currently snapped to the edge of a grid cell, make sure to snap it to the
                //  adjacent grid cell on the bottom.
                y += 1 + settings.GridOddRow;
                y  = MoveDown(settings, y);
                break;

            case SW_SHOWMAXIMIZED:
                // Snap window to rightmost grid cell on the screen.
                y = 1 + settings.GridOddRow;
                y = SnapDown(settings, y);
                break;

            default:
                throw new Exception();
            }

            if (y > settings.ScreenArea.Height - settings.GridOddRow)
            {
                if (rect.top - margins.top - settings.ScreenArea.Top >= settings.ScreenArea.Height - settings.GridOddRow)
                {
                    // Window is entirely off screen. Don't do anything.
                    return;
                }
                y = settings.ScreenArea.Height - settings.GridOddRow;
            }

            rect.bottom = settings.ScreenArea.Top + y + margins.bottom;
        }
Exemple #9
0
        private void ExpandRight(IntPtr window, WINDOWPLACEMENT wndPl, ref RECT rect, RECT margins, ScreenSettings settings)
        {
            int x;

            switch (wndPl.showCmd)
            {
            case SW_SHOWNORMAL:
                // Get x coordinate of right edge of the window, relative to the left edge of its screen.
                x = rect.right - margins.right - settings.ScreenArea.Left;
                // If window is currently snapped to the edge of a grid cell, make sure to snap it to the
                //  adjacent grid cell on the right.
                x += 1 + settings.GridOddCol;
                x  = MoveRight(settings, x);
                break;

            case SW_SHOWMAXIMIZED:
                // Snap window to rightmost grid cell on the screen.
                x = 1 + settings.GridOddCol;
                x = SnapRight(settings, x);
                break;

            default:
                throw new Exception();
            }

            if (x > settings.ScreenArea.Width - settings.GridOddCol)
            {
                if (rect.left - margins.left - settings.ScreenArea.Left >= settings.ScreenArea.Width - settings.GridOddCol)
                {
                    // Window is entirely off screen. Don't do anything.
                    return;
                }
                x = settings.ScreenArea.Width - settings.GridOddCol;
            }

            rect.right = settings.ScreenArea.Left + x + margins.right;
        }
Exemple #10
0
        private void ShrinkUp(IntPtr window, WINDOWPLACEMENT wndPl, ref RECT rect, RECT margins, ScreenSettings settings)
        {
            int y;

            switch (wndPl.showCmd)
            {
            case SW_SHOWNORMAL:
                // Get y coordinate of bottom edge of the window, relative to the top edge of its screen.
                y = rect.bottom - margins.bottom - settings.ScreenArea.Top;
                y = MoveUp(settings, y);
                break;

            case SW_SHOWMAXIMIZED:
                // Snap window to second-bottommost grid cell on the screen.
                y = SnapDown(settings);
                break;

            default:
                throw new Exception();
            }

            if ((rect.bottom - margins.bottom) - (rect.top - margins.top) <= settings.GridCellHeight)
            {
                // Make sure the window has a positive height.
                return;
            }

            rect.bottom = settings.ScreenArea.Top + y + margins.bottom;
        }
Exemple #11
0
        private void ShrinkLeft(IntPtr window, WINDOWPLACEMENT wndPl, ref RECT rect, RECT margins, ScreenSettings settings)
        {
            int x;

            switch (wndPl.showCmd)
            {
            case SW_SHOWNORMAL:
                // Get x coordinate of right edge of the window, relative to the left edge of its screen.
                x = rect.right - margins.right - settings.ScreenArea.Left;
                x = MoveLeft(settings, x);
                break;

            case SW_SHOWMAXIMIZED:
                // Snap window to second-rightmost grid cell on the screen.
                x = SnapRight(settings);
                break;

            default:
                throw new Exception();
            }

            if ((rect.right - margins.right) - (rect.left - margins.left) <= settings.GridCellWidth)
            {
                // Make sure the window has a positive width.
                return;
            }

            rect.right = settings.ScreenArea.Left + x + margins.right;
        }
Exemple #12
0
        private void MoveDown(IntPtr window, WINDOWPLACEMENT wndPl, ref RECT rect, RECT margins, ScreenSettings settings)
        {
            int y;

            switch (wndPl.showCmd)
            {
            case SW_SHOWNORMAL:
                // Get y coordinate of top edge of the window, relative to the top edge of its screen.
                y = rect.top - margins.top - settings.ScreenArea.Top;
                y = MoveDown(settings, y);
                break;

            case SW_SHOWMAXIMIZED:
                // Snap window to bottommost grid cell on the screen.
                y = SnapDown(settings);
                break;

            default:
                throw new Exception();
            }

            if (y >= settings.ScreenArea.Height - settings.GridOddRow)
            {
                // Window has moved to the adjacent screen on the bottom.
                var adjScreen = Screen.FromPoint(new Point((settings.ScreenArea.Left + settings.ScreenArea.Right) / 2, settings.ScreenArea.Bottom + 1));
                if (adjScreen.Equals(Screen.FromHandle(window)))
                {
                    // No more screens to the bottom. Keep the window on the same screen.
                    y = SnapDown(settings);
                }
                else
                {
                    // Snap the window to the topmost cell of the adjacent screen on the bottom.
                    settings = GetScreenSettings(adjScreen);
                    y        = SnapUp(settings);
                }
            }

            rect.top    = settings.ScreenArea.Top + y + margins.top;
            rect.bottom = rect.top + settings.GridCellHeight - margins.top + margins.bottom;
            // Expand the window to take the full height of the screen.
            //rect.top = settings.ScreenArea.Top + margins.top;
            //rect.bottom = settings.ScreenArea.Height - margins.top + margins.bottom;
        }
Exemple #13
0
        private void MoveRight(IntPtr window, WINDOWPLACEMENT wndPl, ref RECT rect, RECT margins, ScreenSettings settings)
        {
            int x;

            switch (wndPl.showCmd)
            {
            case SW_SHOWNORMAL:
                // Get x coordinate of left edge of the window, relative to the left edge of its screen.
                x = rect.left - margins.left - settings.ScreenArea.Left;
                x = MoveRight(settings, x);
                break;

            case SW_SHOWMAXIMIZED:
                // Snap window to rightmost grid cell on the screen.
                x = SnapRight(settings);
                break;

            default:
                throw new Exception();
            }

            if (x >= settings.ScreenArea.Width - settings.GridOddCol)
            {
                // Window has moved to the adjacent screen on the right.
                var adjScreen = Screen.FromPoint(new Point(settings.ScreenArea.Right + 1, (settings.ScreenArea.Top + settings.ScreenArea.Bottom) / 2));
                if (adjScreen.Equals(Screen.FromHandle(window)))
                {
                    // No more screens to the right. Keep the window on the same screen.
                    x = SnapRight(settings);
                }
                else
                {
                    // Snap the window to the leftmost cell of the adjacent screen on the right.
                    settings = GetScreenSettings(adjScreen);
                    x        = SnapLeft(settings);
                }
            }

            rect.left  = settings.ScreenArea.Left + x + margins.left;
            rect.right = rect.left + settings.GridCellWidth - margins.left + margins.right;
            // Expand the window to take the full height of the screen.
            //rect.top = settings.ScreenArea.Top + margins.top;
            //rect.bottom = settings.ScreenArea.Height - margins.top + margins.bottom;
        }
Exemple #14
0
 private int SnapUp(ScreenSettings settings, int y = 0)
 {
     return(y);
 }
Exemple #15
0
 private int SnapLeft(ScreenSettings settings, int x = 0)
 {
     return(x);
 }