summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e09ed2d)
raw | patch | inline | side by side (parent: e09ed2d)
author | Max Kellermann <max@duempel.org> | |
Sat, 3 Oct 2009 19:42:32 +0000 (21:42 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Sat, 3 Oct 2009 19:42:32 +0000 (21:42 +0200) |
src/hscroll.c | patch | blob | history | |
src/hscroll.h | patch | blob | history | |
src/screen_play.c | patch | blob | history | |
src/status_bar.c | patch | blob | history |
diff --git a/src/hscroll.c b/src/hscroll.c
index 065cb7054b0e573e35357368f4015ef67f4cf897..784c17d31c55794dc6d4499b20f850d2e2d33bf0 100644 (file)
--- a/src/hscroll.c
+++ b/src/hscroll.c
#include <ctype.h>
#include <string.h>
-// FIXME: utf-8 length
char *
-strscroll(char *str, char *separator, int width, scroll_state_t *st)
+strscroll(struct hscroll *hscroll, char *str, char *separator, unsigned width)
{
gchar *tmp, *buf;
gsize len, size;
+ assert(hscroll != NULL);
assert(str != NULL);
assert(separator != NULL);
- assert(st != NULL);
- if( st->offset==0 ) {
- st->offset++;
+ if (hscroll->offset == 0) {
+ ++hscroll->offset;
return g_strdup(str);
}
g_strlcat(tmp, separator, size);
len = utf8_width(tmp);
- if (st->offset >= len)
- st->offset = 0;
+ if (hscroll->offset >= len)
+ hscroll->offset = 0;
/* create the new scrolled string */
size = width+1;
if (g_utf8_validate(tmp, -1, NULL) ) {
- int ulen;
+ size_t ulen;
buf = g_malloc(size*6);// max length of utf8 char is 6
- g_utf8_strncpy(buf, g_utf8_offset_to_pointer(tmp,st->offset), size);
+ g_utf8_strncpy(buf, g_utf8_offset_to_pointer(tmp, hscroll->offset), size);
if( (ulen = g_utf8_strlen(buf, -1)) < width )
g_utf8_strncpy(buf+strlen(buf), tmp, size - ulen - 1);
} else {
buf = g_malloc(size);
- g_strlcpy(buf, tmp+st->offset, size);
+ g_strlcpy(buf, tmp + hscroll->offset, size);
if (strlen(buf) < (size_t)width)
g_strlcat(buf, tmp, size);
}
- if( time(NULL)-st->t >= 1 ) {
- st->t = time(NULL);
- st->offset++;
+
+ if (time(NULL) - hscroll->t >= 1) {
+ hscroll->t = time(NULL);
+ hscroll->offset++;
}
+
g_free(tmp);
return buf;
}
diff --git a/src/hscroll.h b/src/hscroll.h
index 9c15a9d49dbfb415026000879b133d9f813c7de6..8b643830de5dca63fccc3f9622f6b7c0669d2295 100644 (file)
--- a/src/hscroll.h
+++ b/src/hscroll.h
#include <glib.h>
-typedef struct {
+struct hscroll {
gsize offset;
GTime t; /* GTime is equivalent to time_t */
-} scroll_state_t;
+};
-char *strscroll(char *str, char *separator, int width, scroll_state_t *st);
+char *
+strscroll(struct hscroll *hscroll, char *str, char *separator, unsigned width);
#endif
diff --git a/src/screen_play.c b/src/screen_play.c
index aaaace14505572e2a152414918985477bc91c66d..3690dd341e3c84dbc2dee34a2918398ad19b6e3b 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
@@ -121,7 +121,7 @@ list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED
{
static char songname[MAX_SONG_LENGTH];
#ifndef NCMPC_MINI
- static scroll_state_t st;
+ static struct hscroll hscroll;
#endif
struct mpd_song *song;
@@ -155,17 +155,17 @@ list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED
must_scroll = true;
if (current_song != lw->selected) {
- st.offset = 0;
+ hscroll.offset = 0;
current_song = lw->selected;
}
- tmp = strscroll(songname, options.scroll_sep,
- MAX_SONG_LENGTH, &st);
+ tmp = strscroll(&hscroll, songname, options.scroll_sep,
+ MAX_SONG_LENGTH);
g_strlcpy(songname, tmp, MAX_SONG_LENGTH);
g_free(tmp);
}
else
- st.offset = 0;
+ hscroll.offset = 0;
}
#else
(void)second_column;
diff --git a/src/status_bar.c b/src/status_bar.c
index 04881afc939ca2ce2b61755b5b7735ed9afe0ac4..204a66ecb28166a7b6a7fadd211e11393fc1e123 100644 (file)
--- a/src/status_bar.c
+++ b/src/status_bar.c
/* scroll if the song name is to long */
#ifndef NCMPC_MINI
if (options.scroll && utf8_width(songname) > (unsigned)width) {
- static scroll_state_t st = { 0, 0 };
- char *tmp = strscroll(songname, options.scroll_sep, width, &st);
+ static struct hscroll hscroll = { 0, 0 };
+ char *tmp = strscroll(&hscroll, songname,
+ options.scroll_sep, width);
g_strlcpy(songname, tmp, sizeof(songname));
g_free(tmp);