/*
* DWN - Desktop Window Manager
* retoor <retoor@molodetz.nl>
* News ticker for bottom panel
*/
#ifndef DWN_NEWS_H
#define DWN_NEWS_H
#include "dwn.h"
#include <stdbool.h>
/* Maximum articles to cache */
#define MAX_NEWS_ARTICLES 50
#define NEWS_API_URL "https://news.app.molodetz.nl/api"
/* Sentiment classification */
typedef enum {
SENTIMENT_NEUTRAL = 0,
SENTIMENT_POSITIVE,
SENTIMENT_NEGATIVE
} NewsSentiment;
/* News article */
typedef struct {
char title[256];
char content[1024];
char link[512];
char author[128];
NewsSentiment sentiment;
float sentiment_score;
} NewsArticle;
/* News ticker state */
typedef struct {
NewsArticle articles[MAX_NEWS_ARTICLES];
int article_count;
int current_article; /* Currently displayed article index */
double scroll_offset; /* Sub-pixel offset for smooth scrolling */
bool fetching; /* Currently fetching from API */
bool has_error; /* Last fetch failed */
long last_fetch; /* Timestamp of last fetch */
long last_scroll_update; /* Timestamp of last scroll update */
bool interactive_mode; /* User is navigating with up/down */
int display_widths[MAX_NEWS_ARTICLES]; /* Cached text widths */
int total_width; /* Total scrollable width */
int render_x; /* X position where news starts rendering */
int render_width; /* Width of news render area */
bool widths_dirty; /* Need to recalculate widths */
} NewsState;
/* Global state */
extern NewsState news_state;
/* Initialization */
void news_init(void);
void news_cleanup(void);
/* Fetching */
void news_fetch_async(void);
void news_update(void); /* Called from main loop */
/* Navigation */
void news_next_article(void);
void news_prev_article(void);
void news_open_current(void);
/* Rendering */
void news_render(Panel *panel, int x, int max_width, int *used_width);
void news_handle_click(int x, int y);
/* Thread-safe access */
void news_lock(void);
void news_unlock(void);
#endif /* DWN_NEWS_H */