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

Get the users current theme programatically (VS2019-2022) #460

Closed
Tim-Maes opened this issue Sep 29, 2023 · 5 comments
Closed

Get the users current theme programatically (VS2019-2022) #460

Tim-Maes opened this issue Sep 29, 2023 · 5 comments

Comments

@Tim-Maes
Copy link

Hi,

I maintain a VSIX extension that provides syntax highlighting provided through classifiers. When running the extensions for the first time I ask the user what VS theme they are currently using and apply colors based on their input.

Now I want to do this automatically without user input - get the users current theme (Light/Dark). I found some online information about this but it seems deprecated or outdated - or I'm missing something

How can this be achieved?

Thanks

@madskristensen
Copy link
Contributor

If you can get the editor background color, you can then figure out if you need to use light or dark colors using this utility function:

ContrastComparisonResult contrast = ColorUtilities.CompareContrastWithBlackAndWhite(brush.Color);

@reduckted
Copy link
Contributor

Now I want to do this automatically without user input - get the users current theme (Light/Dark). I found some online information about this but it seems deprecated or outdated - or I'm missing something

Defining a color category with color definitions might be able to handle this, and would allow users to modify the colors.

Take a look at #414 (yet to be merged).

If you used "automatic" color that was backed by a VisualStudioColor, then it should handle selecting a color that's suitable for the current light/dark theme.

@mrlacey
Copy link

mrlacey commented Oct 4, 2023

Also note that there are more theme options than just light and dark.
VS itself provides Blue & Blue (High Contrast)
And, obviously, there can be custom ones as well. Don't only support dark&light as this frequently (I use a blue high contrast theme and so have seen this many times) leads to some things not showing up correctly for anyone who uses something else.

@Matt-17
Copy link
Contributor

Matt-17 commented Nov 13, 2023

I'm not sure if this fits your problem, but in using Microsoft.VisualStudio.PlatformUI; there is VSColorTheme.

You can listen on

    VSColorTheme.ThemeChanged += VSColorTheme_ThemeChanged;

and easily read some variables in there via

private void VSColorTheme_ThemeChanged(ThemeChangedEventArgs e)
{
    var themedColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
}

@Tim-Maes
Copy link
Author

@Matt-17 That helped, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants