[PATCH/RFC] xkb extension and ob3

ManMower manmower at is.fuckingabitch.com
Tue Jan 7 21:18:17 EST 2003


Attached is a patch against ob3 cvs (current at the time of this posting)
that searches for and initializes the xkb extension, and provides a new
event type - EventBell, fired when X "beeps"
-------------- next part --------------
Index: otk/display.cc
===================================================================
RCS file: /cvs/cvsroot/openbox/otk/display.cc,v
retrieving revision 1.15
diff -p -u -r1.15 display.cc
--- otk/display.cc	2003/01/07 19:24:38	1.15
+++ otk/display.cc	2003/01/08 01:23:02
@@ -11,6 +11,10 @@
 extern "C" {
 #include <X11/keysym.h>
 
+#ifdef    XKB
+#include <X11/XKBlib.h>
+#endif // XKB
+
 #ifdef    SHAPE
 #include <X11/extensions/shape.h>
 #endif // SHAPE
@@ -44,6 +48,8 @@ namespace otk {
 
 
 Display *OBDisplay::display = (Display*) 0;
+bool OBDisplay::_xkb = false;
+int  OBDisplay::_xkb_event_basep = 0;
 bool OBDisplay::_shape = false;
 int  OBDisplay::_shape_event_basep = 0;
 bool OBDisplay::_xinerama = false;
@@ -107,6 +113,11 @@ line argument.\n\n"));
   }
   
   // find the availability of X extensions we like to use
+#ifdef XKB
+  _xkb = XkbQueryExtension(display, &junk, &_xkb_event_basep, &junk, NULL, 
+                           NULL);
+#endif
+
 #ifdef SHAPE
   _shape = XShapeQueryExtension(display, &_shape_event_basep, &junk);
 #endif
Index: otk/display.hh
===================================================================
RCS file: /cvs/cvsroot/openbox/otk/display.hh,v
retrieving revision 1.10
diff -p -u -r1.10 display.hh
--- otk/display.hh	2003/01/07 04:06:34	1.10
+++ otk/display.hh	2003/01/08 01:23:03
@@ -29,14 +29,19 @@ public:
   typedef std::vector<ScreenInfo> ScreenInfoList;
 
 private:
-  //! Does the display have the Shape extention?
+  //! Does the display have the XKB extension?
+  static bool _xkb;
+  //! Base for events for the XKB extension
+  static int  _xkb_event_basep;
+
+  //! Does the display have the Shape extension?
   static bool _shape;
-  //! Base for events for the Shape extention
+  //! Base for events for the Shape extension
   static int  _shape_event_basep;
 
-  //! Does the display have the Xinerama extention?
+  //! Does the display have the Xinerama extension?
   static bool _xinerama;
-  //! Base for events for the Xinerama extention
+  //! Base for events for the Xinerama extension
   static int  _xinerama_event_basep;
 
   //! A list of all possible combinations of keyboard lock masks
@@ -98,12 +103,17 @@ public:
 
   //! Find a ScreenInfo based on a root window
   static const ScreenInfo* findScreen(Window root);
+
+  //! Returns if the display has the xkb extension available
+  inline static bool xkb() { return _xkb; }
+  //! Returns the xkb extension's event base
+  inline static int xkbEventBase() { return _xkb_event_basep; }
 
-  //! Returns if the display has the shape extention available
+  //! Returns if the display has the shape extension available
   inline static bool shape() { return _shape; }
   //! Returns the shape extension's event base
   inline static int shapeEventBase() { return _shape_event_basep; }
-  //! Returns if the display has the xinerama extention available
+  //! Returns if the display has the xinerama extension available
   inline static bool xinerama() { return _xinerama; }
 
   inline static unsigned int numLockMask() { return _numLockMask; }
Index: otk/eventhandler.cc
===================================================================
RCS file: /cvs/cvsroot/openbox/otk/eventhandler.cc,v
retrieving revision 1.5
diff -p -u -r1.5 eventhandler.cc
--- otk/eventhandler.cc	2002/12/04 08:54:43	1.5
+++ otk/eventhandler.cc	2003/01/08 01:23:03
@@ -91,6 +91,10 @@ void OtkEventHandler::handle(const XEven
     if (e.type == otk::OBDisplay::shapeEventBase())
       return shapeHandler((*(XShapeEvent*)&e));
 #endif // SHAPE
+#ifdef    XKB
+    if (e.type == otk::OBDisplay::xkbEventBase())
+      return xkbHandler((*(XkbEvent*)&e));
+#endif // XKB
     ;
   }
 }
