Skip to content

Commit

Permalink
- fix: sometimes pointer doesn't appear (custom pointers related).
Browse files Browse the repository at this point in the history
- change: custom pointer hiding for its current position, including inactive windows then pointer is outside of active one.
- better applying of "Hide after idling" interval.
  • Loading branch information
setsumi committed Nov 26, 2023
1 parent 5acaadf commit 9e545bf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
25 changes: 21 additions & 4 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ HHOOK hMouseHook = NULL, hKbdHook = NULL;
HCURSOR hCurBlank = NULL;
HWND hWindow = NULL;
bool FastTermination = false;
bool DebugMode = false;

// ---------------------------------------------------------------------------
String GetWindowClassPlus(HWND hwnd)
Expand Down Expand Up @@ -125,6 +126,7 @@ void TFormMousePuff1::Save()
ini->WriteInteger(L"MAIN", L"StartToTray", chkStartToTray->Checked ? 1 : 0);
ini->WriteInteger(L"MAIN", L"WinPageIndex", pageControl1->TabIndex);
ini->WriteInteger(L"MAIN", L"HideTrayIcon", chkHideTrayIcon->Checked ? 1 : 0);
ini->WriteInteger(L"MAIN", L"DebugMode", DebugMode ? 1 : 0);
delete ini;
}

Expand All @@ -144,11 +146,13 @@ void TFormMousePuff1::Load()
else
radioBtnProgram->Checked = true;
udTimeout->Position = ini->ReadInteger(L"MAIN", L"Timeout", 3);
TimerReset();
chkStartToTray->Checked = ini->ReadInteger(L"MAIN", L"StartToTray", 0) == 1;
pageControl1->TabIndex = ini->ReadInteger(L"MAIN", L"WinPageIndex", 0);
chkHideTrayIcon->Checked = ini->ReadInteger(L"MAIN", L"HideTrayIcon", 0) == 1;
DebugMode = ini->ReadInteger(L"MAIN", L"DebugMode", 0) == 1;
delete ini;

TimerReset();
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -209,8 +213,15 @@ void MyProcShowCursor(bool show)
HWND hHider = FindWindow(LEASED_WNDCLASS, LEASED_WNDTITLE);
if (hHider)
{
HWND hTarget = GetForegroundWindow();
POINT pt;
GetCursorPos(&pt);
HWND hTarget = GetAncestor(WindowFromPoint(pt), GA_ROOT);
PostMessage(hHider, show ? WMM_SHOWPOINTER : WMM_HIDEPOINTER, (WPARAM)hTarget, 0);
if (show)
{
// do it again, sometimes above is not enough
PostMessage(hHider, WMM_SHOWPOINTER, (WPARAM)hTarget, 0);
}
}
}

Expand All @@ -228,9 +239,9 @@ void MyShowCursor(bool show, bool force = false)
visible = show;

// debug sound
if (FormMousePuff1->chkDebug->Checked)
if (DebugMode)
{
MessageBeep(show ? 0 : MB_ICONASTERISK);
MessageBeep(show ? 0 : MB_ICONERROR);
}

if (show)
Expand Down Expand Up @@ -494,4 +505,10 @@ void __fastcall TFormMousePuff1::WndProc(TMessage& Message)
}
TForm::WndProc(Message);
}

