Commits

Micah Nordland committed cd50a43

fixed tree insertion, so that removing doesn't lose windows.

  • Participants
  • Parent commits dda2664

Comments (0)

Files changed (4)

File include/eventHandlers.h

+#include <string>
+
 #include <xcb/xcb.h>
 
 #include "event.h"
 
     private:
         Setup *setup;
+        int boxUid;
 };

File src/boxTree.cpp

 
 void BoxTree::insert(Box *box)
 {
+    std::cout << "inserting new box" << std::endl;
     if(not focused)
+    {
         root = box;
+    }
     else
     {
         Box *dad = new Box();
         }
         else
         {
-            if (focused->isFirst())
-                focusParent->first = dad;
+            Box *grandpa = focusParent ->parent;
+            if (grandpa)
+            {
+                if (focusParent->isFirst())
+                {
+                    grandpa->first = dad;
+                }
+                else
+                    grandpa->second = dad;
+            }
             else
-                focusParent->second = dad;
-            
-            focused->parent = dad;
+                root = dad;
+            focusParent->parent = dad;
             if (focused->isFirst())
             {
                 dad->first = box;
-                dad->second = focused;
+                dad->second = focusParent;
                 rotate(focusParent, Clockwise);
             }
-            else 
+            else
             {
-                dad->first = focused;
+                dad->first = focusParent;
                 dad->second = box;
                 rotate(focusParent, CounterClockwise);
             }
-        }   
+
+        }          
     }
     std::cout << "added box" << std::endl;
 }
 {
     if (not box)
         return;
-
     Box *parent = box->parent;
 
     if (not parent)
         }
         else
         {
+            std::cout << "we didn't find grandpa" << std::endl;
             root = b;
         }
         box->parent = nullptr;
     if (not box)
         return;
     std::cout << box->getName() << std::endl;
+    if (box->getName() == "parent")
+        std::cout << "   ";
     printTree(box->first);
     printTree(box->second);
 }

File src/eventHandlers.cpp

 #include "monitor.h"
 
 EventHandler::EventHandler(Setup *setup):
-    setup(setup)
+    setup(setup),
+    boxUid(0)
 {
 }
 
     Window *window = new Window(setup, ev->window);
     Box *box = new Box();
     box->window = window;
-
+    box->value = std::to_string(boxUid++);
     BoxTree &tree = setup->monitors[0].tagList[0].boxTree;
     tree.insert(box);
     tree.layoutBoxes(tree.getRoot(), setup->monitors[0].area);
     xcb_map_window(setup->conn, ev->window);
+    tree.printTree(tree.getRoot());
 }
 
 void EventHandler::handleConfigureRequest(EventPtr event)
     if (ev->value_mask & XCB_CONFIG_WINDOW_X)
     {
         mask |= XCB_CONFIG_WINDOW_X;
-        values[i++] = 50;
+        values[i++] = ev->x;
                                         
     }
 
     if (ev->value_mask & XCB_CONFIG_WINDOW_Y)
     {
         mask |= XCB_CONFIG_WINDOW_Y;
-        values[i++] = 80;
+        values[i++] = ev->y;
                                                 
     }
 
     Box *winBox = tree.findWindowBox(ev->window);
     if (winBox)
     {
+        std::cout << "trying to remove: " << winBox->window->id << std::endl;
         tree.remove(winBox);
-        tree.layoutBoxes(tree.getRoot(), setup->monitors[0].area);
     }
+    
+    tree.printTree(tree.getRoot());
+    tree.layoutBoxes(tree.getRoot(), setup->monitors[0].area);
 }
 
 void EventHandler::handleDestroyNotify(EventPtr event)
     Box *winBox = tree.findWindowBox(ev->window);
     if (winBox)
     {
+        std::cout << "trying to remove: " << winBox->window->id << std::endl;
         tree.remove(winBox);
-        tree.layoutBoxes(tree.getRoot(), setup->monitors[0].area);
     }
+    tree.printTree(tree.getRoot());
+    tree.layoutBoxes(tree.getRoot(), setup->monitors[0].area);
 }
 
 void EventHandler::handleEnterNotify(EventPtr event)

File src/window.cpp

 
 void Window::handleTransient()
 {
-    xcb_window_t *transientFor = nullptr;
+    xcb_window_t transientFor = XCB_NONE;
     if (xcb_icccm_get_wm_transient_for_reply(setup->conn, 
-        xcb_icccm_get_wm_transient_for_unchecked(setup->conn, id), transientFor, nullptr)
-        and transientFor)
+        xcb_icccm_get_wm_transient_for_unchecked(setup->conn, id), &transientFor, nullptr)
+        and transientFor != XCB_NONE)
     {
         transient = true;
     }