diff options
Diffstat (limited to 'src/FbTk/App.cc')
-rw-r--r-- | src/FbTk/App.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/FbTk/App.cc b/src/FbTk/App.cc new file mode 100644 index 0000000..309bc41 --- /dev/null +++ b/src/FbTk/App.cc | |||
@@ -0,0 +1,75 @@ | |||
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 | // this allows the use of std::string.c_str(), which returns | ||
44 | // a blank string, rather than a null string, so we make them equivalent | ||
45 | if (displayname != 0 && displayname[0] == '\0') | ||
46 | displayname = 0; | ||
47 | m_display = XOpenDisplay(displayname); | ||
48 | } | ||
49 | |||
50 | App::~App() { | ||
51 | if (m_display != 0) { | ||
52 | XCloseDisplay(m_display); | ||
53 | m_display = 0; | ||
54 | } | ||
55 | s_app = 0; | ||
56 | } | ||
57 | |||
58 | void App::sync(bool discard) { | ||
59 | XSync(display(), discard); | ||
60 | } | ||
61 | |||
62 | void App::eventLoop() { | ||
63 | XEvent ev; | ||
64 | while (!m_done) { | ||
65 | XNextEvent(display(), &ev); | ||
66 | EventManager::instance()->handleEvent(ev); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | |||
71 | void App::end() { | ||
72 | m_done = true; //end loop in App::eventLoop | ||
73 | } | ||
74 | |||
75 | }; // end namespace FbTk | ||