orbitalquark / textadept

Textadept is a fast, minimalist, and remarkably extensible cross-platform text editor for programmers.
https://orbitalquark.github.io/textadept
MIT License
640 stars 38 forks source link

Dark mode for UI #336

Closed snoopy closed 1 year ago

snoopy commented 1 year ago

A proper dark mode for the UI should be possible now that the GUI toolkit has been changed to Qt. This topic came up in the past, mainly in #300 and #320. This issue can serve as a focal point for anything related to the topic at hand.

orbitalquark commented 1 year ago

Note to self: https://github.com/keepassxreboot/keepassxc/tree/develop/src/gui/styles may be a useful reference.

orbitalquark commented 1 year ago

To clarify, the goal for dark mode is to switch the editor theme to dark mode depending on the OS (#199). For example:

Ideally when an OS has switched to dark mode, Qt will emit some sort of notification that Textadept can use to change its editor theme to dark (and vice-versa). The widget theme should already be changed. As of today, Textadept's widget theme changes to dark mode on macOS and Linux (Kubuntu 22.04). It does not change on Windows 11 for some reason. Maybe because Windows 11 is newer than the version of Qt in use (5.15.2).

It is an anti-goal to allow Textadept to change its own widget theme. Users can use GTK stylesheets or the Qt equivalent. Textadept should blend into its environment and be a good citizen.

orbitalquark commented 1 year ago

The next nightly version of Textadept should support auto-detecting and auto-switching between light and dark themes on Linux (and hopefully macOS): https://github.com/orbitalquark/textadept/commit/2fd8e565fe42e50920113c96964939578671363d. I tested on Kubuntu, switching between light and dark Qt themes, and then changing between light and dark GTK themes.

This does not currently work on Windows.

If you have any view:set_theme() calls, please either remove them or adjust them so that they are not passing a theme name (which will override auto-detection). If you'd like to use custom "light" and "dark" themes, but keep the auto-switch and auto-detect feature, move your themes into ~/.textadept/themes/ and rename them to light.lua and dark.lua, respectively.

orbitalquark commented 1 year ago

Windows note: you can get this to work in the latest nightly on Windows by either passing the following command line argument to Textadept: -platform windows:darkmode=2, or by creating a qt.conf file in Textadept's home directory with the following contents:

[Platforms]
WindowsArguments = darkmode=2

While dark mode will be detected and toggled successfully, the Qt style will switch to something different that does not match the current Windows application style. It gets better by passing an additional -style fusion command line argument (I don't know how to set this in qt.conf), but the default light mode style will be different. Supposedly this will get better in Qt 6, but I don't know when Textadept will switch to Qt 6 (Scintilla does not compile against Qt 6 yet).

orbitalquark commented 1 year ago

Support for auto-detecting and auto-switching between light and dark mode should now work on Windows thanks to https://github.com/orbitalquark/textadept/commit/b960e3c2e548f6f4f7ae644e2d5bcd20e6b7db53 and https://github.com/orbitalquark/textadept/commit/a026a66b7e79c16b77280cc3c03a6c4b73665e80, and will be in the next nightly build.

The widget theme on Windows has changed to Qt's "Fusion" theme because it has a dark palette.

Qt 6 has enhanced dark mode support so Textadept has switched to it on Windows.

With this, all 3 major platforms now have auto-detection and auto-switching between light and dark mode.