Author Topic: C::B dark mode in Windows  (Read 12658 times)

Offline adalbert

  • Single posting newcomer
  • *
  • Posts: 5
C::B dark mode in Windows
« on: November 22, 2023, 12:30:54 pm »
Update: test build
https://github.com/adbrt/codeblocks-dark-mode-msw/releases/tag/release
https://github.com/adbrt/codeblocks-dark-mode-msw

Hello,
I am trying to enable dark mode in MSW build. I think this may be a cool feature for some people who tend to use dark mode in everything.
This is easy if I compile it with wxWidgets 3.3 (from GitHub), one line of code is needed after app starts (https://docs.wxwidgets.org/latest/classwx_app.html#af8c93d7e3345e62a58325f3ab1d158d6)

I will post the code soon. However, I cannot find where in the code of C::B are the default values for editor colors. Where in the source code can I find the colors for editor background/foreground and syntax highlighting? Background is white by default even when using the dark mode.
« Last Edit: November 26, 2023, 02:57:41 pm by adalbert »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1632
Re: C::B dark mode in Windows
« Reply #1 on: November 22, 2023, 01:02:51 pm »
The editor is derived from wxStyledTextCtrl, and it uses Styles that define colours (among other parameters).

See StyleSetBackground() and StyleSetForeground().

EDIT: The easiest way may be adding a built-in Colour theme called "default for dark mode" (see Settings->Editor->Syntax highlighting).

If you are working on a patch, remember to guard the wxWidgets version (#if wxCHECK_VERSION(3.3.0)) and the platform (#ifdef __WXMSW__) and (in runtime) check if Windows version is W10-20H1 or newer (wxCheckOsVersion()). Also, create a setting for Normal/Dark mode and use it.

« Last Edit: November 22, 2023, 03:36:52 pm by Miguel Gimenez »

Offline adalbert

  • Single posting newcomer
  • *
  • Posts: 5
Re: C::B dark mode in Windows
« Reply #2 on: November 22, 2023, 07:27:14 pm »
I see that "Syntax highlighting" is loading default colors from XML files in \share\CodeBlocks\lexers.

A lexer for each language has color presets inside, and if I switch around fg and bg values in lexer_cpp.xml or other files, file the colors will indeed be reversed.

However, I don't see an option to create multiple themes inside of the XML files:
Code
<?xml version="1.0"?>
<!DOCTYPE CodeBlocks_lexer_properties>
<CodeBlocks_lexer_properties>
        <Lexer name="C/C++"
                index="3"
                filemasks="*.c,*.cpp,*.cc,*.cxx,*.h,*.hpp,*.hh,*.hxx,*.inl,*.ipp,*.tcc,*.tpp">
                <Style name="Default"
                        index="0,11"
                        fg="255,255,255"
                        bg="0,0,0"
                        bold="0"
                        italics="0"
                        underlined="0"/>
                <Style name="Default (inactive)"
                        index="64,72,75"
                        fg="200,200,200"/>
                <Style name="Comment (normal)"
                        index="1,23"
                        fg="152,152,217"/>

So modifying lexer files would change everything to dark mode only.

If I want to give the ability to change color theme, I need to add that color theme into default.conf file:

Code
	<editor>
<colour_sets>
<default />
<default_dark_mode>
<NAME>
<str>
<![CDATA[default_dark_mode]]>
</str>
</NAME>
<cc>
<style0>
<FORE>
<colour r="233" g="233" b="233" />
</FORE>
<BACK>
<colour r="7" g="7" b="7" />
</BACK>
<NAME>
<str>
<![CDATA[Default]]>
</str>
</NAME>
</style0>
<style1>
<FORE>
<colour r="233" g="233" b="233" />
</FORE>
<BACK>
<colour r="7" g="7" b="7" />
</BACK>
<NAME>
<str>
<![CDATA[Default]]>
</str>
</NAME>
</style1>
<NAME>
<str>
<![CDATA[C/C++]]>
</str>
</NAME>
</cc>
</default_dark_mode>
<ACTIVE_COLOUR_SET>
<str>
<![CDATA[default_dark_mode]]>
</str>
</ACTIVE_COLOUR_SET>
<ACTIVE_LANG>
<str>
<![CDATA[C/C++]]>
</str>
</ACTIVE_LANG>
</colour_sets>

But the default.conf file is created only after the first launch of CodeBlocks. What would be the best way to add a new in-built colour theme, which would be visible even without altering the default.conf file?

I see that editorcolourset.cpp contains this, still wondering how to deal with it:
Code
EditorColourSet::EditorColourSet(const wxString& setName)
    : m_Name(setName)
{
    LoadAvailableSets();

    if (setName.IsEmpty())
        m_Name = COLORSET_DEFAULT;
    else
        Load();
}

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6024
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: C::B dark mode in Windows
« Reply #3 on: November 23, 2023, 02:45:45 pm »
The screen shot shown in the first post looks nice! good work!
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline cacb

  • Lives here!
  • ****
  • Posts: 538
Re: C::B dark mode in Windows
« Reply #4 on: November 23, 2023, 03:43:03 pm »
Dark mode in Code::Blocks is a good idea, great work!

If that can be made a standard and easy to use on/off option in Code::Blocks I would probably use it. It also keeps Code::Blocks up to date with similar features in other IDEs.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1632
Re: C::B dark mode in Windows
« Reply #5 on: November 23, 2023, 04:30:09 pm »
You can test something like this when loading from the lexer
Code
wxColor fg = LoadFromLexer(FOREGROUND);
wxColor bg = LoadFromLexer(BACKGROUND);
if (DarkMode)
{
    fg.SetRGBA(fg.GetRGBA() ^ 0x00FFFFFF);
    bg.SetRGBA(bg.GetRGBA() ^ 0x00FFFFFF);
}
inverting them again when saving.

Offline omlk

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: C::B dark mode in Windows
« Reply #6 on: November 23, 2023, 08:59:55 pm »
Hello,
I am trying to enable dark mode in MSW build. I think this may be a cool feature for some people who tend to use dark mode in everything.
This is easy if I compile it with wxWidgets 3.3 (from GitHub), one line of code is needed after app starts (https://docs.wxwidgets.org/latest/classwx_app.html#af8c93d7e3345e62a58325f3ab1d158d6)

I will post the code soon. However, I cannot find where in the code of C::B are the default values for editor colors. Where in the source code can I find the colors for editor background/foreground and syntax highlighting? Background is white by default even when using the dark mode.
I hope it's not photoshopped. I'm joking. You are still the first to do it (congratulations), but can you use any color in the color palette instead of the black interface, for example?

Offline gd_on

  • Lives here!
  • ****
  • Posts: 799
Re: C::B dark mode in Windows
« Reply #7 on: November 24, 2023, 03:47:33 pm »
Don't forget that dark mode for Windows is only supported by wxWidgets 3.3, still a beta version, and until now no provisionnal date has been given for its release.
The only date given is for wxWidgets 3.2.5, in april 2024. v3.2.4 has just been released. So, C::B will certainly not officially support this dark mode for Windows until official wxWidgets 3.3 release.
But of course, you can try it. There are several discussions on this subject on github forums, at least this one : https://github.com/wxWidgets/wxWidgets/pull/23028.
The simplest way to obtain this dark mode (without modifying C::B code), is of course to first compile and link C::B with wxWidgets 3.3.0 under Windows and simply launch it by adding a command line in a batch file like :
set WX_MSW_DARK_MODE=2
codeblocks.exe

Background and standard text colors are set inside wxWidgets. Some others are set by Windows itself. It's also possible to adjust a few colors, but not everything.
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.5 (tests with 3.3), Msys2 Compilers 14.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline adalbert

  • Single posting newcomer
  • *
  • Posts: 5
Re: C::B dark mode in Windows
« Reply #8 on: November 26, 2023, 02:44:22 pm »
OK, I uploaded the code/build files and binaries to GitHub.

https://github.com/adbrt/codeblocks-dark-mode-msw/releases/tag/release
https://github.com/adbrt/codeblocks-dark-mode-msw

Currently I just wanted to create a working proof of concept, so the dark mode is hardcoded using MSWEnableDarkMode(), I adjusted lexers XML files to have dark mode by defauld and also added a default.conf file which changes additional colors (this is necessary to change ie. the caret color). You need to run it using CbLauncher.exe so the default.conf file gets loaded from the app directory.

To make everything proper, a toggle switch for light/dark mode, automatic theme switching etc. would need to be added. But that will require more time.

Also, not only background/foreground of code editor needs to be adjusted, colours of text need to be adjusted individually for normal and dark mode, so it is readable and looks good.


can you use any color in the color palette instead of the black interface, for example?
Probably not, at least not without going really deep into the wxWidgets/CodeBlocks code, the dark interface colours are probably hardcoded somewhere, or maybe even hardcoded in the Windows itself
« Last Edit: November 26, 2023, 02:54:19 pm by adalbert »

Offline gd_on

  • Lives here!
  • ****
  • Posts: 799
Re: C::B dark mode in Windows
« Reply #9 on: November 27, 2023, 06:47:25 pm »
Reading your modifications in C::B code, I think you should guard them at least in  wxscolourproperty.cpp :
Code
#if wxCHECK_VERSION(3, 3, 0)
    #define wxPG_FL_IN_HANDLECUSTOMEDITOREVENT 0x00080000
#endif // wxCHECK_VERSION
because the value is not the same in wxWidgets 3.2.3 (or 3.2.4), and with those previous official wxWidgets versions, the compiler has no problems to find it in propgrid.h. I have until now no idea why this value is not found correctly with wxWidgets 3.3.0.

May be you can also guard inclusion of wx/hashmap.h in wxsitemeditorcontent.h, but it's probably not very useful.
Code
#if wxCHECK_VERSION(3, 3, 0)
    #include <wx/hashmap.h>
#endif // wxCHECK_VERSION


Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.5 (tests with 3.3), Msys2 Compilers 14.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline J.

  • Multiple posting newcomer
  • *
  • Posts: 47
Re: C::B dark mode in Windows
« Reply #10 on: December 25, 2023, 05:25:29 pm »
+1 ... Interesting: Is the dark mode going to find its way into C::B nightlies?

Offline DigitalSpaceDotName

  • Multiple posting newcomer
  • *
  • Posts: 14
    • IT Portfolio
Re: C::B dark mode in Windows
« Reply #11 on: March 04, 2024, 06:04:06 pm »
Hello.

Dark Mode looks very nice! I look forward for Nightly Build will get this feature.
Fan of C::B :-)

Offline DigitalSpaceDotName

  • Multiple posting newcomer
  • *
  • Posts: 14
    • IT Portfolio
Re: C::B dark mode in Windows
« Reply #12 on: March 07, 2024, 09:09:29 pm »
Win64 Re-Build 13485 compiled against WxWidget 3.3 with Dark Mode Enabled.
It looks it works. (experimental)

compiled with x86_64-13.2.0-release-win32-seh-ucrt-rt_v11-rev1

https://github.com/tomasmark79/codeblocks-dark/releases/download/CB_rev13485_win64-dark/CB_rev13485_win64-dark.7z

I uploaded to my repo fixed changes of several cbp files which was corrupted in adalbert repo.
https://github.com/tomasmark79/codeblocks-dark

Anyway there are some issues with compile some code so it is very big improvisation. Not ready for patch.



Disappeared items in Popup-menu for whispering in Dark Mode. Should be fixable by add change color availability?





« Last Edit: March 07, 2024, 10:18:28 pm by DigitalSpaceDotName »
Fan of C::B :-)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6024
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: C::B dark mode in Windows
« Reply #13 on: March 08, 2024, 01:18:26 am »
Nice work.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline DigitalSpaceDotName

  • Multiple posting newcomer
  • *
  • Posts: 14
    • IT Portfolio
Re: C::B dark mode in Windows
« Reply #14 on: March 08, 2024, 06:54:02 pm »
+ rev 13489
+ created SVN patches for simple patching
= Enjoy!

Link:
https://github.com/tomasmark79/codeblocks-dark
« Last Edit: March 10, 2024, 02:37:55 pm by DigitalSpaceDotName »
Fan of C::B :-)