summaryrefslogtreecommitdiff
path: root/src/events.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2005-01-15 04:06:57 +0000
committersabetts <sabetts>2005-01-15 04:06:57 +0000
commit4ccc6cdf0f85b397edab7e4aec9dd412ceefc99b (patch)
tree22cc0dc116dca71b18e28dc78c02b84818c1bb39 /src/events.c
parenteb4f8c1e431d34bfa27a736af0b5d59dde09b200 (diff)
downloadratpoison-4ccc6cdf0f85b397edab7e4aec9dd412ceefc99b.zip
* src/actions.c (ARG_STRING): new define
(ARG): likewise (set_vars): change to a list_head. (add_set_var): new function (init_set_vars): likewise (user_commands): change to a list_head. Move command definitions to init_user_commands. (add_command): new function (init_user_commands): likewise (cmdret_new): likewise (cmdret_new_printf): likewise (cmdret_free): likewise (read_string): likewise (read_keymap): likewise (read_keydesc): likewise (read_command): likewise (read_shellcmd): likewise (read_frame): likewise (read_window): likewise (read_gravity): likewise (read_group): likewise (read_hook): likewise (read_variable): likewise (hook_completions): likewise (read_number): likewise (read_arg): likewise (parsed_input_to_args): likewise (fill_in_missing_args): likewise (parse_args): likewise (arg_array): likewise (arg_free): likewise (command): use parse_args, parsed_input_to_args, fill_in_missing_args to parse arguments and pass to command functions. (command): return cmdret* structure. prototype updated. (cmd_abort): second arg is an array of struct cmdarg*. Return cmdret*. Updated to use new parsed arguments. (cmd_addhook): likewise (cmd_alias): likewise (cmd_banish): likewise (cmd_bind): likewise (cmd_chdir): likewise (cmd_clrunmanaged): likewise (cmd_colon): likewise (cmd_curframe): likewise (cmd_delete): likewise (cmd_echo): likewise (cmd_escape): likewise (cmd_exec): likewise (cmd_fdump): likewise (cmd_focusdown): likewise (cmd_focuslast): likewise (cmd_focusleft): likewise (cmd_focusright): likewise (cmd_focusup): likewise (cmd_frestore): likewise (cmd_fselect): likewise (cmd_gdelete): likewise (cmd_getenv): likewise (cmd_gmerge): likewise (cmd_gmove): likewise (cmd_gnew): likewise (cmd_gnewbg): likewise (cmd_gnext): likewise (cmd_gprev): likewise (cmd_gravity): likewise (cmd_groups): likewise (cmd_gselect): likewise (cmd_h_split): likewise (cmd_help): likewise (cmd_info): likewise (cmd_kill): likewise (cmd_last): likewise (cmd_lastmsg): likewise (cmd_license): likewise (cmd_link): likewise (cmd_listhook): likewise (cmd_meta): likewise (cmd_msgwait): likewise (cmd_newwm): likewise (cmd_next): likewise (cmd_next_frame): likewise (cmd_nextscreen): likewise (cmd_number): likewise (cmd_only): likewise (cmd_other): likewise (cmd_prev): likewise (cmd_prev_frame): likewise (cmd_prevscreen): likewise (cmd_quit): likewise (cmd_redisplay): likewise (cmd_remhook): likewise (cmd_remove): likewise (cmd_rename): likewise (cmd_resize): likewise (cmd_restart): likewise (cmd_rudeness): likewise (cmd_select): likewise (cmd_setenv): likewise (cmd_shrink): likewise (cmd_source): likewise (cmd_startup_message): likewise (cmd_time): likewise (cmd_tmpwm): likewise (cmd_unalias): likewise (cmd_unbind): likewise (cmd_unimplemented): likewise (cmd_unmanage): likewise (cmd_unsetenv): likewise (cmd_v_split): likewise (cmd_verbexec): likewise (cmd_version): likewise (cmd_warp): likewise (cmd_windows): likewise (cmd_readkey): likewise (cmd_newkmap): likewise (cmd_delkmap): likewise (cmd_definekey): likewise (cmd_undefinekey): likewise (cmd_set): likewise (cmd_sselect): likewise (cmd_ratwarp): likewise (cmd_ratclick): likewise (cmd_ratrelwarp): likewise (cmd_rathold): likewise (cmd_cnext): likewise (cmd_cother): likewise (cmd_cprev): likewise (cmd_dedicate): likewise (cmd_describekey): likewise (cmd_inext): likewise (cmd_iother): likewise (cmd_iprev): likewise (cmd_prompt): likewise (cmd_sdump): likewise (cmd_sfdump): likewise (cmd_undo): likewise (cmd_putsel): likewise (cmd_getsel): likewise (set_resizeunit): arg is an array of struct cmdarg*. Return cmdret*. Updated to use new parsed arguments. (set_wingravity): likewise (set_transgravity): likewise (set_maxsizegravity): likewise (set_bargravity): likewise (set_font): likewise (set_padding): likewise (set_border): likewise (set_barborder): likewise (set_inputwidth): likewise (set_waitcursor): likewise (set_winfmt): likewise (set_winname): likewise (set_fgcolor): likewise (set_bgcolor): likewise (set_barpadding): likewise (set_winliststyle): likewise (set_framesels): likewise (set_maxundos): likewise * src/actions.h: include ratpoison.h (argtype): add arg_FRAME, arg_WINDOW, arg_COMMAND, arg_SHELLCMD, arg_KEYMAP, arg_KEY, arg_GRAVITY, arg_GROUP, arg_HOOK, arg_VARIABLE. (union arg_union): new union (struct cmdarg): new struct (struct argspec): likewise (struct cmdret): likewise (user_command): change func to reflect new command function args. add num_args, ni_required_args, i_required_args. (RP_CMD): new macro for prototyping command functions. all command function prototypes updated to use this macro. (init_user_commands): new prototype (cmdret_free): likewise * src/main.c (read_rc_file): handle cmdret* returned by command. (main): call init_user_commands * src/linkedlist.h (list_size): new prototype * src/linkedlist.c (list_size): new function * src/globals.h (RET_SUCCESS): new define (RET_FAILURE): new define * src/events.c (handle_key): handle the cmdret structure returned by command. (execute_remote_command): return cmdret*. (receive_command): mark the command return string as error or output before sending. * src/data.h (struct rp_action): change data element type to char* * src/communications.c (receive_command_result): print command output to stderr if marked as an error.
Diffstat (limited to 'src/events.c')
-rw-r--r--src/events.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/events.c b/src/events.c
index ce11485..a207de7 100644
--- a/src/events.c
+++ b/src/events.c
@@ -396,12 +396,18 @@ handle_key (KeySym ks, unsigned int mod, rp_screen *s)
default keymap. Ignore the key if it doesn't have a binding. */
if ((key_action = find_keybinding (ks, x11_mask_to_rp_mask (mod), map)))
{
- char *result;
+ cmdret *result;
+
+ PRINT_DEBUG(("%s\n", key_action->data));
+
result = command (1, key_action->data);
- /* Gobble the result. */
if (result)
- free (result);
+ {
+ if (result->output)
+ message (result->output);
+ cmdret_free (result);
+ }
}
else
{
@@ -437,11 +443,11 @@ key_press (XEvent *ev)
text. This text is passed back using the RP_COMMAND_RESULT
Atom. The client will wait for this property change so something
must be returned. */
-static char *
+static cmdret *
execute_remote_command (Window w)
{
int status;
- char *result = NULL;
+ cmdret *ret;
Atom type_ret;
int format_ret;
unsigned long nitems;
@@ -475,10 +481,10 @@ execute_remote_command (Window w)
}
PRINT_DEBUG (("command: %s\n", req));
- result = command (req[0], (char *)&req[1]);
+ ret = command (req[0], (char *)&req[1]);
XFree (req);
- return result;
+ return ret;
}
/* Command requests are posted as a property change using the
@@ -489,6 +495,7 @@ execute_remote_command (Window w)
static void
receive_command (Window root)
{
+ cmdret *cmd_ret;
char *result;
Atom type_ret;
int format_ret;
@@ -535,25 +542,26 @@ receive_command (Window root)
break;
}
- /* We grabbed a window, so now find read the command stored in
+ /* We grabbed a window, so now read the command stored in
this window and execute it. */
w = *(Window *)prop_return;
XFree (prop_return);
- result = execute_remote_command (w);
+ cmd_ret = execute_remote_command (w);
/* notify the client of any text that was returned by the
command. */
+ if (cmd_ret->output)
+ result = xsprintf ("%c%s", cmd_ret->success ? '1':'0', cmd_ret->output);
+ else
+ result = NULL;
if (result)
- {
- XChangeProperty (dpy, w, rp_command_result, XA_STRING,
- 8, PropModeReplace, (unsigned char *)result, strlen (result));
- free (result);
- }
+ XChangeProperty (dpy, w, rp_command_result, XA_STRING,
+ 8, PropModeReplace, (unsigned char *)result, strlen (result));
else
- {
- XChangeProperty (dpy, w, rp_command_result, XA_STRING,
- 8, PropModeReplace, NULL, 0);
- }
+ XChangeProperty (dpy, w, rp_command_result, XA_STRING,
+ 8, PropModeReplace, NULL, 0);
+ free (result);
+ cmdret_free (cmd_ret);
} while (bytes_after > 0);
}