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

[KBSWITCH] Fix keyboard indicator text and font #4723

Merged
merged 5 commits into from
Sep 28, 2022

Conversation

katahiromz
Copy link
Contributor

@katahiromz katahiromz commented Sep 24, 2022

Purpose

JIRA issue: CORE-10667

Comparison

WinXP Japanese:
xp

BEFORE:
before

AFTER:
after

Proposed changes

  • Do the same behaviour as input.dll in getting indicator text.
  • Use full color DIB (device-independent bitmap) to improve icon.
  • Use SPI_GETICONTITLELOGFONT for font.

@katahiromz katahiromz added the bugfix For bugfix PRs. label Sep 24, 2022
@katahiromz katahiromz added this to New PRs in ReactOS PRs via automation Sep 24, 2022
@katahiromz
Copy link
Contributor Author

English:
english
No change.

@katahiromz katahiromz changed the title [KBSWITCH] Fix keyboard indicater text and font [KBSWITCH] Fix keyboard indicator text and font Sep 24, 2022
katahiromz referenced this pull request Sep 24, 2022
@katahiromz katahiromz added the modding Theming, visual designing modifications of ReactOS label Sep 24, 2022
@HBelusca HBelusca added the review pending For PRs undergoing review. label Sep 25, 2022
base/applications/kbswitch/kbswitch.c Outdated Show resolved Hide resolved
base/applications/kbswitch/kbswitch.c Outdated Show resolved Hide resolved

/* Create hdc, hbmColor and hbmMono */
hdc = CreateCompatibleDC(NULL);
hbmColor = CreateCompatibleBitmap(hdc, CX_ICON, CY_ICON);
hbmColor = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

(That's also a question for the other CPL PR): Why forcing here RGB_Colors? What's happening if you keep the original code? Is it going to be monochrome then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 24-bpp DIB is a device-independent full color bitmap. So it doesn't need the color table if conversion was correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The device-dependent bitmap (DDB) has a fear that conversion might be failed if the device was changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BEFORE:
image
Looks like monochrome.

Copy link
Contributor

@HBelusca HBelusca Sep 27, 2022

Choose a reason for hiding this comment

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

I guess that if the CreateCompatibleDC call was called on the hdc of the traybar's window, it could have been in color.
But why I'm overall surprised why this code would need any change, is I know that so far, the kbswitch was drawing a perfectly colored icon in the traybar, so why is it that sometimes it would draw a monochrome-looking one instead? 🤔
See for example:
https://i.ytimg.com/vi/Ne88Is2cymQ/maxresdefault.jpg
image

And switching to french didn't cause problem. But why for japanese (at least in your new tests) the "JA" icon now appears in black with the existing code, is a mystery for me.

EDIT: This is the commit that refactored this CreateTrayIcon:
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0991cedca782f770e41bf991815d7d57f93ba1fd
One question is whether the problem started to appear there. If so, what are the subtle differences between the old code and the new one that triggered it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That DDB bitmap is passed to CreateIconIndirect function. That is non-compatible. Japanese text is antialiased. Antialiasing uses some gray colors. DDB may lack palette.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DDB was not full color. Rendering Japanese text used antialiasing. Antialiasing used gray colors. The DDB lacks palette. Darkblue color is ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe our palette optimization was poor.

Copy link
Contributor

@HBelusca HBelusca Sep 27, 2022

Choose a reason for hiding this comment

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

If you isolate this "CreateTrayIcon" (the one before the fix from this PR) into a standalone test-program that just creates a tray icon (or any other kind of window on which the icon can be drawn), that you then run on Windows (japanese or not): would the created bitmap/icon be in color or not? (I would suggest testing that on Windows XP/2k3 before looking at e.g. Windows 10.)
If it works there (but not in ReactOS), this could indicate a potential bug in our gdi32/win32k code.

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 made a test program: https://jira.reactos.org/secure/attachment/62796/DDBTest.zip

ReactOS Japanese:
DDBTest-ReactOS

WinXP Japanese:
DDBTest-WinXP

Win2k3 English:
DDBTest-Win2k3

Win10 Japanese:
DDBTest-Win10

@katahiromz katahiromz removed the review pending For PRs undergoing review. label Sep 28, 2022
@katahiromz katahiromz merged commit c6ccb92 into reactos:master Sep 28, 2022
ReactOS PRs automation moved this from New PRs to Done Sep 28, 2022
@katahiromz katahiromz deleted the kbswitch-language branch September 28, 2022 22:32
HBelusca added a commit that referenced this pull request Sep 29, 2022
Addendum to commits 5f4bb73 and c6ccb92.

- GetLocaleInfo() returns an int, not a bool: makes it clear in the test.

- No need to use StringCchCopy() to just initialize two chars to the
  same value.

- The question about the test in #4723 (comment)
  was meant to discover that CreateDIBSection() was unnecessary, since
  the very original code (before commit 0991ced) did not use it and was
  working fine in that regard. The simple fix was to use GetDC(NULL).

- Use SM_CXSMICON/SM_CYSMICON metrics for the KBSWITCH indicator as well.

- Override the font size obtained from SPI_GETICONTITLELOGFONT with a
  known one (allows to get a correct indicator even if the user font
  is very large).

- Do the initialization in such a way that in case SPI_GETICONTITLELOGFONT
  or CreateFontIndirect fails, we always fall back to the default stock
  font that is ensured to always exist.

- Initialize *all* the fields of the IconInfo structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix For bugfix PRs. modding Theming, visual designing modifications of ReactOS
Projects
ReactOS PRs
  
Done
2 participants