home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Enlightenment / enl_DR-0.10.tar.gz / enl_DR-0.10.tar / enl / wininfo.c < prev    next >
C/C++ Source or Header  |  1997-06-23  |  7KB  |  268 lines

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