default_shortcuts.h (6602B)
1 static void numlock(const shortcut_arg* arg); 2 static void zoom(const shortcut_arg* arg); 3 static void zoomabs(const shortcut_arg* arg); 4 static void zoomreset(const shortcut_arg* arg); 5 6 static void window_split(const shortcut_arg* arg); 7 static void window_resize(const shortcut_arg* arg); 8 static void window_delete(const shortcut_arg* arg); 9 static void window_change(const shortcut_arg* arg); 10 11 static void cursor_move_x_relative(const shortcut_arg* arg); 12 static void cursor_move_y_relative(const shortcut_arg* arg); 13 static void move_cursor_to_offset(const shortcut_arg* arg); 14 static void move_cursor_to_end_of_buffer(const shortcut_arg* arg); 15 16 static void swap_to_next_file_buffer(const shortcut_arg* arg); 17 static void save_buffer(const shortcut_arg* arg); 18 static void buffer_kill(const shortcut_arg* arg); 19 20 static void clipboard_copy(const shortcut_arg* arg); 21 static void clipboard_paste(const shortcut_arg* arg); 22 static void toggle_selection(const shortcut_arg* arg); 23 static void undo(const shortcut_arg* arg); 24 static void redo(const shortcut_arg* arg); 25 26 static void search(const shortcut_arg* arg); 27 static void search_next(const shortcut_arg* arg); 28 static void search_previous(const shortcut_arg* arg); 29 static void search_for_buffer(const shortcut_arg* arg); 30 static void search_keyword_in_buffers(const shortcut_arg* arg); 31 static void open_file_browser(const shortcut_arg* arg); 32 33 ///////////////////////////////////////////////// 34 // function implementations 35 // 36 37 void 38 numlock(const shortcut_arg* arg) 39 { 40 win.mode ^= MODE_NUMLOCK; 41 } 42 43 void window_split(const shortcut_arg* arg) 44 { 45 window_node_split(focused_node, 0.5, arg->i); 46 #if 1 47 if (focused_node->node2) { 48 focused_node = focused_node->node2; 49 focused_window = &focused_node->window; 50 } 51 #else 52 if (focused_node->node1) { 53 focused_node = focused_node->node1; 54 focused_window = &focused_node->window; 55 } 56 #endif 57 } 58 59 void window_resize(const shortcut_arg* arg) 60 { 61 float amount = (arg->i == MOVE_RIGHT || arg->i == MOVE_LEFT) ? 0.1f : 0.05f; 62 window_node_resize(focused_node, arg->i, amount); 63 } 64 65 void window_delete(const shortcut_arg* arg) 66 { 67 struct window_split_node* new_node = window_node_delete(focused_node); 68 while (new_node->mode != WINDOW_SINGULAR) 69 new_node = new_node->node1; 70 focused_node = new_node; 71 focused_window = &focused_node->window; 72 } 73 74 void window_change(const shortcut_arg* arg) 75 { 76 focused_node = window_switch_to_window(focused_node, arg->i); 77 focused_window = &focused_node->window; 78 } 79 80 void 81 zoom(const shortcut_arg* arg) 82 { 83 shortcut_arg larg; 84 85 larg.f = usedfontsize + arg->f; 86 zoomabs(&larg); 87 } 88 89 void 90 zoomabs(const shortcut_arg* arg) 91 { 92 xunloadfonts(); 93 xloadfonts(fontconfig, arg->f); 94 cresize(0, 0); 95 xhints(); 96 } 97 98 void 99 zoomreset(const shortcut_arg* arg) 100 { 101 shortcut_arg larg; 102 103 if (defaultfontsize > 0) { 104 larg.f = defaultfontsize; 105 zoomabs(&larg); 106 } 107 } 108 109 void 110 cursor_move_x_relative(const shortcut_arg* arg) 111 { 112 if (focused_window->mode != WINDOW_BUFFER_FILE_BROWSER) 113 buffer_move_on_line(focused_window, arg->i, CURSOR_RIGHT_LEFT_MOVEMENT); 114 } 115 116 void 117 cursor_move_y_relative(const shortcut_arg* arg) 118 { 119 buffer_move_lines(focused_window, arg->i, 0); 120 buffer_move_to_x(focused_window, focused_window->cursor_col, CURSOR_UP_DOWN_MOVEMENT); 121 } 122 123 void 124 swap_to_next_file_buffer(const shortcut_arg* arg) 125 { 126 focused_window->buffer_index++; 127 } 128 129 void 130 save_buffer(const shortcut_arg* arg) 131 { 132 buffer_write_to_filepath(get_file_buffer(focused_window)); 133 } 134 135 void 136 toggle_selection(const shortcut_arg* arg) 137 { 138 struct file_buffer* fb = get_file_buffer(focused_window); 139 if (fb->mode & BUFFER_SELECTION_ON) { 140 fb->mode &= ~(BUFFER_SELECTION_ON); 141 } else { 142 fb->mode |= BUFFER_SELECTION_ON; 143 fb->s1o = fb->s2o = focused_window->cursor_offset; 144 } 145 } 146 147 void 148 move_cursor_to_offset(const shortcut_arg* arg) 149 { 150 focused_window->cursor_offset = arg->i; 151 } 152 153 void 154 move_cursor_to_end_of_buffer(const shortcut_arg* arg) 155 { 156 focused_window->cursor_offset = get_file_buffer(focused_window)->len-1; 157 } 158 159 void 160 clipboard_copy(const shortcut_arg* arg) 161 { 162 struct file_buffer* fb = get_file_buffer(focused_window); 163 int len; 164 char* buf = buffer_get_selection(fb, &len); 165 set_clipboard_copy(buf, len); 166 167 buffer_move_cursor_to_selection_start(focused_window); 168 fb->mode &= ~BUFFER_SELECTION_ON; 169 } 170 171 void 172 clipboard_paste(const shortcut_arg* arg) 173 { 174 insert_clipboard_at_cursor(); 175 } 176 177 void 178 undo(const shortcut_arg* arg) 179 { 180 buffer_undo(get_file_buffer(focused_window)); 181 } 182 183 void 184 redo(const shortcut_arg* arg) 185 { 186 buffer_redo(get_file_buffer(focused_window)); 187 } 188 189 void 190 search(const shortcut_arg* arg) 191 { 192 get_file_buffer(focused_window)->mode &= ~BUFFER_SEARCH_BLOCKING_IDLE; 193 get_file_buffer(focused_window)->mode |= BUFFER_SEARCH_BLOCKING; 194 writef_to_status_bar("search: %s", get_file_buffer(focused_window)->search_term); 195 } 196 197 void 198 search_next(const shortcut_arg* arg) 199 { 200 int new_offset = buffer_seek_string_wrap(focused_window, focused_window->cursor_offset+1, 201 get_file_buffer(focused_window)->search_term); 202 if (new_offset < 0) { 203 writef_to_status_bar("no results for \"%s\"", get_file_buffer(focused_window)->search_term); 204 return; 205 } else if (focused_window->cursor_offset > new_offset) { 206 writef_to_status_bar("search wrapped"); 207 } 208 focused_window->cursor_offset = new_offset; 209 } 210 211 void 212 search_previous(const shortcut_arg* arg) 213 { 214 int new_offset = buffer_seek_string_wrap_backwards(focused_window, focused_window->cursor_offset-1, 215 get_file_buffer(focused_window)->search_term); 216 if (new_offset < 0) { 217 writef_to_status_bar("no results for \"%s\"", get_file_buffer(focused_window)->search_term); 218 return; 219 } else if (focused_window->cursor_offset < new_offset) { 220 writef_to_status_bar("search wrapped"); 221 } 222 focused_window->cursor_offset = new_offset; 223 } 224 225 void 226 search_for_buffer(const shortcut_arg* arg) 227 { 228 if (focused_window->mode != WINDOW_BUFFER_NORMAL) 229 return; 230 *focused_node->search = 0; 231 focused_node->selected = 0; 232 focused_window->mode = WINDOW_BUFFER_SEARCH_BUFFERS; 233 } 234 235 void 236 search_keyword_in_buffers(const shortcut_arg* arg) 237 { 238 if (focused_window->mode != WINDOW_BUFFER_NORMAL) 239 return; 240 *focused_node->search = 0; 241 focused_node->selected = 0; 242 focused_window->mode = WINDOW_BUFFER_KEYWORD_ALL_BUFFERS; 243 } 244 245 246 void 247 open_file_browser(const shortcut_arg* arg) 248 { 249 int last_fb = focused_window->buffer_index; 250 struct file_buffer* fb = get_file_buffer(focused_window); 251 252 char* path = file_path_get_path(fb->file_path); 253 *focused_window = window_buffer_new(new_file_buffer_entry(path)); 254 focused_window->cursor_col = last_fb; 255 free(path); 256 } 257 258 void 259 buffer_kill(const shortcut_arg* arg) 260 { 261 destroy_file_buffer_entry(focused_node, &root_node); 262 }