foo-wm

(Archived) Experimental Zooming IPC-based WM
git clone http://milesalan.com/git/foo-wm
Log | Files | Refs | Mirror | README | LICENSE

events.c (3570B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <assert.h>
      4 #include <string.h>
      5 #include <X11/Xlib.h>
      6 
      7 #include "foo-wm.h"
      8 #include "commands.h"
      9 #include "events.h"
     10 #include "tree.h"
     11 #include "window.h"
     12 #include "lookup.h"
     13 #include "util.h"
     14 
     15 
     16 void eMapRequest(XEvent *event) {
     17   fprintf(stderr, "Got a map request\n");
     18   Node *newNode = allocateNode();
     19   newNode -> window = event -> xmaprequest.window;
     20 
     21   /* For Click to Focus */
     22   XGrabButton(display, AnyButton, AnyModifier, newNode -> window,
     23       True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeSync,
     24       None, None);
     25 
     26   //Containerize and move the viewNode
     27   if (focusedNode == viewNode) {
     28     fprintf(stderr, "Focused node is equal to the viewnode\n");
     29     containerize();
     30     viewNode = viewNode -> parent ? viewNode -> parent : viewNode;
     31 
     32     //This is the case in which we reparented the root node
     33     if (focusedNode == rootNode) { rootNode = viewNode; }
     34 
     35     //Brother the new node and rerender
     36     brotherNode(newNode, viewNode -> child, 1);
     37     placeNode(viewNode,  rootX, rootY, rootWidth, rootHeight);
     38   } else if (focusedNode && focusedNode -> parent) {
     39     brotherNode(newNode, focusedNode, 1);
     40     placeNode(focusedNode,
     41         focusedNode -> parent -> x, focusedNode -> parent -> y,
     42         focusedNode -> parent -> width, focusedNode -> parent -> height);
     43   } else {
     44     //No focus node, fist element created
     45     fprintf(stderr, "FIRST NODE YO\n");
     46 
     47     parentNode(newNode, viewNode);
     48   }
     49 
     50   fprintf(stderr, "\n\nAFTA\n\n");
     51 
     52   addLookupEntry(newNode, &newNode -> window);
     53   fprintf(stderr, "added the lookup entry\n");
     54   focusNode(newNode, NULL, True, True);
     55   fprintf(stderr, "done with the map request\n");
     56 }
     57 
     58 void eDestroyNotify(XEvent *event) {
     59   fprintf(stderr, "DESTROY NOTIFY RECIEVED");
     60   fprintf(stderr, "\n\n Got here\n\n");
     61   Node *n = getNodeByWindow(&(event -> xdestroywindow.window));
     62   if (n == NULL) return;
     63 
     64   if (n == viewNode) { 
     65     viewNode = n -> parent; 
     66     fprintf(stderr, "Equals view node\n");
     67   }
     68   destroyNode(n);
     69   placeNode(viewNode, rootX, rootY, rootWidth, rootHeight);
     70 }
     71 
     72 void eConfigureRequest(XEvent *e) {
     73   /* Structed From DWM */
     74   XConfigureRequestEvent *ev = &e->xconfigurerequest;
     75   Node *configuredNode = getNodeByWindow(&ev->window);
     76 
     77   XWindowChanges wc;
     78   wc.x = configuredNode ? configuredNode -> x : ev -> x; 
     79   wc.y = configuredNode ? configuredNode -> y : ev -> y;
     80   wc.width = ev->width;       
     81   wc.height = ev->height;
     82   wc.border_width = ev->border_width;
     83   wc.sibling = ev->above;
     84   wc.stack_mode = ev->detail;
     85   XConfigureWindow(display, ev->window, ev->value_mask, &wc);
     86 
     87   if (configuredNode)
     88     placeNode(configuredNode, 
     89       configuredNode -> x, configuredNode -> y,
     90       configuredNode -> width, configuredNode -> height);
     91 
     92   XSync(display, False);
     93 }
     94 
     95 void eResizeRequest(XEvent *event) {
     96 
     97 }
     98 
     99 void eButtonPress(XEvent *event) {
    100   fprintf(stderr, "Button Event Window is %p\n", &(event -> xbutton.window));
    101 
    102   // Root Window
    103   if (event -> xbutton.window == None) return;
    104 
    105   // Click to Focus
    106   focusNode(getNodeByWindow(&(event -> xbutton.window)), event, True, True);
    107 }
    108 
    109 void handleXEvent(XEvent *event) {
    110   switch (event -> type) {
    111     case MapRequest:        eMapRequest(event);        break;
    112     case DestroyNotify:     eDestroyNotify(event);     break;
    113     case ConfigureRequest:  eConfigureRequest(event);  break;
    114     case ResizeRequest:     eResizeRequest(event);     break;
    115     case ButtonPress:       eButtonPress(event);       break;
    116     default:                                           break;
    117   }
    118 }