Skip to content

Commit

Permalink
Fixed scaling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Pinter committed Jul 15, 2024
1 parent 0a8374c commit 91d6074
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/winpin/Base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
#include <format>
#define LOG( ... ) printf( "%s\n", std::format( __VA_ARGS__ ).c_str() )
#else
#define LOG( ... )
#define LOG( ... ) \
do \
{ \
} while ( false )
#endif
6 changes: 4 additions & 2 deletions src/winpin/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void CALLBACK PeriodicStateCheckTimerFunc( HWND hwnd, UINT message, UINT_PTR idE
auto state = State::Create();
auto &queue = g_WindowStates[state.monitorsHash];

LOG( "State hash: {}", state.monitorsHash );
if ( state.monitorsHash != g_CurrentMonitorsHash )
LOG( "State hash: {}", state.monitorsHash );

bool monitorsChanged = ( g_CurrentMonitorsHash != 0 ) && ( state.monitorsHash != g_CurrentMonitorsHash );
if ( monitorsChanged )
Expand Down Expand Up @@ -75,7 +76,8 @@ void CALLBACK PeriodicStateCheckTimerFunc( HWND hwnd, UINT message, UINT_PTR idE
void ShowAboutDialog( HWND hwnd )
{
auto result = MessageBox( hwnd,
"WinPin 1.0\n\nTool for restoring windows to previous positions,\nwhen monitor layout is "
"WinPin " VERSION_STRING
"\n\nTool for restoring windows to previous positions,\nwhen monitor layout is "
"changed.\n\nClick 'Help' for GitHub page!",
"About WinPin",
MB_OK | MB_HELP | MB_ICONINFORMATION );
Expand Down
2 changes: 2 additions & 0 deletions src/winpin/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
#define IDI_CMD_RESTORE_STATE 3001
#define IDI_CMD_ABOUT 3002
#define IDI_CMD_EXIT 3003

#define VERSION_STRING "1.0.1"
8 changes: 6 additions & 2 deletions src/winpin/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//----------------------------------------------------------------------------------------------------------------------
void WindowInfo::Restore() const
{
HWND hwnd = ( HWND )handle;
auto hwnd = ( HWND )handle;

if ( !IsWindow( hwnd ) )
hwnd = FindWindow( nullptr, name.c_str() );
Expand All @@ -21,14 +21,18 @@ void WindowInfo::Restore() const
if ( currentWindowState != WindowState::Normal )
ShowWindow( hwnd, SW_RESTORE );

auto p = placement;
auto p = placement; // Make a mutable copy
switch ( state )
{
case WindowState::Normal: p.showCmd = SW_SHOWNORMAL; break;
case WindowState::Minimized: p.showCmd = SW_SHOWMINIMIZED; break;
case WindowState::Maximized: p.showCmd = SW_SHOWMAXIMIZED; break;
};

// SetWindowPlacement is a bit flaky, when you have different scalings on different monitors.
// Calling it only once caused some windows to be resized incorrectly.
// Calling it twice seems to fix the issue. I don't know why.
SetWindowPlacement( hwnd, &p );
SetWindowPlacement( hwnd, &p );

if ( state != WindowState::Minimized )
Expand Down

0 comments on commit 91d6074

Please sign in to comment.