Skip to content

Commit

Permalink
Prepare 1.48
Browse files Browse the repository at this point in the history
  • Loading branch information
RamonUnch authored Nov 16, 2021
1 parent 0980554 commit e868cea
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
50 changes: 23 additions & 27 deletions altsnap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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 or later. *
* Modified By Raymond Gillibert in 2020 *
* Modified By Raymond Gillibert in 2021 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "hooks.h"
Expand All @@ -30,9 +30,12 @@ wchar_t inipath[MAX_PATH];
HINSTANCE hinstDLL = NULL;
HHOOK keyhook = NULL;
char elevated = 0;
BYTE WinVer = 0;
char ScrollLockState = 0;
char SnapGap = 0;
BYTE WinVer = 0;

#define VISTA (WinVer >= 6)
#define WIN10 (WinVer >= 10)

#define HOOK_TORESUME ((HHOOK)1)
static int ENABLED() { return keyhook && keyhook != HOOK_TORESUME; }
Expand Down Expand Up @@ -186,10 +189,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
UnhookSystem();
HookSystem();
}
// Reload config language
if (!wParam && IsWindow(g_cfgwnd)) {
SendMessage(g_cfgwnd, WM_UPDATESETTINGS, 0, 0);
}
} else if (msg == WM_ADDTRAY) {
hide = 0;
UpdateTray();
Expand Down Expand Up @@ -242,20 +241,20 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
// Hide cursorwnd if clicked on, this might happen if
// it wasn't hidden by hooks.c for some reason
ShowWindow(hwnd, SW_HIDE);
} else if (WIN10 && msg == WM_POWERBROADCAST) {
if (wParam == PBT_APMQUERYSUSPEND) {
// The system is going to suspend.
// We disable AltSnap on Win10+
if(!UnhookSystem())
keyhook = HOOK_TORESUME; // system was hooked.
}
if (wParam == PBT_APMRESUMESUSPEND) {
if (keyhook == HOOK_TORESUME) {
keyhook = NULL;
HookSystem();
}
}
return TRUE;
// } else if (msg == WM_POWERBROADCAST && WIN10) {
// if (wParam == PBT_APMSUSPEND) {
// // The system is going to suspend.
// // We disable AltSnap on Win10+
// if(!UnhookSystem())
// keyhook = HOOK_TORESUME; // system was hooked.
// }
// if (wParam == PBT_APMRESUMEAUTOMATIC) {
// if (keyhook == HOOK_TORESUME) {
// keyhook = NULL;
// HookSystem();
// }
// }
// return TRUE;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
Expand All @@ -268,6 +267,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, char *szCmdLine, in
LOG("\n\nALTSNAP STARTED");
GetModuleFileName(NULL, inipath, ARR_SZ(inipath));
wcscpy(&inipath[wcslen(inipath)-3], L"ini");
LOG("ini file: %S", inipath);

// Read parameters on command line
int elevate = 0, quiet = 0, config =0, multi = 0;
Expand All @@ -285,13 +285,12 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, char *szCmdLine, in
// Check if elevated if in >= WinVer
WinVer = LOBYTE(LOWORD(GetVersion()));
LOG("Running with Windows version %d", WinVer);
if (VISTA) { // Vista +
if (WinVer >= 6) { // Vista +
HANDLE token;
TOKEN_ELEVATION elevation;
DWORD len;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token)
&& GetTokenInformation(token, TokenElevation, &elevation,
sizeof(elevation), &len)) {
&& GetTokenInformation(token, TokenElevation, &elevation, sizeof(elevation), &len)) {
elevated = elevation.TokenIsElevated;
CloseHandle(token);
}
Expand All @@ -306,7 +305,6 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, char *szCmdLine, in
HWND previnst = FindWindow(APP_NAME, NULL);
if (previnst) {
LOG("Previous instance found and no -multi mode")
// PostMessage(previnst, WM_UPDATESETTINGS, 0, 0);
if(hide) PostMessage(previnst, WM_CLOSECONFIG, 0, 0);
if(config) PostMessage(previnst, WM_OPENCONFIG, 0, 0);
PostMessage(previnst, hide? WM_HIDETRAY : WM_ADDTRAY, 0, 0);
Expand Down Expand Up @@ -377,16 +375,14 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, char *szCmdLine, in
DispatchMessage(&msg);
}
}
// EXIT
UnregisterClass(APP_NAME, hInst);

