fix(windows): support .png format icon in tray icon

Fixes: KEYMAN-WINDOWS-3CT
Fixes: #12905
This commit is contained in:
Marc Durdin 2026-08-13 11:34:46 +02:00
parent b75f0eefc0
commit d7c88b6bae
7 changed files with 107 additions and 6 deletions

View file

@ -1227,16 +1227,35 @@ end;
procedure TfrmKeyman7Main.SetTrayIcon(rp: TRunningProduct; kbd: IKeymanKeyboardInstalled);
var
cust: IKeymanCustomisation;
bb: IPicture;
h: OLE_HANDLE;
lskbd: TLangSwitchKeyboard;
icon: TIcon;
begin
if Assigned(rp) then
begin
bb := kbd.Bitmap;
if Assigned(bb) then
lskbd := LangSwitchManager.FindKeyboardByKeymanID(kbd.KeymanID);
if Assigned(lskbd) and (lskbd is TLangSwitchKeyboard_TIP) then
try
icon := TIcon.Create;
try
icon.Handle := (lskbd as TLangSwitchKeyboard_TIP).IconHandle;
rp.FTrayIcon.Icon.Assign(icon);
icon.ReleaseHandle;
finally
icon.Free;
end;
except
on E:Exception do
begin
// #12905: icon is otherwise invalid
TKeymanSentryClient.ReportHandledException(E, 'SetTrayIcon: Invalid icon for keyboard "'+kbd.ID+'"; icon filename "'+kbd.IconFilename+'"');
// Use the default app icon
rp.FTrayIcon.Icon.Assign(FTrayIcon);
end;
end
else
begin
bb.get_Handle(h);
rp.FTrayIcon.Icon.Handle := CopyIcon(h);
// Use the default app icon
rp.FTrayIcon.Icon.Assign(FTrayIcon);
end;
if VisualKeyboardVisible then

View file

@ -186,6 +186,7 @@ type
procedure Refresh;
function FindKeyboard(FHKL: HKL; FProfileGuid: TGUID): TLangSwitchKeyboard; overload;
function FindKeyboard(id: string): TLangSwitchKeyboard; overload;
function FindKeyboardByKeymanID(id: Integer): TLangSwitchKeyboard; overload;
property Languages[Index: Integer]: TLangSwitchLanguage read GetLanguage;
property LanguageCount: Integer read GetLanguageCount;
property TotalKeyboardCount: Integer read GetTotalKeyboardCount; // I4606
@ -594,6 +595,20 @@ begin
Result := nil;
end;
function TLangSwitchManager.FindKeyboardByKeymanID(
id: Integer): TLangSwitchKeyboard;
var
lang: TLangSwitchLanguage;
kbd: TLangSwitchKeyboard;
begin
for lang in FLanguages do
for kbd in lang.FKeyboards do
if kbd.KeymanID = id then
Exit(kbd);
Result := nil;
end;
function TLangSwitchManager.FindKeyboard(FHKL: HKL;
FProfileGuid: TGUID): TLangSwitchKeyboard;
var

View file

@ -0,0 +1,6 @@
# pngicon keyboard
A keyboard with a PNG format icon - for testing #12905
https://github.com/keymanapp/keyman/issues/12905

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<KeymanDeveloperProject>
<Options>
<Version>2.0</Version>
<CompilerWarningsAsErrors>True</CompilerWarningsAsErrors>
<CheckFilenameConventions>True</CheckFilenameConventions>
</Options>
</KeymanDeveloperProject>

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View file

@ -0,0 +1,12 @@
c pngicon generated from template at 2026-08-13 11:08:13
c with name "pngicon"
store(&VERSION) '10.0'
store(&NAME) 'pngicon'
store(&COPYRIGHT) 'Copyright ©'
store(&KEYBOARDVERSION) '1.0'
store(&TARGETS) 'windows'
store(&BITMAP) 'pngicon.ico'
begin Unicode > use(main)
group(main) using keys

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Package>
<System>
<KeymanDeveloperVersion>18.0.249.0</KeymanDeveloperVersion>
<FileVersion>7.0</FileVersion>
</System>
<Options>
<ExecuteProgram></ExecuteProgram>
<MSIFileName></MSIFileName>
<MSIOptions></MSIOptions>
<FollowKeyboardVersion/>
</Options>
<StartMenu>
<Folder></Folder>
<Items/>
</StartMenu>
<Info>
<Name URL="">pngicon</Name>
<Copyright URL="">Copyright ©</Copyright>
<Author URL=""></Author>
<Description URL="">A keyboard with a PNG icon</Description>
<Version URL=""></Version>
</Info>
<Files>
<File>
<Name>..\build\pngicon.kmx</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.kmx</FileType>
</File>
</Files>
<Keyboards>
<Keyboard>
<ID>pngicon</ID>
<Languages>
<Language ID="de">German</Language>
</Languages>
</Keyboard>
</Keyboards>
<Strings/>
</Package>