Add IdleRegister to deal with destruction while idle func is queued

This adds a little helper class to `guiutils.*` that unregisters
in-flight idle functions queued by `IdleRegister::add()`. It's best
to call `IdleRegister::destroy()` in the destructor of the class
owning the `IdleRegister` instance. Otherwise make sure, it is the
last member which will be deleted first.

`Resize` now makes use of this new facility in `setDimensions()`, which
also fixes #3673.
This commit is contained in:
Flössie
2017-02-09 20:25:58 +01:00
parent 281982f329
commit 824ecaed41
4 changed files with 155 additions and 78 deletions

View File

@@ -19,13 +19,19 @@
#ifndef __GUI_UTILS_
#define __GUI_UTILS_
#include <gtkmm.h>
#include <cairomm/cairomm.h>
#include "../rtengine/rtengine.h"
#include "../rtengine/coord.h"
#include "rtimage.h"
#include <sstream>
#include <iostream>
#include <set>
#include <sstream>
#include <gtkmm.h>
#include <cairomm/cairomm.h>
#include "../rtengine/coord.h"
#include "../rtengine/noncopyable.h"
#include "../rtengine/rtengine.h"
#include "rtimage.h"
Glib::ustring escapeHtmlChars(const Glib::ustring &src);
bool removeIfThere (Gtk::Container* cont, Gtk::Widget* w, bool increference = true);
@@ -40,6 +46,20 @@ void setExpandAlignProperties(Gtk::Widget *widget, bool hExpand, bool vExpand, e
guint add_idle (GSourceFunc function, gpointer data);
class IdleRegister final :
public rtengine::NonCopyable
{
public:
~IdleRegister();
void add(GSourceFunc function, gpointer data);
void destroy();
private:
std::map<void*, guint> ids;
MyMutex mutex;
};
// TODO: The documentation says gdk_threads_enter and gdk_threads_leave should be replaced
// by g_main_context_invoke(), g_idle_add() and related functions, but this will require more extensive changes.
// We silence those warnings until then so that we notice the others.