From 5d95a18b6b58a9e5c600a720b9481122b6b27f1a Mon Sep 17 00:00:00 2001 From: Anton Schwarz Date: Wed, 26 Aug 2026 15:40:24 +0200 Subject: [PATCH] [gui] Native GUI draws canvas without defaulting to web When drawing a canvas in a native GUI (e.g. using `tutorials/visualisation/gui/guitest.C` and Test->Dialog->Tab3), the canvas used to default to black. The workaround was `--web=off`, which is inconvenient. Implements a new method `TGuiFactory::CreateCanvasImpNative` that bypasses the `gROOT->IsWebDisplay()` check and directly returns a `TCanvasImp` as required by the native GUI. `TGuiFactory::CreateCanvasImp` receives `TCanvas *c` as a parameter. For a web canvas, the canvas ID is `111222333` (see `TWebCanvas.cxx:293`), this would be enough to determine that we do not want to create a web canvas element, but a native one instead. However, `TCanvas` is only forward declared within `TGuiFactory`, hence we cannot access its methods. --- core/gui/inc/TGuiFactory.h | 1 + core/gui/src/TGuiFactory.cxx | 8 ++++++++ graf2d/gpad/src/TCanvas.cxx | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/gui/inc/TGuiFactory.h b/core/gui/inc/TGuiFactory.h index 86045fe65642e..6c91e564beb8a 100644 --- a/core/gui/inc/TGuiFactory.h +++ b/core/gui/inc/TGuiFactory.h @@ -50,6 +50,7 @@ class TGuiFactory : public TNamed { virtual TApplicationImp *CreateApplicationImp(const char *classname, int *argc, char **argv); virtual TCanvasImp *CreateCanvasImp(TCanvas *c, const char *title, UInt_t width, UInt_t height); + virtual TCanvasImp *CreateCanvasImpNative(TCanvas *c, const char *title, UInt_t width, UInt_t height); virtual TCanvasImp *CreateCanvasImp(TCanvas *c, const char *title, Int_t x, Int_t y, UInt_t width, UInt_t height); virtual TBrowserImp *CreateBrowserImp(TBrowser *b, const char *title, UInt_t width, UInt_t height, Option_t *opt=""); diff --git a/core/gui/src/TGuiFactory.cxx b/core/gui/src/TGuiFactory.cxx index cacc618583bdc..b9302e744a55b 100644 --- a/core/gui/src/TGuiFactory.cxx +++ b/core/gui/src/TGuiFactory.cxx @@ -81,6 +81,14 @@ TCanvasImp *TGuiFactory::CreateCanvasImp(TCanvas *c, const char *title, UInt_t w return new TCanvasImp(c, title, width, height); } +//////////////////////////////////////////////////////////////////////////////// +/// Create a batch version of TCanvasImpNative, skipping the IsWebDisplay check. + +TCanvasImp *TGuiFactory::CreateCanvasImpNative(TCanvas *c, const char *title, UInt_t width, UInt_t height) +{ + return new TCanvasImp(c, title, width, height); +} + //////////////////////////////////////////////////////////////////////////////// /// Create a batch version of TCanvasImp. diff --git a/graf2d/gpad/src/TCanvas.cxx b/graf2d/gpad/src/TCanvas.cxx index ee2b1a0819f32..ecd80939fd852 100644 --- a/graf2d/gpad/src/TCanvas.cxx +++ b/graf2d/gpad/src/TCanvas.cxx @@ -255,7 +255,7 @@ TCanvas::TCanvas(const char *name, Int_t ww, Int_t wh, Int_t winid) : TPad(), fD fUseGL = kFALSE; } - fCanvasImp = gBatchGuiFactory->CreateCanvasImp(this, name, fCw, fCh); + fCanvasImp = gBatchGuiFactory->CreateCanvasImpNative(this, name, fCw, fCh); if (!fCanvasImp) return; CreatePainter();