00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "App.hh"
00023
00024 #include "EventManager.hh"
00025
00026 #include <cassert>
00027 #include <string>
00028
00029 namespace FbTk {
00030
00031 App *App::s_app = 0;
00032
00033 App *App::instance() {
00034 if (s_app == 0)
00035 throw std::string("You must create an instance of FbTk::App first!");
00036 return s_app;
00037 }
00038
00039 App::App(const char *displayname):m_done(false), m_display(0) {
00040 if (s_app != 0)
00041 throw std::string("Can't create more than one instance of FbTk::App");
00042 s_app = this;
00043
00044
00045 if (displayname != 0 && displayname[0] == '\0')
00046 displayname = 0;
00047 m_display = XOpenDisplay(displayname);
00048 }
00049
00050 App::~App() {
00051 if (m_display != 0) {
00052 XCloseDisplay(m_display);
00053 m_display = 0;
00054 }
00055 s_app = 0;
00056 }
00057
00058 void App::sync(bool discard) {
00059 XSync(display(), discard);
00060 }
00061
00062 void App::eventLoop() {
00063 XEvent ev;
00064 while (!m_done) {
00065 XNextEvent(display(), &ev);
00066 EventManager::instance()->handleEvent(ev);
00067 }
00068 }
00069
00070
00071 void App::end() {
00072 m_done = true;
00073 }
00074
00075 };