-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Set title bar light or dark on Windows based on theme #18198
Set title bar light or dark on Windows based on theme #18198
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code would be much cleaner if you implemented a dtwin_set_titlebar_color
for every architecture (as a no-op on everthing but windows). We've worked hard over the past few years to remove conditional compilation from mainline code and hide it inside macros (e.g. DT_OMP_FOR) or utility functions, because that hiding makes the code more maintainable - you only need to change one definition rather than every location where it is used.
I suggest putting the conttents of win/dtwin.h inside an #ifdef _WIN32
and adding an #else
with
#define dtwin_set_titlebar_color(widget)
Then you can drop the #ifdef
guards around all calls to the function and all #include
s of dtwin.h.
@ralfbrown, Thank you for the good advice. |
Rather than adding a function call for each and every time a gtk window gets shown (and making sure this is done for all new ones in future), you could override/extend the default handler for the This Here you probably want to do something like
in Of course you only override the handler under windows and a separate source file for just the handler |
In case that wasn't clear, its implemented in b9c7846 I've overridden |
@andriiryzhkov : Given the simplicity of @dterrahe proposal in the mentioned commit I suppose we should go this way. Have you double checked that this works on your side? |
@dterrahe: I love your approach; thank you for the advice. The only edge case left is that after a theme change, the title bar will be updated only when any open window is resized or moved. I don't see it as a critical problem, but please advise if you know how to force updating the title bar right after the theme change. |
For the main window, you could explicitly update it in the theme loading code. If you want "all" open windows to update (realistically this would be main+prefs+second preview) then you could override the |
I found that a combination of |
d6a50a8 works and updates main and second preview window titlebars immediately when changing the theme in preferences (upon pressing "save CSS and apply"). |
be careful; those signals have different arguments and return types so using the same call to |
Indeed, the preferences dialog title bar responds to |
Speculating: a theme change may cause a resize (because of font sizes) and that would trigger a configure-event. Maybe not every theme change would trigger it. |
With
|
Sloppy testing on my side! Yes, and this makes sense because the overrides must be in place before the main window is created in |
Done. The initial main window has the correct title bar color. The only thing left is that after CSS tweaks are saved, the preferences dialog does not update the title bar color until it is opened next time. |
It looks like gtk actually checks whether anything in the css has changed that would impact the dialog, before sending it a |
The callback should be
and likewise the chaining call should be
|
So for consistency you could consider changing the code to retrieve the background color to get the actual color of the window/dialog:
|
Done |
Yeah, that was the initial implementation from GIMP. At some point, I decided getting the |
I'm not sure what you mean. If you are saying changing the line
in the CSS tweaks field and then pressing "save CSS and apply" doesn't change the preference dialog box title color, then that's correct, because it does not depend on that color (not in the themes either). When I change
and press "save CSS and apply" the preferences titlebar gets updated immediately (but in this case, obviously, not the application window titlebar, because it is not linked to that). |
Just one comment: if we stick to retrieving the |
Fixes #17392
This implementation is based on this approach from GIMP https://gitlab.gnome.org/GNOME/gimp/-/issues/9646.
It uses
DwmSetWindowAttribute()
to set dialogue title bars to either dark or light mode on Windows. This is done by checking the dialogue's background color and setting to dark mode if it's below a threshold (currently 0.5, 0.5, 0.5).The function
dtwin_set_titlebar_color(GtkWidget *widget)
needs to be called just before each dialog window in darktable is shown.