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 >
Wrap
C/C++ Source or Header
|
1997-06-24
|
27KB
|
1,115 lines
#include "enlightenment.h"
void DoWindowButton(EWin *ewin, Window win, int btn, int mod, int wbtn)
{
int i,j;
/* if it wasnt a left, middle or right mouse button... ignore it */
if ((btn<1)||(btn>3)) return;
/* if the subwindow clicked is a decoration subwindow.. ignore the click */
if (cfg.subwin_type[wbtn]==0) return;
/* flag the button as clicked ... */
ewin->subwin_state[wbtn]=CLICKED;
/* redraw the button */
DrawButton(ewin,wbtn);
/* set the event mode windowbutton pressed to this one */
evmd.wbtn=wbtn;
if (cfg.subwin_action[wbtn][btn-1][mod].id==1)
{
Do_RaiseWin(ewin);
Do_MoveWin(ewin, win);
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==2)
{
Do_RaiseWin(ewin);
Do_ResizeWin(ewin, win);
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==3)
{
Do_IconifyWin(ewin);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==4)
{
Do_KillWin(ewin,0);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==5)
{
Do_RaiseWin(ewin);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==6)
{
Do_LowerWin(ewin);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==7)
{
Do_RaiseLowerWin(ewin);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==8)
{
Do_RaiseWin(ewin);
Do_MaxHeightWin(ewin);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==9)
{
Do_RaiseWin(ewin);
Do_MaxWidthWin(ewin);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==10)
{
Do_RaiseWin(ewin);
Do_MaxSizeWin(ewin);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==11)
{
Do_Configure();
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==12)
{
Do_MenuWin(ewin);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==13)
{
Do_Exec(cfg.subwin_action[wbtn][btn-1][mod].params);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else if (cfg.subwin_action[wbtn][btn-1][mod].id==15)
{
Do_KillWin(ewin,1);
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
else
{
evmd.ewin=ewin;
evmd.wbtn=wbtn;
evmd.mode=MODE_NORMAL;
return;
}
return;
}
void DoBaseMenu(Menu *m, int x, int y)
{
int px,py;
if (m)
{
px=x-m->popup_x;
py=y-m->popup_y;
if (px<0) px=0;
if (py<0) py=0;
if (px+m->width>DisplayWidth(disp,screen))
px=DisplayWidth(disp,screen)-m->width-1;
if (py+m->height>DisplayHeight(disp,screen))
py=DisplayHeight(disp,screen)-m->height-1;
XMoveWindow(disp,m->win,px,py);
ShowMenu(m);
AddActiveMenuToList(m);
}
}
void DoRootMenu(int btn, int mod, int x, int y)
{
Menu *m;
char s[256];
sprintf(s,"root%i",btn);
strcpy(evmd.mname,s);
m=FindMenu(s);
DoBaseMenu(m,x,y);
}
void Do_MoveWin(EWin *ewin, Window win)
{
XEvent ev;
int x,y;
int sx,sy,d;
Window w1,w2;
if(evmd.mode!=MODE_NORMAL)
return;
evmd.ewin=ewin;
if (cfg.move_mode==2)
{
evmd.mode=MODE_MOVE;
Draw_Cursor(ewin, ewin->frame_x, ewin->frame_y, '+', 1);
XGrabPointer(disp, win, True, ButtonMotionMask|PointerMotionMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
return;
}
else
{
MoveLoop(ewin, win);
}
}
void Do_ResizeWin(EWin *ewin, Window win)
{
XEvent ev;
int x,y;
int sx,sy,d;
Window w1,w2;
int wx,wy;
int mode;
int x1,y1,x2,y2;
/* XQueryPointer(disp,root,&w1,&w2,&sx,&sy,&x,&y,&d);*/
/* evmd.px=sx;*/
/* evmd.py=sy;*/
if(evmd.mode!=MODE_NORMAL)
return;
x1=ewin->frame_x;
y1=ewin->frame_y;
x2=ewin->client_width;
y2=ewin->client_height;
wx=evmd.px-x1;
wy=evmd.py-y1;
if ((wx<ewin->frame_width/2)&&(wy<ewin->frame_height/2)) mode=0;
if ((wx>=ewin->frame_width/2)&&(wy<ewin->frame_height/2)) mode=1;
if ((wx<ewin->frame_width/2)&&(wy>=ewin->frame_height/2)) mode=2;
if ((wx>=ewin->frame_width/2)&&(wy>=ewin->frame_height/2)) mode=3;
evmd.x1=x1;
evmd.x2=x2;
evmd.y1=y1;
evmd.y2=y2;
evmd.resize_mode=mode;
evmd.ewin=ewin;
if (cfg.resize_mode==2)
{
evmd.mode=MODE_RESIZE;
Draw_Cursor(ewin, (ewin->client_width-ewin->base_width)/ewin->sizeinc_x, (ewin->client_height-ewin->base_height)/ewin->sizeinc_y, 'x', 1);
XGrabPointer(disp, win, True, ButtonMotionMask|PointerMotionMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
return;
}
else
{
ResizeLoop(ewin, win);
}
}
void Do_IconifyWin(EWin *ewin)
{
struct itimerval tv1,tv2;
struct sigaction sa;
/* concurrency issues! wait for previous iconify requests to */
/* be completeed by checking every 10th of a second to see if they */
/* finished yet */
while (newicon.ewin) usleep(100000);
tv1.it_value.tv_sec=0;
tv1.it_value.tv_usec=icfg.snapshot_time*1000;
tv2.it_value.tv_sec=0;
tv2.it_value.tv_usec=icfg.snapshot_time*1000;
tv1.it_interval.tv_sec=0;
tv1.it_interval.tv_usec=0;
tv2.it_interval.tv_sec=0;
tv2.it_interval.tv_usec=0;
newicon.ewin=ewin;
newicon.win=ewin->client_win;
XRaiseWindow(disp,ewin->frame_win);
setitimer(ITIMER_REAL,&tv1,&tv2);
sa.sa_handler = Finish_Iconify;
sa.sa_flags = 0;
sigemptyset (&sa.sa_mask);
sigaction(SIGALRM, &sa, (struct sigaction *)0);
}
void Do_KillWin(EWin *ewin, int nasty_kill)
{
XClientMessageEvent xev;
Atom atm[2];
Window dummyw;
int dummy;
int wmdel;
int num;
Atom *prot;
Atom dummya;
int i;
unsigned long dummyl,numl;
prot=NULL;
wmdel=0;
if (!(ewin->state&ICONIFIED))
{
newicon.kill=nasty_kill+1;
Do_IconifyWin(ewin);
return;
}
atm[0]=XInternAtom(disp,"WM_DELETE_WINDOW",False);
atm[1]=XInternAtom(disp,"WM_PROTOCOLS",False);
/* work out if client wants to have the wm ask it to quit */
if (!XGetWMProtocols (disp,ewin->client_win,&prot, &num))
{
/* have to work it out the hard way.. nasty client */
XGetWindowProperty(disp,ewin->client_win, atm[1],0,10,False,atm[1],
&dummya,&dummy,&numl,&dummyl,
(unsigned char **)&prot);
num=(int)numl;
}
/* check if it has a "delet me" flag set */
if (prot)
{
for (i=0;i<num;i++)
{
if (prot[i]==atm[0]) wmdel=1;
}
}
if (prot) XFree(prot);
if (wmdel)
{
/* delete */
xev.type=ClientMessage;
xev.window=ewin->client_win;
xev.message_type=atm[1];
xev.format=32;
xev.data.l[0]=atm[0];
xev.data.l[1]=CurrentTime;
XSendEvent(disp,ewin->client_win,False,0,(XEvent *)&xev);
}
else
{
/* kill */
XKillClient(disp,(XID)ewin->client_win);
}
if (nasty_kill)
{
/* kill */
XKillClient(disp,(XID)ewin->client_win);
}
XSync(disp,False);
}
void Do_RaiseWin(EWin *ewin)
{
Window *wl;
int nc,nb;
int i,j;
struct blist *bptr;
struct list *ptr;
if (ewin->top) return;
ToFront(ewin);
j=0;
nc=global_l->num;
nb=0;
bptr=bl.first;
while (bptr)
{
nb++;
bptr=bptr->next;
}
wl=malloc(sizeof(Window)*(nc+nb+3));
bptr=bl.first;
while (bptr)
{
if (bptr->bwin->above) wl[j++]=bptr->bwin->win;
bptr=bptr->next;
}
if (icfg.level)
{
wl[j++]=icfg.left_win;
wl[j++]=icfg.right_win;
wl[j++]=icfg.bg_win;
}
ptr=global_l->first;
while (ptr)
{
wl[j++]=ptr->win->frame_win;
ptr=ptr->next;
}
bptr=bl.first;
while (bptr)
{
if (!bptr->bwin->above) wl[j++]=bptr->bwin->win;
bptr=bptr->next;
}
if (!icfg.level)
{
wl[j++]=icfg.left_win;
wl[j++]=icfg.right_win;
wl[j++]=icfg.bg_win;
}
XRestackWindows(disp,wl,nc+nb+3);
free(wl);
}
void Do_LowerWin(EWin *ewin)
{
Window *wl;
int nc,nb;
int i,j;
struct blist *bptr;
struct list *ptr;
ToBack(ewin);
j=0;
nc=global_l->num;
nb=0;
bptr=bl.first;
while (bptr)
{
nb++;
bptr=bptr->next;
}
wl=malloc(sizeof(Window)*(nc+nb+3));
bptr=bl.first;
while (bptr)
{
if (bptr->bwin->above) wl[j++]=bptr->bwin->win;
bptr=bptr->next;
}
if (icfg.level)
{
wl[j++]=icfg.left_win;
wl[j++]=icfg.right_win;
wl[j++]=icfg.bg_win;
}
ptr=global_l->first;
while (ptr)
{
wl[j++]=ptr->win->frame_win;
ptr=ptr->next;
}
bptr=bl.first;
while (bptr)
{
if (!bptr->bwin->above) wl[j++]=bptr->bwin->win;
bptr=bptr->next;
}
if (!icfg.level)
{
wl[j++]=icfg.left_win;
wl[j++]=icfg.right_win;
wl[j++]=icfg.bg_win;
}
XRestackWindows(disp,wl,nc+nb+3);
free(wl);
}
void Do_RaiseLowerWin(EWin *ewin)
{
if (ewin->top) Do_LowerWin(ewin);
else Do_RaiseWin(ewin);
}
void Do_MaxHeightWin(EWin *ewin)
{
int h;
int y;
if (ewin->lastop==OP_MAXHEIGHT)
{
h=ewin->prev_client_height;
y=ewin->prev_frame_y;
ewin->prev_client_height=ewin->client_height;
ewin->prev_client_width=ewin->client_width;
ewin->prev_frame_x=ewin->frame_x;
ewin->prev_frame_y=ewin->frame_y;
}
else
{
ewin->prev_client_height=ewin->client_height;
ewin->prev_client_width=ewin->client_width;
ewin->prev_frame_x=ewin->frame_x;
ewin->prev_frame_y=ewin->frame_y;
h=DisplayHeight(disp,screen);
h-=ewin->border_t;
h-=ewin->border_b;
while (((h-ewin->base_height)%ewin->sizeinc_y)>0) h--;
while (((h-ewin->base_height)%ewin->sizeinc_y)<0) h++;
y=0;
}
ModifyEWin(ewin,ewin->frame_x,y,ewin->client_width,h);
ewin->lastop=OP_MAXHEIGHT;
}
void Do_MaxWidthWin(EWin *ewin)
{
int w;
int x;
if (ewin->lastop==OP_MAXWIDTH)
{
w=ewin->prev_client_width;
x=ewin->prev_frame_x;
ewin->prev_client_height=ewin->client_height;
ewin->prev_client_width=ewin->client_width;
ewin->prev_frame_x=ewin->frame_x;
ewin->prev_frame_y=ewin->frame_y;
}
else
{
ewin->prev_client_height=ewin->client_height;
ewin->prev_client_width=ewin->client_width;
ewin->prev_frame_x=ewin->frame_x;
ewin->prev_frame_y=ewin->frame_y;
w=DisplayWidth(disp,screen);
w-=ewin->border_l;
w-=ewin->border_r;
while (((w-ewin->base_width)%ewin->sizeinc_x)>0) w--;
while (((w-ewin->base_width)%ewin->sizeinc_x)<0) w++;
x=0;
}
ModifyEWin(ewin,x,ewin->frame_y,w,ewin->client_height);
ewin->lastop=OP_MAXWIDTH;
}
void Do_MaxSizeWin(EWin *ewin)
{
int h;
int y;
int w;
int x;
if (ewin->lastop==OP_MAXSIZE)
{
h=ewin->prev_client_height;
y=ewin->prev_frame_y;
w=ewin->prev_client_width;
x=ewin->prev_frame_x;
ewin->prev_client_height=ewin->client_height;
ewin->prev_client_width=ewin->client_width;
ewin->prev_frame_x=ewin->frame_x;
ewin->prev_frame_y=ewin->frame_y;
}
else
{
ewin->prev_client_height=ewin->client_height;
ewin->prev_client_width=ewin->client_width;
ewin->prev_frame_x=ewin->frame_x;
ewin->prev_frame_y=ewin->frame_y;
h=DisplayHeight(disp,screen);
h-=ewin->border_t;
h-=ewin->border_b;
while (((h-ewin->base_height)%ewin->sizeinc_y)>0) h--;
while (((h-ewin->base_height)%ewin->sizeinc_y)<0) h++;
y=0;
w=DisplayWidth(disp,screen);
w-=ewin->border_l;
w-=ewin->border_r;
while (((w-ewin->base_width)%ewin->sizeinc_x)>0) w--;
while (((w-ewin->base_width)%ewin->sizeinc_x)<0) w++;
x=0;
}
ModifyEWin(ewin,x,y,w,h);
ewin->lastop=OP_MAXSIZE;
}
void Do_Configure()
{
}
void Do_MenuWin(EWin *ewin)
{
}
void Do_Exec(char *line)
{
char *args[2048];
int i,j,k;
char arg[1024];
int inquote=0;
int q1,q2;
if (fork()) return;
setsid();
if (execl("/bin/sh","/bin/sh","-c",line,NULL)==-1) exit(100);
exit(0);
}
void Do_Exit()
{
char s[1024];
if ((Theme_Path[0])&&(!nodel))
{
sprintf(s,"rm -rf %s",Theme_Path);
system(s);
}
XSetInputFocus(disp, PointerRoot, RevertToPointerRoot, CurrentTime);
XSelectInput(disp, root, 0);
UnmapClients(0);
exit(0);
}
void Do_Restart()
{
char s[2048];
if ((Theme_Path[0])&&(!nodel))
{
sprintf(s,"rm -rf %s",Theme_Path);
system(s);
}
UnmapClients(0);
XCloseDisplay(disp);
sleep(1);
if (Theme_Name[0]!=0)
{
sprintf(s,"%s -theme %s",argv1,Theme_Name);
execl("/bin/sh","/bin/sh","-c",s,NULL);
}
else
execl("/bin/sh","/bin/sh","-c",argv1,NULL);
exit(100);
}
void Do_Restart_Theme(char *file)
{
char s[1024];
if ((Theme_Path[0])&&(!nodel))
{
sprintf(s,"rm -rf %s",Theme_Path);
system(s);
}
sprintf(s,"%s -theme %s",argv1,file);
UnmapClients(0);
XCloseDisplay(disp);
sleep(1);
execl("/bin/sh","/bin/sh","-c",s,NULL);
exit(100);
}
void DoButton(BWin *bwin, int btn, int mod)
{
XWindowAttributes xwa;
/* if it wasnt a left, middle or right mouse button... ignore it */
if ((btn<1)||(btn>3)) return;
ButtonDraw(bwin);
if (bwin->action[btn-1][mod].id==12)
{
Menu *m;
evmd.mode=MODE_MENU;
tmp_menu=NULL;
m=FindMenu(bwin->action[btn-1][mod].params);
if (m)
{
XGetWindowAttributes(disp,bwin->win,&xwa);
DoBaseMenu(m,xwa.x+(xwa.width/2),xwa.y+(xwa.height/2));
}
return;
}
if (bwin->action[btn-1][mod].id==13)
{
Do_Exec(bwin->action[btn-1][mod].params);
return;
}
else if (bwin->action[btn-1][mod].id==14)
{
Do_Exit();
return;
}
else if (bwin->action[btn-1][mod].id==16)
{
Do_Restart();
return;
}
else if (bwin->action[btn-1][mod].id==17)
{
Do_Restart_Theme(bwin->action[btn-1][mod].params);
return;
}
else if (bwin->action[btn-1][mod].id==18)
{
int n1,n2;
char s[1024];
sscanf(bwin->action[btn-1][mod].params,"%i %i %s",&n1,&n2,s);
strcpy(cfg.root_pname,s);
cfg.root_width=n1;
cfg.root_height=n2;
SetRoot();
return;
}
else
{
btmd.bwin=bwin;
return;
}
return;
}
void DoMenu(Menu *m, int num)
{
if (!m) return;
if (m->items[num]->action.id==13)
{
Do_Exec(m->items[num]->action.params);
return;
}
else if (m->items[num]->action.id==14)
{
Do_Exit();
return;
}
else if (m->items[num]->action.id==16)
{
Do_Restart();
return;
}
else if (m->items[num]->action.id==17)
{
Do_Restart_Theme(m->items[num]->action.params);
return;
}
else if (m->items[num]->action.id==18)
{
int n1,n2;
char s[1024];
sscanf(m->items[num]->action.params,"%i %i %s",&n1,&n2,s);
strcpy(cfg.root_pname,s);
cfg.root_width=n1;
cfg.root_height=n2;
SetRoot();
return;
}
return;
}
void DoIcon(Icon *icon, int btn, int mod)
{
int i,j;
/* if it wasnt a left, middle or right mouse button... ignore it */
if ((btn<1)||(btn>3)) return;
if (icfg.action[btn-1][mod].id==3)
{
XMapWindow(disp,icon->ewin->frame_win);
if (fx.shadow.on) XMapWindow(disp,icon->ewin->fx.shadow_win);
Do_RaiseWin(icon->ewin);
Msg_DeIconify(icon->ewin);
DelIcon(icon->win);
XSync(disp,False);
return;
}
else if (icfg.action[btn-1][mod].id==4)
{
Do_KillWin(icon->ewin,0);
return;
}
else if (icfg.action[btn-1][mod].id==11)
{
Do_Configure();
return;
}
else if (icfg.action[btn-1][mod].id==12)
{
Do_MenuWin(icon->ewin);
return;
}
else if (icfg.action[btn-1][mod].id==13)
{
Do_Exec(icfg.action[btn-1][mod].params);
return;
}
else if (icfg.action[btn-1][mod].id==15)
{
Do_KillWin(icon->ewin,1);
return;
}
return;
}
void ResizeLoop(EWin *ewin, Window win)
{
GC gc;
XGCValues gcv;
XEvent xev;
int first;
int sx,sy;
Window w1,w2;
int x,y,xx,yy;
int d;
int wx,wy;
Window dummyw;
int dummy;
first=0;
XGrabServer(disp);
XGrabPointer(disp, win, True, ButtonMotionMask|PointerMotionMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
gc=XCreateGC(disp,root,0,&gcv);
XSetSubwindowMode(disp,gc,IncludeInferiors);
XSetForeground(disp,gc,WhitePixel(disp,screen));
XSetFunction(disp,gc,GXxor);
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);
while (1)
{
XMaskEvent(disp,ButtonMotionMask|PointerMotionMask|ButtonReleaseMask,&xev);
XQueryPointer(disp,root,&w1,&w2,&sx,&sy,&xx,&yy,&d);
if (xev.type==ButtonRelease)
{
if (first)
{
XPutBackEvent(disp,&xev);
if (cfg.resize_mode==0)
{
XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
else if (cfg.resize_mode==1)
{
XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
break;
}
else
{
XPutBackEvent(disp,&xev);
break;
}
}
if (first)
{
if (cfg.resize_mode==0)
{
XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
else if (cfg.resize_mode==1)
{
XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
}
wx=sx-evmd.px;
while ((wx%evmd.ewin->sizeinc_x)>0) wx--;
while ((wx%evmd.ewin->sizeinc_x)<0) wx++;
wy=sy-evmd.py;
while ((wy%evmd.ewin->sizeinc_y)>0) wy--;
while ((wy%evmd.ewin->sizeinc_y)<0) wy++;
if ((wx!=0)||(wy!=0))
{
if (evmd.resize_mode==0)
{
if ((wx>0)&&(evmd.x2<wx)) wx=0;
if ((wy>0)&&(evmd.y2<wy)) wy=0;
evmd.x1+=wx;evmd.y1+=wy;
evmd.x2-=wx;evmd.y2-=wy;
}
else if (evmd.resize_mode==1)
{
if ((wx<0)&&(evmd.x2<-wx)) wx=0;
if ((wy>0)&&(evmd.y2<wy)) wy=0;
evmd.y1+=wy;
evmd.x2+=wx;evmd.y2-=wy;
}
else if (evmd.resize_mode==2)
{
if ((wx>0)&&(evmd.x2<wx)) wx=0;
if ((wy<0)&&(evmd.y2<-wy)) wy=0;
evmd.x1+=wx;
evmd.x2-=wx;evmd.y2+=wy;
}
else if (evmd.resize_mode==3)
{
if ((wx<0)&&(evmd.x2<-wx)) wx=0;
if ((wy<0)&&(evmd.y2<-wy)) wy=0;
evmd.x2+=wx;evmd.y2+=wy;
}
if (evmd.x2>evmd.ewin->max_width) evmd.x2=evmd.ewin->max_width;
if (evmd.x2<evmd.ewin->min_width) evmd.x2=evmd.ewin->min_width;
if (evmd.y2>evmd.ewin->max_height) evmd.y2=evmd.ewin->max_height;
if (evmd.y2<evmd.ewin->min_height) evmd.y2=evmd.ewin->min_height;
}
if (cfg.resize_mode==0)
{
XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
else if (cfg.resize_mode==1)
{
XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
first=1;
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);
XSync(disp,False);
evmd.px+=wx;
evmd.py+=wy;
}
XFreeGC(disp,gc);
XUngrabPointer(disp, CurrentTime);
XUngrabServer(disp);
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);
ModifyEWin(evmd.ewin,evmd.x1,evmd.y1,evmd.x2,evmd.y2);
XSync(disp,False);
/* while (XCheckTypedEvent(disp,MotionNotify,&xev));*/
}
void MoveLoop(EWin *ewin, Window win)
{
GC gc;
XGCValues gcv;
XEvent xev;
int first;
int sx,sy;
Window w1,w2;
int x,y,xx,yy;
int d;
int wx,wy;
Window dummyw;
int dummy;
first=0;
XGrabServer(disp);
XGrabPointer(disp, win, True, ButtonMotionMask|PointerMotionMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
Draw_Cursor(ewin, ewin->frame_x, ewin->frame_y, '+', 1);
gc=XCreateGC(disp,root,0,&gcv);
XSetSubwindowMode(disp,gc,IncludeInferiors);
XSetForeground(disp,gc,WhitePixel(disp,screen));
XSetFunction(disp,gc,GXxor);
evmd.x1=ewin->frame_x;
evmd.y1=ewin->frame_y;
evmd.x2=ewin->client_width;
evmd.y2=ewin->client_height;
while (1)
{
XMaskEvent(disp,ButtonMotionMask|PointerMotionMask|ButtonReleaseMask,&xev);
XQueryPointer(disp,root,&w1,&w2,&sx,&sy,&xx,&yy,&d);
if (xev.type==ButtonRelease)
{
if (first)
{
XPutBackEvent(disp,&xev);
if (cfg.move_mode==0)
{
XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
else if (cfg.move_mode==1)
{
XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
break;
}
else
{
XPutBackEvent(disp,&xev);
break;
}
}
if (first)
{
if (cfg.move_mode==0)
{
XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
else if (cfg.move_mode==1)
{
XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
}
evmd.x1+=sx-evmd.px;
evmd.y1+=sy-evmd.py;
if (cfg.move_mode==0)
{
XDrawRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XDrawRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
else if (cfg.move_mode==1)
{
XFillRectangle(disp,root,gc,evmd.x1,evmd.y1,
evmd.x2+ewin->border_l+ewin->border_r,
evmd.y2+ewin->border_t+ewin->border_b);
XFillRectangle(disp,root,gc,evmd.x1+ewin->border_l,
evmd.y1+ewin->border_t,evmd.x2,evmd.y2);
}
first=1;
Draw_Cursor(ewin, evmd.x1,evmd.y1, '+', 0);
XSync(disp,False);
evmd.px=sx;
evmd.py=sy;
}
XFreeGC(disp,gc);
XUngrabPointer(disp, CurrentTime);
Draw_Cursor(ewin, evmd.x1,evmd.y1, '+', 2);
XUngrabServer(disp);
ModifyEWin(evmd.ewin,evmd.x1,evmd.y1,evmd.x2,evmd.y2);
XSync(disp,False);
/* while (XCheckTypedEvent(disp,MotionNotify,&xev));*/
}
void Draw_Cursor(EWin *ewin, int a, int b, char ch, int start)
{
static Cursor cursor;
static Pixmap pix, mask;
static GC cursorgc;
static XGCValues gv;
static XSetWindowAttributes attr;
static unsigned long msk;
char font_string[512];
static char geom[15];
static int height, width, ow, oh;
static XColor col, col2;
static XFontStruct *font;
char *neg;
int wid, hgt;
if(start==1)
{
sprintf(font_string,"-*-%s-%s-%s-*-*-%i-*-*-*-*-*-*-*",
cfg.font,font_weight,font_slant,ccfg.num_size);
font=XLoadQueryFont(disp,font_string);
if (!font) return;
height = font->max_bounds.ascent+font->max_bounds.descent + 2;
width = 10*(font->max_bounds.rbearing-font->max_bounds.lbearing);
pix = XCreatePixmap(disp, root, width, height, 1);
mask = XCreatePixmap(disp, root, width, height, 1);
msk = GCFont|GCForeground;
gv.foreground=0;
gv.font=font->fid;
ow=0; oh=0;
cursorgc=XCreateGC(disp, pix, msk, &gv);
col.red=(ccfg.num_fg_r<<8)|ccfg.num_fg_r;
col.green=(ccfg.num_fg_g<<8)|ccfg.num_fg_g;
col.blue=(ccfg.num_fg_b<<8)|ccfg.num_fg_b;
col2.red=(ccfg.num_bg_r<<8)|ccfg.num_bg_r;
col2.green=(ccfg.num_bg_g<<8)|ccfg.num_bg_g;
col2.blue=(ccfg.num_bg_b<<8)|ccfg.num_bg_b;
XAllocColor(disp, root_cmap, &col);
XAllocColor(disp, root_cmap, &col2);
XFillRectangle(disp, mask, cursorgc, 0, 0, width, height);
XFillRectangle(disp, pix, cursorgc, 0, 0, width, height);
}
else if (start==2)
{
if(pix==0 || font==0)
return;
attr.cursor = (Cursor)NULL;
XChangeWindowAttributes(disp, ewin->frame_win, msk, &attr);
XFreeGC(disp, cursorgc);
XFreePixmap(disp, pix);
XFreePixmap(disp, mask);
XFreeFont(disp, font);
return;
}
if(!font) return;
if(ow!=a || oh!=b || start==1)
{
neg = "";
if(a>=0 && ch == '+')
neg = "+";
else if(ch == '+')
{
neg = "-";
a *= -1;
}
if(b<0)
{
ch = '-';
b *= -1;
}
sprintf(geom, "%s%d%c%d", neg, a, ch, b);
msk = strlen(geom);
hgt = font->max_bounds.ascent;
XSetForeground(disp, cursorgc, 1);
XDrawString(disp, pix, cursorgc, 0, hgt, geom, msk);
XDrawString(disp, pix, cursorgc, 0, hgt+2, geom, msk);
XDrawString(disp, pix, cursorgc, 2, hgt, geom, msk);
XDrawString(disp, pix, cursorgc, 2, hgt+2, geom, msk);
XCopyArea(disp, pix, mask, cursorgc, 0, 0, width, height, 0, 0);
XDrawString(disp, mask, cursorgc, 1, hgt+1, geom, msk);
XSetForeground(disp, cursorgc, 0);
XDrawString(disp, pix, cursorgc, 1, hgt+1, geom, msk);
attr.cursor = XCreatePixmapCursor(disp, pix, mask, &col2, &col, 0, 0);
msk = CWCursor;
XChangeWindowAttributes(disp, ewin->frame_win, msk, &attr);
XFillRectangle(disp, mask, cursorgc, 0, 0, width, height);
XFillRectangle(disp, pix, cursorgc, 0, 0, width, height);
ow = (evmd.x2-evmd.ewin->base_width)/evmd.ewin->sizeinc_x;
oh = (evmd.y2-evmd.ewin->base_height)/evmd.ewin->sizeinc_y;
}
}