home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Enlightenment / enl_BETA-0.13.src.tar.gz / enl_BETA-0.13.src.tar / enl-0.13 / wininfo.c < prev    next >
C/C++ Source or Header  |  1997-11-17  |  7KB  |  278 lines

  1. #include "enlightenment.h"
  2.  
  3. void GetWinName(Window win, char *s) {
  4.     XTextProperty xtp;
  5.  
  6.     if (XGetWMName(disp,win,&xtp))
  7.         strncpy(s,(const char *) xtp.value,256);
  8.     else 
  9.         strcpy(s,"No Title");
  10. }
  11.  
  12. void GetWinSize(Window win,EWin *ewin)
  13. {
  14.    Window www;
  15.    unsigned int nw,nh,dum,dumm;
  16.    int nx,ny;
  17.    XWMHints *hints1;
  18.    XSizeHints hints2;
  19.    long mask;
  20.    
  21.    XGetGeometry(disp,win,&www,&nx,&ny,&nw,&nh,&dum,&dum);
  22.    ewin->base_width=0;
  23.    ewin->base_height=0;
  24.    if (!XGetTransientForHint(disp,win,&ewin->group_win)) ewin->group_win=0;
  25.    hints1=XGetWMHints(disp,win);
  26.    if (hints1)
  27.      {
  28.     if (hints1->flags&StateHint)
  29.       {
  30. /*         if (hints1->initial_state&IconicState)*/
  31. /*           ewin->state|=ICONIFIED;*/
  32.       }
  33.     XFree (hints1);
  34.      }
  35.    if (XGetWMNormalHints(disp,win,&hints2,&mask))
  36.      {
  37.     if (hints2.flags&PResizeInc)
  38.       {
  39.          ewin->sizeinc_x=hints2.width_inc;
  40.          ewin->sizeinc_y=hints2.height_inc;
  41.          if (ewin->sizeinc_x<=0) ewin->sizeinc_x=1;
  42.          if (ewin->sizeinc_y<=0) ewin->sizeinc_y=1;
  43.       }
  44.     else
  45.       {
  46.          ewin->sizeinc_x=1;
  47.          ewin->sizeinc_y=1;
  48.       }
  49.     if (hints2.flags&PBaseSize)
  50.       {
  51.          if (hints2.flags&PMinSize)
  52.            {
  53.           ewin->min_width=hints2.min_width;
  54.           ewin->min_height=hints2.min_height;
  55.            }
  56.          else
  57.            {
  58.           ewin->min_width=hints2.base_width;
  59.           ewin->min_height=hints2.base_height;
  60.            }
  61.          ewin->base_width=hints2.base_width;
  62.          ewin->base_height=hints2.base_height;
  63.       }
  64.     else if (hints2.flags&PMinSize)
  65.       {
  66.          ewin->min_width=hints2.min_width;
  67.          ewin->min_height=hints2.min_height;
  68.       }
  69.     else
  70.       {
  71.          ewin->min_width=1;
  72.          ewin->min_height=1;
  73.       }
  74.     if (hints2.flags&PMaxSize)
  75.       {
  76.          ewin->max_width=hints2.max_width;
  77.          ewin->max_height=hints2.max_height;
  78.       }
  79.     else
  80.       {
  81.          ewin->max_width=MAX_WIDTH;
  82.          ewin->max_height=MAX_HEIGHT;
  83.       }
  84.     if (ewin->min_height<=0) ewin->min_height=1;
  85.     if (ewin->min_width<=0) ewin->min_width=1;
  86.     if (ewin->max_width<ewin->min_width) 
  87.       ewin->max_width=ewin->min_width;
  88.     if (ewin->max_height<ewin->min_height) 
  89.       ewin->max_height=ewin->min_height;
  90.     if (nw>ewin->max_width) nw=ewin->max_width;
  91.     if (nh>ewin->max_height) nh=ewin->max_height;
  92.     if (nw<ewin->min_width) nw=ewin->min_width;
  93.     if (nh<ewin->min_height) nh=ewin->min_height;
  94.     ewin->frame_width=nw+ewin->border_l+ewin->border_r; /* width & */
  95.     ewin->frame_height=nh+ewin->border_t+ewin->border_b; /* height for frame */
  96.     if (hints2.flags&USSize)
  97.       {
  98.          /*ewin->client_width=hints2.width;*/
  99.          /*ewin->client_height=hints2.height;*/
  100.       }
  101.     else
  102.       {
  103.       }
  104.     if (hints2.flags&PPosition)
  105.       {
  106.          /*nx=hints2.x;*/
  107.          /*ny=hints2.y;*/
  108.       }
  109.     else if (hints2.flags&USPosition)
  110.       {
  111.          /*nx=hints2.x;*/
  112.          /*ny=hints2.y;*/
  113.       }
  114.     else
  115.       {
  116.          dum=DisplayWidth(disp,screen)-ewin->frame_width;
  117.          dumm=DisplayHeight(disp,screen)-ewin->frame_height;
  118.          if (dum>0) nx=rand()%dum;
  119.          else nx=0;
  120.          if (dumm>0) ny=rand()%dumm;
  121.          else ny=0;
  122.       }
  123.      }
  124.    else
  125.      {
  126.     ewin->sizeinc_x=1;
  127.     ewin->sizeinc_y=1;
  128.     ewin->min_width=1;
  129.     ewin->min_height=1;
  130.     ewin->max_width=MAX_WIDTH;
  131.     ewin->max_height=MAX_HEIGHT;
  132.     if (nw>ewin->max_width) nw=ewin->max_width;
  133.     if (nh>ewin->max_height) nh=ewin->max_height;
  134.     if (nw<ewin->min_width) nw=ewin->min_width;
  135.     if (nh<ewin->min_height) nh=ewin->min_height;
  136.     ewin->frame_width=nw+ewin->border_l+ewin->border_r; /* width & */
  137.     ewin->frame_height=nh+ewin->border_t+ewin->border_b; /* height for frame */
  138.     dum=DisplayWidth(disp,screen)-ewin->frame_width;
  139.     dumm=DisplayHeight(disp,screen)-ewin->frame_height;
  140.     if (dum>0) nx=rand()%dum;
  141.     else nx=0;
  142.     if (dumm>0) ny=rand()%dumm;
  143.     else ny=0;
  144.      }
  145.    ewin->client_width=nw; /* record the client info for widht & height */
  146.    ewin->client_height=nh;
  147.    XResizeWindow(disp,ewin->client_win,ewin->client_width,ewin->client_height);
  148.    /* dont allow windows to move themselves off the screen under application control */
  149.    if (ewin->state&NEW_WIN)
  150.      {
  151.     ewin->frame_x=nx; /* X & Y locations desired by client */
  152.     ewin->frame_y=ny;
  153.     ewin->state&=~NEW_WIN;
  154.      }
  155. }
  156.  
  157. void GetWinColors(Window win,EWin *ewin)
  158. {
  159.    XWindowAttributes xwa;
  160.    if (XGetWindowAttributes(disp,win,&xwa))
  161.      {
  162.     if (xwa.colormap) ewin->colormap=xwa.colormap;
  163.     else ewin->colormap=0;
  164.      }
  165.    else ewin->colormap=0;
  166. }
  167.  
  168. void UnmapClients(int all)
  169. {
  170.    Window rt;
  171.    Window par;
  172.    Window *list;
  173.    unsigned int num;
  174.    int i;
  175.    XWindowAttributes attr;
  176.    
  177.    if (debug_mode) return;
  178.    XQueryTree(disp,root,&rt,&par,&list,&num);
  179.    Wlist=NULL;  
  180.    
  181.    if (list)
  182.      {
  183.     Wlist=malloc(sizeof(struct winlist)*(num+1));
  184.     for (i=0;i<num;i++)
  185.       {
  186.          XGetWindowAttributes(disp, list[i], &attr);
  187.          Wlist[i].win=list[i];
  188.          if(attr.override_redirect)
  189.            {
  190.           if(attr.map_state==IsUnmapped)
  191.             Wlist[i].state = REDIR;
  192.           else
  193.             Wlist[i].state = REDIRM;
  194.            }
  195.          else if(attr.map_state==IsUnmapped)
  196.            Wlist[i].state = UNMAP;
  197.          else
  198.            Wlist[i].state = MAP;
  199.          if((!attr.override_redirect&&attr.map_state!=IsUnmapped)||all==1)
  200.            XUnmapWindow(disp,list[i]);
  201.       }
  202.     Wlist[num].state=NOEXIST;
  203.     Wlist[num].win=0;
  204.     XFlush(disp);
  205.     free(list);
  206.      }
  207. }
  208.  
  209. void MapClients(listhead *l)
  210. {
  211.    Window rt;
  212.    Window par;
  213.    Window *list;
  214.    unsigned int num;
  215.    int i,j;
  216.    EWin *ewin;
  217.    XWindowAttributes attr;
  218.  
  219.    XQueryTree(disp,root,&rt,&par,&list,&num);
  220.    if (list)
  221.      {
  222.     for (i=0;i<num;i++)
  223.       {
  224.          XGetWindowAttributes(disp, list[i], &attr);
  225.          if (GetButtonWinID(list[i])) XMapWindow(disp,list[i]);
  226.          else if (list[i]==icfg.bg_win) XMapWindow(disp,list[i]);
  227.          else if (list[i]==icfg.left_win) XMapWindow(disp,list[i]);
  228.          else if (list[i]==icfg.right_win) XMapWindow(disp,list[i]);
  229.          else if (GetMenuWin(list[i])) ;
  230.          else if (!GetButtonWinID(list[i]))
  231.            {
  232.           if (Wlist)
  233.             {
  234.                for(j=0;Wlist[j].state!=NOEXIST;j++)
  235.              {
  236.                 if (list[i]==Wlist[j].win)
  237.                   {
  238.                  switch(Wlist[j].state)
  239.                    {
  240.                     case MAP:
  241.                       ewin=InitEWin(Wlist[i].win); 
  242.                       ListAdd(l,ewin);
  243.                       XRaiseWindow(disp,ewin->frame_win);
  244.                       XMapSubwindows(disp,ewin->frame_win);
  245.                       if (!(ewin->state&ICONIFIED)) 
  246.                     {
  247.                        XMapWindow(disp,ewin->frame_win);
  248.                        if (fx.shadow.on) XMapWindow(disp,ewin->fx.shadow_win);
  249.                     }
  250.                       ewin->state|=MAPPED;
  251.                       if (restart) ConformEwinToState(ewin);
  252.                       break;
  253.                     case UNMAP:
  254. /*                      ewin=InitEWin(Wlist[i].win); 
  255.                       ListAdd(l,ewin);
  256.                       ewin->state|=UNMAPPED;
  257.                       XUnmapWindow(disp, ewin->frame_win);
  258.                       if (fx.shadow.on) XUnmapWindow(disp,ewin->fx.shadow_win);
  259. */
  260.                       break;
  261.                     case REDIRM:
  262.                       XMapWindow(disp, list[i]);
  263.                       break;
  264.                     default:
  265.                       break;
  266.                    }
  267.                   }
  268.              }
  269.             }
  270.            }
  271.       }
  272.     XFlush(disp);
  273.     free(list);
  274.     if (Wlist) free(Wlist);
  275.      }
  276. }
  277.  
  278.