feat(autofill): la barrette revient la ou on l'avait posee

Pref DPAPI lazyPos, ecrite sur WM_EXITSIZEMOVE - une ecriture par
deplacement, pas une par pixel parcouru.

La position n'est reprise que si MonitorFromRect la trouve encore sur un
ecran. La barrette n'a pas d'entree dans la barre des taches : une
position heritee d'un ecran debranche, ou d'une resolution changee, la
laisserait hors du bureau et definitivement irrecuperable.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
r-zakarya
2026-08-26 16:20:02 +01:00
parent 7fa26858e3
commit 9ce07ae5d0
2 changed files with 42 additions and 5 deletions
+35 -4
View File
@@ -31,7 +31,7 @@ interface
uses
System.SysUtils, System.Classes, System.Math, System.Types,
FMX.Types, FMX.Forms,
Winapi.Windows, Winapi.ShellAPI, Winapi.Messages,
Winapi.Windows, Winapi.ShellAPI, Winapi.Messages, Winapi.MultiMon,
PM.SingleInstance, PM.UserPrefs;
type
@@ -414,6 +414,9 @@ const
// derriere sans faire disparaitre la barrette du regard.
LAZY_ALPHA_KEY = 'lazyAlphaPct';
LAZY_ALPHA_DEFAULT = 60;
// Coin haut-gauche retenu, 'x,y'. Meme raison que l'opacite d'etre une pref
// DPAPI : la barrette s'allume parfois coffre ferme.
LAZY_POS_KEY = 'lazyPos';
LAZY_W = 236;
LAZY_H = 40;
@@ -1173,6 +1176,14 @@ begin
end;
Exit;
end;
// Fin du glissement (la boucle modale ouverte par HTCAPTION), donc une
// ecriture par deplacement et non une par pixel parcouru.
WM_EXITSIZEMOVE:
begin
GetWindowRect(FLazyWnd, LRect);
SetPref(LAZY_POS_KEY, Format('%d,%d', [LRect.Left, LRect.Top]));
Exit;
end;
// Deux portes pour un seul menu : le fond de la barrette est declare
// non-client (HTCAPTION, pour pouvoir la trainer) et rend donc un clic droit
// NC, tandis qu'un clic droit sur un bouton remonte en WM_CONTEXTMENU.
@@ -1247,7 +1258,9 @@ procedure TPMBridge.SetLazyBar(AOn: Boolean);
end;
var
LWork: TRect;
LWork, LRect: TRect;
LSaved: TArray<string>;
LX, LY, LPosX, LPosY: Integer;
begin
if AOn = LazyBarVisible then Exit;
@@ -1280,8 +1293,26 @@ begin
if not SystemParametersInfo(SPI_GETWORKAREA, 0, @LWork, 0) then
LWork := Rect(0, 0, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN));
SetWindowPos(FLazyWnd, HWND_TOPMOST,
LWork.Right - LAZY_W - 24, LWork.Bottom - LAZY_H - 24, LAZY_W, LAZY_H,
LX := LWork.Right - LAZY_W - 24;
LY := LWork.Bottom - LAZY_H - 24;
// LA POSITION RETENUE, SI ELLE TOMBE ENCORE SUR UN ECRAN. Un ecran debranche
// depuis, ou une resolution changee, laisserait sinon la barrette hors du
// bureau - et elle est sans entree dans la barre des taches, donc perdue pour
// de bon : ni a cliquer, ni a ramener. MonitorFromRect le dit d'un mot.
LSaved := GetPref(LAZY_POS_KEY).Split([',']);
if (Length(LSaved) = 2) and TryStrToInt(LSaved[0], LPosX)
and TryStrToInt(LSaved[1], LPosY) then
begin
LRect := Rect(LPosX, LPosY, LPosX + LAZY_W, LPosY + LAZY_H);
if MonitorFromRect(@LRect, MONITOR_DEFAULTTONULL) <> 0 then
begin
LX := LPosX;
LY := LPosY;
end;
end;
SetWindowPos(FLazyWnd, HWND_TOPMOST, LX, LY, LAZY_W, LAZY_H,
SWP_NOACTIVATE or SWP_SHOWWINDOW);
// La souris est ailleurs a la seconde ou la barrette parait : elle nait donc