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 /* ---------------------------- included header files ----------------------- */
23 /* the following 5 are just to satisfy X11/extensions/shape.h on some systems */
25 #include <X11/Xutil.h>
26 #include <X11/Xproto.h>
27 #include <X11/Xatom.h>
28 #include <X11/Intrinsic.h>
30 #include "libs/Module.h"
31 #include "libs/Strings.h"
32 #include "libs/Parse.h"
33 #include "FvwmButtons.h"
38 /* ---------------------------- local definitions --------------------------- */
40 /* ---------------------------- local macros -------------------------------- */
42 /* ---------------------------- imports ------------------------------------- */
44 extern int Width
, Height
;
47 /* ---------------------------- included code files ------------------------- */
49 /* ---------------------------- local types --------------------------------- */
51 /* ---------------------------- forward declarations ------------------------ */
53 /* ---------------------------- local variables ----------------------------- */
55 static Bool silent
= False
;
57 /* ---------------------------- exported variables (globals) ---------------- */
59 /* ---------------------------- local functions ----------------------------- */
61 static void show_error(const char *msg
, ...)
70 vfprintf(stderr
, CatString3(MyName
, ": ", msg
), args
);
77 /* to be used in module_expand_action */
78 static module_expand_vars mev
=
82 /* array of var names */
84 /* array of values, void *, will be filled later */
86 /* array of booleans, 0 if string, 1 if int */
91 static char *expand_button_vars(const button_info
*b
, const char *line
)
93 /* not fully implemented yet, should expand $title, $icon and so on */
97 /* there should be a function evaluating fore/back from colorset */
98 char *fore
= (b
->flags
.b_Fore
) ? b
->fore
: "black";
99 char *back
= (b
->flags
.b_Back
) ? b
->back
: "gray";
101 get_button_root_geometry(&r
, b
);
102 expanded_line
= module_expand_action(
103 Dpy
, screen
, (char *)line
, &r
, fore
, back
);
105 return expanded_line
;
108 static button_info
*parse_button_id(char **line
)
110 button_info
*b
= NULL
, *ub
= UberButton
;
117 s
= PeekToken(*line
, &rest
);
121 show_error("No button id specified\n");
127 unsigned int JunkWidth
;
128 unsigned int JunkHeight
;
130 mask
= XParseGeometry(s
, &x
, &y
, &JunkWidth
, &JunkHeight
);
131 if (!(mask
& XValue
) || (mask
& XNegative
) ||
132 !(mask
& YValue
) || (mask
& YNegative
))
134 show_error("Illegal button position '%s'\n", s
);
139 show_error("Button column/row must not be negative\n");
142 b
= get_xy_button(ub
, y
, x
);
146 "Button at column %d row %d not found\n", x
, y
);
150 else if (isdigit(*s
))
154 /* find the button */
155 while (NextButton(&ub
, &b
, &i
, 0))
160 if (count
!= x
|| b
== NULL
)
162 show_error("Button number %d not found\n", x
);
166 else if (isalpha(*s
))
170 /* find the button */
171 while (NextButton(&ub
, &b
, &i
, 0))
173 if (b
->flags
.b_Id
&& StrEquals(b
->id
, s
))
181 show_error("Button id '%s' does not exist\n", s
);
187 show_error("Invalid button id '%s' specified\n", s
);
195 /* ---------------------------- interface functions ------------------------- */
197 static char *actions
[] =
199 "Silent", "ChangeButton", "ExpandButtonVars", "PressButton", NULL
202 static char *button_options
[] =
204 "Title", "Icon", "ActiveTitle", "ActiveIcon", "PressTitle", "PressIcon", NULL
207 void parse_message_line(char *line
)
219 action
= GetTokenIndex(line
, actions
, -1, &rest
);
222 show_error("Message not understood: %s", line
);
230 } while (action
== 0);
232 /* find out which button */
233 b
= parse_button_id(&rest
);
243 /* The dimensions of individual buttons (& the overall size of
244 * the FvwmButtons window) is based on the initial
245 * configuration for the module. In some configurations,
246 * dynamically adding/changing a title/icon may mean it no
247 * longer fits on a button. Currently, there are no checks for
249 while (rest
&& rest
[0] != '\0')
253 char *value0
, *value
;
256 /* parse option and value and give diagnostics */
257 rest
= GetQuotedString(
258 rest
, &option_pair
, ",", NULL
, NULL
, NULL
);
259 while (isspace(*rest
))
266 option
= GetTokenIndex(
267 option_pair
, button_options
, -1, &value0
);
271 "Unsupported button option line '%s'\n",
277 GetNextToken(value0
, &value
);
283 "No title/icon to change specified.\n");
290 if (b
->flags
.b_Title
)
292 b
->flags
.b_Title
= 1;
293 CopyString(&b
->title
, value
);
297 if (b
->flags
.b_ActiveTitle
)
298 free(b
->activeTitle
);
299 b
->flags
.b_ActiveTitle
= 1;
300 CopyString(&b
->activeTitle
, value
);
304 if (b
->flags
.b_PressTitle
)
306 b
->flags
.b_PressTitle
= 1;
307 CopyString(&b
->pressTitle
, value
);
312 value
, &icon
, b
->colorset
) == 0)
315 "Cannot load icon \"%s\"\n",
331 &b
->icon_file
, value
);
334 case 3: /* ActiveIcon */
335 if (b
->flags
.b_ActiveIcon
)
337 free(b
->active_icon_file
);
342 b
->flags
.b_ActiveIcon
= 1;
344 &b
->active_icon_file
,
346 b
->activeicon
= icon
;
348 case 5: /* PressIcon */
349 if (b
->flags
.b_PressIcon
)
351 free(b
->press_icon_file
);
356 b
->flags
.b_PressIcon
= 1;
373 RedrawButton(b
, DRAW_FORCE
, NULL
);
374 if (UberButton
->c
->flags
.b_TransBack
)
376 SetTransparentBackground(UberButton
, Width
, Height
);
381 /* ExpandButtonVars */
382 line
= expand_button_vars(b
, rest
);
385 SendText(fd
, line
, 0);
391 rest
= GetQuotedString(rest
, &buttonn
, "", NULL
, NULL
, NULL
);
394 mousebutton
= atoi(buttonn
);
398 mousebutton
> NUMBER_OF_EXTENDED_MOUSE_BUTTONS
)
408 act
= GetButtonAction(b
, mousebutton
);
409 ButtonPressProcess(b
, &act
);
414 CurrentButton
= NULL
;