diff options
author | fluxgen <fluxgen> | 2003-08-23 15:44:06 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-08-23 15:44:06 (GMT) |
commit | efc1ec4b206f3e24c1fd9ca29096f23735f2e7ae (patch) | |
tree | 063d0ecdf263d60e8a083f285bf84696b3978a48 | |
parent | bc8e67136f9df2d0475f0e2f01e03976aabfa259 (diff) | |
download | fluxbox_lack-efc1ec4b206f3e24c1fd9ca29096f23735f2e7ae.zip fluxbox_lack-efc1ec4b206f3e24c1fd9ca29096f23735f2e7ae.tar.bz2 |
fixed dispatch to parent
-rw-r--r-- | src/FbTk/EventManager.cc | 82 | ||||
-rw-r--r-- | src/FbTk/EventManager.hh | 7 |
2 files changed, 62 insertions, 27 deletions
diff --git a/src/FbTk/EventManager.cc b/src/FbTk/EventManager.cc index 1f2aef1..cd23416 100644 --- a/src/FbTk/EventManager.cc +++ b/src/FbTk/EventManager.cc | |||
@@ -19,10 +19,11 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: EventManager.cc,v 1.6 2003/05/17 10:40:12 fluxgen Exp $ | 22 | // $Id: EventManager.cc,v 1.7 2003/08/23 15:44:06 fluxgen Exp $ |
23 | 23 | ||
24 | #include "EventManager.hh" | 24 | #include "EventManager.hh" |
25 | #include "FbWindow.hh" | 25 | #include "FbWindow.hh" |
26 | #include "App.hh" | ||
26 | 27 | ||
27 | #include <iostream> | 28 | #include <iostream> |
28 | using namespace std; | 29 | using namespace std; |
@@ -40,17 +41,45 @@ EventManager::~EventManager() { | |||
40 | } | 41 | } |
41 | 42 | ||
42 | void EventManager::handleEvent(XEvent &ev) { | 43 | void EventManager::handleEvent(XEvent &ev) { |
43 | // find eventhandler for event window | 44 | dispatch(ev.xany.window, ev); |
44 | if (m_eventhandlers.find(ev.xany.window) == m_eventhandlers.end()) { | 45 | } |
45 | //cerr<<"Can't find window="<<ev.xany.window<<endl; | 46 | |
46 | return; | 47 | void EventManager::add(EventHandler &ev, const FbWindow &win) { |
48 | registerEventHandler(ev, win.window()); | ||
49 | } | ||
50 | |||
51 | void EventManager::addParent(EventHandler &ev, const FbWindow &win) { | ||
52 | if (win.window() != 0) | ||
53 | m_parent[win.window()] = &ev; | ||
54 | } | ||
55 | |||
56 | void EventManager::remove(const FbWindow &win) { | ||
57 | unregisterEventHandler(win.window()); | ||
58 | } | ||
59 | |||
60 | void EventManager::registerEventHandler(EventHandler &ev, Window win) { | ||
61 | if (win != None) | ||
62 | m_eventhandlers[win] = &ev; | ||
63 | } | ||
64 | |||
65 | void EventManager::unregisterEventHandler(Window win) { | ||
66 | if (win != None) { | ||
67 | m_eventhandlers.erase(win); | ||
68 | m_parent.erase(win); | ||
47 | } | 69 | } |
48 | EventHandler *evhand = m_eventhandlers[ev.xany.window]; | 70 | } |
49 | if (evhand == 0) { | 71 | |
50 | cerr<<"FbTk::EventManager: Warning: evhand == 0!"<<endl; | 72 | void EventManager::dispatch(Window win, XEvent &ev, bool parent) { |
73 | |||
74 | EventHandler *evhand = 0; | ||
75 | if (parent) | ||
76 | evhand = m_parent[win]; | ||
77 | else | ||
78 | evhand = m_eventhandlers[win]; | ||
79 | |||
80 | if (evhand == 0) | ||
51 | return; | 81 | return; |
52 | } | 82 | |
53 | |||
54 | switch (ev.xany.type) { | 83 | switch (ev.xany.type) { |
55 | case KeyPress: | 84 | case KeyPress: |
56 | evhand->keyPressEvent(ev.xkey); | 85 | evhand->keyPressEvent(ev.xkey); |
@@ -80,24 +109,27 @@ void EventManager::handleEvent(XEvent &ev) { | |||
80 | evhand->handleEvent(ev); | 109 | evhand->handleEvent(ev); |
81 | break; | 110 | break; |
82 | }; | 111 | }; |
83 | } | ||
84 | 112 | ||
85 | void EventManager::add(EventHandler &ev, const FbWindow &win) { | 113 | // find out which window is the parent and |
86 | registerEventHandler(ev, win.window()); | 114 | // dispatch event |
87 | } | 115 | Window root, parent_win, *children = 0; |
116 | unsigned int num_children; | ||
117 | if (XQueryTree(FbTk::App::instance()->display(), win, | ||
118 | &root, &parent_win, &children, &num_children) != 0 && | ||
119 | parent_win != 0 && | ||
120 | parent_win != root) { | ||
88 | 121 | ||
89 | void EventManager::remove(const FbWindow &win) { | 122 | if (children != 0) |
90 | unregisterEventHandler(win.window()); | 123 | XFree(children); |
91 | } | ||
92 | 124 | ||
93 | void EventManager::registerEventHandler(EventHandler &ev, Window win) { | 125 | if (m_parent[parent_win] == 0) |
94 | if (win != None) | 126 | return; |
95 | m_eventhandlers[win] = &ev; | 127 | |
96 | } | 128 | // dispatch event to parent |
129 | dispatch(parent_win, ev, true); | ||
130 | |||
131 | } | ||
97 | 132 | ||
98 | void EventManager::unregisterEventHandler(Window win) { | ||
99 | if (win != None) | ||
100 | m_eventhandlers.erase(win); | ||
101 | } | 133 | } |
102 | 134 | ||
103 | }; | 135 | }; // end namespace FbTk |
diff --git a/src/FbTk/EventManager.hh b/src/FbTk/EventManager.hh index 7d67331..7d1562e 100644 --- a/src/FbTk/EventManager.hh +++ b/src/FbTk/EventManager.hh | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: EventManager.hh,v 1.4 2002/12/03 17:05:45 fluxgen Exp $ | 22 | // $Id: EventManager.hh,v 1.5 2003/08/23 15:44:06 fluxgen Exp $ |
23 | 23 | ||
24 | #include "EventHandler.hh" | 24 | #include "EventHandler.hh" |
25 | #include <map> | 25 | #include <map> |
@@ -36,6 +36,8 @@ public: | |||
36 | static EventManager *instance(); | 36 | static EventManager *instance(); |
37 | 37 | ||
38 | void handleEvent(XEvent &ev); | 38 | void handleEvent(XEvent &ev); |
39 | // adds a parent to listen to the childrens events | ||
40 | void addParent(EventHandler &ev, const FbWindow &parent); | ||
39 | void add(EventHandler &ev, const FbWindow &win); | 41 | void add(EventHandler &ev, const FbWindow &win); |
40 | void remove(const FbWindow &win); | 42 | void remove(const FbWindow &win); |
41 | void add(EventHandler &ev, Window win) { registerEventHandler(ev, win); } | 43 | void add(EventHandler &ev, Window win) { registerEventHandler(ev, win); } |
@@ -45,8 +47,9 @@ public: | |||
45 | private: | 47 | private: |
46 | EventManager() { } | 48 | EventManager() { } |
47 | ~EventManager(); | 49 | ~EventManager(); |
48 | 50 | void dispatch(Window win, XEvent &event, bool parent = false); | |
49 | std::map<Window, EventHandler *> m_eventhandlers; | 51 | std::map<Window, EventHandler *> m_eventhandlers; |
52 | std::map<Window, EventHandler *> m_parent; | ||
50 | }; | 53 | }; |
51 | 54 | ||
52 | }; //end namespace FbTk | 55 | }; //end namespace FbTk |