// -*- mode: C++; indent-tabs-mode: nil; -*-
+#ifdef HAVE_CONFIG_H
+# include "../config.h"
+#endif
+
#include "xeventhandler.hh"
+#include "client.hh"
+#include "openbox.hh"
+#include "screen.hh"
+#include "frame.hh"
#include "otk/display.hh"
#include "otk/rect.hh"
+extern "C" {
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+}
+
namespace ob {
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;
void OBXEventHandler::leaveNotify(const XCrossingEvent &e)
{
_lasttime = e.time;
+
+ OBClient *client = Openbox::instance->findClient(e.window);
+ if (!client) return;
+
/*
BlackboxWindow *win = (BlackboxWindow *) 0;
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))) {
#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 {
+ 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 < ScreenCount(otk::OBDisplay::display));
+
+ Openbox::instance->screen(screen)->manageWindow(e.window);
+ }
+
/*
BlackboxWindow *win = searchWindow(e->xmaprequest.window);
void OBXEventHandler::unmapNotify(const XUnmapEvent &e)
{
- (void)e;
-/*
- BlackboxWindow *win = (BlackboxWindow *) 0;
- BScreen *screen = (BScreen *) 0;
+ OBClient *client = Openbox::instance->findClient(e.window);
+ if (!client) return;
- if ((win = searchWindow(e->xunmap.window))) {
- win->unmapNotifyEvent(&e->xunmap);
- } else if ((screen = searchSystrayWindow(e->xunmap.window))) {
- screen->removeSystrayWindow(e->xunmap.window);
- }
-*/
+ if (client->ignore_unmaps == 0)
+ Openbox::instance->screen(client->screen())->unmanageWindow(client);
+ else
+ client->ignore_unmaps--;
}
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;
+
+ Openbox::instance->screen(client->screen())->unmanageWindow(client);
}
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)
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!
}
#ifdef SHAPE
void OBXEventHandler::shapeEvent(const XShapeEvent &e)
{
- XShapeEvent *shape_event = (XShapeEvent *) e;
- BlackboxWindow *win = searchWindow(e->xany.window);
+ printf("ShapeEvent\n");
+ if (e.kind != ShapeBounding) return;
- if (win && shape_event->kind == ShapeBounding)
- win->shapeEvent(shape_event);
+ OBClient *client = Openbox::instance->findClient(e.window);
+ if (!client) return;
+
+ client->update(e);
+ client->frame->update();
}
#endif // SHAPE
if (e.format != 32)
return;
/*
- if (e->xclient.message_type == xatom->getAtom(XAtom::wm_change_state)) {
- // WM_CHANGE_STATE message
- BlackboxWindow *win = searchWindow(e->xclient.window);
- if (! win || ! win->validateClient()) return;
-
- if (e->xclient.data.l[0] == IconicState)
- win->iconify();
- if (e->xclient.data.l[0] == NormalState)
- win->deiconify();
} else if (e->xclient.message_type ==
xatom->getAtom(XAtom::blackbox_change_workspace) ||
e->xclient.message_type ==
unsigned int workspace = e->xclient.data.l[0];
if (screen && workspace < screen->getWorkspaceCount())
screen->changeWorkspaceID(workspace);
- } else if (e->xclient.message_type ==
- xatom->getAtom(XAtom::blackbox_change_window_focus)) {
- // TEMP HACK TO KEEP BBKEYS WORKING
- BlackboxWindow *win = searchWindow(e->xclient.window);
-
- if (win && win->isVisible() && win->setInputFocus())
- win->installColormap(True);
} else if (e->xclient.message_type ==
xatom->getAtom(XAtom::net_active_window)) {
// NET_ACTIVE_WINDOW
win->installColormap(True);
}
}
- } else if (e->xclient.message_type ==
- xatom->getAtom(XAtom::blackbox_cycle_window_focus)) {
- // BLACKBOX_CYCLE_WINDOW_FOCUS
- BScreen *screen = searchScreen(e->xclient.window);
-
- if (screen) {
- if (! e->xclient.data.l[0])
- screen->prevFocus();
- else
- screen->nextFocus();
- }
- } else if (e->xclient.message_type ==
- xatom->getAtom(XAtom::net_wm_desktop)) {
- // NET_WM_DESKTOP
- BlackboxWindow *win = searchWindow(e->xclient.window);
-
- if (win) {
- BScreen *screen = win->getScreen();
- unsigned long wksp = (unsigned) e->xclient.data.l[0];
- if (wksp < screen->getWorkspaceCount()) {
- if (win->isIconic()) win->deiconify(False, True);
- if (win->isStuck()) win->stick();
- if (wksp != screen->getCurrentWorkspaceID())
- win->withdraw();
- else
- win->show();
- screen->reassociateWindow(win, wksp, True);
- } else if (wksp == 0xfffffffe || // XXX: BUG, BUT DOING THIS SO KDE WORKS FOR NOW!!
- wksp == 0xffffffff) {
- if (win->isIconic()) win->deiconify(False, True);
- if (! win->isStuck()) win->stick();
- if (! win->isVisible()) win->show();
- }
- }
- } else if (e->xclient.message_type ==
- xatom->getAtom(XAtom::blackbox_change_attributes)) {
- // BLACKBOX_CHANGE_ATTRIBUTES
- BlackboxWindow *win = searchWindow(e->xclient.window);
-
- if (win && win->validateClient()) {
- BlackboxHints net;
- net.flags = e->xclient.data.l[0];
- net.attrib = e->xclient.data.l[1];
- net.workspace = e->xclient.data.l[2];
- net.stack = e->xclient.data.l[3];
- net.decoration = e->xclient.data.l[4];
-
- win->changeBlackboxHints(&net);
- }
} else if (e->xclient.message_type ==
xatom->getAtom(XAtom::net_number_of_desktops)) {
// NET_NUMBER_OF_DESKTOPS
win->beginResize(x_root, y_root, BlackboxWindow::BottomRight);
}
}
- } else if (e->xclient.message_type ==
- xatom->getAtom(XAtom::net_wm_state)) {
- // NET_WM_STATE
- BlackboxWindow *win = searchWindow(e->xclient.window);
- if (win && win->validateClient()) {
- const Atom action = (Atom) e->xclient.data.l[0];
- const Atom state[] = { (Atom) e->xclient.data.l[1],
- (Atom) e->xclient.data.l[2] };
-
- for (int i = 0; i < 2; ++i) {
- if (! state[i])
- continue;
-
- if ((Atom) e->xclient.data.l[0] == 1) {
- // ADD
- if (state[i] == xatom->getAtom(XAtom::net_wm_state_modal)) {
- win->setModal(True);
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_maximized_vert)) {
- if (win->isMaximizedHoriz()) {
- win->maximize(0); // unmaximize
- win->maximize(1); // full
- } else if (! win->isMaximized()) {
- win->maximize(2); // vert
- }
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_maximized_horz)) {
- if (win->isMaximizedVert()) {
- win->maximize(0); // unmaximize
- win->maximize(1); // full
- } else if (! win->isMaximized()) {
- win->maximize(3); // horiz
- }
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_shaded)) {
- if (! win->isShaded())
- win->shade();
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_skip_taskbar)) {
- win->setSkipTaskbar(True);
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_skip_pager)) {
- win->setSkipPager(True);
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_fullscreen)) {
- win->setFullscreen(True);
- }
- } else if (action == 0) {
- // REMOVE
- if (state[i] == xatom->getAtom(XAtom::net_wm_state_modal)) {
- win->setModal(False);
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_maximized_vert)) {
- if (win->isMaximizedFull()) {
- win->maximize(0); // unmaximize
- win->maximize(3); // horiz
- } else if (win->isMaximizedVert()) {
- win->maximize(0); // unmaximize
- }
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_maximized_horz)) {
- if (win->isMaximizedFull()) {
- win->maximize(0); // unmaximize
- win->maximize(2); // vert
- } else if (win->isMaximizedHoriz()) {
- win->maximize(0); // unmaximize
- }
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_shaded)) {
- if (win->isShaded())
- win->shade();
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_skip_taskbar)) {
- win->setSkipTaskbar(False);
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_skip_pager)) {
- win->setSkipPager(False);
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_fullscreen)) {
- win->setFullscreen(False);
- }
- } else if (action == 2) {
- // TOGGLE
- if (state[i] == xatom->getAtom(XAtom::net_wm_state_modal)) {
- win->setModal(! win->isModal());
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_maximized_vert)) {
- if (win->isMaximizedFull()) {
- win->maximize(0); // unmaximize
- win->maximize(3); // horiz
- } else if (win->isMaximizedVert()) {
- win->maximize(0); // unmaximize
- } else if (win->isMaximizedHoriz()) {
- win->maximize(0); // unmaximize
- win->maximize(1); // full
- } else {
- win->maximize(2); // vert
- }
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_maximized_horz)) {
- if (win->isMaximizedFull()) {
- win->maximize(0); // unmaximize
- win->maximize(2); // vert
- } else if (win->isMaximizedHoriz()) {
- win->maximize(0); // unmaximize
- } else if (win->isMaximizedVert()) {
- win->maximize(0); // unmaximize
- win->maximize(1); // full
- } else {
- win->maximize(3); // horiz
- }
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_shaded)) {
- win->shade();
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_skip_taskbar)) {
- win->setSkipTaskbar(! win->skipTaskbar());
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_skip_pager)) {
- win->setSkipPager(! win->skipPager());
- } else if (state[i] ==
- xatom->getAtom(XAtom::net_wm_state_fullscreen)) {
- win->setFullscreen(! win->isFullscreen());
- }
- }
- }
- }
}
*/
}
// These types of XEvent's can be bound to actions by the user, and so end
// up getting passed off to the OBBindingMapper class at some point
+ // IOW: THESE WILL HAVE GUILE HOOKS
case ButtonPress:
buttonPress(e.xbutton);
break;
default:
#ifdef SHAPE
if (e.type == otk::OBDisplay::shapeEventBase())
- shapeEvent(e);
+ shapeEvent((*(XShapeEvent*)&e));
#endif // SHAPE
break;