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

How to theme window title bar? #2184

Closed
kitepad opened this issue Apr 19, 2021 · 20 comments
Closed

How to theme window title bar? #2184

kitepad opened this issue Apr 19, 2021 · 20 comments
Labels
bug Something isn't working help wanted Extra attention is needed OS:Windows Tickets affecting only Microsoft Windows

Comments

@kitepad
Copy link

kitepad commented Apr 19, 2021

Select dark theme, but window title bar is not themed. My OS (win 10) system theme is dark mode.

To Reproduce:

Steps to reproduce the behaviour:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Screenshots:

Example code:

Device (please complete the following information):

  • OS: Windows 10
  • Version: Enterprise build 19042
  • Go version: 1.16
  • Fyne version: 2.0.2
@kitepad kitepad added the bug Something isn't working label Apr 19, 2021
@Jacalz
Copy link
Member

Jacalz commented Apr 19, 2021

Could you please fill out all of the issue template? Using the issue template makes it much easier for us to understand, diagnose, and try to resolve the issues.

@Jacalz Jacalz added the OS:Windows Tickets affecting only Microsoft Windows label Apr 19, 2021
@kitepad
Copy link
Author

kitepad commented Apr 19, 2021

OS: Win 10
Version: Enterprise build 19042
Go version: 1.16
Fyne version: 2.0.2

Open fyne_demo.exe, and select Dark theme, but window's title bar is not themed.
My expectation is window title bar should be colored as black. I know some gui toolkit can set color for window's title bar background, some not. I cann't find document about this in fyne, can I don't know is fyne design constraint or bug. If fyne can change title bar's background, pls give me some advice.

Below is image:
image

@andydotxyz
Copy link
Member

This should happen automatically, I wonder if it is something to do with how we are setting up the Window.
With your OS in dark mode can you please confirm what other windows with a standard border look like? (For example the command prompt app or powershell)?

@kitepad
Copy link
Author

kitepad commented Apr 20, 2021

My os setting is dark mode, and command prompt and powershell window are rendered in dark mode. Like this :
image

@Jacalz
Copy link
Member

Jacalz commented Apr 20, 2021

I checked and I am seeing the same thing on my Windows 10 machine. Dark or light theme has no difference.
image

@ghost
Copy link

ghost commented Apr 20, 2021

Here is a small app that can be an investigation starting point: https://github.com/ysc3839/win32-darkmode
See RefreshTitleBarThemeColor in the DarkMode.h
I suppose it should be done somewhere at glfw level but could be a local workaround as well

@Jacalz
Copy link
Member

Jacalz commented Apr 20, 2021

@kitepad
Copy link
Author

kitepad commented Apr 20, 2021

I know win32-darkmode, but I don't have good idea to integrate with fyne and ensure don't break fyne design principle.
It's better if fyne have native support for this.

@andydotxyz
Copy link
Member

Thanks for all of these hints, it is such a shame this doesn't just work.
Let's try and pull something into the next release.

@andydotxyz andydotxyz added the help wanted Extra attention is needed label Apr 21, 2021
@ghost
Copy link

ghost commented Apr 24, 2021

Looks like there's no pure c++ API to handle this and win32-darkmode is not able to do what it states at least on my PC (win10 20H2 build 19042.928) and i see other oldschool apps like notepad++ q-dir, conemu are using white titlebar.

There's quite common workaround though. It's possible to create headless windows and draw titlebar at the toolkit level, basically a toolbar. This way is safer than the https://docs.microsoft.com/en-us/windows/win32/gdi/wm-ncpaint handling.

upd: https://stackoverflow.com/questions/33052651/glfw-how-to-drag-undecorated-window

@kitepad
Copy link
Author

kitepad commented Apr 25, 2021

@ghost
Copy link

ghost commented Apr 25, 2021

Yes, DWM is pretty similar to the NCPaint approach and it allows to extend the titlebar but the main problem is the consistency. I can draw custom colors for the title but there are window buttons and they are not redrawn. They can look differently basing on Windows OS setup and version.

Maybe i'm wrong but i believe to achieve the goal the whole window controls set should be recreated. The question is where:

  1. fragile winapi code in glfw + to convince glfw to accept that PR
  2. same fragile winapi code but with winapi hooks in the fyne
  3. frameless window with fyne toolbar that mimics window controls set

The third one looks like easier to implement and more flexible

@andydotxyz
Copy link
Member

Our solution needs to look and behave identically to the system title bars.
I really hope that there is a better workaround than re-drawing the whole thing.
Is it possible that we are missing something more obvious?

@ghost
Copy link

ghost commented Apr 25, 2021

It's always possible that something is missing and i'm not an expert there so could be wrong so i would treat that as my vision. I'm basing on the several items:

  • 'dark mode is not for win32 apps but for UWP only' is quiet often met during googling
  • numerous apps are drawing their own controls instead of using winapi (firefox, vivaldi broser, sublime-text,...)
  • pre-wpf win32 styling toolkits were replacing whole framesets

@kitepad
Copy link
Author

kitepad commented Apr 25, 2021

I have tested some win32 sdk approach. In my win32 c++ app my choice is : Create main window without caption, and create theme-able title bar control to replace system title bar even I need to implement mouse drag, window resize and system menu.

@ghost
Copy link

ghost commented Apr 25, 2021

That's what i mean. And in my version of reality it's much easier and flexible to do this using fyne controls and this trick:
https://stackoverflow.com/questions/33052651/glfw-how-to-drag-undecorated-window
But that's of course your choice which option to use, sorry if i were to pushy

@andydotxyz
Copy link
Member

That PR should fix the problem for WIndows 10 users, please let me know if it works for you :)

@kitepad
Copy link
Author

kitepad commented May 5, 2021

I tested it. It's work, but can not switch back to light in time, I have to restart it after I changed demo settings.

@andydotxyz
Copy link
Member

Unfortunately we do not yet have a way to be told when the operating system theme changes.

@andydotxyz
Copy link
Member

Marking as closed as the dark mode fix is in release/v2.0.x ready for 2.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed OS:Windows Tickets affecting only Microsoft Windows
Projects
None yet
Development

No branches or pull requests

3 participants