Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

widget demo: enable Windows system DPI awareness #64

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions demos/widget
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ use strict;

$XFT = $Tk::Config::xlib =~ /-lXft\b/;


# Enable system DPI awareness for sharper UI on Windows
# https://www.perlmonks.org/?node_id=11101747
if ($^O eq 'MSWin32') {
require Win32::API;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it guaranteed that Win32::API is available on all Windows Perl installations? Otherwise I would prefer a more defensive approach, e.g. if ($^O eq 'MSWin32' && eval { require Win32::API; 1 }).
Also, do all Windows versions have the SetProcessDPIAware() function available? Otherwise the eval{} should be extended even further.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confess I haven't thought through the details of including this in Perl/Tk very well, so I will mark this as a draft for now.

Win32::API is included in Strawberry Perl going back to at least 5.8.9.2, and I'm not sure about ActivePerl. But it isn't a core module, and its predecessor Win32 was a core module only prior to 5.8.4. However neither should be strictly necessary as Perl/Tk uses XS.

SetProcessDPIAware() is in Vista/2008 or later. What is the minimum version Perl/Tk supports—should I assume the same as Perl 5.8 or and/or Tcl/Tk 8.4, which would include 2000/XP?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say, if the solution is simple (i.e. moving the Win32::API::More->new into the eval{}), then this is the way to go.

# See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setprocessdpiaware
my $SetProcessDPIAware = Win32::API::More->new('User32', 'BOOL SetProcessDPIAware()');
$SetProcessDPIAware->Call() or warn 'Failed to set process DPI awareness';
}


$MW = Tk::MainWindow->new;
$MW->configure(-menu => my $menubar = $MW->Menu);

Expand Down