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 / ewin.c < prev    next >
C/C++ Source or Header  |  1997-11-16  |  7KB  |  218 lines

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