-
Notifications
You must be signed in to change notification settings - Fork 6
/
winsnap.h
78 lines (67 loc) · 2.25 KB
/
winsnap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef WINSNAP_H
#define WINSNAP_H
/*
* Sticky Window Snapper Class
* Copyright (C) 2021-2024 Pedro López-Cabanillas <[email protected]>
* Copyright (C) 2014 mmbob (Nicholas Cook)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <list>
#include <Windows.h>
enum Side
{
Left = 0,
Top = 1,
Right = 2,
Bottom = 3,
Count = 4,
};
struct Edge
{
int Position;
int Start;
int End;
Edge(int position, int start, int end);
bool operator ==(const Edge& other) const;
};
class WinSnap
{
// The distance at which edges will snap.
static const int SNAP_DISTANCE = 30;
// Snap effect is enabled?
bool m_enabled{ true };
// An array of sorted lists of edges which can be snapped to for each side of the window.
std::list<Edge> m_edges[Side::Count];
// Is the window currently being snapped?
bool m_inProgress{ false };
// The difference between the cursor position and the top-left of the window being dragged.
POINT m_originalCursorOffset;
// The window handle
HWND m_window;
// The window border sizes, for Windows 10 Aero theme are: 7,0,7,7
RECT m_border{ 0,0,0,0 };
void AddRectToEdges(const RECT& rect);
void SnapToRect(RECT* bounds, const RECT& rect, bool retainSize, bool left, bool top, bool right, bool bottom) const;
bool CanSnapEdge(int boundsEdges[Side::Count], Side which, int* snapPosition) const;
bool HandleEnterSizeMove();
bool HandleExitSizeMove();
bool HandleMoving(RECT& bounds);
bool HandleSizing(RECT& bounds, int which);
public:
bool HandleMessage(void *message);
bool IsEnabled() const;
void SetEnabled(const bool enabled);
};
#endif // WINSNAP_H