]> Dogcows Code - chaz/openbox/blobdiff - src/screen.cc
updated wrappers
[chaz/openbox] / src / screen.cc
index 991d3dc50aaefe3ea809cb39c13faec17ea2d91a..e97c05b295236b7e2bde13a0e1e4b8275ec6ed55 100644 (file)
@@ -138,6 +138,10 @@ OBScreen::OBScreen(int screen)
 
   // register this class as the event handler for the root window
   Openbox::instance->registerHandler(_info->rootWindow(), this);
+
+  // call the python Startup callbacks
+  EventData data(_number, 0, EventShutdown, 0);
+  Openbox::instance->bindings()->fireEvent(&data);
 }
 
 
@@ -151,6 +155,10 @@ OBScreen::~OBScreen()
   while (!clients.empty())
     unmanageWindow(clients.front());
 
+  // call the python Shutdown callbacks
+  EventData data(_number, 0, EventShutdown, 0);
+  Openbox::instance->bindings()->fireEvent(&data);
+
   XDestroyWindow(otk::OBDisplay::display, _focuswindow);
   XDestroyWindow(otk::OBDisplay::display, _supportwindow);
 
@@ -274,7 +282,6 @@ void OBScreen::changeSupportedAtoms()
   _supportwindow = XCreateSimpleWindow(otk::OBDisplay::display,
                                        _info->rootWindow(),
                                        0, 0, 1, 1, 0, 0, 0);
-  assert(_supportwindow != None);
 
   // set supporting window
   Openbox::instance->property()->set(_info->rootWindow(),
@@ -449,19 +456,21 @@ void OBScreen::manageWindow(Window window)
   XWMHints *wmhint;
   XSetWindowAttributes attrib_set;
 
+  otk::OBDisplay::grab();
+
   // is the window a docking app
   if ((wmhint = XGetWMHints(otk::OBDisplay::display, window))) {
     if ((wmhint->flags & StateHint) &&
         wmhint->initial_state == WithdrawnState) {
       //slit->addClient(w); // XXX: make dock apps work!
+      otk::OBDisplay::ungrab();
+
       XFree(wmhint);
       return;
     }
     XFree(wmhint);
   }
 
-  otk::OBDisplay::grab();
-
   // choose the events we want to receive on the CLIENT window
   attrib_set.event_mask = OBClient::event_mask;
   attrib_set.do_not_propagate_mask = OBClient::no_propagate_mask;
@@ -482,8 +491,12 @@ void OBScreen::manageWindow(Window window)
   // reparented back to root automatically
   XChangeSaveSet(otk::OBDisplay::display, window, SetModeInsert);
 
-  if (!client->positionRequested()) {
-    // XXX: position the window intelligenty
+  if (!(Openbox::instance->state() == Openbox::State_Starting ||
+        client->positionRequested())) {
+    // position the window intelligenty .. hopefully :)
+    // call the python PLACEWINDOW binding
+    EventData data(_number, client, EventPlaceWindow, 0);
+    Openbox::instance->bindings()->fireEvent(&data);
   }
 
   // create the decoration frame for the client window
@@ -502,8 +515,14 @@ void OBScreen::manageWindow(Window window)
   Openbox::instance->addClient(client->frame->grip_left(), client);
   Openbox::instance->addClient(client->frame->grip_right(), client);
 
-  // XXX: if on the current desktop..
-  client->frame->show();
+  // reparent the client to the frame
+  client->frame->grabClient();
+
+  // if on the current desktop.. (or all desktops)
+  if (client->desktop() == _desktop ||
+      client->desktop() == (signed)0xffffffff) {
+    client->frame->show();
+  }
  
   // XXX: handle any requested states such as maximized
 
@@ -519,16 +538,13 @@ void OBScreen::manageWindow(Window window)
 
   Openbox::instance->bindings()->grabButtons(true, client);
 
-  // XXX: make this optional or more intelligent
-  if (client->normal())
-    client->focus();
-
   // call the python NEWWINDOW binding
-  EventData *data = new_event_data(window, EventNewWindow, 0);
-  Openbox::instance->bindings()->fireEvent(data);
-  Py_DECREF((PyObject*)data);
+  EventData data(_number, client, EventNewWindow, 0);
+  Openbox::instance->bindings()->fireEvent(&data);
 
+#ifdef DEBUG
   printf("Managed window 0x%lx\n", window);
+#endif
 }
 
 
@@ -537,28 +553,11 @@ void OBScreen::unmanageWindow(OBClient *client)
   OBFrame *frame = client->frame;
 
   // call the python CLOSEWINDOW binding 
-  EventData *data = new_event_data(client->window(), EventCloseWindow, 0);
-  Openbox::instance->bindings()->fireEvent(data);
-  Py_DECREF((PyObject*)data);
+  EventData data(_number, client, EventCloseWindow, 0);
+  Openbox::instance->bindings()->fireEvent(&data);
 
   Openbox::instance->bindings()->grabButtons(false, client);
 
-  // remove from the stacking order
-  _stacking.remove(client);
-  
-  // pass around focus if this window was focused XXX do this better!
-  if (Openbox::instance->focusedClient() == client) {
-    OBClient *newfocus = 0;
-    OBClient::List::iterator it, end = _stacking.end();
-    for (it = _stacking.begin(); it != end; ++it)
-      if ((*it)->normal() && (*it)->focus()) {
-        newfocus = *it;
-        break;
-      }
-    if (!newfocus)
-      client->unfocus();
-  }
-
   // remove from the wm's map
   Openbox::instance->removeClient(client->window());
   Openbox::instance->removeClient(frame->window());
@@ -586,11 +585,25 @@ void OBScreen::unmanageWindow(OBClient *client)
   // give the client its border back
   client->toggleClientBorder(true);
 
+  // reparent the window out of the frame
+  frame->releaseClient();
+
   delete client->frame;
   client->frame = 0;
 
+  // remove from the stacking order
+  _stacking.remove(client);
+
   // remove from the screen's list
   clients.remove(client);
+
+  // unfocus the client (calls the focus callbacks)
+  client->unfocus();
+
+#ifdef DEBUG
+  printf("Unmanaged window 0x%lx\n", client->window());
+#endif
+  
   delete client;
 
   // update the root properties
@@ -630,6 +643,8 @@ void OBScreen::changeDesktop(long desktop)
 
   if (!(desktop >= 0 && desktop < _num_desktops)) return;
 
+  printf("Moving to desktop %ld\n", desktop);
+  
   long old = _desktop;
   
   _desktop = desktop;
@@ -638,14 +653,20 @@ void OBScreen::changeDesktop(long desktop)
                                      otk::OBProperty::Atom_Cardinal,
                                      _desktop);
 
