From 74cb09bb2cc4832463a57743b1495eef24237d2a Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 2 Dec 2002 21:06:16 +0000 Subject: [PATCH] handle map events with the Openbox class --- otk/eventhandler.hh | 2 +- src/Makefile.am | 2 +- src/client.cc | 18 ++++++++++---- src/client.hh | 17 ++++++-------- src/openbox.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++ src/openbox.hh | 2 ++ 6 files changed, 82 insertions(+), 16 deletions(-) diff --git a/otk/eventhandler.hh b/otk/eventhandler.hh index 8e39a8dc..a70343ed 100644 --- a/otk/eventhandler.hh +++ b/otk/eventhandler.hh @@ -118,7 +118,7 @@ public: #if defined(SHAPE) || defined(DOXYGEN_IGNORE) //! Called when a shape extention event fires - virtual void shapeHandler(const XShapeEvent &) {}; + virtual void shapeHandler(const XShapeEvent &) {} #endif // SHAPE virtual ~OtkEventHandler(); diff --git a/src/Makefile.am b/src/Makefile.am index 8034df0e..456c667d 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 xeventhandler.cc + main.cc MAINTAINERCLEANFILES= Makefile.in diff --git a/src/client.cc b/src/client.cc index 57bf5161..34fcf6fa 100644 --- a/src/client.cc +++ b/src/client.cc @@ -23,10 +23,14 @@ extern "C" { namespace ob { OBClient::OBClient(int screen, Window window) - : _screen(screen), _window(window) + : otk::OtkEventHandler(), + _screen(screen), _window(window) { + assert(screen >= 0); assert(window); + Openbox::instance->registerHandler(_window, this); + ignore_unmaps = 0; // update EVERYTHING the first time!! @@ -494,8 +498,10 @@ void OBClient::updateClass() } -void OBClient::update(const XPropertyEvent &e) +void OBClient::propertyHandler(const XPropertyEvent &e) { + otk::OtkEventHandler::propertyHandler(e); + const otk::OBProperty *property = Openbox::instance->property(); if (e.atom == XA_WM_NORMAL_HINTS) @@ -642,8 +648,10 @@ void OBClient::setState(StateAction action, long data1, long data2) } -void OBClient::update(const XClientMessageEvent &e) +void OBClient::clientMessageHandler(const XClientMessageEvent &e) { + otk::OtkEventHandler::clientMessageHandler(e); + if (e.format != 32) return; const otk::OBProperty *property = Openbox::instance->property(); @@ -659,8 +667,10 @@ void OBClient::update(const XClientMessageEvent &e) #if defined(SHAPE) || defined(DOXYGEN_IGNORE) -void OBClient::update(const XShapeEvent &e) +void OBClient::shapeHandler(const XShapeEvent &e) { + otk::OtkEventHandler::shapeHandler(e); + _shaped = e.shaped; } #endif diff --git a/src/client.hh b/src/client.hh index 5ccf5fd5..b7f8861c 100644 --- a/src/client.hh +++ b/src/client.hh @@ -19,6 +19,7 @@ extern "C" { #include "otk/strut.hh" #include "otk/rect.hh" +#include "otk/eventhandler.hh" namespace ob { @@ -36,7 +37,7 @@ class OBFrame; class' member variables and call whatever is nessary to complete the change (such as causing a redraw of the titlebar after the title is changed). */ -class OBClient { +class OBClient : public otk::OtkEventHandler { public: //! The frame window which decorates around the client window @@ -433,16 +434,12 @@ public: //! Returns the position and size of the client relative to the root window inline const otk::Rect &area() const { return _area; } - //! Updates the OBClient class from a property change XEvent - void update(const XPropertyEvent &e); - //! Processes a client message XEvent for the window and causes an action - //! or whatever was specified to occur - void update(const XClientMessageEvent &e); -#if defined(SHAPE) || defined(DOXYGEN_IGNORE) - //! Updates the client's shape status - void update(const XShapeEvent &e); -#endif + virtual void propertyHandler(const XPropertyEvent &); + virtual void clientMessageHandler(const XClientMessageEvent &); + + virtual void shapeHandler(const XShapeEvent &); + //! Changes the stored positions and size of the OBClient window /*! This does not actually change the physical geometry, that needs to be done diff --git a/src/openbox.cc b/src/openbox.cc index 0c534a0f..d2213ec4 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -121,6 +121,9 @@ Openbox::Openbox(int argc, char **argv) _property = new otk::OBProperty(); + // set this class as the fallback event handler (for map events) + setFallbackHandler(this); + // create the mouse cursors we'll use _cursors.session = XCreateFontCursor(otk::OBDisplay::display, XC_left_ptr); _cursors.move = XCreateFontCursor(otk::OBDisplay::display, XC_fleur); @@ -280,5 +283,59 @@ OBClient *Openbox::findClient(Window window) return (OBClient*) 0; } + +void Openbox::mapRequestHandler(const XMapRequestEvent &e) +{ +#ifdef DEBUG + printf("MapRequest for 0x%lx\n", e.window); +#endif // DEBUG + + otk::OtkEventHandler::mapRequestHandler(e); + + OBClient *client = findClient(e.window); + + if (client) { + // XXX: uniconify and/or unshade the window + } else { + int screen = INT_MAX; + + for (int i = 0; i < ScreenCount(otk::OBDisplay::display); ++i) + if (otk::OBDisplay::screenInfo(i)->getRootWindow() == e.parent) { + screen = i; + break; + } + + if (screen >= ScreenCount(otk::OBDisplay::display)) { + /* + we got a map request for a window who's parent isn't root. this + can happen in only one circumstance: + + a client window unmapped a managed window, and then remapped it + somewhere between unmapping the client window and reparenting it + to root. + + regardless of how it happens, we need to find the screen that + the window is on + */ + XWindowAttributes wattrib; + if (! XGetWindowAttributes(otk::OBDisplay::display, e.window, + &wattrib)) { + // failed to get the window attributes, perhaps the window has + // now been destroyed? + return; + } + + for (int i = 0; i < ScreenCount(otk::OBDisplay::display); ++i) + if (otk::OBDisplay::screenInfo(i)->getRootWindow() == wattrib.root) { + screen = i; + break; + } + } + + assert(screen < static_cast(_screens.size())); + _screens[screen]->manageWindow(e.window); + } +} + } diff --git a/src/openbox.hh b/src/openbox.hh index c810057f..8c2015f9 100644 --- a/src/openbox.hh +++ b/src/openbox.hh @@ -188,6 +188,8 @@ public: manager can be destroyed. */ inline void shutdown() { _doshutdown = true; } + + virtual void mapRequestHandler(const XMapRequestEvent &); }; } -- 2.39.2