summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorculler <culler>2021-11-01 22:09:56 (GMT)
committerculler <culler>2021-11-01 22:09:56 (GMT)
commit288cea6827428e424632326901e73d2807cb2135 (patch)
tree326859d17c8cb83e38aa7956ba71d172e014c816
parent2e905a7d2f59d4cb965071ba541abf27cce68113 (diff)
parent17efef46d0ceb334776458a8d23df6fb6dcf6c75 (diff)
downloadtk-288cea6827428e424632326901e73d2807cb2135.zip
tk-288cea6827428e424632326901e73d2807cb2135.tar.gz
tk-288cea6827428e424632326901e73d2807cb2135.tar.bz2
Appearance and usability issues, mainly for Monterey, mainly for dark mode.
-rw-r--r--generic/tkButton.c5
-rw-r--r--macosx/tkMacOSXButton.c10
-rw-r--r--macosx/tkMacOSXColor.c15
-rw-r--r--macosx/tkMacOSXColor.h4
-rw-r--r--macosx/tkMacOSXDefault.h7
-rw-r--r--macosx/ttkMacOSXTheme.c89
6 files changed, 97 insertions, 33 deletions
diff --git a/generic/tkButton.c b/generic/tkButton.c
index 4b04e9f..2c7d7d2 100644
--- a/generic/tkButton.c
+++ b/generic/tkButton.c
@@ -104,8 +104,13 @@ static const Tk_OptionSpec labelOptionSpecs[] = {
NULL, 0, -1, 0, "-foreground", 0},
{TK_OPTION_FONT, "-font", "font", "Font",
DEF_BUTTON_FONT, -1, Tk_Offset(TkButton, tkfont), 0, 0, 0},
+#ifdef DEF_LABEL_FG
+ {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
+ DEF_LABEL_FG, -1, Tk_Offset(TkButton, normalFg), 0, 0, 0},
+#else
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
DEF_BUTTON_FG, -1, Tk_Offset(TkButton, normalFg), 0, 0, 0},
+#endif
{TK_OPTION_STRING, "-height", "height", "Height",
DEF_BUTTON_HEIGHT, Tk_Offset(TkButton, heightPtr), -1, 0, 0, 0},
{TK_OPTION_BORDER, "-highlightbackground", "highlightBackground",
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index b083531..f8f60f8 100644
--- a/macosx/tkMacOSXButton.c
+++ b/macosx/tkMacOSXButton.c
@@ -765,10 +765,12 @@ TkMacOSXDrawButton(
* Using a ttk::button would be a much better choice, however.
*/
- if (TkMacOSXInDarkMode(butPtr->tkwin) &&
- mbPtr->drawinfo.state != kThemeStatePressed &&
- !(mbPtr->drawinfo.adornment & kThemeAdornmentDefault)) {
- hiinfo.state = kThemeStateInactive;
+ if ([NSApp macOSVersion] < 101500) {
+ if (TkMacOSXInDarkMode(butPtr->tkwin) &&
+ mbPtr->drawinfo.state != kThemeStatePressed &&
+ !(mbPtr->drawinfo.adornment & kThemeAdornmentDefault)) {
+ hiinfo.state = kThemeStateInactive;
+ }
}
HIThemeDrawButton(&cntrRect, &hiinfo, dc.context,
kHIThemeOrientationNormal, &contHIRec);
diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c
index edcd5d3..3951683 100644
--- a/macosx/tkMacOSXColor.c
+++ b/macosx/tkMacOSXColor.c
@@ -24,6 +24,7 @@ static int numSystemColors;
static int rgbColorIndex;
static int controlAccentIndex;
static int selectedTabTextIndex;
+static int pressedButtonTextIndex;
static Bool useFakeAccentColor = NO;
static SystemColorDatum **systemColorIndex;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
@@ -67,7 +68,8 @@ void initColorTable()
if (![NSColor respondsToSelector:colorSelector]) {
if ([colorName isEqualToString:@"controlAccentColor"]) {
useFakeAccentColor = YES;
- } else if (![colorName isEqualToString:@"selectedTabTextColor"]) {
+ } else if ( ![colorName isEqualToString:@"selectedTabTextColor"]
+ && ![colorName isEqualToString:@"pressedButtonTextColor"]) {
/* Uncomment to print all unsupported colors: */
/* printf("Unsupported color %s\n", colorName.UTF8String); */
continue;
@@ -147,6 +149,9 @@ void initColorTable()
hPtr = Tcl_FindHashEntry(&systemColors, "SelectedTabTextColor");
entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
selectedTabTextIndex = entry->index;
+ hPtr = Tcl_FindHashEntry(&systemColors, "PressedButtonTextColor");
+ entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
+ pressedButtonTextIndex = entry->index;
[pool drain];
}
@@ -278,6 +283,7 @@ GetRGBA(
CGFloat *rgba)
{
NSColor *bgColor, *color = nil;
+ int OSVersion = [NSApp macOSVersion];
if (!sRGB) {
sRGB = [NSColorSpace sRGBColorSpace];
@@ -325,12 +331,17 @@ GetRGBA(
colorUsingColorSpace:sRGB];
#endif
} else if (entry->index == selectedTabTextIndex) {
- int OSVersion = [NSApp macOSVersion];
if (OSVersion > 100600 && OSVersion < 110000) {
color = [[NSColor whiteColor] colorUsingColorSpace:sRGB];
} else {
color = [[NSColor textColor] colorUsingColorSpace:sRGB];
}
+ } else if (entry->index == pressedButtonTextIndex) {
+ if (OSVersion < 120000) {
+ color = [[NSColor whiteColor] colorUsingColorSpace:sRGB];
+ } else {
+ color = [[NSColor blackColor] colorUsingColorSpace:sRGB];
+ }
} else {
color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB];
}
diff --git a/macosx/tkMacOSXColor.h b/macosx/tkMacOSXColor.h
index deffbbc..bc9d307 100644
--- a/macosx/tkMacOSXColor.h
+++ b/macosx/tkMacOSXColor.h
@@ -241,8 +241,10 @@ static SystemColorDatum systemColorData[] = {
{"WindowBackgroundColor7", ttkBackground, 7, NULL, 0, NULL },
/* Apple's SecondaryLabelColor is the same as their LabelColor so we roll our own. */
{"SecondaryLabelColor", ttkBackground, 14, NULL, 0, NULL },
-/* Color to use for notebook tab labels -- depends on OS version. */
+/* Color to use for notebook tab label text -- depends on OS version. */
{"SelectedTabTextColor", semantic, 0, "textColor", 0, NULL },
+/* Color to use for selected button labels -- depends on OS version. */
+{"PressedButtonTextColor", semantic, 0, "textColor", 0, NULL },
/* Semantic colors that we simulate on older systems which don't supoort them. */
{"ControlAccentColor", semantic, 0, "controlAccentColor", 0, NULL },
{"LabelColor", semantic, 0, "blackColor", 0, NULL },
diff --git a/macosx/tkMacOSXDefault.h b/macosx/tkMacOSXDefault.h
index c0f72fb..3a8eb92 100644
--- a/macosx/tkMacOSXDefault.h
+++ b/macosx/tkMacOSXDefault.h
@@ -55,7 +55,7 @@
#define DEF_BUTTON_ANCHOR "center"
#define DEF_BUTTON_ACTIVE_BG_COLOR ACTIVE_BG
#define DEF_BUTTON_ACTIVE_BG_MONO BLACK
-#define DEF_BUTTON_ACTIVE_FG_COLOR WHITE
+#define DEF_BUTTON_ACTIVE_FG_COLOR "systemPressedButtonTextColor"
#define DEF_CHKRAD_ACTIVE_FG_COLOR ACTIVE_FG
#define DEF_BUTTON_ACTIVE_FG_MONO WHITE
#define DEF_BUTTON_BG_COLOR NORMAL_BG
@@ -68,8 +68,9 @@
#define DEF_BUTTON_DEFAULT "disabled"
#define DEF_BUTTON_DISABLED_FG_COLOR DISABLED
#define DEF_BUTTON_DISABLED_FG_MONO ""
-#define DEF_BUTTON_FG NORMAL_FG
-#define DEF_CHKRAD_FG DEF_BUTTON_FG
+#define DEF_BUTTON_FG BLACK
+#define DEF_LABEL_FG NORMAL_FG
+#define DEF_CHKRAD_FG DEF_LABEL_FG
#define DEF_BUTTON_FONT "TkDefaultFont"
#define DEF_BUTTON_HEIGHT "0"
#define DEF_BUTTON_HIGHLIGHT_BG_COLOR DEF_BUTTON_BG_COLOR
diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c
index 8379812..3334356 100644
--- a/macosx/ttkMacOSXTheme.c
+++ b/macosx/ttkMacOSXTheme.c
@@ -63,7 +63,10 @@
*/
static CGFloat darkButtonFace[4] = {
- 112.0 / 255, 113.0 / 255, 115.0 / 255, 1.0
+ 90.0 / 255, 86.0 / 255, 95.0 / 255, 1.0
+};
+static CGFloat darkPressedButtonFace[4] = {
+ 114.0 / 255, 110.0 / 255, 118.0 / 255, 1.0
};
static CGFloat darkPressedBevelFace[4] = {
135.0 / 255, 136.0 / 255, 138.0 / 255, 1.0
@@ -77,6 +80,12 @@ static CGFloat darkDisabledButtonFace[4] = {
static CGFloat darkInactiveSelectedTab[4] = {
159.0 / 255, 160.0 / 255, 161.0 / 255, 1.0
};
+static CGFloat darkSelectedTab[4] = {
+ 97.0 / 255, 94.0 / 255, 102.0 / 255, 1.0
+};
+static CGFloat darkTab[4] = {
+ 44.0 / 255, 41.0 / 255, 50.0 / 255, 1.0
+};
static CGFloat darkFocusRing[4] = {
38.0 / 255, 113.0 / 255, 159.0 / 255, 1.0
};
@@ -720,8 +729,15 @@ static void DrawDarkButton(
bounds = CGRectInset(bounds, 1, 1);
if (kind == kThemePushButton && (state & TTK_STATE_PRESSED)) {
- GradientFillRoundedRectangle(context, bounds, 4,
+ if ([NSApp macOSVersion] < 120000) {
+ GradientFillRoundedRectangle(context, bounds, 4,
pressedPushButtonGradient, 2);
+ } else {
+ faceColor = [NSColor colorWithColorSpace: deviceRGB
+ components: darkPressedButtonFace
+ count: 4];
+ SolidFillRoundedRectangle(context, bounds, 4, faceColor);
+ }
} else if (kind == kThemePushButton &&
(state & TTK_STATE_ALTERNATE) &&
!(state & TTK_STATE_BACKGROUND)) {
@@ -996,6 +1012,7 @@ static void DrawDarkTab(
NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
NSColor *faceColor, *stroke;
CGRect originalBounds = bounds;
+ int OSVersion = [NSApp macOSVersion];
CGContextSetLineWidth(context, 1.0);
CGContextClipToRect(context, bounds);
@@ -1005,13 +1022,14 @@ static void DrawDarkTab(
* clipped off.
*/
- if (!(state & TTK_STATE_FIRST_TAB)) {
- bounds.origin.x -= 10;
- bounds.size.width += 10;
- }
-
- if (!(state & TTK_STATE_LAST_TAB)) {
- bounds.size.width += 10;
+ if (OSVersion < 110000 || !(state & TTK_STATE_SELECTED)) {
+ if (!(state & TTK_STATE_FIRST_TAB)) {
+ bounds.origin.x -= 10;
+ bounds.size.width += 10;
+ }
+ if (!(state & TTK_STATE_LAST_TAB)) {
+ bounds.size.width += 10;
+ }
}
/*
@@ -1023,13 +1041,25 @@ static void DrawDarkTab(
bounds = CGRectInset(bounds, 1, 1);
if (!(state & TTK_STATE_SELECTED)) {
if (state & TTK_STATE_DISABLED) {
- faceColor = [NSColor colorWithColorSpace: deviceRGB
- components: darkDisabledButtonFace
- count: 4];
+ if (OSVersion < 110000) {
+ faceColor = [NSColor colorWithColorSpace: deviceRGB
+ components: darkDisabledButtonFace
+ count: 4];
+ } else {
+ faceColor = [NSColor colorWithColorSpace: deviceRGB
+ components: darkTab
+ count: 4];
+ }
} else {
- faceColor = [NSColor colorWithColorSpace: deviceRGB
- components: darkButtonFace
- count: 4];
+ if (OSVersion < 110000) {
+ faceColor = [NSColor colorWithColorSpace: deviceRGB
+ components: darkButtonFace
+ count: 4];
+ } else {
+ faceColor = [NSColor colorWithColorSpace: deviceRGB
+ components: darkTab
+ count: 4];
+ }
}
SolidFillRoundedRectangle(context, bounds, 4, faceColor);
@@ -1056,21 +1086,34 @@ static void DrawDarkTab(
} else {
/*
- * This is the selected tab; paint it blue. If it is first, cover up
- * the separator line drawn by the second one. (The selected tab is
- * always drawn last.)
+ * This is the selected tab. If it is first, cover up the separator
+ * line drawn by the second one. (The selected tab is always drawn
+ * last.)
*/
if ((state & TTK_STATE_FIRST_TAB) && !(state & TTK_STATE_LAST_TAB)) {
bounds.size.width += 1;
}
if (!(state & TTK_STATE_BACKGROUND)) {
- GradientFillRoundedRectangle(context, bounds, 4,
- darkSelectedGradient, 2);
+ if (OSVersion < 110000) {
+ GradientFillRoundedRectangle(context, bounds, 4,
+ darkSelectedGradient, 2);
+ } else {
+ faceColor = [NSColor colorWithColorSpace: deviceRGB
+ components: darkSelectedTab
+ count: 4];
+ SolidFillRoundedRectangle(context, bounds, 4, faceColor);
+ }
} else {
- faceColor = [NSColor colorWithColorSpace: deviceRGB
- components: darkInactiveSelectedTab
- count: 4];
+ if (OSVersion < 110000) {
+ faceColor = [NSColor colorWithColorSpace: deviceRGB
+ components: darkInactiveSelectedTab
+ count: 4];
+ } else {
+ faceColor = [NSColor colorWithColorSpace: deviceRGB
+ components: darkSelectedTab
+ count: 4];
+ }
SolidFillRoundedRectangle(context, bounds, 4, faceColor);
}
HighlightButtonBorder(context, bounds);