From e6fa58939f14ee032c7062b1ac6528e8ed47e767 Mon Sep 17 00:00:00 2001 From: a bellenir Date: Wed, 23 Jul 2014 22:41:30 +0000 Subject: [PATCH] add focused window to state --- source/screen.c | 10 +++------- source/screen.h | 8 ++++++++ source/state.c | 14 +++++++------- source/state.h | 5 +++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/source/screen.c b/source/screen.c index 8357496..89aed2b 100644 --- a/source/screen.c +++ b/source/screen.c @@ -7,11 +7,6 @@ #include "vec.h" #include "mem.h" -typedef struct { - WINDOW* p_win; - WorkDir_T* workdir; -} frame_t; - static void screen_place_windows(void); static frame_t* screen_frame_new(void); static void screen_frame_free(void* p_frame); @@ -23,6 +18,7 @@ static vec_t* Screen_List; void screen_init(void) { Master = screen_frame_new(); Screen_List = vec_new(0); + state_set_focused_frame(Master); } void screen_update(void) { @@ -105,12 +101,12 @@ void screen_frame_draw_files(frame_t* frame){ wattroff(frame->p_win, A_UNDERLINE); //list files while (i < vec_size(frame->workdir->vfiles)){ - if(i == frame->workdir->idx){ + if(frame == state_get_focused_frame() && i == frame->workdir->idx){ wattron(frame->p_win, A_STANDOUT); wattron(frame->p_win, A_BOLD); } mvwaddnstr(frame->p_win, FrameTopBuffer+i-frame->workdir->top_index, 1, vec_at(frame->workdir->vfiles, i), cols-2); - if(i == frame->workdir->idx){ + if(frame == state_get_focused_frame() && i == frame->workdir->idx){ wattroff(frame->p_win, A_STANDOUT); wattroff(frame->p_win, A_BOLD); } diff --git a/source/screen.h b/source/screen.h index ef8a669..ff017f6 100644 --- a/source/screen.h +++ b/source/screen.h @@ -7,6 +7,9 @@ #ifndef SCREEN_H #define SCREEN_H +#include +#include "workdir.h" + void screen_init(void); void screen_update(void); void screen_open(void); @@ -16,4 +19,9 @@ void screen_close(void); static int FrameTopBuffer = 2; static int FrameBotBuffer = 2; +typedef struct { + WINDOW* p_win; + WorkDir_T* workdir; +} frame_t; + #endif /* SCREEN_H */ diff --git a/source/state.c b/source/state.c index 18532da..e8158c3 100644 --- a/source/state.c +++ b/source/state.c @@ -1,4 +1,5 @@ #include "state.h" +#include "screen.h" /** Whether the system is currently running or not. */ static bool Running = true; @@ -12,8 +13,8 @@ static bool Resized = true; /** Whether the aardvark should be displayed */ static bool AardvarkOn = false; -/** The currently focused frame id */ -static int Focused_Index = 0; +/** A pointer to the currently focused frame */ +static frame_t* Focused_Frame = 0; bool state_get_running(void) { @@ -55,13 +56,12 @@ void state_set_aardvark_mode(bool val) AardvarkOn = val; } -int state_get_focused_frame(void) -{ - return Focused_Index; +frame_t* state_get_focused_frame(void) { + return Focused_Frame; } -void state_set_focused_frame(int id) +void state_set_focused_frame(frame_t *p_frame) { - Focused_Index = id; + Focused_Frame = p_frame; } diff --git a/source/state.h b/source/state.h index 6c89af8..92d89d6 100644 --- a/source/state.h +++ b/source/state.h @@ -8,6 +8,7 @@ #define STATE_H #include +#include "screen.h" bool state_get_running(void); void state_set_running(bool val); @@ -17,7 +18,7 @@ bool state_get_screen_resized(void); void state_set_screen_resized(bool val); bool state_get_aardvark_mode(void); void state_set_aardvark_mode(bool val); -int state_get_focused_frame(void); -void state_set_focused_frame(int id); +frame_t* state_get_focused_frame(void); +void state_set_focused_frame(frame_t* p_frame); #endif /* STATE_H */ -- 2.54.0