vitunes
 All Data Structures
keybindings.h
1 /*
2  * Copyright (c) 2010, 2011, 2012 Ryan Flannery <ryan.flannery@gmail.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef KEYBINDINGS_H
18 #define KEYBINDINGS_H
19 
20 #include "compat/compat.h"
21 
22 #include "debug.h"
23 #include "enums.h"
24 #include "paint.h"
25 #include "vitunes.h"
26 
27 /*
28  * List of all actions that can be bound by keybindings.
29  * NOTE: Using "count" trick (see last element), so no enum should be defined.
30  */
31 typedef enum {
32  /* scrolling vertically */
33  scroll_up_e,
34  scroll_down_e,
35  scroll_up_page_e,
36  scroll_down_page_e,
37  scroll_up_halfpage_e,
38  scroll_down_halfpage_e,
39  scroll_up_wholepage_e,
40  scroll_down_wholepage_e,
41  /* scrolling horizontally */
42  scroll_left_e,
43  scroll_right_e,
44  scroll_leftmost_e,
45  scroll_rightmost_e,
46  /* jumping within screen */
47  jumpto_screen_top_e,
48  jumpto_screen_middle_e,
49  jumpto_screen_bottom_e,
50  /* jumping within whole playlist/library */
51  jumpto_line_e,
52  jumpto_percent_e,
53  /* searching */
54  search_forward_e,
55  search_backward_e,
56  find_next_forward_e,
57  find_next_backward_e,
58  /* copy/cut/paste & undo/redo */
59  visual_e,
60  cut_e,
61  yank_e,
62  paste_after_e,
63  paste_before_e,
64  undo_e,
65  redo_e,
66  /* misc. */
67  go_e,
68  quit_e,
69  redraw_e,
70  command_mode_e,
71  shell_e,
72  /* vitunes specific stuff */
73  switch_windows_e,
74  show_file_info_e,
75  load_playlist_e,
76  media_play_e,
77  media_pause_e,
78  media_stop_e,
79  media_next_e,
80  media_prev_e,
81  volume_increase_e,
82  volume_decrease_e,
83  seek_forward_seconds_e,
84  seek_backward_seconds_e,
85  seek_forward_minutes_e,
86  seek_backward_minutes_e,
87  toggle_forward_e,
88  toggle_backward_e
89 } KeyAction;
90 
91 typedef int KeyCode;
92 
93 
94 /* Keybinding initializing and binding routines */
95 void kb_init();
96 void kb_free();
97 void kb_bind(KeyAction, KeyCode);
98 void kb_unbind_action(KeyAction);
99 void kb_unbind_key(KeyCode);
100 void kb_unbind_all();
101 bool kb_execute(KeyCode);
102 bool kb_execute_by_name(const char *);
103 
104 bool kb_str2action(const char*, KeyAction*);
105 KeyCode kb_str2keycode(char*);
106 KeyCode kb_str2keycode2(char*, char*);
107 
108 
109 /*
110  * This is the generic argument structure for all keybinding action handlers.
111  * This is used liberally to prevent any intricate parsing and make heavy use
112  * of code-reuse.
113  */
114 typedef struct {
115  Direction direction;
116  Scale scale;
117  Amount amount;
118  Placement placement;
119  int num;
120 } KbaArgs;
121 typedef void(*ActionHandler)(KbaArgs a);
122 
123 /* Individual keybinding action handlers */
124 void kba_scroll_row(KbaArgs a);
125 void kba_scroll_page(KbaArgs a);
126 void kba_scroll_col(KbaArgs a);
127 
128 void kba_jumpto_screen(KbaArgs a);
129 void kba_jumpto_file(KbaArgs a);
130 
131 void kba_search(KbaArgs a);
132 void kba_search_find(KbaArgs a);
133 
134 void kba_visual(KbaArgs a);
135 void kba_cut(KbaArgs a);
136 void kba_yank(KbaArgs a);
137 void kba_paste(KbaArgs a);
138 void kba_undo(KbaArgs a);
139 void kba_redo(KbaArgs a);
140 
141 void kba_command_mode(KbaArgs a);
142 void kba_go(KbaArgs a);
143 void kba_shell(KbaArgs a);
144 void kba_quit(KbaArgs a);
145 void kba_redraw(KbaArgs a);
146 
147 void kba_switch_windows(KbaArgs a);
148 void kba_show_file_info(KbaArgs a);
149 void kba_load_playlist(KbaArgs a);
150 void kba_play(KbaArgs a);
151 void kba_pause(KbaArgs a);
152 void kba_stop(KbaArgs a);
153 void kba_play_next(KbaArgs a);
154 void kba_play_prev(KbaArgs a);
155 void kba_volume(KbaArgs a);
156 void kba_seek(KbaArgs a);
157 void kba_toggle(KbaArgs a);
158 
159 
160 /*
161  * The 'gnum' is the number n that can be applied to many keybindings. E.g.
162  * how the sequence "15j" will move down 15 lines. "15" is the gnum here.
163  * These are the routines used to init/set/clear the gnum.
164  */
165 void gnum_clear();
166 void gnum_set(int x);
167 void gnum_add(int x);
168 int gnum_get(); /* Return current gnum. */
169 int gnum_retrieve(); /* Return current gnum and then clear it. */
170 
171 
172 /* These are used to set/use the search direction */
173 Direction search_dir_get();
174 void search_dir_set(Direction d);
175 
176 
177 /* This is the copy/cut buffer and the routines used to manipulate it. */
178 #define YANK_BUFFER_CHUNK_SIZE 100
179 typedef struct {
180  meta_info **files;
181  int nfiles;
182  int capacity;
183 } yank_buffer;
184 extern yank_buffer _yank_buffer;
185 
186 void ybuffer_init();
187 void ybuffer_clear();
188 void ybuffer_free();
189 void ybuffer_add(meta_info *f);
190 
191 
192 /* Misc. handy functions used frequently */
193 void redraw_active();
194 bool match_command_name(const char *s, const char *cmd);
195 void execute_external_command(const char *cmd);
196 
197 #endif