news download themes documentation links










App.cc

00001 // App.cc
00002 // Copyright (c) 2002 Henrik Kinnunen (fluxgen at linuxmail.org)
00003 //
00004 // Permission is hereby granted, free of charge, to any person obtaining a
00005 // copy of this software and associated documentation files (the "Software"),
00006 // to deal in the Software without restriction, including without limitation
00007 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 // and/or sell copies of the Software, and to permit persons to whom the
00009 // Software is furnished to do so, subject to the following conditions:
00010 //
00011 // The above copyright notice and this permission notice shall be included in
00012 // all copies or substantial portions of the Software.
00013 //
00014 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00017 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00019 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00020 // DEALINGS IN THE SOFTWARE.
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     // this allows the use of std::string.c_str(), which returns 
00044     // a blank string, rather than a null string, so we make them equivalent
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; //end loop in App::eventLoop
00073 }
00074 
00075 }; // end namespace FbTk

Fluxbox CVS-Jan-2003




      



Got comments about the page? Send them to webmaster.
If you have general Fluxbox related questions ask them on our irc channel or mailing lists.

Show Source








Designed by aLEczapKA