From: Max Kellermann Date: Tue, 16 Sep 2008 17:11:40 +0000 (+0200) Subject: screen: added struct names X-Git-Tag: v0.12_alpha1~286 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1f5d824d59709708350d37e6808383fc948e5dab;p=ncmpc.git screen: added struct names Let us declare struct names in addition to typedef names, so we can forward-declare them. --- diff --git a/src/list_window.c b/src/list_window.c index 01e15c0..297d3f6 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -31,10 +31,10 @@ extern void screen_bell(void); -list_window_t * +struct list_window * list_window_init(WINDOW *w, unsigned width, unsigned height) { - list_window_t *lw; + struct list_window *lw; lw = g_malloc0(sizeof(list_window_t)); lw->w = w; @@ -44,8 +44,8 @@ list_window_init(WINDOW *w, unsigned width, unsigned height) return lw; } -list_window_t * -list_window_free(list_window_t *lw) +struct list_window * +list_window_free(struct list_window *lw) { if (lw) { memset(lw, 0, sizeof(list_window_t)); @@ -56,7 +56,7 @@ list_window_free(list_window_t *lw) } void -list_window_reset(list_window_t *lw) +list_window_reset(struct list_window *lw) { lw->selected = 0; lw->xoffset = 0; @@ -65,7 +65,7 @@ list_window_reset(list_window_t *lw) } void -list_window_check_selected(list_window_t *lw, unsigned length) +list_window_check_selected(struct list_window *lw, unsigned length) { if (lw->start + lw->rows > length) { if (length > lw->rows) @@ -82,13 +82,13 @@ list_window_check_selected(list_window_t *lw, unsigned length) } void -list_window_set_selected(list_window_t *lw, unsigned n) +list_window_set_selected(struct list_window *lw, unsigned n) { lw->selected = n; } void -list_window_next(list_window_t *lw, unsigned length) +list_window_next(struct list_window *lw, unsigned length) { if (lw->selected + 1 < length) lw->selected++; @@ -97,7 +97,7 @@ list_window_next(list_window_t *lw, unsigned length) } void -list_window_previous(list_window_t *lw, unsigned length) +list_window_previous(struct list_window *lw, unsigned length) { if (lw->selected > 0) lw->selected--; @@ -106,14 +106,14 @@ list_window_previous(list_window_t *lw, unsigned length) } void -list_window_first(list_window_t *lw) +list_window_first(struct list_window *lw) { lw->xoffset = 0; lw->selected = 0; } void -list_window_last(list_window_t *lw, unsigned length) +list_window_last(struct list_window *lw, unsigned length) { lw->xoffset = 0; if (length > 0) @@ -123,7 +123,7 @@ list_window_last(list_window_t *lw, unsigned length) } void -list_window_next_page(list_window_t *lw, unsigned length) +list_window_next_page(struct list_window *lw, unsigned length) { if (lw->rows < 2) return; @@ -134,7 +134,7 @@ list_window_next_page(list_window_t *lw, unsigned length) } void -list_window_previous_page(list_window_t *lw) +list_window_previous_page(struct list_window *lw) { if (lw->rows < 2) return; @@ -146,7 +146,7 @@ list_window_previous_page(list_window_t *lw) void -list_window_paint(list_window_t *lw, +list_window_paint(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data) { @@ -201,7 +201,7 @@ list_window_paint(list_window_t *lw, } int -list_window_find(list_window_t *lw, +list_window_find(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data, const char *str, @@ -233,7 +233,7 @@ list_window_find(list_window_t *lw, } int -list_window_rfind(list_window_t *lw, +list_window_rfind(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data, const char *str, @@ -267,7 +267,7 @@ list_window_rfind(list_window_t *lw, /* perform basic list window commands (movement) */ int -list_window_cmd(list_window_t *lw, unsigned rows, command_t cmd) +list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd) { switch (cmd) { case CMD_LIST_PREVIOUS: @@ -331,10 +331,10 @@ list_window_free_state(list_window_state_t *state) } void -list_window_push_state(list_window_state_t *state, list_window_t *lw) +list_window_push_state(list_window_state_t *state, struct list_window *lw) { if (state) { - list_window_t *tmp = g_malloc(sizeof(list_window_t)); + struct list_window *tmp = g_malloc(sizeof(list_window_t)); memcpy(tmp, lw, sizeof(list_window_t)); state->list = g_list_prepend(state->list, (gpointer) tmp); list_window_reset(lw); @@ -342,10 +342,10 @@ list_window_push_state(list_window_state_t *state, list_window_t *lw) } bool -list_window_pop_state(list_window_state_t *state, list_window_t *lw) +list_window_pop_state(list_window_state_t *state, struct list_window *lw) { if (state && state->list) { - list_window_t *tmp = state->list->data; + struct list_window *tmp = state->list->data; memcpy(lw, tmp, sizeof(list_window_t)); g_free(tmp); diff --git a/src/list_window.h b/src/list_window.h index 2fadeeb..2efff8a 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -14,7 +14,7 @@ typedef const char *(*list_window_callback_fn_t)(unsigned index, int *highlight, void *data); -typedef struct { +typedef struct list_window { WINDOW *w; unsigned rows, cols; @@ -26,41 +26,42 @@ typedef struct { int flags; } list_window_t; -typedef struct { +typedef struct list_window_state { GList *list; } list_window_state_t; /* create a new list window */ -list_window_t *list_window_init(WINDOW *w, unsigned width, unsigned height); +struct list_window *list_window_init(WINDOW *w, + unsigned width, unsigned height); /* destroy a list window (returns NULL) */ -list_window_t *list_window_free(list_window_t *lw); +struct list_window *list_window_free(struct list_window *lw); /* reset a list window (selected=0, start=0, clear=1) */ -void list_window_reset(list_window_t *lw); +void list_window_reset(struct list_window *lw); /* paint a list window */ -void list_window_paint(list_window_t *lw, +void list_window_paint(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data); /* perform basic list window commands (movement) */ -int list_window_cmd(list_window_t *lw, unsigned rows, command_t cmd); +int list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd); /* select functions */ -void list_window_set_selected(list_window_t *lw, unsigned n); -void list_window_previous(list_window_t *lw, unsigned length); -void list_window_next(list_window_t *lw, unsigned length); -void list_window_first(list_window_t *lw); -void list_window_last(list_window_t *lw, unsigned length); -void list_window_previous_page(list_window_t *lw); -void list_window_next_page(list_window_t *lw, unsigned length); -void list_window_check_selected(list_window_t *lw, unsigned length); +void list_window_set_selected(struct list_window *lw, unsigned n); +void list_window_previous(struct list_window *lw, unsigned length); +void list_window_next(struct list_window *lw, unsigned length); +void list_window_first(struct list_window *lw); +void list_window_last(struct list_window *lw, unsigned length); +void list_window_previous_page(struct list_window *lw); +void list_window_next_page(struct list_window *lw, unsigned length); +void list_window_check_selected(struct list_window *lw, unsigned length); /* find a string in a list window */ -int list_window_find(list_window_t *lw, +int list_window_find(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data, const char *str, @@ -68,7 +69,7 @@ int list_window_find(list_window_t *lw, /* find a string in a list window (reversed) */ int -list_window_rfind(list_window_t *lw, +list_window_rfind(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data, const char *str, @@ -78,8 +79,9 @@ list_window_rfind(list_window_t *lw, /* list window states */ list_window_state_t *list_window_init_state(void); list_window_state_t *list_window_free_state(list_window_state_t *state); -void list_window_push_state(list_window_state_t *state, list_window_t *lw); -bool list_window_pop_state(list_window_state_t *state, list_window_t *lw); +void list_window_push_state(list_window_state_t *state, + struct list_window *lw); +bool list_window_pop_state(list_window_state_t *state, struct list_window *lw); diff --git a/src/screen.c b/src/screen.c index e89e4eb..da7e132 100644 --- a/src/screen.c +++ b/src/screen.c @@ -50,26 +50,23 @@ /* screens */ -extern screen_functions_t *get_screen_playlist(void); -extern screen_functions_t *get_screen_browse(void); -extern screen_functions_t *get_screen_help(void); -extern screen_functions_t *get_screen_search(void); -extern screen_functions_t *get_screen_artist(void); -extern screen_functions_t *get_screen_keydef(void); -extern screen_functions_t *get_screen_clock(void); -extern screen_functions_t *get_screen_lyrics(void); - -typedef screen_functions_t * (*screen_get_mode_functions_fn_t) (void); - -typedef struct +extern struct screen_functions *get_screen_playlist(void); +extern struct screen_functions *get_screen_browse(void); +extern struct screen_functions *get_screen_help(void); +extern struct screen_functions *get_screen_search(void); +extern struct screen_functions *get_screen_artist(void); +extern struct screen_functions *get_screen_keydef(void); +extern struct screen_functions *get_screen_clock(void); +extern struct screen_functions *get_screen_lyrics(void); + +typedef struct screen_functions * (*screen_get_mode_functions_fn_t) (void); + +static const struct { gint id; const gchar *name; screen_get_mode_functions_fn_t get_mode_functions; -} screen_mode_info_t; - - -static screen_mode_info_t screens[] = { +} screens[] = { { SCREEN_PLAYLIST_ID, "playlist", get_screen_playlist }, { SCREEN_BROWSE_ID, "browse", get_screen_browse }, #ifdef ENABLE_ARTIST_SCREEN @@ -93,7 +90,7 @@ static screen_mode_info_t screens[] = { static gboolean welcome = TRUE; static screen_t *screen = NULL; -static screen_functions_t *mode_fn = NULL; +static struct screen_functions *mode_fn = NULL; static int seek_id = -1; static int seek_target_time = 0; @@ -416,7 +413,7 @@ screen_exit(void) /* close and exit all screens (playlist,browse,help...) */ i=0; while (screens[i].get_mode_functions) { - screen_functions_t *sf = screens[i].get_mode_functions(); + struct screen_functions *sf = screens[i].get_mode_functions(); if (sf && sf->close) sf->close(); @@ -480,7 +477,7 @@ screen_resize(void) /* close and exit all screens (playlist,browse,help...) */ i=0; while (screens[i].get_mode_functions) { - screen_functions_t *sf = screens[i].get_mode_functions(); + struct screen_functions *sf = screens[i].get_mode_functions(); if (sf && sf->resize) sf->resize(screen->main_window.cols, screen->main_window.rows); @@ -629,7 +626,7 @@ screen_init(mpdclient_t *c) i=0; while( screens[i].get_mode_functions ) { - screen_functions_t *fn = screens[i].get_mode_functions(); + struct screen_functions *fn = screens[i].get_mode_functions(); if( fn && fn->init ) fn->init(screen->main_window.w, diff --git a/src/screen.h b/src/screen.h index d6f1620..06ce71d 100644 --- a/src/screen.h +++ b/src/screen.h @@ -1,8 +1,8 @@ #ifndef SCREEN_H #define SCREEN_H -#include "list_window.h" #include "mpdclient.h" +#include "command.h" #include #include @@ -13,17 +13,19 @@ #define MAX_SONGNAME_LENGTH 512 -typedef struct { +struct list_window; + +struct window { WINDOW *w; int rows, cols; int cur_action_id; -} window_t; +}; -typedef struct { - window_t top_window; - window_t main_window; - window_t progress_window; - window_t status_window; +typedef struct screen { + struct window top_window; + struct window main_window; + struct window progress_window; + struct window status_window; /* GTime is equivalent to time_t */ GTime start_timestamp; @@ -47,16 +49,16 @@ typedef struct { typedef void (*screen_init_fn_t)(WINDOW *w, int cols, int rows); typedef void (*screen_exit_fn_t)(void); -typedef void (*screen_open_fn_t)(screen_t *screen, mpdclient_t *c); +typedef void (*screen_open_fn_t)(struct screen *screen, mpdclient_t *c); typedef void (*screen_close_fn_t)(void); typedef void (*screen_resize_fn_t)(int cols, int rows); -typedef void (*screen_paint_fn_t)(screen_t *screen, mpdclient_t *c); -typedef void (*screen_update_fn_t)(screen_t *screen, mpdclient_t *c); -typedef int (*screen_cmd_fn_t)(screen_t *scr, mpdclient_t *c, command_t cmd); +typedef void (*screen_paint_fn_t)(struct screen *screen, mpdclient_t *c); +typedef void (*screen_update_fn_t)(struct screen *screen, mpdclient_t *c); +typedef int (*screen_cmd_fn_t)(struct screen *scr, mpdclient_t *c, command_t cmd); typedef const char *(*screen_title_fn_t)(char *s, size_t size); -typedef list_window_t *(*screen_get_lw_fn_t) (void); +typedef struct list_window *(*screen_get_lw_fn_t) (void); -typedef struct { +typedef struct screen_functions { screen_init_fn_t init; screen_exit_fn_t exit; screen_open_fn_t open; @@ -87,28 +89,28 @@ gint screen_get_id(const char *name); gint get_cur_mode_id(void); int screen_get_mouse_event(mpdclient_t *c, - list_window_t *lw, int lw_length, + struct list_window *lw, int lw_length, unsigned long *bstate, int *row); -screen_functions_t * +struct screen_functions * get_screen_search(void); -screen_functions_t * +struct screen_functions * get_screen_browse(void); -screen_functions_t * +struct screen_functions * get_screen_playlist(void); -screen_functions_t * +struct screen_functions * get_screen_help(void); -screen_functions_t * +struct screen_functions * get_screen_lyrics(void); -screen_functions_t * +struct screen_functions * get_screen_keydef(void); -screen_functions_t * +struct screen_functions * get_screen_clock(void); #endif diff --git a/src/screen_clock.c b/src/screen_clock.c index 995be67..493150b 100644 --- a/src/screen_clock.c +++ b/src/screen_clock.c @@ -28,7 +28,7 @@ #define ENABLE_SECONDS 0 -static window_t win; +static struct window win; static gboolean enable_seconds = ENABLE_SECONDS; /* orginal variables from gdc.c */ diff --git a/src/screen_utils.c b/src/screen_utils.c index d75116f..311c744 100644 --- a/src/screen_utils.c +++ b/src/screen_utils.c @@ -19,6 +19,8 @@ */ #include "screen_utils.h" +#include "screen.h" +#include "mpdclient.h" #include "config.h" #include "ncmpc.h" #include "support.h" @@ -120,7 +122,7 @@ screen_read_password(WINDOW *w, const char *prompt) } static gint -_screen_auth(mpdclient_t *c, gint recursion) +_screen_auth(struct mpdclient *c, gint recursion) { mpd_clearError(c->connection); if(recursion > 2) return 1; @@ -132,7 +134,7 @@ _screen_auth(mpdclient_t *c, gint recursion) } gint -screen_auth(mpdclient_t *c) +screen_auth(struct mpdclient *c) { gint ret = _screen_auth(c, 0); mpdclient_update(c); diff --git a/src/screen_utils.h b/src/screen_utils.h index 6928ba8..74ca7d0 100644 --- a/src/screen_utils.h +++ b/src/screen_utils.h @@ -1,13 +1,14 @@ #ifndef SCREEN_UTILS_H #define SCREEN_UTILS_H -#include "screen.h" #include "list_window.h" -#include "mpdclient.h" #include "command.h" #include +struct screen; +struct mpdclient; + /* sound an audible and/or visible bell */ void screen_bell(void); @@ -21,16 +22,16 @@ char *screen_readln(WINDOW *w, const char *prompt, const char *value, char *screen_readln_masked(WINDOW *w, const char *prompt); char *screen_read_pasword(WINDOW *w, const char *prompt); /* query user for a string and find it in a list window */ -int screen_find(screen_t *screen, - list_window_t *lw, +int screen_find(struct screen *screen, + struct list_window *lw, int rows, command_t findcmd, list_window_callback_fn_t callback_fn, void *callback_data); -gint screen_auth(mpdclient_t *c); +gint screen_auth(struct mpdclient *c); -void screen_display_completion_list(screen_t *screen, GList *list); +void screen_display_completion_list(struct screen *screen, GList *list); void set_xterm_title(const char *format, ...);