From 8a08110f194170cff462d292d5851735aa5f19ed Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Wed, 8 Sep 2010 22:09:06 +0200 Subject: simpler way of expressing 'Singleton' for 'FbAtoms' --- src/FbAtoms.cc | 44 +++++++++++++++++++------------------------- src/FbAtoms.hh | 17 ++++++++--------- src/fluxbox.cc | 2 +- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/FbAtoms.cc b/src/FbAtoms.cc index 13b1703..409a99f 100644 --- a/src/FbAtoms.cc +++ b/src/FbAtoms.cc @@ -22,42 +22,36 @@ #include "FbAtoms.hh" #include "FbTk/App.hh" -#include +namespace { -using std::string; +FbAtoms* s_singleton = 0; -FbAtoms *FbAtoms::s_singleton = 0; +} // end of anonymous namespace -FbAtoms::FbAtoms():m_init(false) { - if (s_singleton != 0) - throw string("You can only create one instance of FbAtoms"); +FbAtoms::FbAtoms() { + + Display* dpy = FbTk::App::instance()->display(); + + xa_wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False); + xa_wm_state = XInternAtom(dpy, "WM_STATE", False); + xa_wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False); + xa_wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + xa_wm_take_focus = XInternAtom(dpy, "WM_TAKE_FOCUS", False); + motif_wm_hints = XInternAtom(dpy, "_MOTIF_WM_HINTS", False); + + blackbox_attributes = XInternAtom(dpy, "_BLACKBOX_ATTRIBUTES", False); s_singleton = this; - initAtoms(); } FbAtoms::~FbAtoms() { - + s_singleton = 0; } FbAtoms *FbAtoms::instance() { - if (s_singleton == 0) - throw string("Create one instance of FbAtoms first!"); + if (s_singleton == 0) { + s_singleton = new FbAtoms(); + } return s_singleton; } -void FbAtoms::initAtoms() { - Display *display = FbTk::App::instance()->display(); - if (display == 0) - return; - - xa_wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False); - xa_wm_state = XInternAtom(display, "WM_STATE", False); - xa_wm_change_state = XInternAtom(display, "WM_CHANGE_STATE", False); - xa_wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False); - xa_wm_take_focus = XInternAtom(display, "WM_TAKE_FOCUS", False); - motif_wm_hints = XInternAtom(display, "_MOTIF_WM_HINTS", False); - - blackbox_attributes = XInternAtom(display, "_BLACKBOX_ATTRIBUTES", False); - -} diff --git a/src/FbAtoms.hh b/src/FbAtoms.hh index 2a48e6e..3ed52a5 100644 --- a/src/FbAtoms.hh +++ b/src/FbAtoms.hh @@ -27,7 +27,6 @@ /// atom handler for basic X atoms class FbAtoms { public: - FbAtoms(); ~FbAtoms(); static FbAtoms *instance(); @@ -45,16 +44,16 @@ public: Atom getFluxboxAttributesAtom() const { return blackbox_attributes; } private: - void initAtoms(); -// NETAttributes + FbAtoms(); + Atom blackbox_attributes; Atom motif_wm_hints; - - Atom xa_wm_protocols, xa_wm_state, - xa_wm_delete_window, xa_wm_take_focus, xa_wm_change_state; - - bool m_init; - static FbAtoms *s_singleton; + Atom xa_wm_protocols; + Atom xa_wm_state; + Atom xa_wm_delete_window; + Atom xa_wm_take_focus; + Atom xa_wm_change_state; }; #endif //FBATOMS_HH + diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 192b44c..d55029b 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -181,7 +181,7 @@ Fluxbox *Fluxbox::s_singleton=0; Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfilename, bool xsync) : FbTk::App(dpy_name), - m_fbatoms(new FbAtoms()), + m_fbatoms(FbAtoms::instance()), m_resourcemanager(rcfilename, true), // TODO: shouldn't need a separate one for screen m_screen_rm(m_resourcemanager), -- cgit v0.11.2