foo-wm

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

lookup.c (1479B)


      1 #include <X11/Xlib.h>
      2 #include <stdlib.h>
      3 #include <stdio.h>
      4 
      5 
      6 #include "foo-wm.h"
      7 #include "util.h"
      8 
      9 //Returns the client associated with given windowv
     10 Node * getNodeByWindow(Window * window) {
     11   Lookup *entry;
     12   for (entry = lookupTail; entry != NULL; entry = entry -> previous)
     13     if (((int) *window) == entry -> window) 
     14       return entry -> node;
     15 
     16   return NULL;
     17 }
     18 
     19 Node * getNodeById(int id) {
     20   Lookup *entry;
     21   for (entry = lookupTail; entry != NULL; entry = entry -> previous)
     22     if (id == (int) entry -> node -> window) 
     23       return entry -> node;
     24 
     25   return NULL;
     26 }
     27 
     28 void removeLookupEntry(Window * window) {
     29   Lookup *cut = NULL;
     30   Lookup *entry = NULL;
     31 
     32   //Removing last entry in list 
     33   if (lookupTail -> window == (int) *window) {
     34     entry = lookupTail -> previous;
     35     free(lookupTail);
     36     lookupTail = entry;
     37     return;
     38   }
     39 
     40   //Rmove any other entry in list
     41   for (entry = lookupTail; entry -> previous != NULL; entry = entry -> previous) {
     42     if ((int)*window == entry -> previous -> window) {
     43       cut = entry -> previous;
     44       entry -> previous = entry -> previous -> previous;
     45       free(cut);
     46       return;
     47     }
     48   }
     49 }
     50 
     51 void addLookupEntry( Node * node, Window * window) {
     52   //Add Client and window to lookup list
     53   Lookup *entry = malloc(sizeof(Lookup));
     54   entry -> node = node;
     55   entry -> window = (int) *window;
     56 
     57   //Set lookup (last item) as aour previous, and now were lookup (last)
     58   entry -> previous = lookupTail;
     59   lookupTail = entry;
     60 }