summaryrefslogtreecommitdiff
path: root/src/actions.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2003-05-27 07:51:03 +0000
committersabetts <sabetts>2003-05-27 07:51:03 +0000
commit6cc80f10f7cb3de33626cf178bda532d741cf388 (patch)
tree87c04a9e6b4ecee8c49dcff7ad9be54b3fceb874 /src/actions.c
parent785627843a7aa83ebf451add7b9a97e0b800e390 (diff)
downloadratpoison-6cc80f10f7cb3de33626cf178bda532d741cf388.zip
* src/editor.c (saved_command): new local global
(edit_binding): new typedef (edit_binding): new struct (edit_bindings): new local global (input_line_new): new function (input_line_free): likewise (execute_edit_action): likewise (editor_forward_char): likewise (editor_backward_char): likewise (editor_forward_word): likewise (editor_backward_word): likewise (editor_beginning_of_line): likewise (editor_end_of_line): likewise (editor_delete_char): likewise (editor_backward_delete_char): likewise (editor_kill_word): likewise (editor_backward_kill_word): likewise (editor_kill_line): likewise (editor_backward_kill_line): likewise (editor_history_previous): likewise (editor_history_next): likewise (editor_abort): likewise (editor_no_action): likewise (editor_insert): likewise (editor_enter): likewise (paste_cut_buffer): likewise (paste_primary_selection): likewise (editor_paste_selection): likewise (editor_complete): likewise (editor_forward_char): new prototype (editor_backward_char): likewise (editor_forward_word): likewise (editor_backward_word): likewise (editor_beginning_of_line): likewise (editor_end_of_line): likewise (editor_delete_char): likewise (editor_backward_delete_char): likewise (editor_kill_word): likewise (editor_backward_kill_word): likewise (editor_kill_line): likewise (editor_paste_selection): likewise (editor_abort): likewise (editor_no_action): likewise (editor_enter): likewise (editor_history_previous): likewise (editor_history_next): likewise (editor_complete): likewise (editor_backward_kill_line): likewise * src/sbuf.h (sbuf): add node field. * src/main.c (xrealloc): don't print debugger output (init_defaults): init history_size (main): initialize rp_selection (main): load history (clean_up): save history * src/linkedlist.h (list_first): new macro * src/input.h (free_history): remove prototype (ring_bell): new function * src/input.c: include unistd.h (input_history): remove (input_num_history_entries): likewise (update_input_window): remove prompt, input, and input_len arguments. add line argument. (update_input_window): use line argument. (ring_bell): new function (get_input): take completion_fn argument. prototype and callers updated. (free_history): remove function (get_more_input): take completion_fn argument. prototype and callers updated. use line structure and its functionality. * src/globals.h (MAX_FONT_WIDTH): new define (rp_selection): new extern * src/globals.c (rp_selection): new global * src/completions.h (completions_new): new prototype (completions_free): likewise (completions_assign): likewise (completions_update): likewise (completions_next_completion): likewise * src/completions.c (completions_new): new function (completions_free): likewise (completions_assign): likewise (completions_update): likewise (completions_next_completion): likewise * src/Makefile.am (ratpoison_SOURCES): add editor.c editor.h history.h and history.c * src/data.h (rp_completions): new typedef (rp_input_line): likewise (completion_fn): likewise (rp_defaults): new field, history_size (rp_completions): new struct (rp_input_line): new struct * src/conf.h (MAX_HISTORY_SIZE): new define (HISTORY_FILE): likewise (VISUAL_BELL): likewise (MODIFIER_PREFIX): set to RP_CONTROL_MASK (INPUT_ABORT_MODIFIER): likewise (INPUT_PREV_HISTORY_MODIFIER): likewise (INPUT_NEXT_HISTORY_MODIFIER): likewise (RESIZE_VGROW_MODIFIER): likewise (RESIZE_VSHRINK_MODIFIER): likewise (RESIZE_HGROW_MODIFIER): likewise (RESIZE_HSHRINK_MODIFIER): likewise * src/actions.c (trivial_completions): new function (window_completions): likewise (colon_completions): likewise (exec_completions): likewise (cmd_select): pass window_completions to get_input (cmd_rename): pass trivial_completions to get_input (cmd_colon): pass colon_completions to get_input and get_more_input (cmd_exec): pass exec_completions to get_input (cmd_newwm): pass trivial_completions to get_input (cmd_resize): convert the keysym modifier to something ratpoison understands.
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c176
1 files changed, 169 insertions, 7 deletions
diff --git a/src/actions.c b/src/actions.c
index 0b5a323..8b2a04b 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -755,6 +755,42 @@ string_to_window_number (char *str)
return *s ? -1 : i;
}
+
+struct list_head *
+trivial_completions (char* str)
+{
+ struct list_head *list;
+
+ /* Initialize our list. */
+ list = xmalloc (sizeof (struct list_head));
+ INIT_LIST_HEAD (list);
+
+ return list;
+}
+
+struct list_head *
+window_completions (char* str)
+{
+ rp_window_elem *cur;
+ struct list_head *list;
+
+ /* Initialize our list. */
+ list = xmalloc (sizeof (struct list_head));
+ INIT_LIST_HEAD (list);
+
+ /* Gather the names of all the windows. */
+ list_for_each_entry (cur, &rp_current_group->mapped_windows, node)
+ {
+ struct sbuf *name;
+
+ name = sbuf_new (0);
+ sbuf_copy (name, window_name (cur->win));
+ list_add_tail (&name->node, list);
+ }
+
+ return list;
+}
+
/* switch to window number or name */
char *
cmd_select (int interactive, char *data)
@@ -763,7 +799,7 @@ cmd_select (int interactive, char *data)
int n;
if (data == NULL)
- str = get_input (MESSAGE_PROMPT_SWITCH_TO_WINDOW);
+ str = get_input (MESSAGE_PROMPT_SWITCH_TO_WINDOW, window_completions);
else
str = xstrdup (data);
@@ -814,7 +850,7 @@ cmd_rename (int interactive, char *data)
if (current_window() == NULL) return NULL;
if (data == NULL)
- winname = get_input (MESSAGE_PROMPT_NEW_WINDOW_NAME);
+ winname = get_input (MESSAGE_PROMPT_NEW_WINDOW_NAME, trivial_completions);
else
winname = xstrdup (data);
@@ -959,6 +995,42 @@ command (int interactive, char *data)
return result;
}
+struct list_head *
+colon_completions (char* str)
+{
+ int i;
+ struct sbuf *s;
+ struct list_head *list;
+
+ /* Initialize our list. */
+ list = xmalloc (sizeof (struct list_head));
+ INIT_LIST_HEAD (list);
+
+ /* Put all the aliases in our list. */
+ for(i=0; i<alias_list_last; ++i)
+ {
+ s = sbuf_new (0);
+ sbuf_copy (s, alias_list[i].name);
+ /* The space is so when the user completes a space is
+ conveniently inserted after the command. */
+ sbuf_concat (s, " ");
+ list_add_tail (&s->node, list);
+ }
+
+ /* Put all the commands in our list. */
+ for(i=0; user_commands[i].name; ++i)
+ {
+ s = sbuf_new (0);
+ sbuf_copy (s, user_commands[i].name);
+ /* The space is so when the user completes a space is
+ conveniently inserted after the command. */
+ sbuf_concat (s, " ");
+ list_add_tail (&s->node, list);
+ }
+
+ return list;
+}
+
char *
cmd_colon (int interactive, char *data)
{
@@ -966,9 +1038,9 @@ cmd_colon (int interactive, char *data)
char *input;
if (data == NULL)
- input = get_input (MESSAGE_PROMPT_COMMAND);
+ input = get_input (MESSAGE_PROMPT_COMMAND, colon_completions);
else
- input = get_more_input (MESSAGE_PROMPT_COMMAND, data);
+ input = get_more_input (MESSAGE_PROMPT_COMMAND, data, colon_completions);
/* User aborted. */
if (input == NULL)
@@ -985,13 +1057,76 @@ cmd_colon (int interactive, char *data)
return NULL;
}
+struct list_head *
+exec_completions (char *str)
+{
+ size_t n = 256;
+ char *partial;
+ struct sbuf *line;
+ FILE *file;
+ struct list_head *head;
+ char *completion_string;
+
+ /* Initialize our list. */
+ head = xmalloc (sizeof (struct list_head));
+ INIT_LIST_HEAD (head);
+
+ /* FIXME: A Bash dependancy?? */
+ completion_string = xsprintf("bash -c \"compgen -ac %s|sort\"", str);
+ file = popen (completion_string, "r");
+ free (completion_string);
+ if (!file)
+ {
+ PRINT_ERROR (("popen failed\n"));
+ return head;
+ }
+
+ partial = (char*)xmalloc (n);
+
+ /* Read data from the file, split it into lines and store it in a
+ list. */
+ line = sbuf_new (0);
+ while (fgets (partial, n, file) != NULL)
+ {
+ /* Read a chunk from the file into our line accumulator. */
+ sbuf_concat (line, partial);
+
+ if (feof(file) || (*(sbuf_get (line) + strlen(sbuf_get (line)) - 1) == '\n'))
+ {
+ char *s;
+ struct sbuf *elem;
+
+ s = sbuf_get (line);
+
+ /* Frob the newline into */
+ if (*(s + strlen(s) - 1) == '\n')
+ *(s + strlen(s) - 1) = '\0';
+
+ /* Add our line to the list. */
+ elem = sbuf_new (0);
+ sbuf_copy (elem, s);
+ /* The space is so when the user completes a space is
+ conveniently inserted after the command. */
+ sbuf_concat (elem, " ");
+ list_add_tail (&elem->node, head);
+
+ sbuf_clear (line);
+ }
+ }
+
+ free (partial);
+ pclose (file);
+
+ return head;
+}
+
char *
cmd_exec (int interactive, char *data)
{
char *cmd;
if (data == NULL)
- cmd = get_input (MESSAGE_PROMPT_SHELL_COMMAND);
+ cmd = get_input (MESSAGE_PROMPT_SHELL_COMMAND, exec_completions);
else
cmd = xstrdup (data);
@@ -1053,7 +1188,7 @@ cmd_newwm(int interactive, char *data)
char *prog;
if (data == NULL)
- prog = get_input (MESSAGE_PROMPT_SWITCH_WM);
+ prog = get_input (MESSAGE_PROMPT_SWITCH_WM, trivial_completions);
else
prog = xstrdup (data);
@@ -1442,6 +1577,9 @@ cmd_resize (int interactive, char *data)
show_frame_message (" Resize frame ");
nbytes = read_key (&c, &mod, buffer, sizeof (buffer));
+ /* Convert the mask to be compatible with ratpoison. */
+ mod = x11_mask_to_rp_mask (mod);
+
if (c == RESIZE_VGROW_KEY && mod == RESIZE_VGROW_MODIFIER)
resize_frame_vertically (current_frame(), defaults.frame_resize_unit);
else if (c == RESIZE_VSHRINK_KEY && mod == RESIZE_VSHRINK_MODIFIER)
@@ -3193,6 +3331,30 @@ find_group (char *str)
return group;
}
+struct list_head *
+group_completions (char *str)
+{
+ struct list_head *list;
+ rp_group *cur;
+
+ /* Initialize our list. */
+ list = xmalloc (sizeof (struct list_head));
+ INIT_LIST_HEAD (list);
+
+ /* Grab all the group names. */
+ list_for_each_entry (cur, &rp_groups, node)
+ {
+ struct sbuf *s;
+
+ s = sbuf_new (0);
+ sbuf_copy (s, cur->name);
+
+ list_add_tail (&s->node, list);
+ }
+
+ return list;
+}
+
char *
cmd_gselect (int interactive, char *data)
{
@@ -3200,7 +3362,7 @@ cmd_gselect (int interactive, char *data)
rp_group *g;
if (data == NULL)
- str = get_input (MESSAGE_PROMPT_SWITCH_TO_GROUP);
+ str = get_input (MESSAGE_PROMPT_SWITCH_TO_GROUP, group_completions);
else
str = xstrdup (data);