diff options
Diffstat (limited to 'src/FbTk/App.cc')
-rw-r--r-- | src/FbTk/App.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/FbTk/App.cc b/src/FbTk/App.cc new file mode 100644 index 0000000..3daf61a --- /dev/null +++ b/src/FbTk/App.cc | |||
@@ -0,0 +1,67 @@ | |||
1 | // App.cc | ||
2 | // Copyright (c) 2002 Henrik Kinnunen (fluxgen at linuxmail.org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | #include "App.hh" | ||
23 | |||
24 | #include "EventManager.hh" | ||
25 | |||
26 | #include <cassert> | ||
27 | #include <string> | ||
28 | |||
29 | namespace FbTk { | ||
30 | |||
31 | App *App::s_app = 0; | ||
32 | |||
33 | App *App::instance() { | ||
34 | if (s_app == 0) | ||
35 | throw std::string("You must create an instance of FbTk::App first!"); | ||
36 | return s_app; | ||
37 | } | ||
38 | |||
39 | App::App(const char *displayname):m_done(false) { | ||
40 | if (s_app != 0) | ||
41 | throw std::string("Can't create more than one instance of FbTk::App"); | ||
42 | s_app = this; | ||
43 | m_display = XOpenDisplay(displayname); | ||
44 | } | ||
45 | |||
46 | App::~App() { | ||
47 | if (m_display != 0) { | ||
48 | XCloseDisplay(m_display); | ||
49 | m_display = 0; | ||
50 | } | ||
51 | s_app = 0; | ||
52 | } | ||
53 | |||
54 | void App::eventLoop() { | ||
55 | XEvent ev; | ||
56 | while (!m_done) { | ||
57 | XNextEvent(display(), &ev); | ||
58 | EventManager::instance()->handleEvent(ev); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | |||
63 | void App::end() { | ||
64 | m_done = true; //end loop in App::eventLoop | ||
65 | } | ||
66 | |||
67 | }; // end namespace FbTk | ||