// ---------------------------------------------------------------------------
void __fastcall TFormMousePuff1::editTimeoutChange(TObject *Sender)
{
TimerReset();
}
// ---------------------------------------------------------------------------
27 changes: 9 additions & 18 deletions Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ object FormMousePuff1: TFormMousePuff1
Hint = 'Hide always'
Caption = 'Global'
Checked = True
TabOrder = 7
TabOrder = 6
TabStop = True
OnClick = radioBtnGlobalClick
end
Expand All @@ -116,7 +116,7 @@ object FormMousePuff1: TFormMousePuff1
Height = 21
Hint = 'Hide only when specific window is active'
Caption = 'Program Specific'
TabOrder = 8
TabOrder = 7
OnClick = radioBtnGlobalClick
end
object udTimeout: TUpDown
Expand All @@ -127,16 +127,17 @@ object FormMousePuff1: TFormMousePuff1
Associate = editTimeout
Min = 1
Position = 3
TabOrder = 10
TabOrder = 9
end
object editTimeout: TEdit
Left = 243
Top = 10
Width = 42
Height = 21
ReadOnly = True
TabOrder = 9
TabOrder = 8
Text = '3'
OnChange = editTimeoutChange
end
object btnSpy: TButton
Left = 301
Expand All @@ -148,16 +149,6 @@ object FormMousePuff1: TFormMousePuff1
TabOrder = 1
OnClick = btnSpyClick
end
object chkDebug: TCheckBox
Left = 297
Top = 112
Width = 57
Height = 25
Caption = 'Debug sounds'
TabOrder = 4
Visible = False
WordWrap = True
end
object btnHide: TButton
Left = 300
Top = 215
Expand All @@ -175,7 +166,7 @@ object FormMousePuff1: TFormMousePuff1
Height = 25
Hint = 'Help information (F1)'
Caption = '?'
TabOrder = 11
TabOrder = 10
OnClick = btnHelpClick
end
object btnExit: TButton
Expand All @@ -194,7 +185,7 @@ object FormMousePuff1: TFormMousePuff1
Width = 134
Height = 17
Caption = 'Start minimized to tray'
TabOrder = 6
TabOrder = 5
end
object chkEnabled: TCheckBox
Left = 133
Expand All @@ -211,7 +202,7 @@ object FormMousePuff1: TFormMousePuff1
Font.Style = [fsBold]
ParentFont = False
State = cbChecked
TabOrder = 12
TabOrder = 11
OnClick = chkEnabledClick
end
object chkHideTrayIcon: TCheckBox
Expand All @@ -221,7 +212,7 @@ object FormMousePuff1: TFormMousePuff1
Height = 17
Hint = 'Hint: In case of completely hidden, run program again to show'
Caption = 'Hide tray icon'
TabOrder = 5
TabOrder = 4
end
object timerPuff: TTimer
Enabled = False
Expand Down
2 changes: 1 addition & 1 deletion Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class TFormMousePuff1 : public TForm
TEdit *editTimeout;
TLabel *Label3;
TButton *btnSpy;
TCheckBox *chkDebug;
TButton *btnHide;
TButton *btnHelp;
TButton *btnExit;
Expand Down Expand Up @@ -51,6 +50,7 @@ class TFormMousePuff1 : public TForm
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall chkEnabledClick(TObject *Sender);
void __fastcall timerKbTimer(TObject *Sender);
void __fastcall editTimeoutChange(TObject *Sender);

protected:
void __fastcall WndProc(TMessage& Message);
Expand Down
4 changes: 2 additions & 2 deletions MousePuff.cbproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<AppEnableHighDPI>true</AppEnableHighDPI>
<Defines>NDEBUG;$(Defines)</Defines>
<VerInfo_Keys>CompanyName=;FileDescription=MousePuff by furniture;FileVersion=1.6.3.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.6.3.0;Comments=;ProgramID=</VerInfo_Keys>
<VerInfo_Keys>CompanyName=;FileDescription=MousePuff by furniture;FileVersion=1.6.4.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.6.4.0;Comments=;ProgramID=</VerInfo_Keys>
<VerInfo_MinorVer>6</VerInfo_MinorVer>
<AppExecutionLevel>requireAdministrator</AppExecutionLevel>
<VerInfo_Release>3</VerInfo_Release>
<VerInfo_Release>4</VerInfo_Release>
<ILINK_MapFileType>None</ILINK_MapFileType>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
Expand Down
Binary file modified MousePuff.res
Binary file not shown.

0 comments on commit 9e545bf

Please sign in to comment.