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
19 * code for processing module configuration commands
21 * Modification History
23 * Created 09/23/98 by Dan Espen:
25 * - Some of this logic used to reside in "read.c", preceeded by a
26 * comment about whether it belonged there. Time tells.
28 * - Added logic to execute module config commands by passing to the
29 * modules that want "active command pipes".
31 * ********************************************************************
38 #include "libs/fvwmlib.h"
39 #include "libs/Parse.h"
40 #include "libs/Strings.h"
41 #include "libs/wild.h"
45 #include "functions.h"
49 #include "module_list.h"
50 #include "module_interface.h"
52 #include "libs/FScreen.h"
54 extern int nColorsets
; /* in libs/Colorset.c */
56 /* do not send ColorLimit, it is not used anymore but maybe by non
57 * "official" modules */
58 #define DISABLE_COLORLIMIT_CONFIG_INFO
60 #define MODULE_CONFIG_DELIM ':'
65 unsigned char alias_len
;
66 struct moduleInfoList
*next
;
69 struct moduleInfoList
*modlistroot
= NULL
;
71 static struct moduleInfoList
*AddToModList(char *tline
);
72 static void SendConfigToModule(
73 fmodule
*module
, const struct moduleInfoList
*entry
, char *match
,
78 * ModuleConfig handles commands starting with "*".
80 * Each command is added to a list from which modules request playback
83 * Some modules request that module config commands be sent to them
84 * as the commands are entered. Send to modules that want it.
86 void ModuleConfig(char *action
)
89 fmodule_list_itr moditr
;
91 struct moduleInfoList
*new_entry
;
93 end
= strlen(action
) - 1;
94 if (action
[end
] == '\n')
96 /* save for config request */
97 new_entry
= AddToModList(action
);
98 /* look at all possible pipes */
99 module_list_itr_init(&moditr
);
100 while ( (module
= module_list_itr_next(&moditr
)) != NULL
)
102 if (IS_MESSAGE_SELECTED(module
, M_SENDCONFIG
))
104 /* module wants config cmds */
105 char *name
= MOD_NAME(module
);
106 if (MOD_ALIAS(module
))
108 name
= MOD_ALIAS(module
);
111 module
, new_entry
, CatString2("*", name
), 0);
118 static struct moduleInfoList
*AddToModList(char *tline
)
120 struct moduleInfoList
*t
, *prev
, *this;
122 char *alias_end
= skipModuleAliasToken(tline
+ 1);
124 /* Find end of list */
134 this = (struct moduleInfoList
*)safemalloc(
135 sizeof(struct moduleInfoList
));
138 if (alias_end
&& alias_end
[0] == MODULE_CONFIG_DELIM
)
140 /* migo (01-Sep-2000): construct an old-style config line */
141 char *conf_start
= alias_end
+ 1;
142 while (isspace(*conf_start
)) conf_start
++;
144 rline
= CatString2(tline
, conf_start
);
145 *alias_end
= MODULE_CONFIG_DELIM
;
146 this->alias_len
= alias_end
- tline
;
149 this->data
= (char *)safemalloc(strlen(rline
)+1);
150 strcpy(this->data
, rline
);
166 * delete from module configuration
168 void CMD_DestroyModuleConfig(F_CMD_ARGS
)
170 struct moduleInfoList
*current
, *next
, *prev
;
171 char *info
; /* info to be deleted - may contain wildcards */
176 while (isspace(*action
))
180 alias_end
= skipModuleAliasToken(action
);
182 if (alias_end
&& alias_end
[0] == MODULE_CONFIG_DELIM
)
184 /* migo: construct an old-style config line */
185 char *conf_start
= alias_end
+ 1;
186 while (isspace(*conf_start
)) conf_start
++;
188 GetNextToken(conf_start
, &conf_start
);
189 if (conf_start
== NULL
)
193 info
= stripcpy(CatString2(action
, conf_start
));
194 *alias_end
= MODULE_CONFIG_DELIM
;
195 /* +1 for a leading '*' */
196 alias_len
= alias_end
- action
+ 1;
201 GetNextToken(action
, &info
);
208 current
= modlistroot
;
211 while (current
!= NULL
)
213 GetNextToken(current
->data
, &mi
);
214 next
= current
->next
;
215 if ((!alias_len
|| !current
->alias_len
||
216 alias_len
== current
->alias_len
) &&
217 matchWildcards(info
, mi
+1))
245 static void send_xinerama_state(fmodule
*module
)
247 SendName(module
, M_CONFIG_INFO
, 0, 0, 0, FScreenGetConfiguration());
252 static void send_desktop_names(fmodule
*module
)
257 for (d
= Scr
.Desktops
->next
; d
!= NULL
; d
= d
->next
)
261 name
= (char *)safemalloc(strlen(d
->name
) + 44);
262 sprintf(name
,"DesktopName %d %s", d
->desk
, d
->name
);
263 SendName(module
, M_CONFIG_INFO
, 0, 0, 0, name
);
271 static void send_desktop_geometry(fmodule
*module
)
275 sprintf(msg
, "DesktopSize %d %d\n", Scr
.VxMax
/ Scr
.MyDisplayWidth
+ 1,
276 Scr
.VyMax
/ Scr
.MyDisplayHeight
+ 1);
277 SendName(module
, M_CONFIG_INFO
, 0, 0, 0, msg
);
282 static void send_image_path(fmodule
*module
)
285 char *ImagePath
= PictureGetImagePath();
287 if (ImagePath
&& *ImagePath
!= 0)
289 msg
= safemalloc(strlen(ImagePath
) + 12);
290 sprintf(msg
, "ImagePath %s\n", ImagePath
);
291 SendName(module
, M_CONFIG_INFO
, 0, 0, 0, msg
);
298 static void send_color_limit(fmodule
*module
)
300 #ifndef DISABLE_COLORLIMIT_CONFIG_INFO
303 sprintf(msg
, "ColorLimit %d\n", Scr
.ColorLimit
);
304 SendName(module
, M_CONFIG_INFO
, 0, 0, 0, msg
);
309 static void send_colorsets(fmodule
*module
)
313 /* dump the colorsets (0 first as others copy it) */
314 for (n
= 0; n
< nColorsets
; n
++)
317 module
, M_CONFIG_INFO
, 0, 0, 0,
318 DumpColorset(n
, &Colorset
[n
]));
324 static void send_click_time(fmodule
*module
)
328 /* Dominik Vogt (8-Nov-1998): Scr.ClickTime patch to set ClickTime to
329 * 'not at all' during InitFunction and RestartFunction. */
330 sprintf(msg
,"ClickTime %d\n", (Scr
.ClickTime
< 0) ?
331 -Scr
.ClickTime
: Scr
.ClickTime
);
332 SendName(module
, M_CONFIG_INFO
, 0, 0, 0, msg
);
337 static void send_move_threshold(fmodule
*module
)
341 sprintf(msg
, "MoveThreshold %d\n", Scr
.MoveThreshold
);
342 SendName(module
, M_CONFIG_INFO
, 0, 0, 0, msg
);
347 void send_ignore_modifiers(fmodule
*module
)
351 sprintf(msg
, "IgnoreModifiers %d\n", GetUnusedModifiers());
352 SendName(module
, M_CONFIG_INFO
, 0, 0, 0, msg
);
357 void CMD_Send_ConfigInfo(F_CMD_ARGS
)
359 struct moduleInfoList
*t
;
360 /* matching criteria for module cmds */
362 /* get length once for efficiency */
364 fmodule
*mod
= exc
->m
.module
;
366 send_desktop_geometry(mod
);
367 /* send ImagePath and ColorLimit first */
368 send_image_path(mod
);
369 send_color_limit(mod
);
370 send_xinerama_state(mod
);
372 send_click_time(mod
);
373 send_move_threshold(mod
);
374 match
= PeekToken(action
, &action
);
377 match_len
= strlen(match
);
379 for (t
= modlistroot
; t
!= NULL
; t
= t
->next
)
381 SendConfigToModule(mod
, t
, match
, match_len
);
383 send_desktop_names(mod
);
384 send_ignore_modifiers(mod
);
386 mod
, M_END_CONFIG_INFO
, (long)0, (long)0, (long)0, (long)0,
387 (long)0, (long)0, (long)0, (long)0);
392 static void SendConfigToModule(
393 fmodule
*module
, const struct moduleInfoList
*entry
, char *match
,
400 match_len
= strlen(match
);
402 if (entry
->alias_len
> 0 && entry
->alias_len
!= match_len
)
406 /* migo: this should be strncmp not strncasecmp probably. */
407 if (strncasecmp(entry
->data
, match
, match_len
) != 0)
412 SendName(module
, M_CONFIG_INFO
, 0, 0, 0, entry
->data
);