patch for ob3

Ruhi Bloodworth ruhi at colophon.cjb.net
Wed Sep 18 22:51:08 EDT 2002


x0r,

This patch adds the following

a screen list to display and a window list to screen
the beginings of an event_loop

Regards,
Colo
-------------- next part --------------
? autom4te.cache
? main.cc
? mychanges.patch
Index: wm/main.cc
===================================================================
RCS file: /cvs/cvsroot/openbox3/wm/main.cc,v
retrieving revision 1.4
diff -p -u -r1.4 main.cc
--- wm/main.cc	2002/09/19 02:18:14	1.4
+++ wm/main.cc	2002/09/19 02:46:26
@@ -1,5 +1,6 @@
 #include "xlib/display.hh"
 #include "xlib/screen.hh"
+#include "xlib/window.hh"
 
 #include <iostream>
 #include <string>
@@ -9,7 +10,40 @@ using std::cerr;
 using std::endl;
 using xlib::XDisplay;
 using xlib::XScreen;
+using xlib::XWindow;
 
+int process_event(XDisplay &display,XEvent *e){
+  switch(e->type) {
+  case MapRequest: {
+    cerr << "process_event(): MapRequest for "<<e->xmaprequest.window << endl;
+   
+    XWindowAttributes attr;
+    XGetWindowAttributes(e->xmaprequest.display,e->xmaprequest.window,
+			 &attr);
+
+    XScreen *screen = display.findScreen(XScreenNumberOfScreen(attr.screen));
+    if (screen){
+      XWindow *win = new XWindow(display,(*screen),e->xmaprequest.window);
+      win->map();
+      return 1;
+    }
+    cerr << "process_event(): error processing MapRequest" << endl;
+    break;
+  }
+  }
+  return 0;
+}
+
+void eventLoop(XDisplay &display){
+  XEvent *e=0;
+  e = display.nextEvent();
+  cerr << "In eventLoop" << endl;
+  while(process_event(display,e)){
+    delete e;
+    e = display.nextEvent();
+  }
+}
+
 int main(int argc, char **argv) {
   string session_display;
 
@@ -39,5 +73,8 @@ int main(int argc, char **argv) {
 
   XScreen screen(display, 0);
 
+  cerr << "Opened X screen " << screen.name() << endl;
+  screen.root().manage();
+  eventLoop(display);
   display.close();
 }
Index: xlib/display.cc
===================================================================
RCS file: /cvs/cvsroot/openbox3/xlib/display.cc,v
retrieving revision 1.6
diff -p -u -r1.6 display.cc
--- xlib/display.cc	2002/09/18 04:53:14	1.6
+++ xlib/display.cc	2002/09/19 02:46:26
@@ -45,3 +45,16 @@ void XDisplay::close()
   XCloseDisplay(_display);
   _display = NULL;
 }
+
+XScreen *XDisplay::findScreen(const int number) const{
+  //Create constant iterator for list
+  list<XScreen*>::const_iterator iter;
+  for (iter=_screen_list.begin(); 
+       ((iter != _screen_list.end())&&((*iter)->number() != number));
+       iter++)
+    ;
+  if (iter != _screen_list.end())
+    return (*iter);
+  else
+    return 0;
+}
Index: xlib/display.hh
===================================================================
RCS file: /cvs/cvsroot/openbox3/xlib/display.hh,v
retrieving revision 1.9
diff -p -u -r1.9 display.hh
--- xlib/display.hh	2002/09/18 05:35:52	1.9
+++ xlib/display.hh	2002/09/19 02:46:27
@@ -6,10 +6,11 @@ extern "C" {
 #include <assert.h>
 }
 #include <string>
+#include <list>
 
+#include "xlib/screen.hh"
 namespace xlib {
 
-class XScreen;
 class XDrawable;
 
 /*!
@@ -22,7 +23,8 @@ private:
   Display *_display;
   //! The name of the display this class has open.
   std::string _name;
-
+  //! The list of screens on this display
+  std::list<XScreen*> _screen_list;
 public:
   //! Constructor for the XDisplay object.
   XDisplay();
@@ -57,6 +59,36 @@ public:
     return ScreenCount(_display);
   }
 
+  //! Returns the number of events waiting on the event queue
+  inline int pendingEvents() const {
+    return XPending(_display);
+  }
+
+  /*! Returns the next event from the event queue
+    If the event queue is empty then the call waits until an event is recived
+    The caller is responsible for freeing the returned event
+  */
+  inline XEvent* nextEvent(){
+    XEvent *e = new XEvent; XNextEvent(_display,e);
+    return e;
+  }
+  /*! Adds an XScreen to the list of screens on this display
+    \param screen the XScreen to add to the list
+  */
+  inline void addScreen(XScreen *screen){
+    _screen_list.push_back(screen);
+  }
+  /*! Finds the XScreen given the screen number or returns Null
+  \param number The screen number of the XScreen to be retrived
+  */
+  XScreen *findScreen(const int number) const;
+  /*! Removes the specified XScreen from the list of screens
+    if screen is not in the list nothing is done
+    \param screen A pointer to the XScreen to remove
+  */
+  inline void removeScreen(XScreen *screen){
+    _screen_list.remove(screen);
+  }
   friend class XScreen;
   friend class XDrawable;
 };
