From: Kalle Wallin Date: Tue, 22 Jun 2004 13:25:53 +0000 (+0000) Subject: added screen_bell() for optional audible/visible bells X-Git-Tag: v0.12_alpha1~500 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=539be061ff11cb2e095393e2e478c5a50979b3bd;p=ncmpc.git added screen_bell() for optional audible/visible bells git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1612 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- diff --git a/src/list_window.c b/src/list_window.c index 5887256..84c19a1 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -31,13 +31,14 @@ #include "colors.h" #include "list_window.h" +extern void screen_bell(void); + list_window_t * list_window_init(WINDOW *w, int width, int height) { list_window_t *lw; - lw = g_malloc(sizeof(list_window_t)); - memset(lw, 0, sizeof(list_window_t)); + lw = g_malloc0(sizeof(list_window_t)); lw->w = w; lw->cols = width; lw->rows = height; @@ -60,6 +61,7 @@ void list_window_reset(list_window_t *lw) { lw->selected = 0; + lw->xoffset = 0; lw->start = 0; lw->clear = 1; } @@ -91,24 +93,43 @@ list_window_next(list_window_t *lw, int length) { if( lw->selected < length-1 ) lw->selected++; + else if ( options.list_wrap ) + lw->selected = 0; } void -list_window_previous(list_window_t *lw) +list_window_previous(list_window_t *lw, int length) { if( lw->selected > 0 ) lw->selected--; + else if( options.list_wrap ) + lw->selected = length-1; +} + +void +list_window_right(list_window_t *lw, int length) +{ + lw->xoffset++; +} + +void +list_window_left(list_window_t *lw) +{ + if( lw->xoffset > 0 ) + lw->xoffset--; } void list_window_first(list_window_t *lw) { + lw->xoffset = 0; lw->selected = 0; } void list_window_last(list_window_t *lw, int length) { + lw->xoffset = 0; lw->selected = length-1; } @@ -218,7 +239,7 @@ list_window_find(list_window_t *lw, if( wrap ) { i=0; /* first item */ - beep(); + screen_bell(); } } return 1; @@ -253,7 +274,7 @@ list_window_rfind(list_window_t *lw, if( wrap ) { i=rows-1; /* last item */ - beep(); + screen_bell(); } } return 1; @@ -267,7 +288,7 @@ list_window_cmd(list_window_t *lw, int rows, command_t cmd) switch(cmd) { case CMD_LIST_PREVIOUS: - list_window_previous(lw); + list_window_previous(lw, rows); lw->repaint=1; break; case CMD_LIST_NEXT: diff --git a/src/list_window.h b/src/list_window.h index 9e91703..8f82791 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -14,6 +14,7 @@ typedef struct int start; int selected; + int xoffset; int clear; int repaint; @@ -40,13 +41,16 @@ int list_window_cmd(list_window_t *lw, int rows, command_t cmd); /* select functions */ void list_window_set_selected(list_window_t *lw, int n); -void list_window_previous(list_window_t *lw); +void list_window_previous(list_window_t *lw, int length); void list_window_next(list_window_t *lw, int length); void list_window_first(list_window_t *lw); void list_window_last(list_window_t *lw, int length); void list_window_previous_page(list_window_t *lw); void list_window_next_page(list_window_t *lw, int length); void list_window_check_selected(list_window_t *lw, int length); +/* not implemented yet */ +void list_window_right(list_window_t *lw, int length); +void list_window_left(list_window_t *lw); /* find a string in a list window */ int list_window_find(list_window_t *lw, diff --git a/src/main.c b/src/main.c index 382897d..f2a0e3d 100644 --- a/src/main.c +++ b/src/main.c @@ -30,9 +30,10 @@ #include "mpdclient.h" #include "support.h" #include "options.h" +#include "conf.h" #include "command.h" #include "screen.h" -#include "conf.h" +#include "screen_utils.h" #define BUFSIZE 256 @@ -67,11 +68,11 @@ error_callback(mpdclient_t *c, gint error, gchar *msg) break; case MPD_ERROR_ACK: screen_status_printf("%s", error_msg(msg)); - beep(); + screen_bell(); break; default: screen_status_printf("%s", msg); - beep(); + screen_bell(); doupdate(); connected = FALSE; } @@ -163,9 +164,10 @@ main(int argc, const char *argv[]) } /* set xterm title */ - /* if( g_getenv("DISPLAY") ) - * printf("%c]0;%s%c", '\033', PACKAGE " version " VERSION, '\007'); - */ +#ifdef DEBUG + options->enable_xterm_title = 1; + set_xterm_title(PACKAGE " version " VERSION); +#endif /* install exit function */ atexit(exit_and_cleanup); diff --git a/src/mpdclient.h b/src/mpdclient.h index c0d897d..bb8771f 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -93,6 +93,7 @@ gint mpdclient_cmd_move(mpdclient_t *c, gint old_index, gint new_index); gint mpdclient_cmd_save_playlist(mpdclient_t *c, gchar *filename); gint mpdclient_cmd_save_playlist_utf8(mpdclient_t *c, gchar *filename); gint mpdclient_cmd_load_playlist_utf8(mpdclient_t *c, gchar *filename_utf8); +gint mpdclient_cmd_delete_playlist(mpdclient_t *c, gchar *filename); gint mpdclient_cmd_delete_playlist_utf8(mpdclient_t *c, gchar *filename_utf8); diff --git a/src/screen_file.c b/src/screen_file.c index 9f1d0b2..8b79f27 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -301,7 +301,7 @@ handle_delete(screen_t *screen, mpdclient_t *c) if( entity->type!=MPD_INFO_ENTITY_TYPE_PLAYLISTFILE ) { screen_status_printf(_("You can only delete playlists!")); - beep(); + screen_bell(); return -1; } diff --git a/src/screen_keydef.c b/src/screen_keydef.c index 809561b..b85c094 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -89,7 +89,7 @@ save_keys(void) { screen_status_printf(_("Error: Unable to create direcory ~/.ncmpc - %s"), strerror(errno)); - beep(); + screen_bell(); return -1; } @@ -98,7 +98,7 @@ save_keys(void) if( (f=fopen(filename,"w")) == NULL ) { screen_status_printf(_("Error: %s - %s"), filename, strerror(errno)); - beep(); + screen_bell(); g_free(filename); return -1; } @@ -165,7 +165,7 @@ assign_new_key(WINDOW *w, int cmd_index, int key_index) screen_status_printf(_("Error: key %s is already used for %s"), key2str(key), get_key_command_name(cmd)); - beep(); + screen_bell(); return; } cmds[cmd_index].keys[key_index] = key; diff --git a/src/screen_utils.c b/src/screen_utils.c index d6e19fa..c5efc8e 100644 --- a/src/screen_utils.c +++ b/src/screen_utils.c @@ -38,6 +38,15 @@ #define FIND_PROMPT _("Find: ") #define RFIND_PROMPT _("Find backward: ") +void +screen_bell(void) +{ + if( options.audible_bell ) + beep(); + if( options.visible_bell ) + flash(); +} + int screen_getch(WINDOW *w, char *prompt) { @@ -150,7 +159,7 @@ screen_find(screen_t *screen, else { screen_status_printf(_("Unable to find \'%s\'"), screen->findbuf); - beep(); + screen_bell(); } return 1; default: @@ -200,3 +209,21 @@ screen_display_completion_list(screen_t *screen, GList *list) doupdate(); colors_use(w, COLOR_LIST); } + +void +set_xterm_title(char *format, ...) +{ + /* the current xterm title exists under the WM_NAME property */ + /* and can be retreived with xprop -id $WINDOWID */ + + if( options.enable_xterm_title && g_getenv("WINDOWID") ) + { + char buffer[512]; + va_list ap; + + va_start(ap,format); + vsnprintf(buffer,sizeof(buffer),format,ap); + va_end(ap); + printf("%c]0;%s%c", '\033', buffer, '\007'); + } +} diff --git a/src/screen_utils.h b/src/screen_utils.h index d60a338..56e44d5 100644 --- a/src/screen_utils.h +++ b/src/screen_utils.h @@ -1,6 +1,9 @@ #ifndef SCREEN_UTILS_H #define SCREEN_UTILS_H +/* sound an audible and/or visible bell */ +void screen_bell(void); + /* read a characher from the status window */ int screen_getch(WINDOW *w, char *prompt); @@ -20,4 +23,6 @@ int screen_find(screen_t *screen, void screen_display_completion_list(screen_t *screen, GList *list); +void set_xterm_title(char *format, ...); + #endif diff --git a/src/wreadln.c b/src/wreadln.c index ea0824d..dd69b41 100644 --- a/src/wreadln.c +++ b/src/wreadln.c @@ -42,6 +42,7 @@ GVoidFunc wrln_resize_callback = NULL; wrln_gcmp_pre_cb_t wrln_pre_completion_callback = NULL; wrln_gcmp_post_cb_t wrln_post_completion_callback = NULL; +extern void screen_bell(void); char * wreadln(WINDOW *w, @@ -196,14 +197,14 @@ wreadln(WINDOW *w, g_free(prefix); } else - beep(); + screen_bell(); if( wrln_post_completion_callback ) wrln_post_completion_callback(gcmp, line, list); } break; case KEY_CTRL_G: - beep(); + screen_bell(); g_free(line); if( history ) {