all repos — fluxbox @ 8a08110f194170cff462d292d5851735aa5f19ed

custom fork of the fluxbox windowmanager

simpler way of expressing 'Singleton' for 'FbAtoms'
Mathias Gumz akira at fluxbox dot org
commit

8a08110f194170cff462d292d5851735aa5f19ed

parent

dc5a105c3e79e8ede296e22217e7406cf24e9495

3 files changed, 28 insertions(+), 35 deletions(-)

jump to
M src/FbAtoms.ccsrc/FbAtoms.cc

@@ -22,42 +22,36 @@

#include "FbAtoms.hh" #include "FbTk/App.hh" -#include <string> +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); - -}
M src/FbAtoms.hhsrc/FbAtoms.hh

@@ -27,7 +27,6 @@

/// atom handler for basic X atoms class FbAtoms { public: - FbAtoms(); ~FbAtoms(); static FbAtoms *instance();

@@ -45,16 +44,16 @@ // ICCCM...

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 +
M src/fluxbox.ccsrc/fluxbox.cc

@@ -181,7 +181,7 @@

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),