summaryrefslogtreecommitdiff
path: root/otk
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-01-08 07:41:17 +0000
committerDana Jansens <danakj@orodu.net>2003-01-08 07:41:17 +0000
commitbd748f74022019c4c9ee3e078afcef14cf47d370 (patch)
tree310cf4948f3a6fd41aeb7af040451c695985a9b7 /otk
parent3b4d453f908437cc0228eed9fbf742dbcc06630b (diff)
rework focus event handling. does it basically like ob2 did now. and it seems to work too :>
Diffstat (limited to 'otk')
-rw-r--r--otk/eventdispatcher.cc166
-rw-r--r--otk/eventdispatcher.hh2
2 files changed, 111 insertions, 57 deletions
diff --git a/otk/eventdispatcher.cc b/otk/eventdispatcher.cc
index 38d395d7..b3c8a587 100644
--- a/otk/eventdispatcher.cc
+++ b/otk/eventdispatcher.cc
@@ -11,7 +11,7 @@
namespace otk {
OtkEventDispatcher::OtkEventDispatcher()
- : _fallback(0), _master(0)
+ : _fallback(0), _master(0), _focus(None)
{
}
@@ -45,67 +45,119 @@ void OtkEventDispatcher::dispatchEvents(void)
printf("Event %d window %lx\n", e.type, e.xany.window);
#endif
- Window win;
-
- // pick a window
- switch (e.type) {
- case UnmapNotify:
- win = e.xunmap.window;
- break;
- case DestroyNotify:
- win = e.xdestroywindow.window;
- break;
- case ConfigureRequest:
- win = e.xconfigurerequest.window;
- break;
- default:
- win = e.xany.window;
- }
+ if (e.type == FocusIn || e.type == FocusOut) {
+ // focus events are a beast all their own.. yuk, hate, etc.
+ dispatchFocus(e);
+ } else {
+ Window win;
+
+ // pick a window
+ switch (e.type) {
+ case UnmapNotify:
+ win = e.xunmap.window;
+ break;
+ case DestroyNotify:
+ win = e.xdestroywindow.window;
+ break;
+ case ConfigureRequest:
+ win = e.xconfigurerequest.window;
+ break;
+ default:
+ win = e.xany.window;
+ }
- // grab the lasttime and hack up the modifiers
- switch (e.type) {
- case ButtonPress:
- case ButtonRelease:
- _lasttime = e.xbutton.time;
- e.xbutton.state &= ~(LockMask | OBDisplay::numLockMask() |
- OBDisplay::scrollLockMask());
- break;
- case KeyPress:
- e.xkey.state &= ~(LockMask | OBDisplay::numLockMask() |
- OBDisplay::scrollLockMask());
- break;
- case MotionNotify:
- _lasttime = e.xmotion.time;
- e.xmotion.state &= ~(LockMask | OBDisplay::numLockMask() |
- OBDisplay::scrollLockMask());
- break;
- case PropertyNotify:
- _lasttime = e.xproperty.time;
- break;
- case EnterNotify:
- case LeaveNotify:
- _lasttime = e.xcrossing.time;
- break;
+ // grab the lasttime and hack up the modifiers
+ switch (e.type) {
+ case ButtonPress:
+ case ButtonRelease:
+ _lasttime = e.xbutton.time;
+ e.xbutton.state &= ~(LockMask | OBDisplay::numLockMask() |
+ OBDisplay::scrollLockMask());
+ break;
+ case KeyPress:
+ e.xkey.state &= ~(LockMask | OBDisplay::numLockMask() |
+ OBDisplay::scrollLockMask());
+ break;
+ case MotionNotify:
+ _lasttime = e.xmotion.time;
+ e.xmotion.state &= ~(LockMask | OBDisplay::numLockMask() |
+ OBDisplay::scrollLockMask());
+ break;
+ case PropertyNotify:
+ _lasttime = e.xproperty.time;
+ break;
+ case EnterNotify:
+ case LeaveNotify:
+ _lasttime = e.xcrossing.time;
+ break;
+ }
+
+ dispatch(win, e);
}
+ }
+}
+
+void OtkEventDispatcher::dispatchFocus(const XEvent &e)
+{
+ Window newfocus = None;
+
+ // any other types are not ones we're interested in
+ if (e.xfocus.detail != NotifyNonlinear)
+ return;
+
+ if (e.type == FocusIn) {
+ printf("---\n");
+ printf("Got FocusIn!\n");
+ printf("Using FocusIn\n");
+ newfocus = e.xfocus.window;
+
+ if (newfocus != _focus) {
+ // send a FocusIn to whatever was just focused
+ dispatch(newfocus, e);
+ printf("Sent FocusIn 0x%lx\n", newfocus);
+
+ // send a FocusOut to whatever used to be focused
+ if (_focus) {
+ XEvent ev;
+ ev.xfocus = e.xfocus;
+ ev.xfocus.window = _focus;
+ ev.type = FocusOut;
+ dispatch(_focus, ev);
+ printf("Sent FocusOut 0x%lx\n", _focus);
+ }
- if (e.type == FocusIn || e.type == FocusOut)
- // any other types are not ones we're interested in
- if (e.xfocus.detail != NotifyNonlinear)
- continue;
-
- if (e.type == FocusOut) {
- XEvent fi;
- // send a FocusIn first if one exists
- while (XCheckTypedEvent(OBDisplay::display, FocusIn, &fi)) {
- // any other types are not ones we're interested in
- if (fi.xfocus.detail == NotifyNonlinear) {
- dispatch(fi.xfocus.window, fi);
- break;
- }
+ // store the new focused window
+ _focus = newfocus;
+ }
+
+ } else if (e.type == FocusOut) {
+ bool focused = false; // found a new focus target?
+ printf("---\n");
+ printf("Got FocusOut!\n");
+
+ // FocusOut events just make us look for FocusIn events. They are ignored
+ // otherwise.
+ XEvent fi;
+ while (XCheckTypedEvent(OBDisplay::display, FocusIn, &fi)) {
+ if (e.xfocus.detail == NotifyNonlinear) {
+ printf("Found FocusIn\n");
+ dispatchFocus(fi);
+ focused = true;
+ break;
}
}
-
- dispatch(win, e);
+ if (!focused) {
+ // send a FocusOut to whatever used to be focused
+ if (_focus) {
+ XEvent ev;
+ ev.xfocus = e.xfocus;
+ ev.xfocus.window = _focus;
+ dispatch(_focus, ev);
+ printf("Sent FocusOut 0x%lx\n", _focus);
+ }
+ // store that no window has focus anymore
+ _focus = None;
+ }
}
}
diff --git a/otk/eventdispatcher.hh b/otk/eventdispatcher.hh
index 97f86564..63e4ff29 100644
--- a/otk/eventdispatcher.hh
+++ b/otk/eventdispatcher.hh
@@ -38,11 +38,13 @@ private:
OtkEventMap _map;
OtkEventHandler *_fallback;
OtkEventHandler *_master;
+ Window _focus;
//! The time at which the last XEvent with a time was received
Time _lasttime;
void dispatch(Window win, const XEvent &e);
+ void dispatchFocus(const XEvent &e);
};
}