From 0574732a69f434707f564cf64290ec0f9b23215b Mon Sep 17 00:00:00 2001 From: nova Date: Sat, 31 May 2025 00:36:05 +0200 Subject: [PATCH] very basic and no good file hover implemented --- interactions.c | 18 +++++++++++++++++- threading.c | 25 ++++++++++++++++++++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/interactions.c b/interactions.c index c8b9ef9..39e39c0 100644 --- a/interactions.c +++ b/interactions.c @@ -1,10 +1,14 @@ #include +#include #include #include #include "defines.h" extern unsigned int file_modifiers; +unsigned long selected_file_current; +unsigned long selected_file_last; +extern pthread_mutex_t mutex_selection; void user_interactions(char *input, unsigned int *status, unsigned int *settings) { if (*input == 'q') { @@ -23,7 +27,19 @@ void user_interactions(char *input, unsigned int *status, unsigned int *settings } else if (*input == 'h') { chdir(".."); *status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); - + } else if (*input == 'n') { + 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 == 't') { + 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); } else { } } diff --git a/threading.c b/threading.c index 5dbd3d5..9cd1e05 100644 --- a/threading.c +++ b/threading.c @@ -12,22 +12,24 @@ pthread_mutex_t mutex_btm; pthread_mutex_t mutex_lft; pthread_mutex_t mutex_mid; pthread_mutex_t mutex_rgt; +pthread_mutex_t mutex_selection; -/* contains entire directory as 2d array - * may be changed in future to only include parts of the dir (currently includes entire dir) */ file *rgt_content; file *mid_content; file *lft_content; + char *top_content; /* current path */ unsigned long rgt_file_count; unsigned long mid_file_count; unsigned long lft_file_count; unsigned long top_width; - + extern unsigned int status; +extern unsigned long selected_file_current; +extern unsigned long selected_file_last; void *thread_mid(void *data){ pthread_mutex_lock(&mutex_mid); @@ -48,6 +50,18 @@ void *thread_mid(void *data){ memset(mid_content, ' ', mid_file_count * sizeof(file)); get_dir_content(path, &mid_file_count, mid_content); + + pthread_mutex_lock(&mutex_selection); + if (selected_file_current >= mid_file_count) { + selected_file_current = mid_file_count-1; + } + mid_content[selected_file_current].status = FILE_STATUS_HOVER; + if (selected_file_current != selected_file_last) { + mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER; + } + selected_file_last = selected_file_current; + pthread_mutex_unlock(&mutex_selection); + } free(path); pthread_mutex_unlock(&mutex_mid); @@ -117,11 +131,12 @@ void threading_init(){ top_content = malloc(sizeof(char)); - - pthread_mutex_init(&mutex_top, NULL); pthread_mutex_init(&mutex_mid, NULL); pthread_mutex_init(&mutex_lft, NULL); + pthread_mutex_init(&mutex_selection, NULL); + selected_file_current = 0; + selected_file_last = 0; } void threading_free(){ free(rgt_content);