summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0b2eee9)
raw | patch | inline | side by side (parent: 0b2eee9)
author | Max Kellermann <max@duempel.org> | |
Fri, 3 Oct 2008 12:31:00 +0000 (14:31 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 3 Oct 2008 12:31:00 +0000 (14:31 +0200) |
screen_t is a singleton. We do not have to pass it around
everywhere. Export the one global variable.
everywhere. Export the one global variable.
14 files changed:
diff --git a/src/screen.c b/src/screen.c
index 5345f49ef8665bca530a20689d533742797d1a64..ea6d5d4bad36e2c88f9eec0c23cfd0ee76d1bc89 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
/* screens */
static gboolean welcome = TRUE;
-static struct screen screen;
+struct screen screen;
static const struct screen_functions *mode_fn = &screen_playlist;
static int seek_id = -1;
static int seek_target_time = 0;
/* open the new mode */
if (mode_fn->open != NULL)
- mode_fn->open(&screen, c);
+ mode_fn->open(c);
screen_paint(c);
}
screen.main_window.cols, screen.main_window.rows);
if (mode_fn->open != NULL)
- mode_fn->open(&screen, c);
+ mode_fn->open(c);
/* initialize wreadln */
wrln_wgetch = my_wgetch;
screen.last_cmd = cmd;
welcome = FALSE;
- if (mode_fn->cmd != NULL && mode_fn->cmd(&screen, c, cmd))
+ if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
return;
if (screen_client_cmd(c, cmd))
diff --git a/src/screen.h b/src/screen.h
index 976c75c9012dc0bce8b1fdfce39f0767f0da2715..ef7940a31e45dfcda744f6d2633065b3c479d039 100644 (file)
--- a/src/screen.h
+++ b/src/screen.h
unsigned rows, cols;
};
-typedef struct screen {
+struct screen {
struct window top_window;
struct window main_window;
struct window progress_window;
char *findbuf;
GList *find_history;
-} screen_t;
+};
+
+extern struct screen screen;
extern const struct screen_functions screen_playlist;
extern const struct screen_functions screen_browse;
typedef struct screen_functions {
void (*init)(WINDOW *w, int cols, int rows);
void (*exit)(void);
- void (*open)(struct screen *screen, mpdclient_t *c);
+ void (*open)(mpdclient_t *c);
void (*close)(void);
void (*resize)(int cols, int rows);
void (*paint)(void);
void (*update)(mpdclient_t *c);
- int (*cmd)(struct screen *scr, mpdclient_t *c, command_t cmd);
+ int (*cmd)(mpdclient_t *c, command_t cmd);
const char *(*get_title)(char *s, size_t size);
} screen_functions_t;
diff --git a/src/screen_artist.c b/src/screen_artist.c
index 52b7eeee8727753ec4ffd92d9edf3d998f8e4dff..846902e0a4807d09cfcc0216be595887d359ec45 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
}
static void
-open(mpd_unused screen_t *screen, mpdclient_t *c)
+open(mpdclient_t *c)
{
static gboolean callback_installed = FALSE;
}
static int
-artist_lw_cmd(struct screen *screen, struct mpdclient *c, command_t cmd)
+artist_lw_cmd(struct mpdclient *c, command_t cmd)
{
switch (mode) {
case LIST_ARTISTS:
return list_window_cmd(browser.lw, metalist_length(), cmd);
case LIST_SONGS:
- return browser_cmd(&browser, screen, c, cmd);
+ return browser_cmd(&browser, c, cmd);
}
assert(0);
}
static int
-artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
+artist_cmd(mpdclient_t *c, command_t cmd)
{
char *selected;
char *old;
case CMD_LIST_RFIND_NEXT:
switch (mode) {
case LIST_ARTISTS:
- screen_find(screen,
- browser.lw, artist_list->len,
+ screen_find(browser.lw, artist_list->len,
cmd, artist_lw_callback, artist_list);
artist_repaint();
return 1;
case LIST_ALBUMS:
- screen_find(screen,
- browser.lw, album_list->len + 2,
+ screen_find(browser.lw, album_list->len + 2,
cmd, artist_lw_callback, album_list);
artist_repaint();
return 1;
break;
}
- if (artist_lw_cmd(screen, c, cmd)) {
+ if (artist_lw_cmd(c, cmd)) {
artist_repaint();
return 1;
}
diff --git a/src/screen_browser.c b/src/screen_browser.c
index e68e7028556ac27feac7825754b4b09f99e7d40a..00965edb0e07e493f61ac4ef07d34da79525ad60 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
#endif
bool
-browser_cmd(struct screen_browser *browser, struct screen *screen,
+browser_cmd(struct screen_browser *browser,
struct mpdclient *c, command_t cmd)
{
struct filelist_entry *entry;
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(screen,
- browser->lw, filelist_length(browser->filelist),
+ screen_find(browser->lw, filelist_length(browser->filelist),
cmd, browser_lw_callback,
browser->filelist);
return true;
diff --git a/src/screen_browser.h b/src/screen_browser.h
index 17e41f6ec06094bce455693c90ce88cf5af179c6..802886aa0b75b8e167c9b222a9245782a6ecbe3c 100644 (file)
--- a/src/screen_browser.h
+++ b/src/screen_browser.h
filelist_entry_t *entry, const char *new_path);
bool
-browser_cmd(struct screen_browser *browser, struct screen *screen,
+browser_cmd(struct screen_browser *browser,
struct mpdclient *c, command_t cmd);
#endif
diff --git a/src/screen_file.c b/src/screen_file.c
index 9dfe4ac6892d8822c7b4e0aded8326237384b353..bef155f5948e10669e9c728c56b54bc2c2efa979 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
}
static int
-handle_save(screen_t *screen, mpdclient_t *c)
+handle_save(mpdclient_t *c)
{
filelist_entry_t *entry;
char *defaultname = NULL;
}
}
- return playlist_save(screen, c, NULL, defaultname);
+ return playlist_save(c, NULL, defaultname);
}
static int
-handle_delete(screen_t *screen, mpdclient_t *c)
+handle_delete(mpdclient_t *c)
{
filelist_entry_t *entry;
mpd_InfoEntity *entity;
str = utf8_to_locale(g_basename(plf->path));
buf = g_strdup_printf(_("Delete playlist %s [%s/%s] ? "), str, YES, NO);
g_free(str);
- key = tolower(screen_getch(screen->status_window.w, buf));
+ key = tolower(screen_getch(screen.status_window.w, buf));
g_free(buf);
if( key != YES[0] ) {
screen_status_printf(_("Aborted!"));
}
static void
-browse_open(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c)
+browse_open(mpd_unused mpdclient_t *c)
{
if (browser.filelist == NULL) {
browser.filelist = mpdclient_filelist_get(c, "");
}
static int
-browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
+browse_cmd(mpdclient_t *c, command_t cmd)
{
switch(cmd) {
case CMD_GO_ROOT_DIRECTORY:
return 1;
case CMD_DELETE:
- handle_delete(screen, c);
+ handle_delete(c);
file_repaint();
break;
case CMD_SAVE_PLAYLIST:
- handle_save(screen, c);
+ handle_save(c);
break;
case CMD_SCREEN_UPDATE:
browser.filelist = mpdclient_filelist_update(c, browser.filelist);
break;
}
- if (browser_cmd(&browser, screen, c, cmd)) {
+ if (browser_cmd(&browser, c, cmd)) {
file_repaint();
return 1;
}
diff --git a/src/screen_help.c b/src/screen_help.c
index fbcbf2b820f4fc40200415c93708fb2f292fea3d..3b66403d7c88202be2245ae69ed69e1781107e99 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
}
static int
-help_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd)
+help_cmd(mpd_unused mpdclient_t *c, command_t cmd)
{
if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
list_window_paint(lw, list_callback, NULL);
}
lw->selected = lw->start+lw->rows;
- if (screen_find(screen,
- lw, help_text_rows,
+ if (screen_find(lw, help_text_rows,
cmd, list_callback, NULL)) {
/* center the row */
list_window_center(lw, help_text_rows, lw->selected);
diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index b84289d5bb1e8bdcee6767125685e7d4db9c54fb..86faabaf403da448279f67e8f994095571e12604 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
}
static void
-keydef_open(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c)
+keydef_open(mpd_unused mpdclient_t *c)
{
if (cmds == NULL) {
command_definition_t *current_cmds = get_command_definitions();
}
static int
-keydef_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd)
+keydef_cmd(mpd_unused mpdclient_t *c, command_t cmd)
{
int length = LIST_LENGTH();
keydef_repaint();
} else
- assign_new_key(screen->status_window.w,
+ assign_new_key(screen.status_window.w,
subcmd,
lw->selected - STATIC_SUB_ITEMS);
}
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(screen,
- lw, length,
+ screen_find(lw, length,
cmd, list_callback, NULL);
keydef_repaint();
return 1;
diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c
index be99e6b750847a511484f37be22053f164ce4d30..2a8e10b67fad0f6bc4c180994bdc37d17492c006 100644 (file)
--- a/src/screen_lyrics.c
+++ b/src/screen_lyrics.c
}
static void
-lyrics_open(mpd_unused screen_t *screen, mpdclient_t *c)
+lyrics_open(mpdclient_t *c)
{
if (next_song == NULL)
next_song = c->song;
}
static int
-lyrics_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
+lyrics_cmd(mpdclient_t *c, command_t cmd)
{
if (list_window_scroll_cmd(lw, current.lines->len, cmd)) {
lyrics_repaint();
}
lw->selected = lw->start+lw->rows;
- if (screen_find(screen,
- lw, current.lines->len,
+ if (screen_find(lw, current.lines->len,
cmd, list_callback, NULL)) {
/* center the row */
list_window_center(lw, current.lines->len, lw->selected);
diff --git a/src/screen_play.c b/src/screen_play.c
index 4b285c533c52b9add633fc33900e49841d24517d..37705c559d4a8800df1903d575b93b4c2e19200a 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
{
GList **list;
GList **dir_list;
- screen_t *screen;
mpdclient_t *c;
} completion_callback_data_t;
static void
save_post_completion_cb(mpd_unused GCompletion *gcmp, mpd_unused gchar *line,
- GList *items, void *data)
+ GList *items, mpd_unused void *data)
{
- completion_callback_data_t *tmp = (completion_callback_data_t *)data;
- screen_t *screen = tmp->screen;
-
if (g_list_length(items) >= 1)
- screen_display_completion_list(screen, items);
+ screen_display_completion_list(items);
}
int
-playlist_save(screen_t *screen, mpdclient_t *c, char *name, char *defaultname)
+playlist_save(mpdclient_t *c, char *name, char *defaultname)
{
gchar *filename;
gint error;
g_completion_set_compare(gcmp, strncmp);
data.list = &list;
data.dir_list = NULL;
- data.screen = screen;
data.c = c;
wrln_completion_callback_data = &data;
wrln_pre_completion_callback = save_pre_completion_cb;
/* query the user for a filename */
- filename = screen_readln(screen->status_window.w,
+ filename = screen_readln(screen.status_window.w,
_("Save playlist as: "),
defaultname,
NULL,
buf = g_strdup_printf(_("Replace %s [%s/%s] ? "),
filename, YES, NO);
- key = tolower(screen_getch(screen->status_window.w,
+ key = tolower(screen_getch(screen.status_window.w,
buf));
g_free(buf);
return -1;
}
- error = playlist_save(screen, c, filename, NULL);
+ error = playlist_save(c, filename, NULL);
g_free(filename);
return error;
}
GList **dir_list = tmp->dir_list;
GList **list = tmp->list;
mpdclient_t *c = tmp->c;
- screen_t *screen = tmp->screen;
if (g_list_length(items) >= 1)
- screen_display_completion_list(screen, items);
+ screen_display_completion_list(items);
if (line && line[0] && line[strlen(line) - 1] == '/' &&
string_list_find(*dir_list, line) == NULL) {
}
static int
-handle_add_to_playlist(screen_t *screen, mpdclient_t *c)
+handle_add_to_playlist(mpdclient_t *c)
{
gchar *path;
GCompletion *gcmp;
g_completion_set_compare(gcmp, strncmp);
data.list = &list;
data.dir_list = &dir_list;
- data.screen = screen;
data.c = c;
wrln_completion_callback_data = &data;
wrln_pre_completion_callback = add_pre_completion_cb;
wrln_post_completion_callback = add_post_completion_cb;
/* get path */
- path = screen_readln(screen->status_window.w,
+ path = screen_readln(screen.status_window.w,
_("Add: "),
NULL,
NULL,
}
static void
-play_open(mpd_unused screen_t *screen, mpdclient_t *c)
+play_open(mpdclient_t *c)
{
static gboolean install_cb = TRUE;
#endif
static int
-play_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
+play_cmd(mpdclient_t *c, command_t cmd)
{
lw->flags &= ~LW_HIDE_CURSOR;
mpdclient_cmd_delete(c, lw->selected);
return 1;
case CMD_SAVE_PLAYLIST:
- playlist_save(screen, c, NULL, NULL);
+ playlist_save(c, NULL, NULL);
return 1;
case CMD_ADD:
- handle_add_to_playlist(screen, c);
+ handle_add_to_playlist(c);
return 1;
case CMD_SCREEN_UPDATE:
center_playing_item(c);
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(screen,
- lw, playlist_length(&c->playlist),
+ screen_find(lw, playlist_length(&c->playlist),
cmd, list_callback, NULL);
playlist_repaint();
return 1;
diff --git a/src/screen_play.h b/src/screen_play.h
index 36d57a2fad07fb5335f4182407dce45c8ecd062b..3ff3cb02aa56f5c40eda22902e27e7bb24e6419c 100644 (file)
--- a/src/screen_play.h
+++ b/src/screen_play.h
-int playlist_save(screen_t *screen, mpdclient_t *c, char *name, char *defaultname);
+int playlist_save(mpdclient_t *c, char *name, char *defaultname);
diff --git a/src/screen_search.c b/src/screen_search.c
index bf9278b53fa4c6280c946c486fad02ed8f042660..4e2f922ec0caa39c7bf669eedb10857732378a2c 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
}
static void
-search_clear(mpd_unused screen_t *screen, mpdclient_t *c,
+search_clear(mpdclient_t *c,
gboolean clear_pattern)
{
if (browser.filelist) {
}
static void
-search_new(screen_t *screen, mpdclient_t *c)
+search_new(mpdclient_t *c)
{
- search_clear(screen, c, TRUE);
+ search_clear(c, TRUE);
- pattern = screen_readln(screen->status_window.w,
+ pattern = screen_readln(screen.status_window.w,
_("Search: "),
NULL,
&search_history,
}
static void
-open(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c)
+open(mpd_unused mpdclient_t *c)
{
// if( pattern==NULL )
// search_new(screen, c);
}
static int
-search_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
+search_cmd(mpdclient_t *c, command_t cmd)
{
switch (cmd) {
case CMD_SEARCH_MODE:
/* continue and update... */
case CMD_SCREEN_UPDATE:
if (pattern) {
- search_clear(screen, c, FALSE);
+ search_clear(c, FALSE);
browser.filelist = filelist_search(c,
FALSE,
mode[options.search_mode].table,
return 1;
case CMD_SCREEN_SEARCH:
- search_new(screen, c);
+ search_new(c);
search_repaint();
return 1;
case CMD_CLEAR:
- search_clear(screen, c, TRUE);
+ search_clear(c, TRUE);
list_window_reset(browser.lw);
search_repaint();
return 1;
}
if (browser.filelist != NULL &&
- browser_cmd(&browser, screen, c, cmd)) {
+ browser_cmd(&browser, c, cmd)) {
search_repaint();
return 1;
}
diff --git a/src/screen_utils.c b/src/screen_utils.c
index d83015503abd4310bdc268239fb4d2b694359e01..5134756163f4686865e96783d0a86844f9e3fbda 100644 (file)
--- a/src/screen_utils.c
+++ b/src/screen_utils.c
/* query user for a string and find it in a list window */
int
-screen_find(screen_t *screen,
- list_window_t *lw,
+screen_find(list_window_t *lw,
int rows,
command_t findcmd,
list_window_callback_fn_t callback_fn,
switch (findcmd) {
case CMD_LIST_FIND:
case CMD_LIST_RFIND:
- if (screen->findbuf) {
- g_free(screen->findbuf);
- screen->findbuf=NULL;
+ if (screen.findbuf) {
+ g_free(screen.findbuf);
+ screen.findbuf=NULL;
}
/* continue... */
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- if (!screen->findbuf)
- screen->findbuf=screen_readln(screen->status_window.w,
- prompt,
- value,
- &screen->find_history,
- NULL);
-
- if (!screen->findbuf || !screen->findbuf[0])
+ if (!screen.findbuf)
+ screen.findbuf=screen_readln(screen.status_window.w,
+ prompt,
+ value,
+ &screen.find_history,
+ NULL);
+
+ if (!screen.findbuf || !screen.findbuf[0])
return 1;
if (reversed)
retval = list_window_rfind(lw,
callback_fn,
callback_data,
- screen->findbuf,
+ screen.findbuf,
options.find_wrap,
rows);
else
retval = list_window_find(lw,
callback_fn,
callback_data,
- screen->findbuf,
+ screen.findbuf,
options.find_wrap);
if (retval != 0) {
- screen_status_printf(_("Unable to find \'%s\'"), screen->findbuf);
+ screen_status_printf(_("Unable to find \'%s\'"),
+ screen.findbuf);
screen_bell();
}
return 1;
}
void
-screen_display_completion_list(screen_t *screen, GList *list)
+screen_display_completion_list(GList *list)
{
static GList *prev_list = NULL;
static guint prev_length = 0;
static guint offset = 0;
- WINDOW *w = screen->main_window.w;
+ WINDOW *w = screen.main_window.w;
guint length, y=0;
length = g_list_length(list);
if (list == prev_list && length == prev_length) {
- offset += screen->main_window.rows;
+ offset += screen.main_window.rows;
if (offset >= length)
offset = 0;
} else {
}
colors_use(w, COLOR_STATUS_ALERT);
- while (y < screen->main_window.rows) {
+ while (y < screen.main_window.rows) {
GList *item = g_list_nth(list, y+offset);
wmove(w, y++, 0);
diff --git a/src/screen_utils.h b/src/screen_utils.h
index 74ca7d0126704707c9716ca4b3825d2cb3c6dff9..a550f17428301d6864bcd6da274ff3ebbe9fbd0f 100644 (file)
--- a/src/screen_utils.h
+++ b/src/screen_utils.h
#include <ncurses.h>
-struct screen;
struct mpdclient;
/* sound an audible and/or visible bell */
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(struct screen *screen,
- struct list_window *lw,
+int screen_find(struct list_window *lw,
int rows,
command_t findcmd,
list_window_callback_fn_t callback_fn,
gint screen_auth(struct mpdclient *c);
-void screen_display_completion_list(struct screen *screen, GList *list);
+void screen_display_completion_list(GList *list);
void set_xterm_title(const char *format, ...);