-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathMainLoop.cpp
56 lines (44 loc) · 1.13 KB
/
MainLoop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "MainLoop.hpp"
#include "common/logger/Logging.hpp"
#include "control/widgets/gtk/WindowGtk.hpp"
static std::thread::id g_uiThreadId;
MainLoop::MainLoop(const std::string& name) : parentApp_(Gtk::Application::create(name))
{
g_uiThreadId = std::this_thread::get_id();
}
std::thread::id MainLoop::uiThreadId()
{
return g_uiThreadId;
}
int MainLoop::run(WindowGtk& adaptor)
{
auto&& windowHandler = adaptor.handler();
parentApp_->signal_shutdown().connect([this]() {
idleConnection_.disconnect();
if (shutdownAction_)
{
shutdownAction_();
}
});
parentApp_->signal_startup().connect([this, &windowHandler]() {
parentApp_->add_window(windowHandler);
started_();
});
return parentApp_->run();
}
void MainLoop::quit()
{
parentApp_->quit();
}
SignalStarted& MainLoop::started()
{
return started_;
}
void MainLoop::setShutdownAction(const ShutdownAction& action)
{
shutdownAction_ = action;
}
void MainLoop::setIdleAction(const IdleAction& action)
{
idleConnection_ = Glib::MainContext::get_default()->signal_idle().connect(action);
}