Index: otk/eventhandler.hh
===================================================================
RCS file: /cvs/cvsroot/openbox/otk/eventhandler.hh,v
retrieving revision 1.8
diff -p -u -r1.8 eventhandler.hh
--- otk/eventhandler.hh	2002/12/24 21:27:16	1.8
+++ otk/eventhandler.hh	2003/01/08 01:23:03
@@ -7,6 +7,11 @@ extern "C" {
 #ifdef    SHAPE
 #include <X11/extensions/shape.h>
 #endif // SHAPE
+
+#ifdef    XKB
+#include <X11/XKBlib.h>
+#endif // XKB
+
 }
 
 namespace otk {
@@ -120,9 +125,14 @@ public:
   virtual void clientMessageHandler(const XClientMessageEvent &);
 
 #if defined(SHAPE) || defined(DOXYGEN_IGNORE)
-  //! Called when a shape extention event fires
+  //! Called when a shape extension event fires
   virtual void shapeHandler(const XShapeEvent &) {}
 #endif // SHAPE 
+
+#if defined(XKB) || defined(DOXYGEN_IGNORE)
+  //! Called when an xkb extension event fires
+  virtual void xkbHandler(const XkbEvent &) {}
+#endif // XKB
 
   virtual ~OtkEventHandler();
 
Index: src/actions.cc
===================================================================
RCS file: /cvs/cvsroot/openbox/src/actions.cc,v
retrieving revision 1.32
diff -p -u -r1.32 actions.cc
--- src/actions.cc	2003/01/07 02:24:43	1.32
+++ src/actions.cc	2003/01/08 01:23:04
@@ -243,4 +243,25 @@ void OBActions::destroyHandler(const XDe
   // do this in OBScreen::unmanageWindow
 }
 
+#ifdef    XKB
+void OBActions::xkbHandler(const XkbEvent &e)
+{
+  Window w;
+  OtkEventHandler::xkbHandler(e);
+
+  switch (((XkbAnyEvent*)&e)->xkb_type) {
+  case XkbBellNotify:
+    w = ((XkbBellNotifyEvent*)&e)->window;
+    OBClient *c = Openbox::instance->findClient(w);
+    if (c) {
+      EventData *data = new_event_data(c->screen(), w, EventBell, 0);
+      Openbox::instance->bindings()->fireEvent(data);
+      Py_DECREF((PyObject*)data);
+    }
+    break;
+  }
 }
+#endif // XKB
+
+}
+
Index: src/actions.hh
===================================================================
RCS file: /cvs/cvsroot/openbox/src/actions.hh,v
retrieving revision 1.21
diff -p -u -r1.21 actions.hh
--- src/actions.hh	2003/01/03 21:48:11	1.21
+++ src/actions.hh	2003/01/08 01:23:04
@@ -80,6 +80,10 @@ public:
   virtual void unmapHandler(const XUnmapEvent &e);
   virtual void destroyHandler(const XDestroyWindowEvent &e);
 
+#ifdef    XKB
+  virtual void xkbHandler(const XkbEvent &e);
+#endif // XKB
+
 };
 
 }
Index: src/bindings.cc
===================================================================
RCS file: /cvs/cvsroot/openbox/src/bindings.cc,v
retrieving revision 1.47
diff -p -u -r1.47 bindings.cc
--- src/bindings.cc	2003/01/07 02:24:43	1.47
+++ src/bindings.cc	2003/01/08 01:23:04
@@ -524,7 +524,12 @@ bool OBBindings::addEvent(EventAction ac
   if (action < 0 || action >= NUM_EVENTS) {
     return false;
   }
-
+#ifdef    XKB
+  if (action == EventBell) {
+    XkbSelectEvents (otk::OBDisplay::display, XkbUseCoreKbd,
+                     XkbBellNotifyMask, XkbBellNotifyMask);
+  }
+#endif // XKB
   _eventlist[action].push_back(callback);
   Py_INCREF(callback);
   return true;
@@ -542,6 +547,11 @@ bool OBBindings::removeEvent(EventAction
   if (it != _eventlist[action].end()) {
     Py_XDECREF(*it);
     _eventlist[action].erase(it);
+#ifdef    XKB
+    if (action == EventBell && _eventlist[action].empty())
+      XkbSelectEvents (otk::OBDisplay::display, XkbUseCoreKbd,
+                       XkbBellNotifyMask, 0);
+#endif // XKB
     return true;
   }
   return false;
Index: src/openbox.cc
===================================================================
RCS file: /cvs/cvsroot/openbox/src/openbox.cc,v
retrieving revision 1.111
diff -p -u -r1.111 openbox.cc
--- src/openbox.cc	2003/01/07 19:24:38	1.111
+++ src/openbox.cc	2003/01/08 01:23:05
@@ -281,7 +281,8 @@ void Openbox::showHelp()
   printf(_("Compile time options:\n\
   Debugging: %s\n\
   Shape:     %s\n\
-  Xinerama:  %s\n"),
+  Xinerama:  %s\n\
+  Xkb:       %s\n"),
 #ifdef    DEBUG
          _("yes"),
 #else // !DEBUG
@@ -295,10 +296,16 @@ void Openbox::showHelp()
 #endif // SHAPE
 
 #ifdef    XINERAMA
-         _("yes")
+         _("yes"),
 #else // !XINERAMA
-         _("no")
+         _("no"),
 #endif // XINERAMA
+
+#ifdef    XKB
+         _("yes")
+#else // !XKB
+         _("no")
+#endif // XKB
     );
 }
 
Index: src/python.hh
===================================================================
RCS file: /cvs/cvsroot/openbox/src/python.hh,v
retrieving revision 1.22
diff -p -u -r1.22 python.hh
--- src/python.hh	2003/01/07 06:50:21	1.22
+++ src/python.hh	2003/01/08 01:23:05
@@ -58,6 +58,7 @@ enum EventAction {
   EventStartup,
   EventShutdown,
   EventFocus,
+  EventBell,
   NUM_EVENTS
 };
 


More information about the openbox mailing list