Renamed package to ion1, and made it conflict with package 'ion'.
[ion1.git] / src / function.c
blob8f56a06a6179c15787ff728ee2d390bf34653cf8
1 /*
2 * ion/function.c
4 * Copyright (c) Tuomo Valkonen 1999-2001.
5 * See the included file LICENSE for details.
6 */
8 #include <string.h>
9 #include "common.h"
10 #include "functionp.h"
11 #include "exec.h"
12 #include "frame.h"
13 #include "clientwin.h"
14 #include "client.h"
15 #include "focus.h"
16 #include "workspace.h"
17 #include "pointer.h"
18 #include "wedln.h"
19 #include "edln.h"
20 #include "query.h"
21 #include "resize.h"
22 #include "modules.h"
23 #include "complete.h"
24 #include "key.h"
25 #include "shortcut.h"
28 /*{{{ Definitions and stuff */
31 extern WDragHandler p_tabdrag_handler;
32 extern WDragHandler p_resize_handler;
34 extern void commandmode_enter();
35 extern void commandmode_leave();
38 /*}}}*/
41 /*{{{ Wrappers/helpers */
44 static void wrap_switch_client(WClient *client)
46 frame_switch_client(CLIENT_FRAME(client), client);
50 /*}}}*/
53 /*{{{ Function table */
55 static WFunction funcs[]={
56 /* frame */
57 FN(l, generic, WFrame, "switch_nth", frame_switch_nth),
58 FN_VOID(generic, WFrame, "switch_next", frame_switch_next),
59 FN_VOID(generic, WFrame, "switch_prev", frame_switch_prev),
60 FN_VOID(generic, WFrame, "split_vert", split_vert),
61 FN_VOID(generic, WFrame, "split_horiz", split_horiz),
62 FN_VOID(generic, WFrame, "destroy_frame", destroy_frame),
63 FN_VOID(generic, WFrame, "closedestroy", closedestroy),
64 FN_VOID(generic, WFrame, "attach_tagged", frame_attach_tagged),
65 FN_VOID(generic, WFrame, "set_shortcut", set_shortcut),
66 FN_VOID(generic, WFrame, "goto_shortcut", goto_shortcut),
68 FN(ss, generic, WFrame, "query_runfile", query_runfile),
69 FN(ss, generic, WFrame, "query_runwith", query_runwith),
70 FN(ss, generic, WFrame, "query_yesno", query_yesno),
71 FN_VOID(generic, WFrame, "query_function", query_function),
72 FN_VOID(generic, WFrame, "query_exec", query_exec),
73 FN_VOID(generic, WFrame, "query_attachclient", query_attachclient),
74 FN_VOID(generic, WFrame, "query_gotoclient", query_gotoclient),
75 FN_VOID(generic, WFrame, "query_workspace", query_workspace),
76 FN_VOID(generic, WFrame, "query_workspace_with", query_workspace_with),
77 FN_VOID(generic, WFrame, "query_renameworkspace", query_renameworkspace),
79 FN_VOID(generic, WWindow, "goto_above", goto_above),
80 FN_VOID(generic, WWindow, "goto_below", goto_below),
81 FN_VOID(generic, WWindow, "goto_right", goto_right),
82 FN_VOID(generic, WWindow, "goto_left", goto_left),
83 FN_VOID(generic, WWindow, "resize_vert", resize_vert),
84 FN_VOID(generic, WWindow, "resize_horiz", resize_horiz),
85 FN_VOID(generic, WWindow, "maximize_vert", maximize_vert),
86 FN_VOID(generic, WWindow, "maximize_horiz", maximize_horiz),
88 FN(l, generic, WFrame, "set_width", set_width),
89 FN(l, generic, WFrame, "set_height", set_height),
90 FN(d, generic, WFrame, "set_widthq", set_widthq),
91 FN(d, generic, WFrame, "set_heightq", set_heightq),
93 FN(s, generic, WWorkspace,"split_top", split_top),
95 /* client */
96 FN_VOID(cclient, WClient, "close", close_client),
97 FN_VOID(cclient, WClient, "close_main", close_client_main),
98 FN_VOID(cclient, WClient, "kill", kill_client),
99 FN_VOID(cclient, WClient, "toggle_tagged", client_toggle_tagged),
100 FN_VOID(cclient, WClient, "quote_next", quote_next),
101 FN_VOID(generic, WClient, "switch_tab", wrap_switch_client),
103 /* mouse move/resize and tab drag */
104 FN_VOID(drag, WFrame, "p_resize", &p_resize_handler),
105 FN_VOID(drag, WClient, "p_tabdrag", &p_tabdrag_handler),
107 /* screen */
108 FN_SCREEN(l, "switch_ws_nth", switch_workspace_nth),
109 FN_SCREEN_VOID( "switch_ws_next", switch_workspace_next),
110 FN_SCREEN_VOID( "switch_ws_prev", switch_workspace_prev),
111 FN_SCREEN(l, "switch_ws_next_n", switch_workspace_next_n),
112 FN_SCREEN(l, "switch_ws_prev_n", switch_workspace_prev_n),
113 FN_SCREEN(s, "exec", wm_exec),
115 /* global */
116 FN_GLOBAL_VOID( "goto_previous", goto_previous),
117 FN_GLOBAL_VOID( "restart", wm_restart),
118 FN_GLOBAL_VOID( "exit", wm_exit),
119 FN_GLOBAL(s, "restart_other", wm_restart_other),
120 FN_GLOBAL(s, "goto_client_name", goto_client_name),
121 FN_GLOBAL(s, "switch_ws_name", switch_workspace_name),
122 FN_GLOBAL(ll, "switch_ws_nth2", switch_workspace_nth2),
123 FN_GLOBAL_VOID( "clear_tags", clear_tags),
125 FN(s, generic, WThing, "command_sequence", command_sequence),
127 FN_VOID(generic, WFrame, "enter_command_mode", commandmode_enter),
128 FN_VOID(generic, WFrame, "leave_command_mode", commandmode_leave),
130 {NULL, NULL, NULL, NULL, NULL}
134 static WFunction moveres_funcs[]={
135 FN_VOID(generic, WWindow, "end_resize", end_resize),
136 FN_VOID(generic, WWindow, "cancel_resize", cancel_resize),
137 FN_VOID(generic, WWindow, "grow", grow),
138 FN_VOID(generic, WWindow, "shrink", shrink),
139 {NULL, NULL, NULL, NULL, NULL}
143 static WFunction input_funcs[]={
144 FN_VOID(edln, WEdln, "back", edln_back),
145 FN_VOID(edln, WEdln, "forward", edln_forward),
146 FN_VOID(edln, WEdln, "bol", edln_bol),
147 FN_VOID(edln, WEdln, "eol", edln_eol),
148 FN_VOID(edln, WEdln, "skip_word", edln_skip_word),
149 FN_VOID(edln, WEdln, "bskip_word", edln_bskip_word),
150 FN_VOID(edln, WEdln, "delete", edln_delete),
151 FN_VOID(edln, WEdln, "backspace", edln_backspace),
152 FN_VOID(edln, WEdln, "kill_to_eol", edln_kill_to_eol),
153 FN_VOID(edln, WEdln, "kill_to_bol", edln_kill_to_bol),
154 FN_VOID(edln, WEdln, "kill_line", edln_kill_line),
155 FN_VOID(edln, WEdln, "kill_word", edln_kill_word),
156 FN_VOID(edln, WEdln, "bkill_word", edln_bkill_word),
157 FN_VOID(edln, WEdln, "set_mark", edln_set_mark),
158 FN_VOID(edln, WEdln, "cut", edln_cut),
159 FN_VOID(edln, WEdln, "copy", edln_copy),
160 FN_VOID(edln, WEdln, "complete", edln_complete),
161 FN_VOID(edln, WEdln, "history_next", edln_history_next),
162 FN_VOID(edln, WEdln, "history_prev", edln_history_prev),
163 FN_VOID(generic, WEdln, "paste", wedln_paste),
164 FN_VOID(generic, WEdln, "finish", wedln_finish),
165 FN_VOID(generic, WInput, "cancel", input_cancel),
166 FN_VOID(generic, WInput, "scrollup", input_scrollup),
167 FN_VOID(generic, WInput, "scrolldown", input_scrolldown),
168 {NULL, NULL, NULL, NULL, NULL}
172 static WFunction *funtabs[]={
173 funcs,
174 moveres_funcs,
175 input_funcs
179 /*}}}*/
182 /*{{{ lookup_func */
185 static WFunction *look_in_funtab(WFunction *func, const char *name)
187 while(func->callhnd!=NULL){
188 if(strcmp(func->name, name)==0)
189 return func;
190 func++;
192 return NULL;
196 WFunction *lookup_func(const char *name, int funtab)
198 WFunction *func=funtabs[funtab];
199 WFunction *ft;
201 func=look_in_funtab(func, name);
203 if(func!=NULL || funtab!=FUNTAB_MAIN)
204 return func;
206 for(ft=(WFunction*)miter_begin("funtab");
207 ft!=NULL;
208 ft=(WFunction*)miter_next("funtab")){
210 func=look_in_funtab(ft, name);
212 if(func!=NULL)
213 break;
216 miter_end();
218 return func;
222 int complete_mainfunc(char *nam, char ***cp_ret, char **beg)
224 char *name;
225 char **cp;
226 int n=0, l=strlen(nam);
227 WFunction *func=funtabs[FUNTAB_MAIN];
228 bool m=FALSE;
230 *cp_ret=NULL;
232 again:
234 for(; func->callhnd!=NULL; func++){
236 if((name=func->name)==NULL)
237 continue;
239 if(l && strncmp(name, nam, l))
240 continue;
242 add_to_complist_copy(cp_ret, &n, name);
245 if(!m){
246 func=(WFunction*)miter_begin("funtab");
247 m=TRUE;
248 }else{
249 func=(WFunction*)miter_next("funtab");
252 if(func!=NULL)
253 goto again;
255 miter_end();
257 return n;
260 /*}}}*/
263 /*{{{ Call handlers */
266 void callhnd_direct(WThing *thing, WFunction *func,
267 int n, const Token *args)
269 typedef void Func(WThing*, int, const Token*);
270 ((Func*)func->fn)(thing, n, args);
274 void callhnd_generic_void(WThing *thing, WFunction *func,
275 int n, const Token *args)
277 typedef void Func(WThing*);
278 thing=find_parent(thing, func->objdescr);
280 if(thing!=NULL)
281 ((Func*)func->fn)(thing);
285 void callhnd_generic_l(WThing *thing, WFunction *func,
286 int n, const Token *args)
288 typedef void Func(WThing*, int);
289 thing=find_parent(thing, func->objdescr);
290 if(thing!=NULL)
291 ((Func*)func->fn)(thing, TOK_LONG_VAL(args));
295 void callhnd_generic_d(WThing *thing, WFunction *func,
296 int n, const Token *args)
298 typedef void Func(WThing*, double);
299 thing=find_parent(thing, func->objdescr);
300 if(thing!=NULL)
301 ((Func*)func->fn)(thing, TOK_DOUBLE_VAL(args));
305 void callhnd_generic_s(WThing *thing, WFunction *func,
306 int n, const Token *args)
308 typedef void Func(WThing*, char*);
309 thing=find_parent(thing, func->objdescr);
310 if(thing!=NULL)
311 ((Func*)func->fn)(thing, TOK_STRING_VAL(args));
315 void callhnd_generic_ss(WThing *thing, WFunction *func,
316 int n, const Token *args)
318 typedef void Func(WThing*, char*, char*);
319 thing=find_parent(thing, func->objdescr);
320 if(thing!=NULL)
321 ((Func*)func->fn)(thing, TOK_STRING_VAL(args), TOK_STRING_VAL(args+1));
325 void callhnd_global_void(WThing *thing, WFunction *func,
326 int n, const Token *args)
328 typedef void Func();
329 ((Func*)func->fn)();
333 void callhnd_global_l(WThing *thing, WFunction *func,
334 int n, const Token *args)
336 typedef void Func(int);
337 ((Func*)func->fn)(TOK_LONG_VAL(args));
341 void callhnd_global_ll(WThing *thing, WFunction *func,
342 int n, const Token *args)
344 typedef void Func(int, int);
345 ((Func*)func->fn)(TOK_LONG_VAL(args), TOK_LONG_VAL(args+1));
349 void callhnd_global_s(WThing *thing, WFunction *func,
350 int n, const Token *args)
352 typedef void Func(char*);
353 ((Func*)func->fn)(TOK_STRING_VAL(args));
357 void callhnd_edln_void(WThing *thing, WFunction *func,
358 int n, const Token *args)
360 WEdln *wedln;
361 typedef void Func(Edln*);
363 if(!WTHING_IS(thing, WEdln))
364 return;
366 wedln=(WEdln*)thing;
368 ((Func*)func->fn)(&(wedln->edln));
372 static WClient *get_cclient(WThing *thing)
374 WFrame *frame;
376 if(WTHING_IS(thing, WClient))
377 return (WClient*)thing;
379 frame=FIND_PARENT(thing, WFrame);
381 if(frame==NULL)
382 return NULL;
384 return frame->current_client;
389 void callhnd_cclient_void(WThing *thing, WFunction *func,
390 int n, const Token *args)
392 typedef void Func(WClient*);
393 WClient *client=get_cclient(thing);
395 if(client!=NULL)
396 ((Func*)func->fn)(client);
400 /*}}}*/