Restructure how we look for Read files slightly.
[fvwm.git] / modules / FvwmScript / Widgets / Swallow.c
blob65ed04c3402e0e1c036a100264beb40b42e53e70
1 /* -*-c-*- */
2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include "config.h"
19 #include "libs/fvwmlib.h"
20 #include "libs/ColorUtils.h"
21 #include "libs/Strings.h"
22 #include "Tools.h"
24 extern int fd[2];
27 * Fonction pour Swallow
30 void DrawRelief(struct XObj *xobj)
32 XSegment segm[2];
33 int i;
35 if (xobj->value!=0)
37 for (i=1;i<2;i++)
39 segm[0].x1=xobj->x-i;
40 segm[0].y1=xobj->y-i;
41 segm[0].x2=xobj->x+xobj->width+i-2;
42 segm[0].y2=xobj->y-i;
43 segm[1].x1=xobj->x-i;
44 segm[1].y1=xobj->y-i;
45 segm[1].x2=xobj->x-i;
46 segm[1].y2=xobj->y+xobj->height+i-2;
47 if (xobj->value==-1)
48 XSetForeground(
49 dpy,xobj->gc,xobj->TabColor[shad]);
50 else
51 XSetForeground(
52 dpy,xobj->gc,xobj->TabColor[hili]);
53 XDrawSegments(dpy,x11base->win,xobj->gc,segm,2);
55 segm[0].x1=xobj->x-i;
56 segm[0].y1=xobj->y+xobj->height+i-1;
57 segm[0].x2=xobj->x+xobj->width+i-1;
58 segm[0].y2=xobj->y+xobj->height+i-1;
59 segm[1].x1=xobj->x+xobj->width+i-1;
60 segm[1].y1=xobj->y-i;
61 segm[1].x2=xobj->x+xobj->width+i-1;
62 segm[1].y2=xobj->y+xobj->height+i-1;
63 if (xobj->value==-1)
64 XSetForeground(
65 dpy,xobj->gc,xobj->TabColor[hili]);
66 else
67 XSetForeground(
68 dpy,xobj->gc,xobj->TabColor[shad]);
69 XDrawSegments(dpy,x11base->win,xobj->gc,segm,2);
75 void InitSwallow(struct XObj *xobj)
77 unsigned long mask;
78 XSetWindowAttributes Attr;
79 static char *my_sm_env = NULL;
80 static char *orig_sm_env = NULL;
81 static int len = 0;
82 static Bool sm_initialized = False;
83 static Bool session_manager = False;
84 char *cmd;
86 /* Enregistrement des couleurs et de la police */
87 if (xobj->colorset >= 0) {
88 xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
89 xobj->TabColor[back] = Colorset[xobj->colorset].bg;
90 xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
91 xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
92 } else {
93 xobj->TabColor[fore] = GetColor(xobj->forecolor);
94 xobj->TabColor[back] = GetColor(xobj->backcolor);
95 xobj->TabColor[hili] = GetColor(xobj->hilicolor);
96 xobj->TabColor[shad] = GetColor(xobj->shadcolor);
99 mask=0;
100 xobj->win=XCreateWindow(dpy,*xobj->ParentWin,
101 -1000,-1000,xobj->width,xobj->height,0,
102 CopyFromParent,InputOutput,CopyFromParent,
103 mask,&Attr);
105 /* Redimensionnement du widget */
106 if (xobj->height<30)
107 xobj->height=30;
108 if (xobj->width<30)
109 xobj->width=30;
111 if (xobj->swallow == NULL)
113 fprintf(stderr,"Error\n");
114 return;
117 if (!sm_initialized)
119 /* use sm only when needed */
120 sm_initialized = True;
121 orig_sm_env = getenv("SESSION_MANAGER");
122 if (orig_sm_env && !StrEquals("", orig_sm_env))
124 /* this set the new SESSION_MANAGER env */
125 session_manager = fsm_init(x11base->TabArg[0]);
129 if (!session_manager)
131 SendText(fd, xobj->swallow, 0);
132 return;
135 if (my_sm_env == NULL)
137 my_sm_env = getenv("SESSION_MANAGER");
138 len = 45 + strlen(my_sm_env) + strlen(orig_sm_env);
141 cmd = safemalloc(len + strlen(xobj->swallow));
142 sprintf(
143 cmd,
144 "FSMExecFuncWithSessionManagment \"%s\" \"%s\" \"%s\"",
145 my_sm_env, xobj->swallow, orig_sm_env);
146 SendText(fd, cmd, 0);
147 free (cmd);
150 void DestroySwallow(struct XObj *xobj)
152 /* Arrete le programme swallow */
153 if (xobj->win!=None)
154 XKillClient(dpy, xobj->win);
155 xobj->win = None;
158 void DrawSwallow(struct XObj *xobj, XEvent *evp)
160 DrawRelief(xobj);
163 void EvtMouseSwallow(struct XObj *xobj,XButtonEvent *EvtButton)
167 void EvtKeySwallow(struct XObj *xobj,XKeyEvent *EvtKey)
171 /* Recupere le pointeur de la fenetre Swallow */
172 void CheckForHangon(struct XObj *xobj,unsigned long *body)
174 char *cbody;
176 cbody=(char*)calloc(strlen((char *)&body[3]) + 1,sizeof(char));
177 sprintf(cbody,"%s",(char *)&body[3]);
178 if(strcmp(cbody,xobj->title)==0)
180 xobj->win = (Window)body[0];
181 free(xobj->title);
182 xobj->title=(char*)calloc(sizeof(char),20);
183 sprintf(xobj->title,"No window");
184 XUnmapWindow(dpy,xobj->win);
185 XSetWindowBorderWidth(dpy,xobj->win,0);
187 free(cbody);
190 void swallow(struct XObj *xobj,unsigned long *body)
192 char cmd[256];
194 if(xobj->win == (Window)body[0])
196 XReparentWindow(
197 dpy,xobj->win,*xobj->ParentWin,xobj->x,xobj->y);
198 XResizeWindow(dpy,xobj->win,xobj->width,xobj->height);
199 XMapWindow(dpy,xobj->win);
200 sprintf(
201 cmd,"PropertyChange %u %u %lu %lu",
202 MX_PROPERTY_CHANGE_SWALLOW, 1, xobj->win,
203 (x11base->swallower_win)?
204 x11base->swallower_win:x11base->win);
205 SendText(fd,cmd,0);
206 fsm_proxy(dpy, xobj->win, getenv("SESSION_MANAGER"));
210 void ProcessMsgSwallow(
211 struct XObj *xobj,unsigned long type,unsigned long *body)
213 switch(type)
215 case M_MAP:
216 swallow(xobj,body);
217 break;
218 case M_WINDOW_NAME:
219 case M_RES_NAME:
220 case M_RES_CLASS:
221 CheckForHangon(xobj,body);
222 break;