summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 38f52fb)
raw | patch | inline | side by side (parent: 38f52fb)
author | Max Kellermann <max@duempel.org> | |
Mon, 28 Sep 2009 16:10:58 +0000 (18:10 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 28 Sep 2009 16:10:58 +0000 (18:10 +0200) |
Create it only on demand, while seeking.
src/main.c | patch | blob | history | |
src/player_command.c | patch | blob | history | |
src/player_command.h | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/screen.h | patch | blob | history |
diff --git a/src/main.c b/src/main.c
index 8313d019308a49a0f045683acf6e8bf9c83f2cc6..8d0d4b2f2ef6067d96cfc4db3388a4b8c028f586 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#include "screen_utils.h"
#include "strfsong.h"
#include "i18n.h"
+#include "player_command.h"
#ifndef NCMPC_MINI
#include "conf.h"
#define BUFSIZE 1024
-static const guint idle_interval = 500;
-
static struct mpdclient *mpd = NULL;
static gboolean connected = FALSE;
static GMainLoop *main_loop;
-static guint reconnect_source_id, idle_source_id, update_source_id;
+static guint reconnect_source_id, update_source_id;
#ifndef NCMPC_MINI
static guint check_key_bindings_source_id;
return GPOINTER_TO_INT(data);
}
-/**
- * This idle timer is invoked when the user hasn't typed a key for
- * 500ms. It is used for delayed seeking.
- */
-static gboolean
-timer_idle(G_GNUC_UNUSED gpointer data)
-{
- screen_idle(mpd);
- return TRUE;
-}
-
void begin_input_event(void)
{
- /* remove the idle timeout; add it later with fresh interval */
- g_source_remove(idle_source_id);
}
void end_input_event(void)
{
screen_update(mpd);
-
- idle_source_id = g_timeout_add(idle_interval, timer_idle, NULL);
}
int do_input_event(command_t cmd)
#ifndef NCMPC_MINI
check_key_bindings_source_id = g_timeout_add(10000, timer_check_key_bindings, NULL);
#endif
- idle_source_id = g_timeout_add(idle_interval, timer_idle, NULL);
screen_paint(mpd);
/* cleanup */
+ cancel_seek_timer();
+
g_source_remove(update_source_id);
- g_source_remove(idle_source_id);
#ifndef NCMPC_MINI
if (check_key_bindings_source_id != 0)
diff --git a/src/player_command.c b/src/player_command.c
index 478d09073d5e6841c5e0ef210300daa6cbe28bc1..dab3d525def6462bea0943296843f58a1dd5969c 100644 (file)
--- a/src/player_command.c
+++ b/src/player_command.c
#define IS_STOPPED(s) (!(IS_PLAYING(s) | IS_PAUSED(s)))
int seek_id = -1;
-int seek_target_time = 0;
+int seek_target_time;
+
+static guint seek_source_id;
+
+static void
+commit_seek(struct mpdclient *c)
+{
+ if (seek_id < 0)
+ return;
+
+ if (c->song != NULL && (unsigned)seek_id == mpd_song_get_id(c->song))
+ mpdclient_cmd_seek(c, seek_id, seek_target_time);
+
+ seek_id = -1;
+}
+
+/**
+ * This timer is invoked after seeking when the user hasn't typed a
+ * key for 500ms. It is used to do the real seeking.
+ */
+static gboolean
+seek_timer(gpointer data)
+{
+ struct mpdclient *c = data;
+
+ seek_source_id = 0;
+ commit_seek(c);
+ return false;
+}
+
+static void
+schedule_seek_timer(struct mpdclient *c)
+{
+ assert(seek_source_id == 0);
+
+ seek_source_id = g_timeout_add(500, seek_timer, c);
+}
+
+void
+cancel_seek_timer(void)
+{
+ if (seek_source_id != 0) {
+ g_source_remove(seek_source_id);
+ seek_source_id = 0;
+ }
+}
bool
handle_player_command(struct mpdclient *c, command_t cmd)
if (c->connection == NULL || c->status == NULL)
return false;
+ cancel_seek_timer();
+
switch(cmd) {
/*
case CMD_PLAY:
seek_target_time = mpd_status_get_elapsed_time(c->status);
}
seek_target_time+=options.seek_time;
- if (seek_target_time < (int)mpd_status_get_total_time(c->status))
- break;
- seek_target_time = mpd_status_get_total_time(c->status);
- /* seek_target_time=0; */
+ if (seek_target_time > (int)mpd_status_get_total_time(c->status))
+ seek_target_time = mpd_status_get_total_time(c->status);
+ schedule_seek_timer(c);
}
break;
/* fall through... */
seek_target_time-=options.seek_time;
if (seek_target_time < 0)
seek_target_time=0;
+ schedule_seek_timer(c);
}
break;
case CMD_TRACK_PREVIOUS:
diff --git a/src/player_command.h b/src/player_command.h
index d854515003b248df68a228c5bb9c024e9fa294ff..689116fe7eae0cb63a98b998e6cfe9a2f36cb8d4 100644 (file)
--- a/src/player_command.h
+++ b/src/player_command.h
extern int seek_id;
extern int seek_target_time;
+/**
+ * Call this before exiting; it will unschedule the timer for delayed
+ * seeking.
+ */
+void
+cancel_seek_timer(void);
+
bool
handle_player_command(struct mpdclient *c, command_t cmd);
diff --git a/src/screen.c b/src/screen.c
index 0545bd079c4b8cb2f11595ae397ce5e58e2e669c..13dd1175ad1f92ddc2ed58271bcfa080d09ced7c 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
screen.buf_size = screen.cols;
screen.findbuf = NULL;
screen.start_timestamp = time(NULL);
- screen.last_cmd = CMD_NONE;
/* create top window */
screen.top_window.rows = 2;
/* update title/header window */
if (welcome && options.welcome_screen_list &&
- screen.last_cmd==CMD_NONE &&
time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
paint_top_window("", c, 0);
else
doupdate();
}
-void
-screen_idle(struct mpdclient *c)
-{
- if (c->song != NULL && seek_id == (int)mpd_song_get_id(c->song) &&
- (screen.last_cmd == CMD_SEEK_FORWARD ||
- screen.last_cmd == CMD_SEEK_BACKWARD))
- mpdclient_cmd_seek(c, seek_id, seek_target_time);
-
- screen.last_cmd = CMD_NONE;
- seek_id = -1;
-}
-
#ifdef HAVE_GETMOUSE
int
screen_get_mouse_event(struct mpdclient *c, unsigned long *bstate, int *row)
void
screen_cmd(struct mpdclient *c, command_t cmd)
{
- screen.last_cmd = cmd;
#ifndef NCMPC_MINI
welcome = FALSE;
#endif
diff --git a/src/screen.h b/src/screen.h
index b22eae455d93c194129c98ccdcaa2eba3374221b..32d57b03c6e644cb6f91f21ad8de98e381b462ac 100644 (file)
--- a/src/screen.h
+++ b/src/screen.h
GTime start_timestamp;
GTime status_timestamp;
- command_t last_cmd;
-
unsigned cols, rows;
char *buf;
char *screen_error(void);
void screen_paint(struct mpdclient *c);
void screen_update(struct mpdclient *c);
-void screen_idle(struct mpdclient *c);
void screen_cmd(struct mpdclient *c, command_t cmd);
gint screen_get_id(const char *name);