diff --git a/timetracker.c b/timetracker.c index 70a4c98..4d225e3 100644 --- a/timetracker.c +++ b/timetracker.c @@ -1,10 +1,10 @@ ////////////////////////////////////////////////////////////////////////// // TODOS: // // [X] Lower the the time text lower below the activity title. // -// [ ] On timeline, hower, display additional activity chunk info. // +// [X] On timeline, hower, display additional activity chunk info. // // [X] Display distribution timeline below the activity line. // // [ ] Better file save error handling. // -// [ ] Make Linux and MacOS libraries for RayLib; store locally. // +// [X] Make Linux and MacOS libraries for RayLib; store locally. // ////////////////////////////////////////////////////////////////////////// @@ -78,9 +78,7 @@ U64 now() return (U64)time(NULL); } -B32 activity_button(Rectangle rect, char *title, char *subtitle, - F32 font_size, Color font_color, - Color background_color) +B32 activity_button(Rectangle rect, char *title, char *subtitle, F32 font_size, Color font_color, Color background_color) { B32 button_pressed = false; @@ -274,7 +272,7 @@ void save_activities(FILE *f, char *file_path, U32 current_activity, activity *a // NOTE: We use "w+" because want to clear file contents before the next write. f = freopen(file_path, "w+", f); if(f) { - char write_buffer[128]; + local_persist char write_buffer[128]; for(U32 i = 0; i <= current_activity; i++) { snprintf(write_buffer, sizeof(write_buffer), "%s %llu %llu\n", activity_type_string_representation[activities[i].type], activities[i].began, activities[i].ended); @@ -290,6 +288,10 @@ void save_activities(FILE *f, char *file_path, U32 current_activity, activity *a } } +#define ACTIVE_FPS 60 +#define IDLE_FPS 1 +#define IDLE_TIME 5 /* seconds */ + int main(int argc, char *argv[]) { // TODO: Move into global state. @@ -321,7 +323,7 @@ int main(int argc, char *argv[]) InitWindow(state.window_w, state.window_h, "Time Tracker"); SetWindowState(FLAG_MSAA_4X_HINT|FLAG_WINDOW_RESIZABLE); - SetTargetFPS(30); + SetTargetFPS(ACTIVE_FPS); state.font = LoadFontFromMemory(".ttf", opensans_ttf, opensans_ttf_len, 96, NULL, 0); if(!IsFontValid(state.font)) { @@ -338,11 +340,20 @@ int main(int argc, char *argv[]) state.font_size = 30; - //DisableEventWaiting(); - //EnableEventWaiting(); + double last_input_s = now(); + while(!WindowShouldClose()) { U64 now_s = now(); + if(GetMouseDelta().x != 0 || GetMouseDelta().y != 0 || GetMouseWheelMove() != 0 || GetKeyPressed() != 0 || IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) { + last_input_s = now_s; + SetTargetFPS(ACTIVE_FPS); + } + + if(now_s - last_input_s > IDLE_TIME) { + SetTargetFPS(IDLE_FPS); + } + if(now_s >= upper_bound_s) { t = today(); ts = start_of_day_seconds(t);