/* What the app's files share; the core's is sky.h */
#ifndef SKY_APP_H
#define SKY_APP_H
#include <c8ui/c8ui.h>
#include <c8ui/c8ui-charms.h>
#include <c8ui/c8ui-files.h>
#include <c8ui/c8ui-wayland.h>
#include "sky.h"
#ifndef SKY_GLYPHS
#define SKY_GLYPHS "/usr/local/share/c8-cirrus"
#endif
#define BACKGROUND 0xe9eef3
#define CARD 0xffffff
#define CARD_HOVER 0xf5f8fb
#define INK 0x1b2127
#define BLUE 0x0a7aff
#define LIKED 0xe0245e
#define REPOSTED 0x12995a
#define BAR 0x0b2740 // the nav bar
#define BAR_TILE 0x14507f
#define COLUMN_W 440 // the hub's columns of posts: a reading width
#define COLUMN_GAP 10 // between columns: what a c8ui list puts there
#define FORM_W 620 // the composer
#define NARROW_PAD 10
#define PAGE_PAD 24
/* A page, wide: Metro's grid, the title and content 120 in from the left,
* posts in one reading column at most PAGE_COLUMN wide */
#define PAGE_LEFT 120
#define PAGE_COLUMN 680
#define PAD_COLUMN (-1) // ui_pad's right: what is left beside the column
#define TRAIL_W 520 // a column of a trail (Miller columns, pages.c)
/* cards.c: an entry of a list, measured, drawn and pressed */
enum card_part {
PART_NONE,
PART_BODY, // anywhere else on it
PART_AUTHOR,
PART_REPLY,
PART_REPOST,
PART_LIKE,
PART_MEDIA, // sub: which picture
PART_VIDEO,
PART_EXTERNAL,
PART_QUOTE,
PART_LINK, // sub: which of the post's links
PART_FOLLOW, // a person's Follow button
};
double card_height(const char *family, struct sky_item *it, double width);
/* False: a picture was still on its way, so this isn't how it will look */
bool card_draw(cairo_t *cr, const char *family, struct sky_item *it,
struct c8ui_rect r, const struct c8ui_list_item *state);
enum card_part card_hit(const char *family, struct sky_item *it,
struct c8ui_rect r, double x, double y, int *sub);
/* 950, 1.2K, 36K, 1.5M */
void card_count(int count, char *text, size_t size);
/* The little pictures of the action row, for other drawing */
void card_glyph(cairo_t *cr, const char *name, double x, double y, double s,
bool filled);
/* feeds.c: a list of posts (or notices, or people) and where it comes
* from. It outlives its widgets: the hub's are kept while the hub is
* built again for another width. */
enum view_kind {
VIEW_TIMELINE,
VIEW_FEED, // param: the feed's address
VIEW_LIST, // param: the list's
VIEW_AUTHOR, // param: a DID; filter: getAuthorFeed's
VIEW_SEARCH, // param: the words; filter: top or latest
VIEW_PEOPLE, // param: the words
VIEW_FOLLOWERS, // param: a DID
VIEW_FOLLOWS,
VIEW_NOTICES,
VIEW_THREAD, // param: the post's address
};
enum view_shape {
SHAPE_COLUMN, // one column, as wide as the hub's (g.column_w)
SHAPE_PAGE, // one column: a page's reading column (wide) or the window's
SHAPE_TRAIL, // a trail's column (pages.c), TRAIL_W; narrow the window's
};
struct feedview {
int refs;
enum view_kind kind;
enum view_shape shape;
char *param, *filter, *name;
GPtrArray *items; // struct sky_item
char *cursor;
bool loading, ended, loaded;
bool mark_seen; // notices: tell the server they were seen, once loaded
char *error;
unsigned gen; // the account it was asked for
int serial; // goes up with every reload: a late answer is dropped
struct c8ui_widget *box, *list, *status; // NULL while it has no widgets
double width; // of a column
int columns; // how many there are across
/* Its posts' pictures as square tiles, three across (a profile's
* Media): view_set_tiles */
bool tiles;
/* Runs after each answer is in (a thread scrolls to its post) */
void (*on_loaded)(struct feedview *fv, void *data);
void *on_loaded_data;
};
struct feedview *view_new(enum view_kind kind, const char *param,
const char *filter, const char *name);
struct feedview *view_ref(struct feedview *fv);
void view_unref(struct feedview *fv);
/* A box with the list in it (to put in a scroll); one at a time */
struct c8ui_widget *view_widget(struct feedview *fv, enum view_shape shape);
void view_reload(struct feedview *fv);
void view_ensure(struct feedview *fv); // loads it if it never was
void view_resized(struct feedview *fv); // the window's width changed
void view_changed(struct feedview *fv); // its items look different
void view_set_tiles(struct feedview *fv, bool tiles);
struct sky_item *view_selected(struct feedview *fv);
void views_redraw(void); // posts changed, or their ages
void views_pictures(void); // a picture came
void views_resized(void);
void views_forget_account(void); // everything shown is the old account's
/* Loads again every list on screen of a kind (-1: all of them) */
void views_reload(int kind);
/* Our follow of someone changed (uri NULL: no more), a post was deleted */
void views_set_follow(const char *did, const char *uri);
void views_remove_post(const char *uri);
/* main.c */
struct app {
struct c8ui_app *app;
struct c8ui_window *win;
struct c8ui_root *root;
/* stack: deck (holding main, the hub), then the pages
* over it, each the whole window */
struct c8ui_widget *stack, *main, *deck;
struct c8ui_widget *appbar, *navbar;
struct c8ui_charms *charms;
bool narrow;
double column_w; // the hub's columns
/* struct feedview: Following and the notifications (the hub's
* columns), then the pinned feeds */
GPtrArray *sections;
GPtrArray *saved; // struct sky_saved, NULL until the preferences come
struct sky_post *target; // what the app bar acts on
struct sky_profile *me;
int unread; // notifications
};
extern struct app g;
double ui_width(void); // the window's
void ui_error(const char *message);
void ui_push(struct c8ui_widget *page); // over the whole window
void ui_open_page(struct c8ui_widget *page); // the same: Back comes back
void ui_close_pages(void);
void ui_pop(void);
void ui_back(void); // what the back button and Escape do: may ask first
/* A record of ours made (fields: the record's members after its type and
* date, starting with a comma) or deleted by its address */
void ui_create_record(const char *collection, const char *fields, sky_fn fn,
void *data);
void ui_delete_record(const char *collection, const char *uri, sky_fn fn,
void *data);
void ui_home(void); // back to the hub
void ui_rebuild(void); // the hub again: the account or its feeds changed
void ui_set_target(struct sky_post *post);
void ui_show_bars(void);
/* An entry was clicked, tapped or opened with Enter (part PART_BODY) */
void ui_activate(struct feedview *fv, struct sky_item *it,
enum card_part part, int sub);
void ui_like(struct sky_post *post);
void ui_repost(struct sky_post *post);
/* Follows, or stops: follow_uri is our follow of them, NULL if none */
void ui_follow(const char *did, const char *follow_uri);
void ui_play(struct sky_post *post); // its video
void ui_open_uri(const char *uri); // a web address, or at://
void ui_signed_in(void); // an account was added or chosen
/* A box's paddings wide, and narrow (smaller, set on the box, which
* switches by itself); right may be PAD_COLUMN, kept up with the width */
void ui_pad(struct c8ui_widget *box, double left, double top, double right,
double bottom);
/* home.c: the hub (narrow, c8ui's pivot of it) */
struct c8ui_widget *home_new(struct feedview *timeline,
struct feedview *notices);
double home_hero_width(void);
void home_resized(void); // the hero follows the width
void home_timeline_loaded(void); // the hero is picked again
void home_redraw(void); // pictures came, the minute, our profile, stealth
/* A hub's section: "Name ›" (open NULL: just the name) over the content;
* scrolls: the content goes up and down, so it keeps the wheel */
struct c8ui_widget *hub_section_new(const char *name, void (*open)(void),
struct c8ui_widget *content, bool scrolls);
/* Its header shows narrow too (a trail's column) */
void hub_section_keep_head(struct c8ui_widget *sec);
/* pages.c */
/* The back button and the title over the body, the window's width */
struct c8ui_widget *page_new(const char *title, struct c8ui_widget **body);
void page_set_title(struct c8ui_widget *page, const char *title);
void open_thread(const char *uri);
void open_profile(const char *actor); // a DID or a handle
void open_feed(enum view_kind kind, const char *param, const char *filter,
const char *title);
void open_notifications(void);
void open_search(const char *query);
void open_feeds(void);
void open_accounts(void);
void pages_stealth_changed(void); // profiles and Accounts shown again
void open_viewer(struct sky_post *post, int index);
struct c8ui_widget *welcome_new(void); // the sign-in form, as the main view
void profile_set_follow(const char *did, const char *uri);
/* A scroll with a view's list in it, the pads a page's content has */
struct c8ui_widget *view_scroller(struct feedview *fv, enum view_shape shape);
/* Trails: feeds and threads in Miller columns. Opens a post as the
* column after the one fv is in; false if fv isn't in a trail. */
bool trail_open_thread(struct feedview *fv, const char *uri);
bool trail_has(struct feedview *fv);
bool trail_back(void); // closed the last column of the trail on top
/* compose.c */
void open_compose(struct sky_post *reply, struct sky_post *quote,
const char *text);
/* False: there is a post half written, and it asked what to do with it */
bool compose_may_leave(void);
#endif