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 / actions.c next >
C/C++ Source or Header  |  1997-06-24  |  27KB  |  1,115 lines

  1. #include "enlightenment.h"
  2.  
  3. void DoWindowButton(EWin *ewin, Window win, int btn, int mod, int wbtn)
  4. {
  5.    int i,j;
  6.    
  7.    /* if it wasnt a left, middle or right mouse button... ignore it */
  8.    if ((btn<1)||(btn>3)) return;
  9.    /* if the subwindow clicked is a decoration subwindow.. ignore the click */
  10.    if (cfg.subwin_type[wbtn]==0) return;
  11.    /* flag the button as clicked ... */
  12.    ewin->subwin_state[wbtn]=CLICKED;
  13.    /* redraw the button */
  14.    DrawButton(ewin,wbtn);
  15.    /* set the event mode windowbutton pressed to this one */
  16.    evmd.wbtn=wbtn;
  17.    if (cfg.subwin_action[wbtn][btn-1][mod].id==1)
  18.      {
  19.     Do_RaiseWin(ewin);
  20.     Do_MoveWin(ewin, win);
  21.     return;
  22.      }
  23.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==2)
  24.      {
  25.     Do_RaiseWin(ewin);
  26.     Do_ResizeWin(ewin, win);
  27.     return;
  28.      }
  29.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==3)
  30.      {
  31.     Do_IconifyWin(ewin);    
  32.     evmd.ewin=ewin;
  33.     evmd.wbtn=wbtn;
  34.     evmd.mode=MODE_NORMAL;
  35.     return;
  36.      }
  37.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==4)
  38.      {
  39.     Do_KillWin(ewin,0);
  40.     evmd.ewin=ewin;
  41.     evmd.wbtn=wbtn;
  42.     evmd.mode=MODE_NORMAL;
  43.     return;
  44.      }
  45.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==5)
  46.      {
  47.     Do_RaiseWin(ewin);
  48.     evmd.ewin=ewin;
  49.     evmd.wbtn=wbtn;
  50.     evmd.mode=MODE_NORMAL;
  51.     return;
  52.      }
  53.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==6)
  54.      {
  55.     Do_LowerWin(ewin);
  56.     evmd.ewin=ewin;
  57.     evmd.wbtn=wbtn;
  58.     evmd.mode=MODE_NORMAL;
  59.     return;
  60.      }
  61.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==7)
  62.      {
  63.     Do_RaiseLowerWin(ewin);
  64.     evmd.ewin=ewin;
  65.     evmd.wbtn=wbtn;
  66.     evmd.mode=MODE_NORMAL;
  67.     return;
  68.      }
  69.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==8)
  70.      {
  71.     Do_RaiseWin(ewin);
  72.     Do_MaxHeightWin(ewin);
  73.     evmd.ewin=ewin;
  74.     evmd.wbtn=wbtn;
  75.     evmd.mode=MODE_NORMAL;
  76.     return;
  77.      }
  78.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==9)
  79.      {
  80.     Do_RaiseWin(ewin);
  81.     Do_MaxWidthWin(ewin);
  82.     evmd.ewin=ewin;
  83.     evmd.wbtn=wbtn;
  84.     evmd.mode=MODE_NORMAL;
  85.     return;
  86.      }
  87.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==10)
  88.      {
  89.     Do_RaiseWin(ewin);
  90.     Do_MaxSizeWin(ewin);
  91.     evmd.ewin=ewin;
  92.     evmd.wbtn=wbtn;
  93.     evmd.mode=MODE_NORMAL;
  94.     return;
  95.      }
  96.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==11)
  97.      {
  98.     Do_Configure();
  99.     evmd.ewin=ewin;
  100.     evmd.wbtn=wbtn;
  101.     evmd.mode=MODE_NORMAL;
  102.     return;
  103.      }
  104.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==12)
  105.      {
  106.     Do_MenuWin(ewin);
  107.     evmd.ewin=ewin;
  108.     evmd.wbtn=wbtn;
  109.     evmd.mode=MODE_NORMAL;
  110.     return;
  111.      }
  112.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==13)
  113.      {
  114.     Do_Exec(cfg.subwin_action[wbtn][btn-1][mod].params);
  115.     evmd.ewin=ewin;
  116.     evmd.wbtn=wbtn;
  117.     evmd.mode=MODE_NORMAL;
  118.     return;
  119.      }
  120.    else if (cfg.subwin_action[wbtn][btn-1][mod].id==15)
  121.      {
  122.     Do_KillWin(ewin,1);
  123.     evmd.ewin=ewin;
  124.     evmd.wbtn=wbtn;
  125.     evmd.mode=MODE_NORMAL;
  126.     return;
  127.      }
  128.    else
  129.      {
  130.     evmd.ewin=ewin;
  131.                                                                                                                            evmd.wbtn=wbtn;
  132.     evmd.mode=MODE_NORMAL;
  133.     return;
  134.      }
  135.    return;
  136. }
  137.  
  138. void DoBaseMenu(Menu *m, int x, int y)
  139. {
  140.    int px,py;
  141.    
  142.    if (m) 
  143.      {
  144.     px=x-m->popup_x;
  145.     py=y-m->popup_y;
  146.     if (px<0) px=0;
  147.     if (py<0) py=0;
  148.     if (px+m->width>DisplayWidth(disp,screen)) 
  149.       px=DisplayWidth(disp,screen)-m->width-1;
  150.     if (py+m->height>DisplayHeight(disp,screen)) 
  151.       py=DisplayHeight(disp,screen)-m->height-1;
  152.     XMoveWindow(disp,m->win,px,py);
  153.     ShowMenu(m);
  154.     AddActiveMenuToList(m);
  155.      }
  156. }
  157.  
  158. void DoRootMenu(int btn, int mod, int x, int y)
  159. {
  160.    Menu *m;
  161.    char s[256];
  162.    
  163.    sprintf(s,"root%i",btn);
  164.    strcpy(evmd.mname,s);
  165.    m=FindMenu(s);
  166.    DoBaseMenu(m,x,y);
  167. }
  168.  
  169. void Do_MoveWin(EWin *ewin, Window win)
  170. {
  171.    XEvent ev;
  172.    int x,y;
  173.    int sx,sy,d;
  174.    Window w1,w2;
  175.    
  176.    if(evmd.mode!=MODE_NORMAL)
  177.      return;
  178.    evmd.ewin=ewin;
  179.    if (cfg.move_mode==2)
  180.      {
  181.     evmd.mode=MODE_MOVE;
  182.     Draw_Cursor(ewin, ewin->frame_x, ewin->frame_y, '+', 1);
  183.     XGrabPointer(disp, win, True, ButtonMotionMask|PointerMotionMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
  184.     return;
  185.      }
  186.    else
  187.      {
  188.     MoveLoop(ewin, win);
  189.      }
  190. }
  191.  
  192. void Do_ResizeWin(EWin *ewin, Window win)
  193. {
  194.    XEvent ev;
  195.    int x,y;
  196.    int sx,sy,d;
  197.    Window w1,w2;
  198.    int wx,wy;
  199.    int mode;
  200.    int x1,y1,x2,y2;
  201.    
  202. /*   XQueryPointer(disp,root,&w1,&w2,&sx,&sy,&x,&y,&d);*/
  203. /*   evmd.px=sx;*/
  204. /*   evmd.py=sy;*/
  205.    if(evmd.mode!=MODE_NORMAL)
  206.        return;
  207.    x1=ewin->frame_x;
  208.    y1=ewin->frame_y;
  209.    x2=ewin->client_width;
  210.    y2=ewin->client_height;
  211.    wx=evmd.px-x1;
  212.    wy=evmd.py-y1;
  213.    if ((wx<ewin->frame_width/2)&&(wy<ewin->frame_height/2)) mode=0;
  214.    if ((wx>=ewin->frame_width/2)&&(wy<ewin->frame_height/2)) mode=1;
  215.    if ((wx<ewin->frame_width/2)&&(wy>=ewin->frame_height/2)) mode=2;
  216.    if ((wx>=ewin->frame_width/2)&&(wy>=ewin->frame_height/2)) mode=3;
  217.    evmd.x1=x1;
  218.    evmd.x2=x2;
  219.    evmd.y1=y1;
  220.    evmd.y2=y2;
  221.    evmd.resize_mode=mode;
  222.    evmd.ewin=ewin;
  223.    if (cfg.resize_mode==2)
  224.      {
  225.     evmd.mode=MODE_RESIZE;
  226.     Draw_Cursor(ewin, (ewin->client_width-ewin->base_width)/ewin->sizeinc_x, (ewin->client_height-ewin->base_height)/ewin->sizeinc_y, 'x', 1);
  227.     XGrabPointer(disp, win, True, ButtonMotionMask|PointerMotionMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
  228.     return;
  229.      }
  230.    else
  231.      {
  232.     ResizeLoop(ewin, win);
  233.      }
  234. }
  235.  
  236. void Do_IconifyWin(EWin *ewin)
  237. {
  238.    struct itimerval tv1,tv2;
  239.    struct sigaction sa;
  240.    
  241.    /* concurrency issues! wait for previous iconify requests to */
  242.    /* be completeed by checking every 10th of a second to see if they */
  243.    /* finished yet */
  244.    while (newicon.ewin) usleep(100000);
  245.    tv1.it_value.tv_sec=0;
  246.    tv1.it_value.tv_usec=icfg.snapshot_time*1000;
  247.    tv2.it_value.tv_sec=0;
  248.    tv2.it_value.tv_usec=icfg.snapshot_time*1000;
  249.    tv1.it_interval.tv_sec=0;
  250.    tv1.it_interval.tv_usec=0;
  251.    tv2.it_interval.tv_sec=0;
  252.    tv2.it_interval.tv_usec=0;
  253.    newicon.ewin=ewin;
  254.    newicon.win=ewin->client_win;
  255.    XRaiseWindow(disp,ewin->frame_win);
  256.    setitimer(ITIMER_REAL,&tv1,&tv2);
  257.    sa.sa_handler = Finish_Iconify;
  258.    sa.sa_flags = 0;
  259.    sigemptyset (&sa.sa_mask);
  260.    sigaction(SIGALRM, &sa, (struct sigaction *)0);
  261. }
  262.  
  263. void Do_KillWin(EWin *ewin, int nasty_kill)
  264. {
  265.    XClientMessageEvent xev;
  266.    Atom atm[2];
  267.    Window dummyw;
  268.    int dummy;
  269.    int wmdel;
  270.    int num;
  271.    Atom *prot;
  272.    Atom dummya;
  273.    int i;
  274.    unsigned long dummyl,numl;
  275.    
  276.    prot=NULL;
  277.    wmdel=0;
  278.    if (!(ewin->state&ICONIFIED))
  279.      {
  280.     newicon.kill=nasty_kill+1;
  281.     Do_IconifyWin(ewin);
  282.     return;
  283.      }
  284.    atm[0]=XInternAtom(disp,"WM_DELETE_WINDOW",False);
  285.    atm[1]=XInternAtom(disp,"WM_PROTOCOLS",False);
  286.    /* work out if client wants to have the wm ask it to quit */
  287.    if (!XGetWMProtocols (disp,ewin->client_win,&prot, &num))
  288.      {
  289.     /* have to work it out the hard way.. nasty client */
  290.     XGetWindowProperty(disp,ewin->client_win, atm[1],0,10,False,atm[1],
  291.                &dummya,&dummy,&numl,&dummyl,
  292.                (unsigned char **)&prot);
  293.     num=(int)numl;
  294.      }
  295.    /* check if it has a "delet me" flag set */
  296.    if (prot)
  297.      {
  298.     for (i=0;i<num;i++)
  299.       {
  300.          if (prot[i]==atm[0]) wmdel=1;
  301.       }
  302.      }
  303.    if (prot) XFree(prot);
  304.    if (wmdel)
  305.      {
  306.     /* delete */
  307.     xev.type=ClientMessage;
  308.     xev.window=ewin->client_win;
  309.     xev.message_type=atm[1];
  310.     xev.format=32;
  311.     xev.data.l[0]=atm[0];
  312.     xev.data.l[1]=CurrentTime;
  313.     XSendEvent(disp,ewin->client_win,False,0,(XEvent *)&xev);
  314.      }
  315.    else
  316.      {
  317.     /* kill */
  318.     XKillClient(disp,(XID)ewin->client_win);
  319.      }
  320.    if (nasty_kill)
  321.      {
  322.     /* kill */
  323.     XKillClient(disp,(XID)ewin->client_win);
  324.      }
  325.    XSync(disp,False);
  326. }
  327.  
  328. void Do_RaiseWin(EWin *ewin)
  329. {
  330.    Window *wl;
  331.    int nc,nb;
  332.    int i,j;
  333.    struct blist *bptr;
  334.    struct list *ptr;
  335.    
  336.    if (ewin->top) return;
  337.    ToFront(ewin);
  338.    j=0;
  339.    nc=global_l->num;
  340.    nb=0;
  341.    bptr=bl.first;
  342.    while (bptr)
  343.      {
  344.     nb++;
  345.     bptr=bptr->next;
  346.      }
  347.    wl=malloc(sizeof(Window)*(nc+nb+3));
  348.    bptr=bl.first;
  349.    while (bptr)
  350.      {
  351.     if (bptr->bwin->above) wl[j++]=bptr->bwin->win;
  352.     bptr=bptr->next;
  353.      }
  354.    if (icfg.level)
  355.      {
  356.     wl[j++]=icfg.left_win;
  357.     wl[j++]=icfg.right_win;
  358.     wl[j++]=icfg.bg_win;
  359.      }
  360.    ptr=global_l->first;
  361.    while (ptr)
  362.      {
  363.     wl[j++]=ptr->win->frame_win;
  364.     ptr=ptr->next;
  365.      }
  366.    bptr=bl.first;
  367.    while (bptr)
  368.      {
  369.     if (!bptr->bwin->above) wl[j++]=bptr->bwin->win;
  370.     bptr=bptr->next;
  371.      }
  372.    if (!icfg.level)
  373.      {
  374.     wl[j++]=icfg.left_win;
  375.     wl[j++]=icfg.right_win;
  376.     wl[j++]=icfg.bg_win;
  377.      }
  378.    XRestackWindows(disp,wl,nc+nb+3);
  379.    free(wl);
  380. }
  381.  
  382. void Do_LowerWin(EWin *ewin)
  383. {
  384.    Window *wl;
  385.    int nc,nb;
  386.    int i,j;
  387.    struct blist *bptr;
  388.    struct list *ptr;
  389.    
  390.    ToBack(ewin);
  391.    j=0;
  392.    nc=global_l->num;
  393.    nb=0;
  394.    bptr=bl.first;
  395.    while (bptr)
  396.      {
  397.     nb++;
  398.     bptr=bptr->next;
  399.      }
  400.    wl=malloc(sizeof(Window)*(nc+nb+3));
  401.    bptr=bl.first;
  402.    while (bptr)
  403.      {
  404.     if (bptr->bwin->above) wl[j++]=bptr->bwin->win;
  405.     bptr=bptr->next;
  406.      }
  407.    if (icfg.level)
  408.      {
  409.     wl[j++]=icfg.left_win;
  410.     wl[j++]=icfg.right_win;
  411.     wl[j++]=icfg.bg_win;
  412.      }
  413.    ptr=global_l->first;
  414.    while (ptr)
  415.      {
  416.     wl[j++]=ptr->win->frame_win;
  417.     ptr=ptr->next;
  418.      }
  419.    bptr=bl.first;
  420.    while (bptr)
  421.      {
  422.     if (!bptr->bwin->above) wl[j++]=bptr->bwin->win;
  423.     bptr=bptr->next;
  424.      }
  425.    if (!icfg.level)
  426.      {
  427.     wl[j++]=icfg.left_win;
  428.     wl[j++]=icfg.right_win;
  429.     wl[j++]=icfg.bg_win;
  430.      }
  431.    XRestackWindows(disp,wl,nc+nb+3);
  432.    free(wl);
  433. }
  434.  
  435. void Do_RaiseLowerWin(EWin *ewin)
  436. {
  437.    if (ewin->top) Do_LowerWin(ewin);
  438.    else Do_RaiseWin(ewin);
  439. }
  440.  
  441. void Do_MaxHeightWin(EWin *ewin)
  442. {
  443.    int h;
  444.    int y;
  445.    
  446.    if (ewin->lastop==OP_MAXHEIGHT)
  447.      {
  448.     h=ewin->prev_client_height;
  449.     y=ewin->prev_frame_y;
  450.     ewin->prev_client_height=ewin->client_height;
  451.     ewin->prev_client_width=ewin->client_width;
  452.     ewin->prev_frame_x=ewin->frame_x;
  453.     ewin->prev_frame_y=ewin->frame_y;
  454.      }
  455.    else
  456.      {
  457.     ewin->prev_client_height=ewin->client_height;
  458.     ewin->prev_client_width=ewin->client_width;
  459.     ewin->prev_frame_x=ewin->frame_x;
  460.     ewin->prev_frame_y=ewin->frame_y;
  461.     h=DisplayHeight(disp,screen);
  462.     h-=ewin->border_t;
  463.     h-=ewin->border_b;
  464.     while (((h-ewin->base_height)%ewin->sizeinc_y)>0) h--;
  465.     while (((h-ewin->base_height)%ewin->sizeinc_y)<0) h++;
  466.     y=0;
  467.      }
  468.    ModifyEWin(ewin,ewin->frame_x,y,ewin->client_width,h);
  469.    ewin->lastop=OP_MAXHEIGHT;
  470. }
  471.  
  472. void Do_MaxWidthWin(EWin *ewin)
  473. {
  474.    int w;
  475.    int x;
  476.    
  477.    if (ewin->lastop==OP_MAXWIDTH)
  478.      {
  479.     w=ewin->prev_client_width;
  480.     x=ewin->prev_frame_x;
  481.     ewin->prev_client_height=ewin->client_height;
  482.     ewin->prev_client_width=ewin->client_width;
  483.     ewin->prev_frame_x=ewin->frame_x;
  484.     ewin->prev_frame_y=ewin->frame_y;
  485.      }
  486.    else
  487.      {
  488.     ewin->prev_client_height=ewin->client_height;
  489.     ewin->prev_client_width=ewin->client_width;
  490.     ewin->prev_frame_x=ewin->frame_x;
  491.     ewin->prev_frame_y=ewin->frame_y;
  492.     w=DisplayWidth(disp,screen);
  493.     w-=ewin->border_l;
  494.     w-=ewin->border_r;
  495.     while (((w-ewin->base_width)%ewin->sizeinc_x)>0) w--;
  496.     while (((w-ewin->base_width)%ewin->sizeinc_x)<0) w++;
  497.     x=0;
  498.      }
  499.    ModifyEWin(ewin,x,ewin->frame_y,w,ewin->client_height);
  500.    ewin->lastop=OP_MAXWIDTH;
  501. }
  502.  
  503. void Do_MaxSizeWin(EWin *ewin)
  504. {
  505.    int h;
  506.    int y;
  507.    int w;
  508.    int x;
  509.    
  510.    if (ewin->lastop==OP_MAXSIZE)
  511.      {
  512.     h=ewin->prev_client_height;
  513.     y=ewin->prev_frame_y;
  514.     w=ewin->prev_client_width;
  515.     x=ewin->prev_frame_x;
  516.     ewin->prev_client_height=ewin->client_height;
  517.     ewin->prev_client_width=ewin->client_width;
  518.     ewin->prev_frame_x=ewin->frame_x;
  519.     ewin->prev_frame_y=ewin->frame_y;
  520.      }
  521.    else
  522.      {
  523.     ewin->prev_client_height=ewin->client_height;
  524.     ewin->prev_client_width=ewin->client_width;
  525.     ewin->prev_frame_x=ewin->frame_x;
  526.     ewin->prev_frame_y=ewin->frame_y;
  527.     h=DisplayHeight(disp,screen);
  528.     h-=ewin->border_t;
  529.     h-=ewin->border_b;
  530.     while (((h-ewin->base_height)%ewin->sizeinc_y)>0) h--;
  531.     while (((h-ewin->base_height)%ewin->sizeinc_y)<0) h++;
  532.     y=0;
  533.     w=DisplayWidth(disp,screen);
  534.     w-=ewin->border_l;
  535.     w-=ewin->border_r;
  536.     while (((w-ewin->base_width)%ewin->sizeinc_x)>0) w--;
  537.     while (((w-ewin->base_width)%ewin->sizeinc_x)<0) w++;
  538.     x=0;
  539.      }
  540.    ModifyEWin(ewin,x,y,w,h);
  541.    ewin->lastop=OP_MAXSIZE;
  542. }
  543.  
  544. void Do_Configure()
  545. {
  546. }
  547.  
  548. void Do_MenuWin(EWin *ewin)
  549. {
  550. }
  551.  
  552. void Do_Exec(char *line)
  553. {
  554.    char *args[2048];
  555.    int i,j,k;
  556.    char arg[1024];
  557.    int inquote=0;
  558.    int q1,q2;
  559.    
  560.    if (fork()) return;
  561.    setsid();
  562.    if (execl("/bin/sh","/bin/sh","-c",line,NULL)==-1) exit(100);
  563.    exit(0);
  564. }
  565.  
  566. void Do_Exit()
  567. {
  568.    char s[1024];
  569.    
  570.    if ((Theme_Path[0])&&(!nodel))
  571.      {
  572.     sprintf(s,"rm -rf %s",Theme_Path);
  573.     system(s); 
  574.      }
  575.    XSetInputFocus(disp, PointerRoot, RevertToPointerRoot, CurrentTime);
  576.    XSelectInput(disp, root, 0);
  577.    UnmapClients(0);
  578.    exit(0);
  579. }
  580.  
  581. void Do_Restart()
  582. {
  583.    char s[2048];
  584.    
  585.    if ((Theme_Path[0])&&(!nodel))
  586.      {
  587.     sprintf(s,"rm -rf %s",Theme_Path);
  588.     system(s); 
  589.      }
  590.    UnmapClients(0);
  591.    XCloseDisplay(disp);
  592.    sleep(1);
  593.    if (Theme_Name[0]!=0)
  594.      {
  595.     sprintf(s,"%s -theme %s",argv1,Theme_Name);
  596.     execl("/bin/sh","/bin/sh","-c",s,NULL);
  597.      }
  598.    else
  599.      execl("/bin/sh","/bin/sh","-c",argv1,NULL);
  600.    exit(100);
  601. }
  602.  
  603. void Do_Restart_Theme(char *file)
  604. {
  605.    char s[1024];
  606.    if ((Theme_Path[0])&&(!nodel))
  607.      {
  608.     sprintf(s,"rm -rf %s",Theme_Path);
  609.     system(s); 
  610.      }
  611.    sprintf(s,"%s -theme %s",argv1,file);
  612.    UnmapClients(0);
  613.    XCloseDisplay(disp);
  614.    sleep(1);
  615.    execl("/bin/sh","/bin/sh","-c",s,NULL);
  616.    exit(100);
  617. }
  618.  
  619. void DoButton(BWin *bwin, int btn, int mod)
  620. {
  621.    XWindowAttributes xwa;
  622.    
  623.    /* if it wasnt a left, middle or right mouse button... ignore it */
  624.    if ((btn<1)||(btn>3)) return;
  625.    ButtonDraw(bwin);
  626.    if (bwin->action[btn-1][mod].id==12)
  627.      {
  628.     Menu *m;
  629.     
  630.         evmd.mode=MODE_MENU;
  631.     tmp_menu=NULL;
  632.     m=FindMenu(bwin->action[btn-1][mod].params);
  633.     if (m)
  634.       {
  635.          XGetWindowAttributes(disp,bwin->win,&xwa);
  636.          DoBaseMenu(m,xwa.x+(xwa.width/2),xwa.y+(xwa.height/2));
  637.       }
  638.     return;
  639.      }
  640.    if (bwin->action[btn-1][mod].id==13)
  641.      {
  642.     Do_Exec(bwin->action[btn-1][mod].params);
  643.     return;
  644.      }
  645.    else if (bwin->action[btn-1][mod].id==14)
  646.      {
  647.     Do_Exit();
  648.     return;
  649.      }
  650.    else if (bwin->action[btn-1][mod].id==16)
  651.      {
  652.     Do_Restart();
  653.     return;
  654.      }
  655.    else if (bwin->action[btn-1][mod].id==17)
  656.      {
  657.     Do_Restart_Theme(bwin->action[btn-1][mod].params);
  658.     return;
  659.      }
  660.    else if (bwin->action[btn-1][mod].id==18)
  661.      {
  662.     int n1,n2;
  663.     char s[1024];
  664.     
  665.     sscanf(bwin->action[btn-1][mod].params,"%i %i %s",&n1,&n2,s);
  666.     strcpy(cfg.root_pname,s);
  667.     cfg.root_width=n1;
  668.     cfg.root_height=n2;
  669.     SetRoot();
  670.     return;
  671.      }
  672.    else
  673.      {
  674.     btmd.bwin=bwin;
  675.     return;
  676.      }
  677.    return;
  678. }
  679.  
  680. void DoMenu(Menu *m, int num)
  681. {
  682.    if (!m) return;
  683.    if (m->items[num]->action.id==13)
  684.      {
  685.     Do_Exec(m->items[num]->action.params);
  686.     return;
  687.      }
  688.    else if (m->items[num]->action.id==14)
  689.      {
  690.     Do_Exit();
  691.     return;
  692.      }
  693.    else if (m->items[num]->action.id==16)
  694.      {
  695.     Do_Restart();
  696.     return;
  697.      }
  698.    else if (m->items[num]->action.id==17)
  699.      {
  700.     Do_Restart_Theme(m->items[num]->action.params);
  701.     return;
  702.      }
  703.    else if (m->items[num]->action.id==18)
  704.      {
  705.     int n1,n2;
  706.     char s[1024];
  707.     
  708.     sscanf(m->items[num]->action.params,"%i %i %s",&n1,&n2,s);
  709.     strcpy(cfg.root_pname,s);
  710.     cfg.root_width=n1;
  711.     cfg.root_height=n2;
  712.     SetRoot();
  713.     return;
  714.      }
  715.    return;
  716. }
  717.  
  718. void DoIcon(Icon *icon, int btn, int mod)
  719. {
  720.    int i,j;
  721.    
  722.    /* if it wasnt a left, middle or right mouse button... ignore it */
  723.    if ((btn<1)||(btn>3)) return;
  724.    if (icfg.action[btn-1][mod].id==3)
  725.      {
  726.     XMapWindow(disp,icon->ewin->frame_win);
  727.     if (fx.shadow.on) XMapWindow(disp,icon->ewin->fx.shadow_win);
  728.     Do_RaiseWin(icon->ewin);
  729.     Msg_DeIconify(icon->ewin);
  730.     DelIcon(icon->win);
  731.     XSync(disp,False);
  732.     return;
  733.      }
  734.    else if (icfg.action[btn-1][mod].id==4)
  735.      {
  736.     Do_KillWin(icon->ewin,0);
  737.     return;
  738.      }
  739.    else if (icfg.action[btn-1][mod].id==11)
  740.      {
  741.     Do_Configure();
  742.     return;
  743.      }
  744.    else if (icfg.action[btn-1][mod].id==12)
  745.      {
  746.     Do_MenuWin(icon->ewin);
  747.     return;
  748.      }
  749.    else if (icfg.action[btn-1][mod].id==13)
  750.      {
  751.     Do_Exec(icfg.action[btn-1][mod].params);
  752.     return;
  753.      }
  754.    else if (icfg.action[btn-1][mod].id==15)
  755.      {
  756.     Do_KillWin(icon->ewin,1);
  757.     return;
  758.      }
  759.    return;
  760. }
  761.  
  762. void ResizeLoop(EWin *ewin, Window win)
  763. {
  764.    GC gc;
  765.    XGCValues gcv;
  766.    XEvent xev;     
  767.    int first;
  768.    int sx,sy;
  769.    Window w1,w2;
  770.    int x,y,xx,yy;
  771.    int d;
  772.    int wx,wy;
  773.    Window dummyw;
  774.    int dummy;
  775.    
  776.    first=0;
  777.  
  778.    XGrabServer(disp);
  779.    XGrabPointer(disp, win, True, ButtonMotionMask|PointerMotionMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
  780.    gc=XCreateGC(disp,root,0,&gcv);
  781.    XSetSubwindowMode(disp,gc,IncludeInferiors);
  782.    XSetForeground(disp,gc,WhitePixel(disp,screen));
  783.    XSetFunction(disp,gc,GXxor);
  784.  
  785.    Draw_Cursor(ewin,(evmd.ewin->client_width-evmd.ewin->base_width)/evmd.ewin->sizeinc_x,(evmd.ewin->client_height-evmd.ewin->base_height)/evmd.ewin->sizeinc_y, 'x', 1);
  786.    while (1)
  787.      {
  788.     XMaskEvent(disp,ButtonMotionMask|PointerMotionMask|ButtonReleaseMask,&xev);
  789.         XQueryPointer(disp,root,&w1,&w2,&sx,&sy,&xx,&yy,&d);
  790.     if (xev.type==ButtonRelease)
  791.       {
  792.          if (first)
  793.            {
  794.           XPutBackEvent(disp,&xev);
  795.           if (cfg.resize_mode==0)
  796.             {
  797.                XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
  798.                       evmd.x2+ewin->border_l+ewin->border_r,
  799.                       evmd.y2+ewin->border_t+ewin->border_b);
  800.                XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  801.                       evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  802.             }
  803.           else if (cfg.resize_mode==1) 
  804.             {
  805.                XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
  806.                       evmd.x2+ewin->border_l+ewin->border_r,
  807.                       evmd.y2+ewin->border_t+ewin->border_b);
  808.                XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  809.                       evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  810.             }
  811.           break;
  812.            }
  813.          else
  814.            {
  815.           XPutBackEvent(disp,&xev);
  816.           break;
  817.            }
  818.       }
  819.     if (first)
  820.       {
  821.          if (cfg.resize_mode==0)
  822.            {
  823.           XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
  824.                  evmd.x2+ewin->border_l+ewin->border_r,
  825.                  evmd.y2+ewin->border_t+ewin->border_b);
  826.           XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  827.                  evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  828.            }
  829.          else if (cfg.resize_mode==1) 
  830.            {
  831.           XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
  832.                  evmd.x2+ewin->border_l+ewin->border_r,
  833.                  evmd.y2+ewin->border_t+ewin->border_b);
  834.           XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  835.                  evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  836.            }
  837.       }
  838.     wx=sx-evmd.px;
  839.     while ((wx%evmd.ewin->sizeinc_x)>0) wx--;
  840.     while ((wx%evmd.ewin->sizeinc_x)<0) wx++;
  841.     wy=sy-evmd.py;
  842.     while ((wy%evmd.ewin->sizeinc_y)>0) wy--;
  843.     while ((wy%evmd.ewin->sizeinc_y)<0) wy++;
  844.     if ((wx!=0)||(wy!=0))
  845.       {
  846.          if (evmd.resize_mode==0)
  847.            {
  848.           if ((wx>0)&&(evmd.x2<wx)) wx=0;
  849.           if ((wy>0)&&(evmd.y2<wy)) wy=0;
  850.           evmd.x1+=wx;evmd.y1+=wy;
  851.           evmd.x2-=wx;evmd.y2-=wy;
  852.            }
  853.          else if (evmd.resize_mode==1)
  854.            {
  855.           if ((wx<0)&&(evmd.x2<-wx)) wx=0;
  856.           if ((wy>0)&&(evmd.y2<wy)) wy=0;
  857.           evmd.y1+=wy;
  858.           evmd.x2+=wx;evmd.y2-=wy;
  859.            }
  860.          else if (evmd.resize_mode==2)
  861.            {
  862.           if ((wx>0)&&(evmd.x2<wx)) wx=0;
  863.           if ((wy<0)&&(evmd.y2<-wy)) wy=0;
  864.           evmd.x1+=wx;
  865.           evmd.x2-=wx;evmd.y2+=wy;
  866.            }
  867.          else if (evmd.resize_mode==3)
  868.            {
  869.           if ((wx<0)&&(evmd.x2<-wx)) wx=0;
  870.           if ((wy<0)&&(evmd.y2<-wy)) wy=0;
  871.           evmd.x2+=wx;evmd.y2+=wy;
  872.            }
  873.          if (evmd.x2>evmd.ewin->max_width) evmd.x2=evmd.ewin->max_width;
  874.          if (evmd.x2<evmd.ewin->min_width) evmd.x2=evmd.ewin->min_width;
  875.          if (evmd.y2>evmd.ewin->max_height) evmd.y2=evmd.ewin->max_height;
  876.          if (evmd.y2<evmd.ewin->min_height) evmd.y2=evmd.ewin->min_height;
  877.       }
  878.     if (cfg.resize_mode==0)
  879.       {
  880.          XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
  881.                 evmd.x2+ewin->border_l+ewin->border_r,
  882.                 evmd.y2+ewin->border_t+ewin->border_b);
  883.          XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  884.                 evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  885.       }
  886.     else if (cfg.resize_mode==1) 
  887.       {
  888.          XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
  889.                 evmd.x2+ewin->border_l+ewin->border_r,
  890.                 evmd.y2+ewin->border_t+ewin->border_b);
  891.          XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  892.                 evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  893.       }
  894.     first=1;
  895.     Draw_Cursor(ewin,(evmd.x2-evmd.ewin->base_width)/evmd.ewin->sizeinc_x,(evmd.y2-evmd.ewin->base_height)/evmd.ewin->sizeinc_y, 'x', 0);
  896.     XSync(disp,False);
  897.     evmd.px+=wx;
  898.     evmd.py+=wy;
  899.      }
  900.    XFreeGC(disp,gc);
  901.    XUngrabPointer(disp, CurrentTime);
  902.    XUngrabServer(disp);
  903.    Draw_Cursor(ewin,(evmd.x2-evmd.ewin->base_width)/evmd.ewin->sizeinc_x,(evmd.y2-evmd.ewin->base_height)/evmd.ewin->sizeinc_y, 'x', 2);
  904.    ModifyEWin(evmd.ewin,evmd.x1,evmd.y1,evmd.x2,evmd.y2);
  905.    XSync(disp,False);
  906. /*   while (XCheckTypedEvent(disp,MotionNotify,&xev));*/
  907. }
  908.  
  909. void MoveLoop(EWin *ewin, Window win)
  910. {
  911.    GC gc;
  912.    XGCValues gcv;
  913.    XEvent xev;     
  914.    int first;
  915.    int sx,sy;
  916.    Window w1,w2;
  917.    int x,y,xx,yy;
  918.    int d;
  919.    int wx,wy;
  920.    Window dummyw;
  921.    int dummy;
  922.    
  923.    first=0;
  924.    XGrabServer(disp);
  925.    XGrabPointer(disp, win, True, ButtonMotionMask|PointerMotionMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
  926.    Draw_Cursor(ewin, ewin->frame_x, ewin->frame_y, '+', 1);
  927.    gc=XCreateGC(disp,root,0,&gcv);
  928.    XSetSubwindowMode(disp,gc,IncludeInferiors);
  929.    XSetForeground(disp,gc,WhitePixel(disp,screen));
  930.    XSetFunction(disp,gc,GXxor);
  931.    evmd.x1=ewin->frame_x;
  932.    evmd.y1=ewin->frame_y;
  933.    evmd.x2=ewin->client_width;
  934.    evmd.y2=ewin->client_height;
  935.    while (1)
  936.      {
  937.     XMaskEvent(disp,ButtonMotionMask|PointerMotionMask|ButtonReleaseMask,&xev);
  938.         XQueryPointer(disp,root,&w1,&w2,&sx,&sy,&xx,&yy,&d);
  939.     if (xev.type==ButtonRelease)
  940.       {
  941.          if (first)
  942.            {
  943.           XPutBackEvent(disp,&xev);
  944.           if (cfg.move_mode==0)
  945.             {
  946.                XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
  947.                       evmd.x2+ewin->border_l+ewin->border_r,
  948.                       evmd.y2+ewin->border_t+ewin->border_b);
  949.                XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  950.                       evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  951.             }
  952.           else if (cfg.move_mode==1) 
  953.             {
  954.                XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
  955.                       evmd.x2+ewin->border_l+ewin->border_r,
  956.                       evmd.y2+ewin->border_t+ewin->border_b);
  957.                XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  958.                       evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  959.             }
  960.           break;
  961.            }
  962.          else
  963.            {
  964.           XPutBackEvent(disp,&xev);
  965.           break;
  966.            }
  967.       }
  968.     if (first)
  969.       {
  970.          if (cfg.move_mode==0)
  971.            {
  972.           XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
  973.                  evmd.x2+ewin->border_l+ewin->border_r,
  974.                  evmd.y2+ewin->border_t+ewin->border_b);
  975.           XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  976.                  evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  977.            }
  978.          else if (cfg.move_mode==1) 
  979.            {
  980.           XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
  981.                  evmd.x2+ewin->border_l+ewin->border_r,
  982.                  evmd.y2+ewin->border_t+ewin->border_b);
  983.           XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  984.                  evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  985.            }
  986.       }
  987.         evmd.x1+=sx-evmd.px;
  988.     evmd.y1+=sy-evmd.py;
  989.     if (cfg.move_mode==0)
  990.       {
  991.          XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
  992.                 evmd.x2+ewin->border_l+ewin->border_r,
  993.                 evmd.y2+ewin->border_t+ewin->border_b);
  994.          XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  995.                 evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  996.       }
  997.     else if (cfg.move_mode==1) 
  998.       {
  999.          XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
  1000.                 evmd.x2+ewin->border_l+ewin->border_r,
  1001.                 evmd.y2+ewin->border_t+ewin->border_b);
  1002.          XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
  1003.                 evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
  1004.       }
  1005.     first=1;
  1006.     Draw_Cursor(ewin, evmd.x1,evmd.y1, '+', 0);
  1007.     XSync(disp,False);
  1008.         evmd.px=sx;
  1009.     evmd.py=sy;
  1010.      }
  1011.    XFreeGC(disp,gc);
  1012.    XUngrabPointer(disp, CurrentTime);
  1013.    Draw_Cursor(ewin, evmd.x1,evmd.y1, '+', 2);
  1014.    XUngrabServer(disp);
  1015.    ModifyEWin(evmd.ewin,evmd.x1,evmd.y1,evmd.x2,evmd.y2);
  1016.    XSync(disp,False);
  1017. /*   while (XCheckTypedEvent(disp,MotionNotify,&xev));*/
  1018. }
  1019.  
  1020. void Draw_Cursor(EWin *ewin, int a, int b, char ch, int start)
  1021. {
  1022.    static Cursor cursor;
  1023.    static Pixmap pix, mask;
  1024.    static GC cursorgc;
  1025.    static XGCValues gv;
  1026.    static XSetWindowAttributes attr;
  1027.    static unsigned long msk;
  1028.    char font_string[512];
  1029.    static char geom[15];
  1030.    static int height, width, ow, oh;
  1031.    static XColor col, col2;
  1032.    static XFontStruct *font;
  1033.    char *neg;
  1034.    int wid, hgt;
  1035.    
  1036.    if(start==1)
  1037.      {    
  1038.     sprintf(font_string,"-*-%s-%s-%s-*-*-%i-*-*-*-*-*-*-*",
  1039.         cfg.font,font_weight,font_slant,ccfg.num_size);
  1040.     font=XLoadQueryFont(disp,font_string);
  1041.     if (!font) return;
  1042.     height = font->max_bounds.ascent+font->max_bounds.descent + 2;
  1043.     width = 10*(font->max_bounds.rbearing-font->max_bounds.lbearing);
  1044.     pix = XCreatePixmap(disp, root, width, height, 1);
  1045.     mask = XCreatePixmap(disp, root, width, height, 1);
  1046.     msk = GCFont|GCForeground;
  1047.     gv.foreground=0;
  1048.     gv.font=font->fid;
  1049.     ow=0; oh=0;
  1050.     cursorgc=XCreateGC(disp, pix, msk, &gv);
  1051.     col.red=(ccfg.num_fg_r<<8)|ccfg.num_fg_r;
  1052.     col.green=(ccfg.num_fg_g<<8)|ccfg.num_fg_g;
  1053.     col.blue=(ccfg.num_fg_b<<8)|ccfg.num_fg_b;
  1054.     col2.red=(ccfg.num_bg_r<<8)|ccfg.num_bg_r;
  1055.     col2.green=(ccfg.num_bg_g<<8)|ccfg.num_bg_g;
  1056.     col2.blue=(ccfg.num_bg_b<<8)|ccfg.num_bg_b;
  1057.     XAllocColor(disp, root_cmap, &col);
  1058.     XAllocColor(disp, root_cmap, &col2);
  1059.     XFillRectangle(disp, mask, cursorgc, 0, 0, width, height);
  1060.     XFillRectangle(disp, pix, cursorgc, 0, 0, width, height);
  1061.      }
  1062.    else if (start==2) 
  1063.      {
  1064.     if(pix==0 || font==0)
  1065.       return;
  1066.     attr.cursor = (Cursor)NULL;
  1067.     XChangeWindowAttributes(disp, ewin->frame_win, msk, &attr);
  1068.     XFreeGC(disp, cursorgc);
  1069.     XFreePixmap(disp, pix);
  1070.     XFreePixmap(disp, mask);
  1071.     XFreeFont(disp, font);
  1072.     return;
  1073.      }
  1074.    if(!font) return;
  1075.    if(ow!=a || oh!=b || start==1)
  1076.      {
  1077.     neg = "";
  1078.     if(a>=0 && ch == '+')
  1079.       neg = "+";
  1080.     else if(ch == '+')
  1081.       {
  1082.          neg = "-";
  1083.          a *= -1;
  1084.       }
  1085.     if(b<0) 
  1086.       {
  1087.          ch = '-';
  1088.          b *= -1;
  1089.       }
  1090.     sprintf(geom, "%s%d%c%d", neg, a, ch, b);
  1091.     msk = strlen(geom);
  1092.     hgt = font->max_bounds.ascent;
  1093.     XSetForeground(disp, cursorgc, 1);
  1094.     XDrawString(disp, pix, cursorgc, 0, hgt, geom, msk);
  1095.     XDrawString(disp, pix, cursorgc, 0, hgt+2, geom, msk);
  1096.     XDrawString(disp, pix, cursorgc, 2, hgt, geom, msk);
  1097.     XDrawString(disp, pix, cursorgc, 2, hgt+2, geom, msk);
  1098.     
  1099.     XCopyArea(disp, pix, mask, cursorgc, 0, 0, width, height, 0, 0);
  1100.     
  1101.     XDrawString(disp, mask, cursorgc, 1, hgt+1, geom, msk);
  1102.     XSetForeground(disp, cursorgc, 0);
  1103.     XDrawString(disp, pix, cursorgc, 1, hgt+1, geom, msk);
  1104.     
  1105.     attr.cursor = XCreatePixmapCursor(disp, pix, mask, &col2, &col, 0, 0);
  1106.     msk = CWCursor;
  1107.     XChangeWindowAttributes(disp, ewin->frame_win, msk, &attr);
  1108.     
  1109.     XFillRectangle(disp, mask, cursorgc, 0, 0, width, height);
  1110.     XFillRectangle(disp, pix, cursorgc, 0, 0, width, height);
  1111.     ow = (evmd.x2-evmd.ewin->base_width)/evmd.ewin->sizeinc_x;
  1112.     oh = (evmd.y2-evmd.ewin->base_height)/evmd.ewin->sizeinc_y;
  1113.      }
  1114. }
  1115.