Scroom  0.14
Scroom::GtkHelpers Namespace Reference

Namespaces

 Detail
 

Functions

template<typename T >
std::pair< GSourceFunc, gpointer > wrap (T f)
 
bool on_ui_thread ()
 
template<typename T >
void async_on_ui_thread (T f)
 
template<typename T >
void async_on_ui_thread_and_wait (T f)
 
template<typename T >
void sync_on_ui_thread (T f)
 
cairo_rectangle_int_t createCairoIntRectangle (int x, int y, int width, int height)
 
GtkWindow * get_parent_window (GtkWidget *widget)
 

Function Documentation

◆ async_on_ui_thread()

template<typename T >
void Scroom::GtkHelpers::async_on_ui_thread ( f)
43  {
44  const auto& [function, data] = wrap(std::move(f));
45  gdk_threads_add_idle(function, data);
46  }

Referenced by async_on_ui_thread_and_wait(), TiledBitmapViewData::tileLoaded(), and Scroom::GtkTestHelpers::GtkMainLoop::~GtkMainLoop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ async_on_ui_thread_and_wait()

template<typename T >
void Scroom::GtkHelpers::async_on_ui_thread_and_wait ( f)
50  {
52  std::packaged_task<void(void)> t(f);
53  std::future<void> const future = t.get_future();
54  async_on_ui_thread(std::move(t));
55  future.wait();
56  }

Referenced by sync_on_ui_thread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createCairoIntRectangle()

cairo_rectangle_int_t Scroom::GtkHelpers::createCairoIntRectangle ( int  x,
int  y,
int  width,
int  height 
)
inline
72  {
73  cairo_rectangle_int_t rect;
74  rect.x = x;
75  rect.y = y;
76  rect.width = width;
77  rect.height = height;
78  return rect;
79  }

Referenced by BOOST_AUTO_TEST_CASE(), and Scroom::Utils::Rectangle< int >::toGdkRectangle().

Here is the caller graph for this function:

◆ get_parent_window()

GtkWindow * Scroom::GtkHelpers::get_parent_window ( GtkWidget *  widget)
18  {
19  auto* topLevel = gtk_widget_get_toplevel(widget);
20  if(GTK_IS_WINDOW(topLevel))
21  {
22  return GTK_WINDOW(topLevel);
23  }
24 
25  return nullptr;
26  }

Referenced by on_image_properties_activate().

Here is the caller graph for this function:

◆ on_ui_thread()

bool Scroom::GtkHelpers::on_ui_thread ( )
15 { return g_main_context_is_owner(g_main_context_default()); }

Referenced by async_on_ui_thread_and_wait(), BOOST_AUTO_TEST_CASE(), and sync_on_ui_thread().

Here is the caller graph for this function:

◆ sync_on_ui_thread()

template<typename T >
void Scroom::GtkHelpers::sync_on_ui_thread ( f)
60  {
61  if(on_ui_thread())
62  {
63  f();
64  }
65  else
66  {
67  async_on_ui_thread_and_wait(std::move(f));
68  }
69  }

Referenced by View::addToolButton(), BOOST_AUTO_TEST_CASE(), PipetteHandler::computeValues(), PipetteHandler::displayValues(), invalidate_view(), Scroom::TiledBitmap::scheduleLoadingBitmap(), ProgressBarManager::setWorking(), TiledBitmap::tileFinished(), and Metadata::viewAdded().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wrap()

template<typename T >
std::pair<GSourceFunc, gpointer> Scroom::GtkHelpers::wrap ( f)
35  {
36  return std::make_pair<GSourceFunc, gpointer>(Detail::gtkWrapper<T>, new T(std::move(f)));
37  }

Referenced by async_on_ui_thread(), and BOOST_AUTO_TEST_CASE().

Here is the caller graph for this function:
Scroom::GtkHelpers::async_on_ui_thread
void async_on_ui_thread(T f)
Definition: gtk-helpers.hh:42
require
#define require(expr)
Definition: assertions.hh:28
Scroom::GtkHelpers::async_on_ui_thread_and_wait
void async_on_ui_thread_and_wait(T f)
Definition: gtk-helpers.hh:49
Scroom::GtkHelpers::on_ui_thread
bool on_ui_thread()
Definition: gtk-helpers.cc:15
Scroom::GtkHelpers::wrap
std::pair< GSourceFunc, gpointer > wrap(T f)
Definition: gtk-helpers.hh:34