Index: xlib/screen.cc
===================================================================
RCS file: /cvs/cvsroot/openbox3/xlib/screen.cc,v
retrieving revision 1.6
diff -p -u -r1.6 screen.cc
--- xlib/screen.cc	2002/09/18 13:45:14	1.6
+++ xlib/screen.cc	2002/09/19 02:46:27
@@ -79,6 +79,8 @@ XScreen::XScreen(XDisplay &xdisplay, int
   // set the name to the display plus this screen's number
   _name = default_string + '.' + itostring(_number);
 
+  // register with the display
+  xdisplay.addScreen(this);
 
   // this is done last since XWindow uses XScreen
   _root = new XWindow(_xdisplay, *this, RootWindow(_display, number));
@@ -86,6 +88,7 @@ XScreen::XScreen(XDisplay &xdisplay, int
 
 XScreen::~XScreen()
 {
+  _xdisplay.removeScreen(this);
   delete _root;
 }
 
Index: xlib/screen.hh
===================================================================
RCS file: /cvs/cvsroot/openbox3/xlib/screen.hh,v
retrieving revision 1.8
diff -p -u -r1.8 screen.hh
--- xlib/screen.hh	2002/09/18 13:45:14	1.8
+++ xlib/screen.hh	2002/09/19 02:46:27
@@ -8,8 +8,8 @@ extern "C" {
 
 #include "window.hh"
 #include "util/rect.hh"
-
 #include <string>
+#include <list>
 
 namespace xlib {
 
@@ -47,7 +47,8 @@ private:
   Colormap _colormap;
   //! The name of the screen on the display.
   std::string _name;
-
+  //! The windows that are on this screen
+  std::list<XWindow*> _window_list;
 public:
   /*! Constructor for the XScreen object.
     \param display The XDisplay on which this screen will reside.
@@ -87,6 +88,19 @@ public:
     return _depth;
   }
   
+  /*! Adds an XWindow to the screens list of windows
+    \param win The window to be inserted into the window list
+  */
+  inline void addWindow(XWindow *win){
+    _window_list.push_back(win);
+  }
+  /*! Removes the XWindow from the window list. If window is not in the list
+    nothign is done.
+    \param win The XWindow to remove from the list
+  */
+  inline void removeWindow(XWindow *win){
+    _window_list.remove(win);
+  }
   friend class XDrawable;
   friend class XWindow;
 };
Index: xlib/window.cc
===================================================================
RCS file: /cvs/cvsroot/openbox3/xlib/window.cc,v
retrieving revision 1.4
diff -p -u -r1.4 window.cc
--- xlib/window.cc	2002/09/18 13:45:14	1.4
+++ xlib/window.cc	2002/09/19 02:46:27
@@ -21,7 +21,8 @@ XWindow::XWindow(XDisplay &xdisplay, XSc
                       0,
                       0);
   _area = area;
-
+  
+  _xscreen.addWindow(this);
   assert(_id != None);
 }
 
@@ -34,11 +35,13 @@ XWindow::XWindow(XDisplay &xdisplay, XSc
   _id = id;
   // XXX: Set _area properly from the id
   _area = Rect(0,0,1,1);
+  _xscreen.addWindow(this);
 }
 
 
 XWindow::~XWindow()
 {
+  _xscreen.removeWindow(this);
   XDestroyWindow(_display, _id);
   _id = 0;
 }
@@ -57,4 +60,15 @@ void XWindow::unmap()
   assert(_id != None);
 
   XUnmapWindow(_display, _id);
+}
+
+int XWindow::manage()
+{
+  assert (_id != None);
+  const long rootEventMask = SubstructureRedirectMask |
+                             PropertyChangeMask | EnterWindowMask |
+                             ButtonPressMask | ButtonReleaseMask;
+  //-BUG-We are not checking to see if XSelectInput fails
+  XSelectInput(_display, _id, rootEventMask);
+  return 1;
 }
Index: xlib/window.hh
===================================================================
RCS file: /cvs/cvsroot/openbox3/xlib/window.hh,v
retrieving revision 1.4
diff -p -u -r1.4 window.hh
--- xlib/window.hh	2002/09/18 13:45:14	1.4
+++ xlib/window.hh	2002/09/19 02:46:27
@@ -39,6 +39,7 @@ public:
   XWindow(XDisplay &xdisplay, XScreen &xscreen,
           util::Rect area = util::Rect(0, 0, 1, 1),
           XWindow *parent = static_cast<XWindow*>(0));
+
   /*! Constructor for the XWindow object.
     Creates an X window for the class to contain.
     \param xdisplay The X display to host the window on.
@@ -47,6 +48,7 @@ public:
     not create a new window.
   */
   XWindow(XDisplay &xdisplay, XScreen &xscreen, Window id);
+
   /*! Destructor for the XWindow object.
     Destroys the window contained by the class.
   */
@@ -54,6 +56,9 @@ public:
 
   void map();
   void unmap();
+  
+  //! Indicates the caller will intercept events for this window and its children
+  int manage();
 };
 
 }


More information about the openbox mailing list