4 * Copyright (c) Tuomo Valkonen 1999-2001.
5 * See the included file LICENSE for details.
10 #include "functionp.h"
13 #include "clientwin.h"
16 #include "workspace.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();
41 /*{{{ Wrappers/helpers */
44 static void wrap_switch_client(WClient
*client
)
46 frame_switch_client(CLIENT_FRAME(client
), client
);
53 /*{{{ Function table */
55 static WFunction funcs
[]={
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
),
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
),
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
),
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
[]={
185 static WFunction
*look_in_funtab(WFunction
*func
, const char *name
)
187 while(func
->callhnd
!=NULL
){
188 if(strcmp(func
->name
, name
)==0)
196 WFunction
*lookup_func(const char *name
, int funtab
)
198 WFunction
*func
=funtabs
[funtab
];
201 func
=look_in_funtab(func
, name
);
203 if(func
!=NULL
|| funtab
!=FUNTAB_MAIN
)
206 for(ft
=(WFunction
*)miter_begin("funtab");
208 ft
=(WFunction
*)miter_next("funtab")){
210 func
=look_in_funtab(ft
, name
);
222 int complete_mainfunc(char *nam
, char ***cp_ret
, char **beg
)
226 int n
=0, l
=strlen(nam
);
227 WFunction
*func
=funtabs
[FUNTAB_MAIN
];
234 for(; func
->callhnd
!=NULL
; func
++){
236 if((name
=func
->name
)==NULL
)
239 if(l
&& strncmp(name
, nam
, l
))
242 add_to_complist_copy(cp_ret
, &n
, name
);
246 func
=(WFunction
*)miter_begin("funtab");
249 func
=(WFunction
*)miter_next("funtab");
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
);
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
);
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
);
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
);
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
);
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
)
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
)
361 typedef void Func(Edln
*);
363 if(!WTHING_IS(thing
, WEdln
))
368 ((Func
*)func
->fn
)(&(wedln
->edln
));
372 static WClient
*get_cclient(WThing
*thing
)
376 if(WTHING_IS(thing
, WClient
))
377 return (WClient
*)thing
;
379 frame
=FIND_PARENT(thing
, WFrame
);
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
);
396 ((Func
*)func
->fn
)(client
);