+  if (old == _desktop) return;
+
   OBClient::List::iterator it, end = clients.end();
   for (it = clients.begin(); it != end; ++it) {
     if ((*it)->desktop() == old) {
-      // XXX hide
+      (*it)->frame->hide();
     } else if ((*it)->desktop() == _desktop) {
-      // XXX show
+      (*it)->frame->show();
     }
   }
+
+  // force the callbacks to fire
+  if (!Openbox::instance->focusedClient())
+    Openbox::instance->setFocusedClient(0);
 }
 
 void OBScreen::changeNumDesktops(long num)
@@ -654,6 +675,8 @@ void OBScreen::changeNumDesktops(long num)
   
   if (!(num > 0)) return;
 
+  // XXX: move windows on desktops that will no longer exist!
+  
   _num_desktops = num;
   Openbox::instance->property()->set(_info->rootWindow(),
                                      otk::OBProperty::net_number_of_desktops,
@@ -760,10 +783,22 @@ void OBScreen::mapRequestHandler(const XMapRequestEvent &e)
   OBClient *c = Openbox::instance->findClient(e.window);
 
   if (c) {
-    if (c->shaded())
-      c->shade(false);
-    // XXX: uniconify the window
-    c->focus();
+    // send a net_active_window message
+    XEvent ce;
+    ce.xclient.type = ClientMessage;
+    ce.xclient.message_type =
+      Openbox::instance->property()->atom(otk::OBProperty::net_active_window);
+    ce.xclient.display = otk::OBDisplay::display;
+    ce.xclient.window = c->window();
+    ce.xclient.format = 32;
+    ce.xclient.data.l[0] = 0l;
+    ce.xclient.data.l[1] = 0l;
+    ce.xclient.data.l[2] = 0l;
+    ce.xclient.data.l[3] = 0l;
+    ce.xclient.data.l[4] = 0l;
+    XSendEvent(otk::OBDisplay::display, _info->rootWindow(), false,
+               SubstructureRedirectMask | SubstructureNotifyMask,
+               &ce);
   } else
     manageWindow(e.window);
 }
This page took 0.02455 seconds and 4 git commands to generate.