]> Dogcows Code - chaz/openbox/blobdiff - src/xeventhandler.cc
read protocols too in OBClient
[chaz/openbox] / src / xeventhandler.cc
index ba60edf7e5c9e4e6e61b71585963f1b9854d9a79..88d16f5607207853177359695aa1210df16d9a67 100644 (file)
@@ -1,9 +1,16 @@
 // -*- mode: C++; indent-tabs-mode: nil; -*-
 
 #include "xeventhandler.hh"
+#include "client.hh"
+#include "openbox.hh"
 #include "otk/display.hh"
 #include "otk/rect.hh"
 
+extern "C" {
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+}
+
 namespace ob {
 
 
@@ -45,6 +52,10 @@ void OBXEventHandler::motion(const XMotionEvent &e)
 void OBXEventHandler::enterNotify(const XCrossingEvent &e)
 {
   _lasttime = e.time;
+
+  OBClient *client = Openbox::instance->findClient(e.window);
+  if (!client) return;
+  
 /*
   BScreen *screen = (BScreen *) 0;
   BlackboxWindow *win = (BlackboxWindow *) 0;
@@ -65,6 +76,10 @@ void OBXEventHandler::enterNotify(const XCrossingEvent &e)
 void OBXEventHandler::leaveNotify(const XCrossingEvent &e)
 {
   _lasttime = e.time;
+
+  OBClient *client = Openbox::instance->findClient(e.window);
+  if (!client) return;
+  
 /*
   BlackboxWindow *win = (BlackboxWindow *) 0;
 
@@ -76,7 +91,9 @@ void OBXEventHandler::leaveNotify(const XCrossingEvent &e)
 
 void OBXEventHandler::configureRequest(const XConfigureRequestEvent &e)
 {
-  (void)e;
+  OBClient *client = Openbox::instance->findClient(e.window);
+  if (!client) return;
+  
 /*  BlackboxWindow *win = (BlackboxWindow *) 0;
 
   if ((win = searchWindow(e->xconfigurerequest.window))) {
@@ -101,11 +118,51 @@ void OBXEventHandler::configureRequest(const XConfigureRequestEvent &e)
 }
 
 
+// XXX: put this into the OBScreen class!
+static void manageWindow(Window window)
+{
+  XWMHints *wmhint;
+  XSetWindowAttributes attrib_set;
+
+  // XXX: manage the window, i.e. grab events n shit
+
+  // is the window a docking app
+  if ((wmhint = XGetWMHints(otk::OBDisplay::display, window))) {
+    if ((wmhint->flags & StateHint) &&
+        wmhint->initial_state == WithdrawnState) {
+      //slit->addClient(w); // XXX: make dock apps work!
+      XFree(wmhint);
+      return;
+    }
+    XFree(wmhint);
+  }
+
+  // choose the events we want to receive on the CLIENT window
+  attrib_set.event_mask = PropertyChangeMask | FocusChangeMask |
+                          StructureNotifyMask;
+  attrib_set.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask |
+                                     ButtonMotionMask;
+  XChangeWindowAttributes(otk::OBDisplay::display, window,
+                          CWEventMask|CWDontPropagate, &attrib_set);
+
+  // create the OBClient class, which gets all of the hints on the window
+  Openbox::instance->addClient(window, new OBClient(window));
+}
+
 void OBXEventHandler::mapRequest(const XMapRequestEvent &e)
 {
 #ifdef    DEBUG
   printf("MapRequest for 0x%lx\n", e.window);
 #endif // DEBUG
+
+  OBClient *client = Openbox::instance->findClient(e.window);
+
+  if (client) {
+    // XXX: uniconify and/or unshade the window
+  } else {
+    manageWindow(e.window);
+  }
+  
 /*
   BlackboxWindow *win = searchWindow(e->xmaprequest.window);
 
@@ -160,48 +217,37 @@ void OBXEventHandler::mapRequest(const XMapRequestEvent &e)
 
 void OBXEventHandler::unmapNotify(const XUnmapEvent &e)
 {
-  (void)e;
-/*
-  BlackboxWindow *win = (BlackboxWindow *) 0;
-  BScreen *screen = (BScreen *) 0;
-
-  if ((win = searchWindow(e->xunmap.window))) {
-    win->unmapNotifyEvent(&e->xunmap);
-  } else if ((screen = searchSystrayWindow(e->xunmap.window))) {
-    screen->removeSystrayWindow(e->xunmap.window);
-  }
-*/
+  OBClient *client = Openbox::instance->findClient(e.window);
+  if (!client) return;
+  
+  // XXX: unmanage the window, i.e. ungrab events n reparent n shit
+  Openbox::instance->removeClient(e.window);
 }
 
 
 void OBXEventHandler::destroyNotify(const XDestroyWindowEvent &e)
 {
-  (void)e;
-/*
-  BlackboxWindow *win = (BlackboxWindow *) 0;
-  BScreen *screen = (BScreen *) 0;
-  BWindowGroup *group = (BWindowGroup *) 0;
-
-  if ((win = searchWindow(e->xdestroywindow.window))) {
-    win->destroyNotifyEvent(&e->xdestroywindow);
-  } else if ((group = searchGroup(e->xdestroywindow.window))) {
-    delete group;
-  } else if ((screen = searchSystrayWindow(e->xunmap.window))) {
-    screen->removeSystrayWindow(e->xunmap.window);
-  }
-*/
+  // XXX: window group leaders can come through here too!
+  
+  OBClient *client = Openbox::instance->findClient(e.window);
+  if (!client) return;
+  
+  // XXX: unmanage the window, i.e. ungrab events n reparent n shit
+  Openbox::instance->removeClient(e.window);
 }
 
 
 void OBXEventHandler::reparentNotify(const XReparentEvent &e)
 {
-  (void)e;
   /*
     this event is quite rare and is usually handled in unmapNotify
     however, if the window is unmapped when the reparent event occurs
     the window manager never sees it because an unmap event is not sent
     to an already unmapped window.
   */
+  OBClient *client = Openbox::instance->findClient(e.window);
+  if (!client) return;
+
 /*
   BlackboxWindow *win = searchWindow(e->xreparent.window);
   if (win)
@@ -213,45 +259,40 @@ void OBXEventHandler::reparentNotify(const XReparentEvent &e)
 void OBXEventHandler::propertyNotify(const XPropertyEvent &e)
 {
   _lasttime = e.time;
-/*
-  BlackboxWindow *win = (BlackboxWindow *) 0;
-  BScreen *screen = (BScreen *) 0;
 
-  if ((win = searchWindow(e->xproperty.window)))
-    win->propertyNotifyEvent(&e->xproperty);
-  else if ((screen = searchScreen(e->xproperty.window)))
-    screen->propertyNotifyEvent(&e->xproperty);
-*/
+  OBClient *client = Openbox::instance->findClient(e.window);
+  if (!client) return;
+
+  client->update(e);
 }
 
 
 void OBXEventHandler::expose(const XExposeEvent &first)
 {
-    // compress expose events
-    XEvent e; e.xexpose = first;
-    unsigned int i = 0;
-    otk::Rect area(e.xexpose.x, e.xexpose.y, e.xexpose.width,
-                   e.xexpose.height);
-    while (XCheckTypedWindowEvent(otk::OBDisplay::display,
-                                  e.xexpose.window, Expose, &e)) {
-      i++;
-      // merge expose area
-      area |= otk::Rect(e.xexpose.x, e.xexpose.y, e.xexpose.width,
-                        e.xexpose.height);
-    }
-    if ( i > 0 ) {
-      // use the merged area
-      e.xexpose.x = area.x();
-      e.xexpose.y = area.y();
-      e.xexpose.width = area.width();
-      e.xexpose.height = area.height();
-    }
-/*
-    BlackboxWindow *win = (BlackboxWindow *) 0;
+  OBClient *client = Openbox::instance->findClient(first.window);
+  if (!client) return;
+
+  // compress expose events
+  XEvent e; e.xexpose = first;
+  unsigned int i = 0;
+  otk::Rect area(e.xexpose.x, e.xexpose.y, e.xexpose.width,
+                 e.xexpose.height);
+  while (XCheckTypedWindowEvent(otk::OBDisplay::display,
+                                e.xexpose.window, Expose, &e)) {
+    i++;
+    // merge expose area
+    area |= otk::Rect(e.xexpose.x, e.xexpose.y, e.xexpose.width,
+                      e.xexpose.height);
+  }
+  if ( i > 0 ) {
+    // use the merged area
+    e.xexpose.x = area.x();
+    e.xexpose.y = area.y();
+    e.xexpose.width = area.width();
+    e.xexpose.height = area.height();
+  }
 
-    if ((win = searchWindow(e->xexpose.window)))
-      win->exposeEvent(&e->xexpose);
-*/
+  // XXX: make the decorations redraw!
 }
 
 
This page took 0.025614 seconds and 4 git commands to generate.