user input now handled through function pointers, now defined in config.h
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include "defines.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
extern unsigned int file_modifiers;
|
||||
@ -13,39 +14,60 @@ extern file *mid_content;
|
||||
extern file *lft_content;
|
||||
extern file *rgt_content;
|
||||
|
||||
void user_interactions(char *input, unsigned int *status, unsigned int *settings) {
|
||||
if (*input == 'q') {
|
||||
*status ^= STATUS_QUIT_PROGRAM;
|
||||
} else if (*input == *"KEY_BACKSPACE") {
|
||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||
} else if (*input == 'a') {
|
||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
} else if (*input == 'o') {
|
||||
file_modifiers ^= FILE_MODIFIERS_SORT_BITMASK;
|
||||
} else if (*input == 'e') {
|
||||
file_modifiers ^= FILE_MODIFIERS_SORT_ALPHABETIC;
|
||||
} else if (*input == 'u') {
|
||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
} else if (*input == 'h') {
|
||||
chdir("..");
|
||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
} else if (*input == 't') {
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
/* capping the maximum file is done inside thread_mid */
|
||||
selected_file_current++;
|
||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
} else if (*input == 'n') {
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
if (selected_file_current != 0) {
|
||||
selected_file_current--;
|
||||
extern unsigned int status;
|
||||
|
||||
void quit_program(){
|
||||
status = STATUS_QUIT_PROGRAM;
|
||||
}
|
||||
void move_down(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
/*capping the maximum file is done inside thread_mid */
|
||||
selected_file_current++;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
}
|
||||
void move_up(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
if (selected_file_current != 0) {
|
||||
selected_file_current--;
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
}
|
||||
void move_right(){
|
||||
chdir("..");
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void move_left(){
|
||||
chdir(mid_content[selected_file_current].file_name);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void toggle_hidden_files(){
|
||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void jump_bottom(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
selected_file_current = 0 - 1;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
}
|
||||
void jump_top(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
selected_file_current = 0;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void user_interactions(char *input) {
|
||||
void (*func_ptr)();
|
||||
unsigned long i = 0;
|
||||
for (i = 0; i < binding_count; i++) {
|
||||
if (*input == key_binding[i].key) {
|
||||
func_ptr = key_binding[i].func;
|
||||
func_ptr();
|
||||
}
|
||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
} else if (*input == 's') {
|
||||
chdir(mid_content[selected_file_current].file_name);
|
||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user