Skip to content

Commit

Permalink
Enable FLTK graphics toolkit on macOS if not multi-threaded (bug #664…
Browse files Browse the repository at this point in the history
…82).

* libinterp/octave.h (octave::application): Add new member functions
"multi_threaded" and "is_multi_threaded". The latter can be used to query if
Octave uses multiple threads (e.g., for the interpreter and various QThreads for
the GUI).
* libinterp/octave.cc (F__is_multi_threaded__): New (internal) function to query
whether Octave is running with multiple threads from .m-file code.
* libgui/src/qt-application.h (octave::qt_application::multi_threaded): Overload
new member function.
* libinterp/dldfcn/__init_fltk__.cc (PKG_ADD): Register the graphics toolkit
"fltk" on macOS unless Octave is running with multiple threads (QThread using
GUI).
  • Loading branch information
mmuetzel committed Nov 18, 2024
1 parent cf4f5f8 commit ac9f011
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions libgui/src/qt-application.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class OCTGUI_API qt_application : public application
bool gui_running () const { return m_gui_running; }
void gui_running (bool arg) { m_gui_running = arg; }

bool multi_threaded () const { return true; }

private:

// If TRUE, the GUI should be started.
Expand Down
4 changes: 2 additions & 2 deletions libinterp/dldfcn/__init_fltk__.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To initialize:
*/

// PKG_ADD: if (__have_feature__ ("FLTK") && __have_feature__ ("OPENGL") && have_window_system () && ! (ismac () && __event_manager_enabled__ ())) register_graphics_toolkit ("fltk"); endif
// PKG_ADD: if (__have_feature__ ("FLTK") && __have_feature__ ("OPENGL") && have_window_system () && ! (ismac () && __is_multi_threaded__ ())) register_graphics_toolkit ("fltk"); endif

#if defined (HAVE_CONFIG_H)
# include "config.h"
Expand Down Expand Up @@ -1296,8 +1296,8 @@ class plot_window : public Fl_Window
graphics_object robj = gh_mgr.get_object (m_fp.get_parent ());

root_figure::properties& rp

= dynamic_cast<root_figure::properties&> (robj.get_properties ());

rp.set_currentfigure (m_fp.get___myhandle__ ().value ());
}
}
Expand Down
21 changes: 21 additions & 0 deletions libinterp/octave.cc
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,27 @@ Return true if Octave is running in GUI mode and false otherwise.
%!error <Invalid call> isguirunning (1)
*/

DEFUN (__is_multi_threaded__, args, ,
doc: /* -*- texinfo -*-
@deftypefn {} {@var{tf} =} __is_multi_threaded__ ()
Return true if Octave is running with multiple threads.
@seealso{isguirunning}
@end deftypefn */)
{
if (args.length () != 0)
print_usage ();

// FIXME: This isn't quite right, it just says that we intended to
// start the GUI, not that it is actually running.

return ovl (application::is_multi_threaded ());
}

/*
%!assert (islogical (__is_multi_threaded__ ()))
%!error <Invalid call> __is_multi_threaded__ (1)
*/

DEFUN (argv, args, ,
doc: /* -*- texinfo -*-
@deftypefn {} {@var{args} =} argv ()
Expand Down
8 changes: 8 additions & 0 deletions libinterp/octave.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ class OCTINTERP_API application
virtual bool gui_running () const { return false; }
virtual void gui_running (bool) { }

// TRUE if Octave uses multiple threads (e.g., for interpreter and GUI).
virtual bool multi_threaded () const { return false; }

void program_invocation_name (const std::string& nm)
{ m_program_invocation_name = nm; }

Expand Down Expand Up @@ -320,6 +323,11 @@ class OCTINTERP_API application
return s_instance ? s_instance->gui_running () : false;
}

static bool is_multi_threaded ()
{
return s_instance ? s_instance->multi_threaded () : false;
}

// Convenience functions.

static bool forced_interactive ();
Expand Down

0 comments on commit ac9f011

Please sign in to comment.