DestroyWindow(g_hwnd);
LOG("GOOD NORMAL EXIT");
return msg.wParam;
}
/////////////////////////////////////////////////////////////////////////////
// Use -nostdlib and -e_unfuckMain@0 to use this main, -eunfuckMain for x64.
void WINAPI noreturn unfuckWinMain(void)
void WINAPI unfuckWinMain(void)
{
HINSTANCE hInst;
HINSTANCE hPrevInstance = NULL;
Expand Down
16 changes: 8 additions & 8 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static void SetAutostart(int on, int hhide, int eelevate)

/////////////////////////////////////////////////////////////////////////////
// Only used in the case of Vista+
BOOL ElevateNow(int showconfig)
static BOOL ElevateNow(int showconfig)
{
wchar_t path[MAX_PATH];
GetModuleFileName(NULL, path, ARR_SZ(path));
Expand All @@ -105,7 +105,7 @@ BOOL ElevateNow(int showconfig)
}
/////////////////////////////////////////////////////////////////////////////
// Entry point
void OpenConfig(int startpage)
static void OpenConfig(int startpage)
{
if (IsWindow(g_cfgwnd)) {
PropSheet_SetCurSel(g_cfgwnd, 0, startpage);
Expand Down Expand Up @@ -149,13 +149,13 @@ void OpenConfig(int startpage)
PropertySheet(&psh);
}
/////////////////////////////////////////////////////////////////////////////
void CloseConfig()
static void CloseConfig()
{
PostMessage(g_cfgwnd, WM_CLOSE, 0, 0);
}
void UpdateSettings()
static void UpdateSettings()
{
PostMessage(g_hwnd, WM_UPDATESETTINGS, 1, 0);
PostMessage(g_hwnd, WM_UPDATESETTINGS, 0, 0);
}
static void MoveButtonUporDown(WORD id, WINDOWPLACEMENT *wndpl, int diffrows)
{
Expand Down Expand Up @@ -305,7 +305,7 @@ INT_PTR CALLBACK GeneralPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
ReadOptionInt(IDC_MDI, L"General", L"MDI", 1, -1);
ReadOptionInt(IDC_FULLWIN, L"Performance", L"FullWin", 1, -1);
ReadOptionInt(IDC_RESIZEALL, L"Advanced", L"ResizeAll", 1, -1);
ReadOptionInt(IDC_USEZONES, L"Zones", L"UseZones", 1, -1);
ReadOptionInt(IDC_USEZONES, L"Zones", L"UseZones", 0, -1);

ret = GetPrivateProfileInt(L"General", L"ResizeCenter", 1, inipath);
ret = ret==1? IDC_RZCENTER_NORM: ret==2? IDC_RZCENTER_MOVE: IDC_RZCENTER_BR;
Expand Down Expand Up @@ -368,13 +368,13 @@ INT_PTR CALLBACK GeneralPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
wchar_t txt[8];
WriteOptionBool(IDC_AUTOFOCUS, L"General", L"AutoFocus");
WriteOptionBool(IDC_AERO, L"General", L"Aero");
WriteOptionBoolB(IDC_SMARTAERO, L"General", L"SmartAero", 0);
WriteOptionBoolB(IDC_SMARTAERO, L"General", L"SmartAero", 0);
WriteOptionBoolB(IDC_STICKYRESIZE, L"General", L"StickyResize", 0);
WriteOptionBool(IDC_INACTIVESCROLL,L"General", L"InactiveScroll");
WriteOptionBool(IDC_MDI, L"General", L"MDI");
WriteOptionBool(IDC_FULLWIN, L"Performance",L"FullWin");
WriteOptionBool(IDC_RESIZEALL, L"Advanced", L"ResizeAll");
WriteOptionBool(IDC_USEZONES, L"Zones", L"UseZones");
WriteOptionBool(IDC_USEZONES, L"Zones", L"UseZones");

int val = ComboBox_GetCurSel(GetDlgItem(hwnd, IDC_AUTOSNAP));
WritePrivateProfileString(L"General", L"AutoSnap", _itow(val, txt, 10), inipath);
Expand Down
19 changes: 13 additions & 6 deletions hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ static struct {
char InterZone;
char SnapGap;

UCHAR ShiftSnaps;

UCHAR Hotkeys[MAXKEYS+1];
UCHAR Shiftkeys[MAXKEYS+1];
UCHAR Hotclick[MAXKEYS+1];
UCHAR Killkey[MAXKEYS+1];

Expand Down Expand Up @@ -1001,6 +1004,8 @@ static void GetAeroSnappingMetrics(int *leftWidth, int *rightWidth, int *topHeig
*topHeight = CLAMPH((mon->bottom - mon->top)* conf.AVoff /100);
*bottomHeight = CLAMPH((mon->bottom - mon->top)*(100-conf.AVoff)/100);

if (state.snap != conf.AutoSnap) return; // do not go further is snapping state is toggled.

// Check on all the other snapped windows from the bottom most
// To give precedence to the topmost windows
unsigned i = numsnwnds;
Expand Down Expand Up @@ -1580,7 +1585,7 @@ static void MouseMove(POINT pt)

} else if (mouse_thread_finished) {
// Resize other windows
if (!ResizeTouchingWindows(&LastWin)) {
if (!ResizeTouchingWindows(&LastWin)) {
// The resize touching also resizes LastWin.
MoveWindowInThread(&LastWin);
}
Expand Down Expand Up @@ -1722,10 +1727,10 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP
} else if (conf.KeyCombo && !state.alt1 && IsHotkey(vkey)) {
state.alt1 = vkey;

} else if (vkey == VK_LSHIFT || vkey == VK_RSHIFT) {
} else if (IsHotkeyy(vkey, conf.Shiftkeys)) {
if (!state.shift && vkey != conf.ModKey) {
EnumOnce(NULL); // Reset enum state.
state.snap = 3;
if(conf.ShiftSnaps) state.snap = 3;
state.shift = 1;
state.shiftpt = state.prevpt; // Save point where shift was pressed.
}
Expand Down Expand Up @@ -1788,7 +1793,7 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP
} else if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP) {
if (IsHotkey(vkey)) {
HotkeyUp();
} else if (vkey == VK_LSHIFT || vkey == VK_RSHIFT) {
} else if (IsHotkeyy(vkey, conf.Shiftkeys)) {
state.shift = 0;
state.snap = conf.AutoSnap;
} else if (vkey == VK_LCONTROL || vkey == VK_RCONTROL) {
Expand Down Expand Up @@ -2841,6 +2846,7 @@ static void FinishMovement()

state.action = AC_NONE;
state.moving = 0;
state.snap = conf.AutoSnap;

// Unhook mouse if Alt is released
if (!state.alt) {
Expand Down Expand Up @@ -3242,7 +3248,7 @@ __declspec(dllexport) void Load(HWND mainhwnd)
conf.TitlebarMove = GetPrivateProfileInt(L"Advanced", L"TitlebarMove", 0, inipath);
if (conf.TitlebarMove) conf.NormRestore = 0; // in this case disable NormRestore
conf.SnapGap = CLAMP(-128, GetPrivateProfileInt(L"Advanced", L"SnapGap", 0, inipath), 127);

conf.ShiftSnaps = GetPrivateProfileInt(L"Advanced", L"ShiftSnaps", 1, inipath);
// [Performance]
conf.MoveRate = GetPrivateProfileInt(L"Performance", L"MoveRate", 1, inipath);
conf.ResizeRate= GetPrivateProfileInt(L"Performance", L"ResizeRate", 2, inipath);
Expand Down Expand Up @@ -3307,6 +3313,7 @@ __declspec(dllexport) void Load(HWND mainhwnd)
conf.ScrollLockState = GetPrivateProfileInt(L"Input", L"ScrollLockState", 0, inipath);

readhotkeys(inipath, L"Hotkeys", L"A4 A5", conf.Hotkeys);
readhotkeys(inipath, L"Shiftkeys",L"A0 A1", conf.Shiftkeys);
readhotkeys(inipath, L"Hotclicks",L"", conf.Hotclick);
readhotkeys(inipath, L"Killkeys", L"09 4C 2E",conf.Killkey);

Expand All @@ -3323,7 +3330,7 @@ __declspec(dllexport) void Load(HWND mainhwnd)
readblacklist(inipath, &BlkLst.AResize, L"AResize");
readblacklist(inipath, &BlkLst.SSizeMove, L"SSizeMove");
readblacklist(inipath, &BlkLst.NCHittest, L"NCHittest");
ResetDB(); // Zero database
ResetDB(); // Zero database of restore info (snap.c)

// Zones
conf.UseZones = GetPrivateProfileInt(L"Zones", L"UseZones", 0, inipath);
Expand Down

0 comments on commit e868cea

Please sign in to comment.