changeset 18618:c644cfa9cb3b stable

suppress all X11 and Qt error messages by default * octave-gui.cc (fdstderr): Delete variable and all uses. (message_handler): Don't print anything. (octave_start_gui): Check OCTAVE_SHOW_GUI_MESSAGES environment variable to decide whether to install message_handler to suppress messages. * __init_fltk__.cc (xerror_handler): New function. (plot_window::plot_window): Check OCTAVE_SHOW_GUI_MESSAGES environment variable to decide whether to install xerror_handler to suppress messages.
author John W. Eaton <jwe@octave.org>
date Fri, 04 Apr 2014 10:48:07 -0400
parents aa861a98d84d
children f1b91e3137b9 3283ce934648
files libgui/src/octave-gui.cc libinterp/dldfcn/__init_fltk__.cc
diffstat 2 files changed, 30 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/octave-gui.cc	Thu Apr 03 19:50:14 2014 -0400
+++ b/libgui/src/octave-gui.cc	Fri Apr 04 10:48:07 2014 -0400
@@ -85,42 +85,11 @@
   int m_result;
 };
 
-#if ! defined (__WIN32__) || defined (__CYGWIN__)
-static int fdstderr = -1;
-#endif
+// Disable all Qt messages by default.
 
-// Custom message handler for filtering some messages from Qt.
-
-void
+static void
 message_handler (QtMsgType type, const char *msg)
 {
-#if ! defined (__WIN32__) || defined (__CYGWIN__)
-  static FILE *errstream = fdopen (fdstderr, "a+");
-#else
-  static FILE *errstream = stderr;
-#endif
-
-  switch (type)
-    {
-    case QtDebugMsg:
-      gnulib::fprintf (errstream, "Debug: %s\n", msg);
-      break;
-
-    case QtWarningMsg:
-      gnulib::fprintf (errstream, "Warning: %s\n", msg);
-      break;
-
-    case QtCriticalMsg:
-      gnulib::fprintf (errstream, "Critical: %s\n", msg);
-      break;
-
-    case QtFatalMsg:
-      gnulib::fprintf (errstream, "Fatal: %s\n", msg);
-      abort ();
-
-    default:
-      break;
-    }
 }
 
 // If START_GUI is false, we still set up the QApplication so that we
@@ -131,14 +100,11 @@
 {
   octave_thread_manager::block_interrupt_signal ();
 
-#if ! defined (__WIN32__) || defined (__CYGWIN__)
-  // Store the file descriptor associated with the STDERR stream.  Send
-  // Qt messages there instead of to the STDERR stream that will be
-  // associated with the GUI command window.
-  fdstderr = gnulib::dup (STDERR_FILENO);
-#endif
+  std::string show_gui_msgs = octave_env::getenv ("OCTAVE_SHOW_GUI_MESSAGES");
 
-  qInstallMsgHandler (message_handler);
+  // Installing our handler suppresses the messages.
+  if (show_gui_msgs.empty ())
+    qInstallMsgHandler (message_handler);
 
   if (start_gui)
     {
--- a/libinterp/dldfcn/__init_fltk__.cc	Thu Apr 03 19:50:14 2014 -0400
+++ b/libinterp/dldfcn/__init_fltk__.cc	Fri Apr 04 10:48:07 2014 -0400
@@ -42,6 +42,10 @@
 
 #ifdef HAVE_FLTK
 
+#if defined (HAVE_X_WINDOWS)
+#include <X11/Xlib.h>
+#endif
+
 #include <map>
 #include <set>
 #include <sstream>
@@ -73,6 +77,7 @@
 
 #include "cmd-edit.h"
 #include "lo-ieee.h"
+#include "oct-env.h"
 
 #include "display.h"
 #include "file-ops.h"
@@ -674,6 +679,14 @@
   Fl_Menu_Bar* menubar;
 };
 
+#if defined (HAVE_X_WINDOWS)
+static int
+xerror_handler (Display *, XErrorEvent *)
+{
+  return 0;
+}
+#endif
+
 class plot_window : public Fl_Window
 {
   friend class fltk_uimenu;
@@ -762,7 +775,18 @@
           // Set WM_CLASS which allows window managers to properly group
           // related windows.  Otherwise, the class is just "FLTK"
           xclass ("Octave");
+
           show ();
+
+#if defined (HAVE_X_WINDOWS)
+          std::string show_gui_msgs
+            = octave_env::getenv ("OCTAVE_SHOW_GUI_MESSAGES");
+
+          // Installing our handler suppresses the messages.
+          if (show_gui_msgs.empty ())
+            XSetErrorHandler (xerror_handler);
+#endif
+
           if (fp.get_currentaxes ().ok ())
             show_canvas ();
           else