diff --git a/lib/matplotlib/tests/test_backends_interactive.py b/lib/matplotlib/tests/test_backends_interactive.py index 4494efa35437..fe83e0bdd445 100644 --- a/lib/matplotlib/tests/test_backends_interactive.py +++ b/lib/matplotlib/tests/test_backends_interactive.py @@ -154,13 +154,8 @@ def check_alt_backend(alt_backend): @pytest.mark.parametrize("toolbar", ["toolbar2", "toolmanager"]) @pytest.mark.flaky(reruns=3) def test_interactive_backend(backend, toolbar): - if backend == "macosx": - if toolbar == "toolmanager": - pytest.skip("toolmanager is not implemented for macosx.") - if toolbar == "toolbar2" and os.environ.get('TRAVIS'): - # See https://github.com/matplotlib/matplotlib/issues/18213 - pytest.skip("toolbar2 for macosx is buggy on Travis.") - + if backend == "macosx" and toolbar == "toolmanager": + pytest.skip("toolmanager is not implemented for macosx.") proc = subprocess.run( [sys.executable, "-c", _test_script, json.dumps({"toolbar": toolbar})], diff --git a/src/_macosx.m b/src/_macosx.m index 1d559d195b73..65a5c76127be 100755 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -207,6 +207,7 @@ @interface View : NSView } - (void)dealloc; - (void)drawRect:(NSRect)rect; +- (void)updateScale:(double)scale; - (void)windowDidResize:(NSNotification*)notification; - (View*)initWithFrame:(NSRect)rect; - (void)setCanvas: (PyObject*)newCanvas; @@ -680,6 +681,7 @@ static CGFloat _get_device_scale(CGContextRef cr) [window setDelegate: view]; [window makeFirstResponder: view]; [[window contentView] addSubview: view]; + [view updateScale: [window backingScaleFactor]]; return 0; } @@ -1617,6 +1619,16 @@ static int _copy_agg_buffer(CGContextRef cr, PyObject *renderer) return 0; } +- (void)updateScale:(double)scale +{ + if (device_scale != scale) { + device_scale = scale; + if (!PyObject_CallMethod(canvas, "_set_device_scale", "d", device_scale, NULL)) { + PyErr_Print(); + } + } +} + -(void)drawRect:(NSRect)rect { PyObject* renderer = NULL; @@ -1627,14 +1639,8 @@ -(void)drawRect:(NSRect)rect CGContextRef cr = [[NSGraphicsContext currentContext] graphicsPort]; double new_device_scale = _get_device_scale(cr); + [self updateScale: new_device_scale]; - if (device_scale != new_device_scale) { - device_scale = new_device_scale; - if (!PyObject_CallMethod(canvas, "_set_device_scale", "d", device_scale, NULL)) { - PyErr_Print(); - goto exit; - } - } if (!(renderer = PyObject_CallMethod(canvas, "_draw", "", NULL)) || !(renderer_buffer = PyObject_GetAttrString(renderer, "_renderer"))) { PyErr_Print();