]> Dogcows Code - chaz/openbox/blob - otk/eventdispatcher.cc
support the button pressed resources better
[chaz/openbox] / otk / eventdispatcher.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 #include "eventdispatcher.hh"
8 #include "display.hh"
9 #include <iostream>
10
11 namespace otk {
12
13 OtkEventDispatcher::OtkEventDispatcher()
14 : _fallback(0), _master(0), _focus(None)
15 {
16 _focus_e.xfocus.mode = NotifyNormal;
17 _focus_e.xfocus.detail = NotifyNonlinear;
18 }
19
20 OtkEventDispatcher::~OtkEventDispatcher()
21 {
22 }
23
24 void OtkEventDispatcher::clearAllHandlers(void)
25 {
26 _map.clear();
27 }
28
29 void OtkEventDispatcher::registerHandler(Window id, OtkEventHandler *handler)
30 {
31 _map.insert(std::pair<Window, OtkEventHandler*>(id, handler));
32 }
33
34 void OtkEventDispatcher::clearHandler(Window id)
35 {
36 _map.erase(id);
37 }
38
39 void OtkEventDispatcher::dispatchEvents(void)
40 {
41 OtkEventMap::iterator it;
42 XEvent e;
43 Window focus = _focus;
44 Window unfocus = None;
45
46 while (XPending(OBDisplay::display)) {
47 XNextEvent(OBDisplay::display, &e);
48
49 #if 0
50 printf("Event %d window %lx\n", e.type, e.xany.window);
51 #endif
52
53 // these ConfigureRequests require some special attention
54 if (e.type == ConfigureRequest) {
55 // find the actual window! e.xany.window is the parent window
56 it = _map.find(e.xconfigurerequest.window);
57
58 if (it != _map.end())
59 it->second->handle(e);
60 else {
61 // unhandled configure requests must be used to configure the window
62 // directly
63 XWindowChanges xwc;
64
65 xwc.x = e.xconfigurerequest.x;
66 xwc.y = e.xconfigurerequest.y;
67 xwc.width = e.xconfigurerequest.width;
68 xwc.height = e.xconfigurerequest.height;
69 xwc.border_width = e.xconfigurerequest.border_width;
70 xwc.sibling = e.xconfigurerequest.above;
71 xwc.stack_mode = e.xconfigurerequest.detail;
72
73 XConfigureWindow(otk::OBDisplay::display, e.xconfigurerequest.window,
74 e.xconfigurerequest.value_mask, &xwc);
75 }
76 // madly compress all focus events
77 } else if (e.type == FocusIn) {
78 // any other types are not ones we're interested in
79 if (e.xfocus.detail == NotifyNonlinear) {
80 if (e.xfocus.window != focus) {
81 if (focus)
82 unfocus = focus;
83 focus = e.xfocus.window;
84 printf("FocusIn focus=%lx unfocus=%lx\n", focus, unfocus);
85 }
86 }
87 } else if (e.type == FocusOut) {
88 // any other types are not ones we're interested in
89 if (e.xfocus.detail == NotifyNonlinear) {
90 if (e.xfocus.window == focus) {
91 unfocus = focus;
92 focus = None;
93 printf("FocusIn focus=%lx unfocus=%lx\n", focus, unfocus);
94 }
95 }
96 } else {
97 // normal events
98 dispatch(e);
99 }
100 }
101
102 if (focus != _focus) {
103 _focus_e.xfocus.type = FocusIn;
104 _focus_e.xfocus.window = focus;
105 dispatch(_focus_e);
106 _focus = focus;
107 }
108 if (unfocus != None) {
109 _focus_e.xfocus.type = FocusOut;
110 _focus_e.xfocus.window = unfocus;
111 dispatch(_focus_e);
112 }
113 }
114
115 void OtkEventDispatcher::dispatch(const XEvent &e) {
116 OtkEventHandler *handler;
117 OtkEventMap::iterator it;
118
119 it = _map.find(e.xany.window);
120
121 if (it != _map.end())
122 handler = it->second;
123 else
124 handler = _fallback;
125
126 if (handler)
127 handler->handle(e);
128
129 if (_master)
130 _master->handle(e);
131 }
132
133 OtkEventHandler *OtkEventDispatcher::findHandler(Window win)
134 {
135 OtkEventMap::iterator it = _map.find(win);
136 if (it != _map.end())
137 return it->second;
138 return 0;
139 }
140
141 }
This page took 0.044306 seconds and 4 git commands to generate.