]> Dogcows Code - chaz/openbox/commitdiff
add an OBRootWindow class that watches events/properties on root windows
authorDana Jansens <danakj@orodu.net>
Mon, 2 Dec 2002 22:12:26 +0000 (22:12 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 2 Dec 2002 22:12:26 +0000 (22:12 +0000)
src/Makefile.am
src/client.hh
src/rootwindow.cc [new file with mode: 0644]
src/rootwindow.hh [new file with mode: 0644]
src/screen.cc
src/screen.hh

index 456c667d6f4a0c9f385d72d14ac4f07688ddf75f..ac4534c6026630564d9a5d844439eab8b343882e 100644 (file)
@@ -16,7 +16,7 @@ bin_PROGRAMS= openbox3
 openbox3_LDADD=../otk/libotk.a @LIBINTL@
 
 openbox3_SOURCES= client.cc frame.cc openbox.cc screen.cc \
-                  main.cc
+                  main.cc rootwindow.cc
 
 MAINTAINERCLEANFILES= Makefile.in
 
index b7f8861c2c0a3141fb1a0e36cf324437e06c3cd5..325162edd9070916468012b541a6cbdf16908b5d 100644 (file)
@@ -434,11 +434,11 @@ public:
   //! Returns the position and size of the client relative to the root window
   inline const otk::Rect &area() const { return _area; }
 
-  virtual void propertyHandler(const XPropertyEvent &);
+  virtual void propertyHandler(const XPropertyEvent &e);
 
-  virtual void clientMessageHandler(const XClientMessageEvent &);
+  virtual void clientMessageHandler(const XClientMessageEvent &e);
 
-  virtual void shapeHandler(const XShapeEvent &);
+  virtual void shapeHandler(const XShapeEvent &e);
   
   //! Changes the stored positions and size of the OBClient window
   /*!
diff --git a/src/rootwindow.cc b/src/rootwindow.cc
new file mode 100644 (file)
index 0000000..4123125
--- /dev/null
@@ -0,0 +1,83 @@
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+
+#ifdef HAVE_CONFIG_H
+# include "../config.h"
+#endif
+
+#include "rootwindow.hh"
+#include "openbox.hh"
+#include "otk/display.hh"
+
+namespace ob {
+
+OBRootWindow::OBRootWindow(int screen)
+  : _info(otk::OBDisplay::screenInfo(screen))
+{
+  updateDesktopNames();
+
+  Openbox::instance->registerHandler(_info->getRootWindow(), this);
+}
+
+
+OBRootWindow::~OBRootWindow()
+{
+}
+
+
+void OBRootWindow::updateDesktopNames()
+{
+  const int numWorkspaces = 1; // XXX: change this to the number of workspaces!
+
+  const otk::OBProperty *property = Openbox::instance->property();
+
+  unsigned long num = (unsigned) -1;
+  
+  if (!property->get(_info->getRootWindow(),
+                     otk::OBProperty::net_desktop_names,
+                     otk::OBProperty::utf8, &num, &_names))
+    _names.clear();
+  for (int i = 0; i < numWorkspaces; ++i)
+    if (i <= static_cast<int>(_names.size()))
+      _names.push_back("Unnamed workspace");
+}
+
+
+void OBRootWindow::propertyHandler(const XPropertyEvent &e)
+{
+  otk::OtkEventHandler::propertyHandler(e);
+
+  const otk::OBProperty *property = Openbox::instance->property();
+
+  if (e.atom == property->atom(otk::OBProperty::net_desktop_names))
+    updateDesktopNames();
+}
+
+
+void OBRootWindow::clientMessageHandler(const XClientMessageEvent &e)
+{
+  otk::OtkEventHandler::clientMessageHandler(e);
+
+  if (e.format != 32) return;
+
+  //const otk::OBProperty *property = Openbox::instance->property();
+  
+  // XXX: so many client messages to handle here!
+}
+
+
+void OBRootWindow::setDesktopName(int i, const std::string &name)
+{
+  const int numWorkspaces = 1; // XXX: change this to the number of workspaces!
+  assert(i >= 0);
+  assert(i < numWorkspaces); 
+
+  const otk::OBProperty *property = Openbox::instance->property();
+  
+  otk::OBProperty::StringVect newnames = _names;
+  newnames[i] = name;
+  property->set(_info->getRootWindow(), otk::OBProperty::net_desktop_names,
+                otk::OBProperty::utf8, newnames);
+}
+
+
+}
diff --git a/src/rootwindow.hh b/src/rootwindow.hh
new file mode 100644 (file)
index 0000000..7879244
--- /dev/null
@@ -0,0 +1,69 @@
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+#ifndef   __rootwindow_hh
+#define   __rootwindow_hh
+
+/*! @file client.hh
+  @brief The OBClient class maintains the state of a client window by handling
+  property changes on the window and some client messages
+*/
+
+extern "C" {
+#include <X11/Xlib.h>
+
+#ifdef    SHAPE
+#include <X11/extensions/shape.h>
+#endif // SHAPE
+}
+
+#include <string>
+#include <vector>
+
+#include "otk/screeninfo.hh"
+#include "otk/eventhandler.hh"
+#include "otk/property.hh"
+
+namespace ob {
+
+//! Maintains the state of a root window's properties.
+/*!
+  OBRootWindow maintains the state of a root window. The state consists of the
+  hints that the wm sets on the window, such as the number of desktops,
+  gravity.
+  <p>
+  OBRootWindow also manages client messages for the root window.
+*/
+class OBRootWindow : public otk::OtkEventHandler {
+private:
+  //! Information about this screen
+  const otk::ScreenInfo *_info;
+
+  //! The names of all desktops
+  otk::OBProperty::StringVect _names;
+
+  //! Get desktop names from the 
+  void updateDesktopNames();
+
+public:
+  //! Constructs a new OBRootWindow for a screen
+  /*!
+    @param screen The screen whose root window to wrap
+  */
+  OBRootWindow(int screen);
+  //! Destroys the OBRootWindow object
+  virtual ~OBRootWindow();
+
+  virtual void propertyHandler(const XPropertyEvent &e);
+
+  virtual void clientMessageHandler(const XClientMessageEvent &e);
+
+  //! Sets the name of a desktop
+  /*!
+    @param i The index of the desktop to set the name for (base 0)
+    @param name The name to set for the desktop
+  */
+  void setDesktopName(int i, const std::string &name);
+};
+
+}
+
+#endif // __client_hh
index 4457096b240a35c680331b594c5b232acf233d18..3c6731c2c940ad5732bbd241bc88352922219d77 100644 (file)
@@ -37,7 +37,8 @@ namespace ob {
 
 
 OBScreen::OBScreen(int screen, const otk::Configuration &config)
-  : _number(screen)
+  : _number(screen),
+    _root(screen)
 {
   assert(screen >= 0); assert(screen < ScreenCount(otk::OBDisplay::display));
   _info = otk::OBDisplay::screenInfo(screen);
index d047d0c219e69634182960857cc410adae082574..543e216cb05974e1b1310922d0c040e7d67a9b6e 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 #include <X11/Xlib.h>
 }
 
+#include "rootwindow.hh"
 #include "otk/image.hh"
 #include "otk/strut.hh"
 #include "otk/rect.hh"
@@ -21,6 +22,7 @@ extern "C" {
 namespace ob {
 
 class OBClient;
+class OBRootWindow;
 
 //! Manages a single screen
 /*!
@@ -57,6 +59,8 @@ private:
   //! The style with which to render on the screen
   otk::Style _style;
 
+  OBRootWindow _root;
+  
   //! Is the root colormap currently installed?
   bool _root_cmap_installed;
 
This page took 0.033262 seconds and 4 git commands to generate.