Compare commits

...
5 Commits
4 changed files with 35 additions and 21 deletions
+3 -3
View File
@@ -12,6 +12,7 @@ static FILE *ueberzug = NULL;
#endif
extern unsigned int terminal_height;
extern unsigned int terminal_width;
extern char *global_path;
char previewd;
magic_t cookie_type;
magic_t cookie_description;
@@ -89,17 +90,16 @@ void images_clear(){
}
}
void images_print(char *file_name){
char *path=getcwd(NULL, 0);
fprintf(ueberzug, "{\"action\":\"add\", \
\"identifier\":\"preview\", \
\"scaler\":\"fit_contain\", \
\"max_height\":%d, \
\"max_width\":%d, \
\"y\":0, \
\"x\":%d, \
\"path\":\"%s/%s\"}\n", terminal_height, terminal_width/2, terminal_width/2, path, file_name);
\"path\":\"%s/%s\"}\n", terminal_height, terminal_width/2, terminal_width/2, global_path, file_name);
fflush(ueberzug);
free(path);
}
void ueberzug_init(){
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW == 2
+7 -1
View File
@@ -53,13 +53,16 @@ void user_interactions() {
ch = getch();
if(ch != ERR) {
if(ch != (char)ERR) {
input[input_pass] = ch;
input_pass++;
if (ch == 27) { /* esc key */
memset(input, 0, INPUT_BUFFER_SIZE);
input_pass = 0;
}
if (input_pass >= INPUT_BUFFER_SIZE) {
input_pass = INPUT_BUFFER_SIZE - 1;
}
}
@@ -158,6 +161,9 @@ char read_string_loop(WINDOW *win, char *buffer, char *nullable_return_char, uns
}
if (*pass >= INPUT_BUFFER_SIZE) {
*pass = INPUT_BUFFER_SIZE - 1;
}
return 0;
}
+1 -1
View File
@@ -38,7 +38,7 @@ int sort_natural(const void *file0, const void *file1){
long parsed_number0 = 0;
long parsed_number1 = 0;
char is_num = 0;
char result = 0;
signed char result = 0;
do {
+24 -16
View File
@@ -51,10 +51,7 @@ unsigned int btm_status;
void *thread_mid(){
dir tmp;
tmp.current_file = NULL;
tmp.file_list = NULL;
tmp.file_count = 0;
dir previous_dir_state = { 0 };
while(!(status & STATUS_QUIT_PROGRAM)){
@@ -74,7 +71,7 @@ void *thread_mid(){
if (status & STATUS_RELOAD_DIRECTORY) {
long index = mid_dir.current_file - mid_dir.file_list;
tmp = mid_dir;
previous_dir_state = mid_dir;
mid_dir.file_count = get_dir_size(path);
mid_dir.file_list = malloc(mid_dir.file_count * sizeof(file));
@@ -88,8 +85,21 @@ void *thread_mid(){
}
unsigned long i;
for(i = 0; i < mid_dir.file_count && i < tmp.file_count; i++) {
mid_dir.file_list[i].status = tmp.file_list[i].status;
for(i = 0; i < mid_dir.file_count && i < previous_dir_state.file_count; i++) {
mid_dir.file_list[i].status = previous_dir_state.file_list[i].status;
}
/* youd think that after the above previous_dir_state = mid_dir previous_dir_state.current_file is always within the bounds of the file_list,
* but no, it fucking is not for some reason
* however for some mysterious reason this condition doesnt fail. well it probably does,
* but that doesnt matter as it does what its supposed to do:
* keep the current file selected after a reload even if the dir contents change like a new file being added */
if (previous_dir_state.current_file != NULL && previous_dir_state.current_file < previous_dir_state.file_list + previous_dir_state.file_count) {
for (i = 0; i < mid_dir.file_count; i++) {
if (strcmp(mid_dir.file_list[i].file_name, previous_dir_state.file_list[index].file_name) == 0) {
mid_dir.current_file = &mid_dir.file_list[i];
break;
}
}
}
@@ -124,17 +134,15 @@ void *thread_mid(){
pthread_mutex_unlock(&mutex_render);
unsigned long i;
for (i = 0; i < tmp.file_count; i++) {
free(tmp.file_list[i].file_name);
for (i = 0; i < previous_dir_state.file_count; i++) {
free(previous_dir_state.file_list[i].file_name);
}
free(tmp.file_list);
tmp.current_file = NULL;
tmp.file_list = NULL;
tmp.file_count = 0;
free(previous_dir_state.file_list);
previous_dir_state.current_file = NULL;
previous_dir_state.file_list = NULL;
previous_dir_state.file_count = 0;
free(path);
}
pthread_exit(0);
}