SDL_GetDisplayDPI doesn't work on android - sdl

I'm trying to get the DPI of the display by calling SDL_GetDisplayDPI, and it doesn't work both on my Nook Color (with CyanogenMod) and Galaxy S5 (with the default version of Android). SDL_GetError says "That operaion is not supported". Is there a different way to find out DPI with SDL?

An answer can be found in this thread:
https://discourse.libsdl.org/t/an-issue-with-sdl-getdisplaydpi-on-android/23312
"It looks like GetDisplayDPI is only implemented on Windows, macOS, and X11 currently.
Looking at the Android docs a bit, 160 * getResources().getDisplayMetrics().density; would give a DPI based on the UI scale factor."

Related

Detect dark application style/theme of currently used desktop in Qt

The bounty expires in 7 days. Answers to this question are eligible for a +50 reputation bounty.
codeling wants to draw more attention to this question:
Give concise information (and ideally code) on how to detect dark theme on KDE and Gnome desktop environments using Qt, or if there is no direct way with Qt, using plain C++ (or at least as little additional libraries as possible).
In our Qt-based C++ application, I'm trying to automatically switch application styles based on whether the user has configured dark or bright theme.
I have figured out the notification of when a change happens (see below, for other's reference).
My main problem is the reliable detection of whether currently a dark or bright theme is used on linux (for windows see below); on XFCE, the check for QPalette color roles as mentioned in this answer works, but this does not work on Gnome and KDE Plasma for me (tested under both Ubuntu 22.04 and Fedora 36, my app built against Qt versions 6.5beta2 and 6.4.2, respectively); there the colors still seem to be taken from what I've set as XFCE theme on the same machine (and when starting xfce4-appearance-settings and changing the theme there, my app picks up the change). I would however like to adapt to the current desktop's dark mode setting.
So, my question is: How do I reliably detect application dark mode of the currently used desktop on Qt? I'm not averse to implementing a little custom platform-specific code if nothing is available directly in Qt, but it would be great if it would work without using additional libraries.
A note I saw for QApplication::setPalette I thought might be relevant here, namely "Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines.", what are these all about? I did not see a link to a documentation for this feature, and a quick search for the term "qt native theme engine" also didn't seem to yield any useful results.
Since on Linux, some events are reliably triggered whenever a system theme change happens (see below), I suppose Qt can detect the theme change, it just doesn't expose data about it publicly?
Getting notified of theme changes
On Linux: via listening for QEvent::StyleChange events of the application's QMainWindow; two caveats and one side note:
That event does, despite QWidget::changeEvent documentation explicitly mentioning it, not trigger a changeEvent (for me), but has to be caught via the more generic QWidget::event
StyleChange only seems to be triggered since some Qt 6.4 version (in my tests, it was not triggered by 5.15.2 and 6.3.1, but triggered for 6.4.2 and 6.5.0beta2).
I've also noticed that there's a ThemeChange event that is also triggered (at the same time as the StyleChange; not sure what the difference is between these two though, and in what case one would be triggered but not the other... I suppose StyleChange is used for any change to the style of a widget, so that it's also called when applying some style sheet settings, while ThemeChange really indicates a change of the system theme? Though ThemeChange seems to be considered a non-public Event type, at least it doesn't appear in the documentation (marked \omitvalue)
On Windows, via checking for changes to the registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize (the StyleChange unfortunately isn't triggered there at all - a Qt bug?). .
Detecting dark theme on Windows
Application bright/dark mode determined by registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme (1 for bright, 0 for dark). This check is also done in Qt's plugins/platforms/windows/qwindowstheme (queryDarkMode`), but I think this is not exposed publicly as generic interface anywhere?

All of a sudden, my Qt application displays at 100% instead of the normal 200%, what did I changed that made it lose that feature?

In my settings, I clearly have my screen setup to 200% like so:
When I worked on my Qt application earlier, it would properly follow that setup.
Somehow, I changed a something and now it always appears at 100%. That makes it difficult to read the text.
What option(s) would Qt have that would turn that feature off?
I have other Qt applications that still work as expected, so I'm really thinking that's something I did. Maybe a widget I added? Or a call I make? I just have no idea what it could be so looking at my changes doesn't help at the moment.
One thing I added recently is a QSvgWidget, but even if I remove it, it still doesn't work. Another thing I've notice is that the OS (Ubuntu 18.04) updated the desktop themes. But I don't think that happened at that time.
UPDATE:
This seems to be generalized. I just upgraded my OS. The VirtualBox snap was updated and now the window also appears small (i.e. ignores the High DPI setup). So it must be an OS thing (i.e. a library that was updated and it breaks the Qt High DPI feature).
Okay! I got the answer to that one in my situation.
Whenever nvidia sends a new version of their driver, my X11 session continues to work, but OpenGL is not accessible anymore. There must be something in Qt that decides to use OpenGL and since it (silently) fails opening a connection, it falls back to "no DPI scaling capability".
After a reboot, everything is back to normal and zooms in and out as expected in my app and also the VirtualBox window.

How to set app to always `open in low resolution`

I have an application developed with Qt3D (which uses OpenGL) by Qt 5.11.3 and Xcode 9.4.1 build tools. App runs fine on Linux and Windows, but on macOS Retina display (10.14, Mojave), I observe:
There are two workarounds for the above observation:
Set Retina display to full native resolution (microscopically small) then open app which seems to look and function correctly. Then lower the resolution to something usable and app continues to work properly
Get info of the app and check the open in low resolution checkbox like this image from a website:
I have studied similar questions but the posted solutions look more like a hack. And my app is a complex one, I cannot just simply multiply everything by a ratio. Is there any other solution for this? How can I force my app to open in low resolution on macOS, already asked here? Thanks.

What is the effectiveness of using the compatibility feature for older operating systems in Windows XP, Vista, 7 and 8?

I've been trying to research why certain compatibility features differ based on operating system so I can program a patch. I'm using the compatibility settings in the registry for Windows 95 to run a game (that of which the game was produced on) in each system. In Windows XP, the game runs perfectly. None of the scenes lag, and the sound works just as well as the scenes. I'm unsure of how it runs in Windows Vista, but in Windows 7 & 8 the compatibility feature breaks the game. I used a VM to run XP, but that doesn't effect the game's playability; real XP users have tested it. Whenever I play the game using the Win95 setting for compatibility in 7 & 8, everything lags. The music doesn't slow down during gameplay, but the graphics do. During cutscenes, they literally break. Everything pixelates, white noise and static increases volume, and the video lags every two seconds.
I therein tested it in Ubuntu Linux via WINE, and it runs better than it does in XP. I just had to use the alsa sound driver. What changed? If so, is it programmatically fixable? I'm using an amalgamation of C++, Batch and Java.
If it is necessary, the video game is entitled "The Neverhood."
Thanks.
The compatibility feature available in the shell is just scratching the surface of the "Application Compatibility" subject in Windows.
There is a tool called "Microsoft Application Compatibility Toolkit (ACT)" (that exist since Windows XP exist I believe) that has much more to offer, so maybe that can help.
For example here are some compatibility settings for Graphics Control Issues
I currently play "The Neverhood" on Win7 x64 without any visual problem, you are right when I played on Win7 for first time (4 years ago) was a headache and a little tricky to do the correct compatibility flags for each win version but finally I wrote this reg code for Win7 and worked for me while 4 years, sure it will work for you too:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\Folder\\nhc.exe"="# WIN95 256COLOR 640X480 DISABLEDWM"
Where "C:\\Folder\\nhc.exe" of course is the path to your Neverhood. (Notice the double backslashes)
that flags means: Change Display color to 256 colors, change display resolution to 640x480, disable Themes service (DWM Service).
I hope this help you.
This may not answer the question directly, but if you want to improve performance of The Neverhood, change the compatibility to run in Windows 95 - then switch all other options ON, except the bottom three. This helps to make the game as fast and smooth as possible.

AviSaveOptions() dialog window is distorted!

I'm using windows XP , hebrew version.
I am trying to save an AVI file using the Video For Windows API in C++, when I run the AviSaveOptions() function, the dialog opens as a thin unclickable strip at the corner of the screen.
Would it have anything to do with the language (Hebrew)? maybe with the vfw driver itself? what might cause a windows dialog window to be distorted/invisible?
thanks
Roey
Can't really answer your question, but I've seen problems with localized versions of AVISaveOptions dialog. The Swedish Windows XP version of it never showed but one codec, although more were installed on the system. Verified on several Swedish XP installations. Other languages we could test didn't show this. Submitted a bug report to MS, and to my great surprise, never heard back.
The AVIFile API in general seems to be spec'ed and and implemented by a bunch of drunken monkeys, so I wouldn't be hugely surprised if they had botched the Hebrew version beyond recognition.
I've seen a similar distortion of the AVISaveOptions dialog, only with Windows 7 Ultimate (English) with the Arabic language pack installed and the display language set to Arabic.
For me the workaround was setting the uiFlags parameter to ICMF_CHOOSE_PREVIEW, check the AVISaveOptions documentation. Not an ideal solution if you don't want the preview functionality on the dialog, but at least it is visible and displayed correctly.