From dca0c9f5a308e115ec308cdc8ca7987ff4fc0479 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 2 Dec 2002 22:12:26 +0000 Subject: [PATCH] add an OBRootWindow class that watches events/properties on root windows --- src/Makefile.am | 2 +- src/client.hh | 6 ++-- src/rootwindow.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++ src/rootwindow.hh | 69 +++++++++++++++++++++++++++++++++++++++ src/screen.cc | 3 +- src/screen.hh | 4 +++ 6 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 src/rootwindow.cc create mode 100644 src/rootwindow.hh diff --git a/src/Makefile.am b/src/Makefile.am index 456c667d..ac4534c6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/client.hh b/src/client.hh index b7f8861c..325162ed 100644 --- a/src/client.hh +++ b/src/client.hh @@ -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 index 00000000..41231257 --- /dev/null +++ b/src/rootwindow.cc @@ -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(_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 index 00000000..7879244d --- /dev/null +++ b/src/rootwindow.hh @@ -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 + +#ifdef SHAPE +#include +#endif // SHAPE +} + +#include +#include + +#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. +

+ 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 diff --git a/src/screen.cc b/src/screen.cc index 4457096b..3c6731c2 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -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); diff --git a/src/screen.hh b/src/screen.hh index d047d0c2..543e216c 100644 --- a/src/screen.hh +++ b/src/screen.hh @@ -10,6 +10,7 @@ extern "C" { #include } +#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; -- 2.39.2