Skip to content

Commit e26efa5

Browse files
authored
Merge pull request #22928 from greglucas/macosx-raise-window
ENH: Add option to disable raising the window for macosx
2 parents 1dbaae3 + 6c7baf0 commit e26efa5

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/matplotlib/backends/backend_macosx.py

+8
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class FigureManagerMac(_macosx.FigureManager, FigureManagerBase):
140140
_toolbar2_class = NavigationToolbar2Mac
141141

142142
def __init__(self, canvas, num):
143+
self._shown = False
143144
_macosx.FigureManager.__init__(self, canvas)
144145
icon_path = str(cbook._get_data_path('images/matplotlib.pdf'))
145146
_macosx.FigureManager.set_icon(icon_path)
@@ -154,6 +155,13 @@ def close(self):
154155
Gcf.destroy(self)
155156
self.canvas.flush_events()
156157

158+
def show(self):
159+
if not self._shown:
160+
self._show()
161+
self._shown = True
162+
if mpl.rcParams["figure.raise_window"]:
163+
self._raise()
164+
157165

158166
@_Backend.export
159167
class _BackendMac(_Backend):

src/_macosx.m

+12-3
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,15 @@ static CGFloat _get_device_scale(CGContextRef cr)
586586
}
587587

588588
static PyObject*
589-
FigureManager_show(FigureManager* self)
589+
FigureManager__show(FigureManager* self)
590590
{
591591
[self->window makeKeyAndOrderFront: nil];
592+
Py_RETURN_NONE;
593+
}
594+
595+
static PyObject*
596+
FigureManager__raise(FigureManager* self)
597+
{
592598
[self->window orderFrontRegardless];
593599
Py_RETURN_NONE;
594600
}
@@ -695,8 +701,11 @@ static CGFloat _get_device_scale(CGContextRef cr)
695701
.tp_new = (newfunc)FigureManager_new,
696702
.tp_doc = "A FigureManager object wraps a Cocoa NSWindow object.",
697703
.tp_methods = (PyMethodDef[]){ // All docstrings are inherited.
698-
{"show",
699-
(PyCFunction)FigureManager_show,
704+
{"_show",
705+
(PyCFunction)FigureManager__show,
706+
METH_NOARGS},
707+
{"_raise",
708+
(PyCFunction)FigureManager__raise,
700709
METH_NOARGS},
701710
{"destroy",
702711
(PyCFunction)FigureManager_destroy,

0 commit comments

Comments
 (0)