From 063b218f2d7e9b7e05452b79c520f312da3b8490 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Mon, 14 Dec 2020 23:50:14 +0000 Subject: Fix [80e4c6f695]: progress bars are weird on macOS 11.0. --- generic/ttk/ttkProgress.c | 9 +++++---- macosx/ttkMacOSXTheme.c | 27 ++++++++++++++------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/generic/ttk/ttkProgress.c b/generic/ttk/ttkProgress.c index ae945ae..42da84d 100644 --- a/generic/ttk/ttkProgress.c +++ b/generic/ttk/ttkProgress.c @@ -102,7 +102,6 @@ static void AnimateProgressProc(ClientData clientData) Progressbar *pb = (Progressbar *)clientData; pb->progress.timer = 0; - if (AnimationEnabled(pb)) { int phase = 0; Tcl_GetIntFromObj(NULL, pb->progress.phaseObj, &phase); @@ -110,9 +109,11 @@ static void AnimateProgressProc(ClientData clientData) /* * Update -phase: */ + ++phase; - if (pb->progress.maxPhase) - phase %= pb->progress.maxPhase; + if (phase > pb->progress.maxPhase) { + phase = 0; + } Tcl_DecrRefCount(pb->progress.phaseObj); pb->progress.phaseObj = Tcl_NewIntObj(phase); Tcl_IncrRefCount(pb->progress.phaseObj); @@ -120,9 +121,9 @@ static void AnimateProgressProc(ClientData clientData) /* * Reschedule: */ + pb->progress.timer = Tcl_CreateTimerHandler( pb->progress.period, AnimateProgressProc, clientData); - TtkRedisplayWidget(&pb->core); } } diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index 17982b6..37f84cd 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -2290,15 +2290,20 @@ static void PbarElementDraw( Ttk_State state) { PbarElement *pbar = elementRecord; - int orientation = TTK_ORIENT_HORIZONTAL, phase = 0; - double value = 0, maximum = 100, factor; + int orientation = TTK_ORIENT_HORIZONTAL, phase = 0, kind; + double value = 100, maximum = 100, factor = 1; CGRect bounds; Ttk_GetOrientFromObj(NULL, pbar->orientObj, &orientation); - Tcl_GetDoubleFromObj(NULL, pbar->valueObj, &value); - Tcl_GetDoubleFromObj(NULL, pbar->maximumObj, &maximum); - Tcl_GetIntFromObj(NULL, pbar->phaseObj, &phase); - factor = RangeToFactor(maximum); + kind = !strcmp("indeterminate", Tcl_GetString(pbar->modeObj)) ? + kThemeIndeterminateBar : kThemeProgressBar; + if (kind == kThemeIndeterminateBar) { + Tcl_GetIntFromObj(NULL, pbar->phaseObj, &phase); + } else { + Tcl_GetDoubleFromObj(NULL, pbar->valueObj, &value); + Tcl_GetDoubleFromObj(NULL, pbar->maximumObj, &maximum); + factor = RangeToFactor(maximum); + } /* * HIThemeTrackDrawInfo uses 2-byte alignment; assigning to a separate @@ -2308,19 +2313,15 @@ static void PbarElementDraw( bounds = BoxToRect(d, b); HIThemeTrackDrawInfo info = { .version = 0, - .kind = - (!strcmp("indeterminate", - Tcl_GetString(pbar->modeObj)) && value) ? - kThemeIndeterminateBar : kThemeProgressBar, + .kind = kind, .bounds = bounds, .min = 0, .max = maximum * factor, .value = value * factor, .attributes = kThemeTrackShowThumb | - (orientation == TTK_ORIENT_HORIZONTAL ? - kThemeTrackHorizontal : 0), + (orientation == TTK_ORIENT_HORIZONTAL ? kThemeTrackHorizontal : 0), .enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state), - .trackInfo.progress.phase = phase, + .trackInfo.progress.phase = phase }; BEGIN_DRAWING(d) -- cgit v0.12 From f5b9400c1c5f2c33f7955084a81435348792cd6b Mon Sep 17 00:00:00 2001 From: marc_culler Date: Tue, 15 Dec 2020 15:38:40 +0000 Subject: Fine tune the Big Sur behavior. --- library/ttk/aquaTheme.tcl | 2 +- macosx/ttkMacOSXTheme.c | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/library/ttk/aquaTheme.tcl b/library/ttk/aquaTheme.tcl index 51c3e49..3ccdd70 100644 --- a/library/ttk/aquaTheme.tcl +++ b/library/ttk/aquaTheme.tcl @@ -99,7 +99,7 @@ namespace eval ttk::theme::aqua { } # Enable animation for ttk::progressbar widget: - ttk::style configure TProgressbar -period 100 -maxphase 255 + ttk::style configure TProgressbar -period 100 -maxphase 120 # For Aqua, labelframe labels should appear outside the border, # with a 14 pixel inset and 4 pixels spacing between border and label diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index 37f84cd..a723408 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -2291,18 +2291,35 @@ static void PbarElementDraw( { PbarElement *pbar = elementRecord; int orientation = TTK_ORIENT_HORIZONTAL, phase = 0, kind; - double value = 100, maximum = 100, factor = 1; + + /* + * Using 1000 as the maximum should give better than 1 pixel + * resolution for most progress bars. + */ + + int ivalue, imaximum = 1000; CGRect bounds; Ttk_GetOrientFromObj(NULL, pbar->orientObj, &orientation); kind = !strcmp("indeterminate", Tcl_GetString(pbar->modeObj)) ? - kThemeIndeterminateBar : kThemeProgressBar; + kThemeIndeterminateBar : kThemeProgressBar; if (kind == kThemeIndeterminateBar) { Tcl_GetIntFromObj(NULL, pbar->phaseObj, &phase); + + /* + * On macOS 11 the fraction of an indeterminate progress bar which is + * traversed by the oscillating thumb is value / maximum. The phase + * determines the position of the moving thumb in that range and is + * apparently expected to vary between 0 and 120. On earlier systems + * it is unclear how the phase is used in generating the animation. + */ + + ivalue = imaximum; } else { + double value, maximum; Tcl_GetDoubleFromObj(NULL, pbar->valueObj, &value); Tcl_GetDoubleFromObj(NULL, pbar->maximumObj, &maximum); - factor = RangeToFactor(maximum); + ivalue = (value / maximum)*1000; } /* @@ -2316,14 +2333,13 @@ static void PbarElementDraw( .kind = kind, .bounds = bounds, .min = 0, - .max = maximum * factor, - .value = value * factor, + .max = imaximum, + .value = ivalue, .attributes = kThemeTrackShowThumb | (orientation == TTK_ORIENT_HORIZONTAL ? kThemeTrackHorizontal : 0), .enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state), .trackInfo.progress.phase = phase }; - BEGIN_DRAWING(d) if (TkMacOSXInDarkMode(tkwin)) { bounds = BoxToRect(d, b); -- cgit v0.12