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 / ewin.c < prev    next >
C/C++ Source or Header  |  1997-06-20  |  6KB  |  206 lines

  1. #include "enlightenment.h"
  2.  
  3. int CheckClientExists(EWin *ewin)
  4. {
  5.    int d;
  6.    Window wd;
  7.    
  8.    if (!XGetGeometry(disp,ewin->client_win,&wd,&d,&d,&d,&d,&d,&d))
  9.      {
  10.     fprintf(stderr,"How Rude! A client just pissed off without even saying\n");
  11.     fprintf(stderr,"Goodbye! How utterly rude! I'm offended now.\n");
  12.     global_killewin=ewin;
  13.     return 0;
  14.      }
  15.    return 1;
  16. }
  17.  
  18. EWin *InitEWin(Window client)
  19. {
  20.    EWin *ewin;
  21.    XSetWindowAttributes xatt;
  22.    XSizeHints *sizehints;
  23.    XWMHints *wmhints;
  24.    XClassHint *classhint;
  25.    int i,j;
  26.    Window wl[65];
  27.    
  28.    ewin=(EWin *)malloc(sizeof(EWin));/* malloc ram for the new ewin */
  29.    
  30.    ewin->border_l=cfg.border_l;
  31.    ewin->border_r=cfg.border_r;
  32.    ewin->border_t=cfg.border_t;
  33.    ewin->border_b=cfg.border_b;
  34.    ewin->state=NEW_WIN; /* set its state to UNMAPPED.... */
  35.    ewin->client_win=client; /* the actual client window */
  36.    ewin->group_win=0;
  37.    ewin->icon_win=0;
  38.    ewin->client_x=ewin->border_l; /* offset it into the frame */
  39.    ewin->client_y=ewin->border_t;
  40.    ewin->lastop=0;
  41.    ewin->top=0;
  42.    ewin->icon=NULL;
  43.    GetWinName(client,ewin->title); 
  44.    GetWinSize(client,ewin);
  45.    GetWinColors(client,ewin);
  46.    ewin->num_subwins=cfg.num_subwins; /* no subwins yet */
  47.    
  48.    xatt.save_under=True;
  49.    xatt.override_redirect=False;
  50.    xatt.background_pixel=0;
  51.    
  52.    XSetWindowBorderWidth(disp,client,0);
  53.    ewin->frame_win=XCreateWindow(disp,root,ewin->frame_x,ewin->frame_y,
  54.                  ewin->frame_width,ewin->frame_height,0,
  55.                  CopyFromParent,CopyFromParent,CopyFromParent,
  56.                  CWOverrideRedirect|CWSaveUnder|CWBackPixel,
  57.                  &xatt); 
  58.    if (fx.shadow.on)
  59.      {
  60.     int r,g,b;
  61.     
  62.     r=fx.shadow.r;
  63.     g=fx.shadow.g;
  64.     b=fx.shadow.b;
  65.     xatt.background_pixel=ImlibBestColorMatch(imd,&r,&g,&b);
  66.     ewin->fx.shadow_win=XCreateWindow(disp,root,ewin->frame_x+fx.shadow.x,
  67.                       ewin->frame_y+fx.shadow.y,
  68.                       ewin->frame_width,ewin->frame_height,0,
  69.                       CopyFromParent,CopyFromParent,CopyFromParent,
  70.                       CWOverrideRedirect|CWSaveUnder|CWBackPixel,
  71.                       &xatt);
  72.     XLowerWindow(disp,ewin->fx.shadow_win);
  73.      }
  74.    for (i=0;i<ewin->num_subwins;i++)
  75.      {
  76.     ewin->subwins[i]=XCreateSimpleWindow(disp,ewin->frame_win,0,0,10,10,0,0,0);
  77.     XSelectInput(disp,ewin->subwins[i],PointerMotionMask);
  78.     XMapWindow(disp,ewin->subwins[i]);
  79.     ewin->subwin_pm_clk[i]=0;
  80.     ewin->subwin_pm_sel[i]=0;
  81.     ewin->subwin_pm_uns[i]=0;
  82.     ewin->subwin_pm_clk_mask[i]=0;
  83.     ewin->subwin_pm_sel_mask[i]=0;
  84.     ewin->subwin_pm_uns_mask[i]=0;
  85.     ewin->subwin_state[i]=NORM;
  86.      }
  87.    ewin->mask_sel=0;
  88.    ewin->mask_uns=0;
  89.    XAddToSaveSet(disp,client);
  90.    XReparentWindow(disp,client,ewin->frame_win,
  91.            ewin->client_x,ewin->client_y);
  92.    j=0;
  93.    for (i=0;i<ewin->num_subwins;i++)
  94.      {
  95.     if (cfg.subwin_level[i]) wl[j++]=ewin->subwins[i];
  96.      }
  97.    wl[j++]=ewin->client_win;
  98.    for (i=0;i<ewin->num_subwins;i++)
  99.      {
  100.     if (!cfg.subwin_level[i]) wl[j++]=ewin->subwins[i];
  101.      }
  102.    XRestackWindows(disp,wl,j);
  103.    XSelectInput(disp,client,PropertyChangeMask);
  104.    XSelectInput(disp,ewin->frame_win,SubstructureNotifyMask|ButtonPressMask|
  105.         ButtonReleaseMask|EnterWindowMask|LeaveWindowMask|
  106.         ButtonMotionMask|FocusChangeMask|ColormapChangeMask|
  107.         PropertyChangeMask|SubstructureRedirectMask|
  108.         PointerMotionMask); 
  109.    ewin->changes=MOD_ALL;
  110.    ewin->state=0;
  111.    DrawSetupWindowBorder(ewin);
  112.    return ewin;
  113. }
  114.  
  115. void ModifyEWin(EWin *ewin, int nx, int ny, int nw, int nh)
  116. {
  117.    XWindowChanges xwc;
  118.    int mask;
  119.    XEvent ev;
  120.    
  121.    mask=0;
  122.    if (nx!=ewin->frame_x) mask|=CWX;
  123.    if (ny!=ewin->frame_y) mask|=CWY;
  124.    if (nw!=ewin->client_width) mask|=CWWidth;
  125.    if (nh!=ewin->client_height) mask|=CWHeight;
  126.    
  127.    ewin->frame_x=nx; /* record the new x & y in the ewin */
  128.    ewin->frame_y=ny;
  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.    if ((nw!=ewin->client_width)||(nh!=ewin->client_height))
  134.      {
  135.     ewin->client_width=nw; /* new width & height for client */
  136.     ewin->client_height=nh;
  137.     ewin->frame_width=nw+ewin->border_l+ewin->border_r; /* wew widtht & */
  138.     ewin->frame_height=nh+ewin->border_t+ewin->border_b; /* height for frame */
  139.     ewin->changes|=MOD_SIZE;
  140.      }
  141.    xwc.x=ewin->frame_x;
  142.    xwc.y=ewin->frame_y;
  143.    xwc.width=ewin->frame_width;
  144.    xwc.height=ewin->frame_height;
  145.    XConfigureWindow(disp,ewin->frame_win,mask,&xwc);
  146.    if (fx.shadow.on)
  147.      {
  148.     xwc.x=ewin->frame_x+fx.shadow.x;
  149.     xwc.y=ewin->frame_y+fx.shadow.y;
  150.     XConfigureWindow(disp,ewin->fx.shadow_win,mask,&xwc);
  151.     XLowerWindow(disp,ewin->fx.shadow_win);
  152.      }
  153.    xwc.x=ewin->client_x;
  154.    xwc.y=ewin->client_y;
  155.    xwc.width=ewin->client_width;
  156.    xwc.height=ewin->client_height;
  157.    XConfigureWindow(disp,ewin->client_win,mask,&xwc);
  158.    ev.type=ConfigureNotify;
  159.    ev.xconfigure.display=disp;
  160.    ev.xconfigure.event=ewin->client_win;
  161.    ev.xconfigure.window=ewin->client_win;
  162.    ev.xconfigure.x=ewin->frame_x+ewin->client_x;
  163.    ev.xconfigure.y=ewin->frame_y+ewin->client_y;
  164.    ev.xconfigure.width=ewin->client_width;
  165.    ev.xconfigure.height=ewin->client_height;
  166.    ev.xconfigure.border_width=0;
  167.    ev.xconfigure.above=ewin->frame_win;
  168.    ev.xconfigure.override_redirect=False;
  169.    XSendEvent(disp,ewin->client_win,False,StructureNotifyMask,&ev);
  170.    DrawWindowBorder(ewin);
  171.    CheckClientExists(ewin);
  172. }
  173.  
  174. void KillEWin(EWin *ewin)
  175. {
  176.    int i;
  177.    
  178.    XDestroySubwindows(disp,ewin->frame_win);
  179.    XDestroyWindow(disp,ewin->frame_win);
  180.    if (fx.shadow.on) XDestroyWindow(disp,ewin->fx.shadow_win);
  181.    for (i=0;i<ewin->num_subwins;i++)
  182.      {
  183.     if (ewin->subwin_pm_clk[i]) XFreePixmap(disp,ewin->subwin_pm_clk[i]);
  184.     if (ewin->subwin_pm_uns[i]) XFreePixmap(disp,ewin->subwin_pm_uns[i]);
  185.     if (ewin->subwin_pm_sel[i]) XFreePixmap(disp,ewin->subwin_pm_sel[i]);
  186.     if (ewin->subwin_pm_clk_mask[i]) XFreePixmap(disp,ewin->subwin_pm_clk_mask[i]);
  187.     if (ewin->subwin_pm_uns_mask[i]) XFreePixmap(disp,ewin->subwin_pm_uns_mask[i]);
  188.     if (ewin->subwin_pm_sel_mask[i]) XFreePixmap(disp,ewin->subwin_pm_sel_mask[i]);
  189.      }
  190.    if (ewin->mask_sel) XFreePixmap(disp,ewin->mask_sel);
  191.    if (ewin->mask_uns) XFreePixmap(disp,ewin->mask_uns);
  192.    if (ewin->icon) DelIcon(ewin->icon->win);
  193.    free(ewin);
  194. }
  195.  
  196. int GetEWinButtonID(EWin *ewin, Window win)
  197. {
  198.    int i;
  199.    
  200.    for (i=0;i<ewin->num_subwins;i++)
  201.      {
  202.     if (ewin->subwins[i]==win) return i;
  203.      }
  204.    return -1;
  205. }
  206.