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 #include "FvwmIconMan.h"
20 #include "readconfig.h"
23 #include "libs/Module.h"
24 #include "libs/wild.h"
26 static Button
*get_select_button(void);
29 Button
*current_button
;
33 static void init_function_context(Function
*func
)
35 function_context
.current_button
= get_select_button();
36 function_context
.fp
= func
;
39 void run_function_list(Function
*func
)
41 init_function_context(func
);
43 while (function_context
.fp
)
45 function_context
.fp
->func(
46 function_context
.fp
->numargs
,
47 function_context
.fp
->args
);
48 if (function_context
.fp
)
50 function_context
.fp
= function_context
.fp
->next
;
55 static Button
*get_select_button(void)
57 if (globals
.select_win
)
59 return globals
.select_win
->button
;
64 static Button
*get_focus_button(void)
66 if (globals
.focus_win
)
68 return globals
.focus_win
->button
;
73 static WinManager
*get_current_man(void)
75 Button
*b
= function_context
.current_button
;
77 if (globals
.num_managers
==1)
79 return globals
.managers
;
81 if (b
&& b
->drawn_state
.win
)
83 return b
->drawn_state
.win
->manager
;
88 static WinData
*get_current_win(void)
90 Button
*b
= function_context
.current_button
;
92 if (b
&& b
->drawn_state
.win
)
94 return b
->drawn_state
.win
;
99 static Button
*get_current_button(void)
101 return function_context
.current_button
;
104 static Button
*button_move(ButtonValue
*bv
)
106 Button
*b
= NULL
, *cur
;
110 cur
= get_current_button();
115 ConsoleMessage("gotobutton: need a button to change to\n");
119 b
= get_select_button();
123 b
= get_focus_button();
127 man
= get_current_man();
128 if (man
&& man
->buttons
.num_windows
> 0)
130 i
= bv
->offset
% man
->buttons
.num_windows
;
133 i
+= man
->buttons
.num_windows
;
135 b
= man
->buttons
.buttons
[i
];
140 man
= get_current_man();
144 FUNCTIONS
, "\tno current button, skipping\n");
151 b
= button_above(man
, cur
);
155 b
= button_below(man
, cur
);
159 b
= button_left(man
, cur
);
163 b
= button_right(man
, cur
);
167 b
= button_next(man
, cur
);
171 b
= button_prev(man
, cur
);
175 ConsoleMessage("Internal error in gotobutton\n");
183 int builtin_gotobutton(int numargs
, BuiltinArg
*args
)
188 ConsoleDebug(FUNCTIONS
, "gotobutton: ");
189 print_args(numargs
, args
);
191 bv
= &args
[0].value
.button_value
;
197 function_context
.current_button
= b
;
203 int builtin_gotomanager(int numargs
, BuiltinArg
*args
)
206 WinManager
*man
, *new;
209 ConsoleDebug(FUNCTIONS
, "gotomanager: ");
210 print_args(numargs
, args
);
212 bv
= &args
[0].value
.button_value
;
214 new = man
= get_current_man();
219 ConsoleMessage("gotomanager: need a manager argument\n");
225 "gotomanager: \"select\" or \"focus\" does not specify"
231 /* Now we find the manager modulo the VISIBLE managers */
232 static WinManager
**wa
= NULL
;
233 int i
, num_mapped
, n
;
235 n
= globals
.num_managers
;
240 wa
= (WinManager
**)safemalloc(
241 n
* sizeof(WinManager
*));
243 for (i
= 0, num_mapped
= 0; i
< n
; i
++)
245 if (globals
.managers
[i
].buttons
.num_windows
> 0
246 && globals
.managers
[i
].window_mapped
)
248 wa
[num_mapped
++] = &globals
.managers
[i
];
253 i
= bv
->offset
% num_mapped
;
271 for (i
= man
->index
+ 1, new = man
+ 1;
272 i
< globals
.num_managers
&&
273 new->buttons
.num_windows
== 0;
278 if (i
== globals
.num_managers
)
288 for (i
= man
->index
- 1, new = man
- 1;
289 i
> -1 && new->buttons
.num_windows
== 0;
302 ConsoleMessage("gotomanager: bad argument\n");
306 if (new && new != man
&& new->buttons
.num_windows
> 0)
308 function_context
.current_button
= new->buttons
.buttons
[0];
314 int builtin_select(int numargs
, BuiltinArg
*args
)
316 WinManager
*man
= get_current_man();
319 move_highlight(man
, get_current_button());
320 if (get_current_button())
322 run_binding(man
, SELECT
);
328 int builtin_sendcommand(int numargs
, BuiltinArg
*args
)
330 WinData
*win
= get_current_win();
333 Button
*current_button
;
342 command
= args
[0].value
.string_value
;
343 current_button
= win
->manager
->select_button
;
345 r
.x
= current_button
->x
;
346 r
.y
= current_button
->y
;
347 r
.width
= current_button
->w
;
348 r
.height
= current_button
->h
;
349 XTranslateCoordinates(theDisplay
, win
->manager
->theWindow
, theRoot
,
350 r
.x
, r
.y
, &r
.x
, &r
.y
, &tmpw
);
352 tmp
= module_expand_action(
353 theDisplay
, theScreen
, command
, &r
, NULL
, NULL
);
359 SendFvwmPipe(fvwm_fd
, command
, win
->app_id
);
368 int builtin_printdebug(int numargs
, BuiltinArg
*args
)
372 for (i
= 0; i
< globals
.num_managers
; i
++)
374 ConsoleDebug(FUNCTIONS
, "Manager %d\n---------\n", i
);
375 ConsoleDebug(FUNCTIONS
, "Keys:\n");
376 print_bindings(globals
.managers
[i
].bindings
[KEYPRESS
]);
377 ConsoleDebug(FUNCTIONS
, "Mice:\n");
378 print_bindings(globals
.managers
[i
].bindings
[MOUSE
]);
379 ConsoleDebug(FUNCTIONS
, "Select:\n");
380 print_bindings(globals
.managers
[i
].bindings
[SELECT
]);
381 ConsoleDebug(FUNCTIONS
, "\n");
387 int builtin_quit(int numargs
, BuiltinArg
*args
)
389 ConsoleDebug(FUNCTIONS
, "quit: ");
390 print_args(numargs
, args
);
395 static void do_jmp(int off
)
398 ConsoleDebug(FUNCTIONS
, "jmp: %d\n", off
);
402 ConsoleMessage("Can't have a negative relative jump offset\n");
405 for (i
= 0; i
< off
; i
++)
407 if (function_context
.fp
)
409 function_context
.fp
= function_context
.fp
->next
;
414 static int eval_if(ButtonValue
*bv
)
422 ConsoleMessage("Internal error in eval_if: 1\n");
426 if (get_select_button())
433 if (get_focus_button())
447 cur
= get_current_button();
448 man
= get_current_man();
457 return (button_above(man
, cur
) != cur
);
460 return (button_below(man
, cur
) != cur
);
463 return (button_left(man
, cur
) != cur
);
466 return (button_right(man
, cur
) != cur
);
469 return (button_next(man
, cur
) != cur
);
472 return (button_prev(man
, cur
) != cur
);
475 ConsoleMessage("Internal error in eval_if: 2\n");
483 int builtin_bif(int numargs
, BuiltinArg
*args
)
485 int off
= args
[1].value
.int_value
;
486 ConsoleDebug(FUNCTIONS
, "bif: off = %d\n", off
);
488 if (eval_if(&args
[0].value
.button_value
))
496 int builtin_bifn(int numargs
, BuiltinArg
*args
)
498 int off
= args
[1].value
.int_value
;
499 ConsoleDebug(FUNCTIONS
, "bifn: off = %d\n", off
);
501 if (eval_if(&args
[0].value
.button_value
) == 0)
509 int builtin_jmp(int numargs
, BuiltinArg
*args
)
511 int off
= args
[0].value
.int_value
;
512 ConsoleDebug(FUNCTIONS
, "jmp: off = %d\n", off
);
518 int builtin_ret(int numargs
, BuiltinArg
*args
)
520 function_context
.fp
= NULL
;
524 int builtin_print(int numargs
, BuiltinArg
*args
)
528 ConsoleDebug(FUNCTIONS
, "print: %s\n", args
[0].value
.string_value
);
530 s
= args
[0].value
.string_value
;
533 ConsoleMessage("String too long\n");
537 sprintf(buf
, "%s\n", s
);
544 int builtin_searchforward(int numargs
, BuiltinArg
*args
)
550 s
= args
[0].value
.string_value
;
552 ConsoleDebug(FUNCTIONS
, "searchforward: %s\n", s
);
554 cur
= get_current_button();
555 man
= get_current_man();
561 if (cur
->drawn_state
.display_string
&& matchWildcards(
562 s
, cur
->drawn_state
.display_string
))
566 b
= button_next(man
, cur
);
577 function_context
.current_button
= cur
;
583 int builtin_searchback(int numargs
, BuiltinArg
*args
)
589 s
= args
[0].value
.string_value
;
591 ConsoleDebug(FUNCTIONS
, "searchback: %s\n", s
);
593 cur
= get_current_button();
594 man
= get_current_man();
600 if (cur
->drawn_state
.display_string
&& matchWildcards(
601 s
, cur
->drawn_state
.display_string
))
605 b
= button_prev(man
, cur
);
616 function_context
.current_button
= cur
;
622 int builtin_warp(int numargs
, BuiltinArg
*args
)
628 ConsoleDebug(FUNCTIONS
, "warp\n");
630 cur
= get_current_button();
633 man
= get_current_man();
634 x
= cur
->x
+ cur
->w
/ 2;
635 y
= cur
->y
+ cur
->h
/ 2;
637 theDisplay
, None
, man
->theWindow
, 0, 0, 0, 0, x
, y
);
643 int builtin_refresh(int numargs
, BuiltinArg
*args
)