seamus

commit ed9f3d53abe0faa194df78beb41389c37087cc97

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

seamus: add highlight_index, scroll_offset, current_window to frontend struct

- Replace scroll_position with highlight_index + scroll_offset
  for proper viewport-based scrolling
- Add current_window enum for future window focus support
- Initialize new fields in seamus_init
- Fix seamus_finish queue_size decrement bug

 include/seamus.h | 9 ++++++++-
 src/seamus.c | 18 ++++++++++--------


diff --git a/include/seamus.h b/include/seamus.h
index 3dfdf43dc4aa20a3fa26198aa6252661c5eff4dc..552f107a484c9c420670091f1babbbdad25d58a9 100644
--- a/include/seamus.h
+++ b/include/seamus.h
@@ -30,6 +30,10 @@ 	enum mpd_state state;
 	char *description;
 };
 
+enum window_type {
+	WINDOW_QUEUE,
+};
+
 struct seamus_frontend {
 	struct mpd_connection *conn;
 	struct seamus_song *queue;
@@ -37,7 +41,10 @@ 	struct seamus_status *status;
 
 	int version;
 	int queue_size;
-	int scroll_position;
+	int highlight_index;
+	int scroll_offset;
+
+	enum window_type current_window;
 
 	TickitWindow *main_window;
 	TickitWindow *status_window;




diff --git a/src/seamus.c b/src/seamus.c
index 53c2b29ab37dabb5294ddfedf7d02bb4a6218685..04113d0da0e306a5bb298fbaa58e46f924d99eaf 100755
--- a/src/seamus.c
+++ b/src/seamus.c
@@ -33,15 +33,14 @@ void
 seamus_finish(struct seamus_frontend *seamus)
 {
 	int i;
-	for (i = 0; i < seamus->queue_size; i++) {
+	int n = seamus->queue_size;
+	for (i = 0; i < n; i++) {
 		struct seamus_song *s = &seamus->queue[i];
-		if (s->title != NULL && s->artist != NULL) {
-			free(s->title);
-			free(s->artist);
-		}
-
-		seamus->queue_size--;
+		free(s->title);
+		free(s->artist);
 	}
+
+	seamus->queue_size = 0;
 
 	free(seamus->queue);
 
@@ -53,7 +52,10 @@
 int
 seamus_init(struct seamus_frontend *s)
 {
-	// Setup MPD connection
+	s->highlight_index = 0;
+	s->scroll_offset = 0;
+	s->current_window = WINDOW_QUEUE;
+
 	int mpd_con = setup_connection(s);
 	if (mpd_con != 0) {
 		log_error("Weren't able to connect with MPD");