aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2010-09-08 20:09:06 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2010-09-08 20:09:06 (GMT)
commit8a08110f194170cff462d292d5851735aa5f19ed (patch)
tree6047d4ea2b95fef762c0dfb31c8fa90cc77aab5b /src
parentdc5a105c3e79e8ede296e22217e7406cf24e9495 (diff)
downloadfluxbox-8a08110f194170cff462d292d5851735aa5f19ed.zip
fluxbox-8a08110f194170cff462d292d5851735aa5f19ed.tar.bz2
simpler way of expressing 'Singleton' for 'FbAtoms'
Diffstat (limited to 'src')
-rw-r--r--src/FbAtoms.cc44
-rw-r--r--src/FbAtoms.hh17
-rw-r--r--src/fluxbox.cc2
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 @@
22#include "FbAtoms.hh" 22#include "FbAtoms.hh"
23#include "FbTk/App.hh" 23#include "FbTk/App.hh"
24 24
25#include <string> 25namespace {
26 26
27using std::string; 27FbAtoms* s_singleton = 0;
28 28
29FbAtoms *FbAtoms::s_singleton = 0; 29} // end of anonymous namespace
30 30
31FbAtoms::FbAtoms():m_init(false) { 31FbAtoms::FbAtoms() {
32 if (s_singleton != 0) 32
33 throw string("You can only create one instance of FbAtoms"); 33 Display* dpy = FbTk::App::instance()->display();
34
35 xa_wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
36 xa_wm_state = XInternAtom(dpy, "WM_STATE", False);
37 xa_wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False);
38 xa_wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
39 xa_wm_take_focus = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
40 motif_wm_hints = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
41
42 blackbox_attributes = XInternAtom(dpy, "_BLACKBOX_ATTRIBUTES", False);
34 43
35 s_singleton = this; 44 s_singleton = this;
36 initAtoms();
37} 45}
38 46
39FbAtoms::~FbAtoms() { 47FbAtoms::~FbAtoms() {
40 48 s_singleton = 0;
41} 49}
42 50
43FbAtoms *FbAtoms::instance() { 51FbAtoms *FbAtoms::instance() {
44 if (s_singleton == 0) 52 if (s_singleton == 0) {
45 throw string("Create one instance of FbAtoms first!"); 53 s_singleton = new FbAtoms();
54 }
46 return s_singleton; 55 return s_singleton;
47} 56}
48 57
49void FbAtoms::initAtoms() {
50 Display *display = FbTk::App::instance()->display();
51 if (display == 0)
52 return;
53
54 xa_wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False);
55 xa_wm_state = XInternAtom(display, "WM_STATE", False);
56 xa_wm_change_state = XInternAtom(display, "WM_CHANGE_STATE", False);
57 xa_wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
58 xa_wm_take_focus = XInternAtom(display, "WM_TAKE_FOCUS", False);
59 motif_wm_hints = XInternAtom(display, "_MOTIF_WM_HINTS", False);
60
61 blackbox_attributes = XInternAtom(display, "_BLACKBOX_ATTRIBUTES", False);
62
63}
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 @@
27/// atom handler for basic X atoms 27/// atom handler for basic X atoms
28class FbAtoms { 28class FbAtoms {
29public: 29public:
30 FbAtoms();
31 ~FbAtoms(); 30 ~FbAtoms();
32 31
33 static FbAtoms *instance(); 32 static FbAtoms *instance();
@@ -45,16 +44,16 @@ public:
45 Atom getFluxboxAttributesAtom() const { return blackbox_attributes; } 44 Atom getFluxboxAttributesAtom() const { return blackbox_attributes; }
46 45
47private: 46private:
48 void initAtoms(); 47 FbAtoms();
49// NETAttributes 48
50 Atom blackbox_attributes; 49 Atom blackbox_attributes;
51 Atom motif_wm_hints; 50 Atom motif_wm_hints;
52 51 Atom xa_wm_protocols;
53 Atom xa_wm_protocols, xa_wm_state, 52 Atom xa_wm_state;
54 xa_wm_delete_window, xa_wm_take_focus, xa_wm_change_state; 53 Atom xa_wm_delete_window;
55 54 Atom xa_wm_take_focus;
56 bool m_init; 55 Atom xa_wm_change_state;
57 static FbAtoms *s_singleton;
58}; 56};
59 57
60#endif //FBATOMS_HH 58#endif //FBATOMS_HH
59
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;
181Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, 181Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name,
182 const char *rcfilename, bool xsync) 182 const char *rcfilename, bool xsync)
183 : FbTk::App(dpy_name), 183 : FbTk::App(dpy_name),
184 m_fbatoms(new FbAtoms()), 184 m_fbatoms(FbAtoms::instance()),
185 m_resourcemanager(rcfilename, true), 185 m_resourcemanager(rcfilename, true),
186 // TODO: shouldn't need a separate one for screen 186 // TODO: shouldn't need a separate one for screen
187 m_screen_rm(m_resourcemanager), 187 m_screen_rm(m_resourcemanager),