diff options
author | Kalle Wallin <kaw@linux.se> | 2004-03-28 23:25:00 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-03-28 23:25:00 +0000 |
commit | 30327ee6f3bc929ae9f8ceca73a6b0ef8e5a0282 (patch) | |
tree | 235b82949e1f81c780a10c6d2defe66da3fb91a3 | |
parent | 8a7c44223cbea87ef27a2f9f876a2cdaba8abec3 (diff) | |
download | mpd-30327ee6f3bc929ae9f8ceca73a6b0ef8e5a0282.tar.gz mpd-30327ee6f3bc929ae9f8ceca73a6b0ef8e5a0282.tar.xz mpd-30327ee6f3bc929ae9f8ceca73a6b0ef8e5a0282.zip |
Started to use glibs neat timer functionality in the main loop.
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@527 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r-- | main.c | 32 |
1 files changed, 19 insertions, 13 deletions
@@ -14,8 +14,11 @@ #include "conf.h" -static mpd_client_t *mpc = NULL; +#define MPD_UPDATE_TIME 1.0 + +static mpd_client_t *mpc = NULL; +static GTimer *timer = NULL; void exit_and_cleanup(void) @@ -29,6 +32,8 @@ exit_and_cleanup(void) mpc_close(mpc); } g_free(options.host); + if( timer ) + g_timer_destroy(timer); } void @@ -43,7 +48,7 @@ main(int argc, const char *argv[]) { options_t *options; struct sigaction act; - int counter, connected; + int connected; /* initialize options */ options = options_init(); @@ -100,14 +105,16 @@ main(int argc, const char *argv[]) /* initialize curses */ screen_init(); - - counter=0; + + /* initialize timer */ + timer = g_timer_new(); + connected=1; while( connected || options->reconnect ) { - command_t cmd; + static gdouble t = G_MAXDOUBLE; - if( connected && counter==0 ) + if( connected && t>=MPD_UPDATE_TIME ) { mpc_update(mpc); if( mpc_error(mpc) ) @@ -120,20 +127,21 @@ main(int argc, const char *argv[]) } else mpd_finishCommand(mpc->connection); - counter=10; + g_timer_start(timer); } if( connected ) { + command_t cmd; + screen_update(mpc); if( (cmd=get_keyboard_command()) != CMD_NONE ) { screen_cmd(mpc, cmd); if( cmd==CMD_VOLUME_UP || cmd==CMD_VOLUME_DOWN) - counter=10; /* make shure we dont update the volume yet */ - else - counter=0; + /* make shure we dont update the volume yet */ + g_timer_start(timer); } } else if( options->reconnect ) @@ -145,13 +153,11 @@ main(int argc, const char *argv[]) { screen_status_printf("Connected to %s!", options->host); connected=1; - counter=0; } doupdate(); } - if( counter>0 ) - counter--; + t = g_timer_elapsed(timer, NULL); } exit(EXIT_FAILURE); |