summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2c6af73)
raw | patch | inline | side by side (parent: 2c6af73)
author | Kalle Wallin <kaw@linux.se> | |
Tue, 13 Jul 2004 15:28:43 +0000 (15:28 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Tue, 13 Jul 2004 15:28:43 +0000 (15:28 +0000) |
12 files changed:
src/command.c | patch | blob | history | |
src/command.h | patch | blob | history | |
src/conf.c | patch | blob | history | |
src/main.c | patch | blob | history | |
src/ncmpc.h | patch | blob | history | |
src/options.c | patch | blob | history | |
src/options.h | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/screen_keydef.c | patch | blob | history | |
src/screen_utils.c | patch | blob | history | |
src/wreadln.c | patch | blob | history | |
src/wreadln.h | patch | blob | history |
diff --git a/src/command.c b/src/command.c
index c8d43d99dcdaa607ab36351c1a76f43f74c7761f..c256d0c5ce73cab035d1737b31aa93a4707dfa05 100644 (file)
--- a/src/command.c
+++ b/src/command.c
#define DK(x)
#endif
+extern void sigstop(void);
extern void screen_resize(void);
#define BS KEY_BACKSPACE
return find_key_command(key, cmds);
}
+int
+my_wgetch(WINDOW *w)
+{
+ int c;
+
+ c = wgetch(w);
+
+ /* handle resize event */
+ if( c==KEY_RESIZE )
+ screen_resize();
+
+#ifdef ENABLE_RAW_MODE
+ /* handle SIGSTOP (Ctrl-Z) */
+ if( c==26 || c==407 )
+ sigstop();
+ /* handle SIGINT (Ctrl-C) */
+ if( c==3 )
+ exit(EXIT_SUCCESS);
+#endif
+
+ return c;
+}
+
command_t
get_keyboard_command_with_timeout(int ms)
{
if( ms != SCREEN_TIMEOUT)
timeout(ms);
- key = wgetch(stdscr);
+ key = my_wgetch(stdscr);
if( ms != SCREEN_TIMEOUT)
timeout(SCREEN_TIMEOUT);
- if( key==KEY_RESIZE )
- screen_resize();
-
-#ifdef ENABLE_RAW_MODE
- if( key==KEY_SIGSTOP )
- sigstop();
-#endif
-
if( key==ERR )
return CMD_NONE;
}
int
-write_key_bindings(FILE *f)
+write_key_bindings(FILE *f, int flags)
{
int i,j;
- fprintf(f, "# Key bindings for ncmpc (generated by ncmpc)\n\n");
+ if( flags & KEYDEF_WRITE_HEADER )
+ fprintf(f, "## Key bindings for ncmpc (generated by ncmpc)\n\n");
i=0;
while( cmds[i].name && !ferror(f) )
{
- if( cmds[i].flags & COMMAND_KEY_MODIFIED )
+ if( cmds[i].flags & COMMAND_KEY_MODIFIED || flags & KEYDEF_WRITE_ALL)
{
- fprintf(f, "# %s\n", cmds[i].description);
+ fprintf(f, "## %s\n", cmds[i].description);
+ if( flags & KEYDEF_COMMENT_ALL )
+ fprintf(f, "#");
fprintf(f, "key %s = ", cmds[i].name);
for(j=0; j<MAX_COMMAND_KEYS; j++)
{
diff --git a/src/command.h b/src/command.h
index db2c9cee0b861fa1339fc3e2cafc72262ac16cdf..fc436a4435a66f7ef105cbbae2acca9030dc7722 100644 (file)
--- a/src/command.h
+++ b/src/command.h
} command_t;
-/* flags */
+/* command definition flags */
#define COMMAND_KEY_MODIFIED 0x01
#define COMMAND_KEY_CONFLICT 0x02
+/* write key bindings flags */
+#define KEYDEF_WRITE_HEADER 0x01
+#define KEYDEF_WRITE_ALL 0x02
+#define KEYDEF_COMMENT_ALL 0x04
+
typedef struct
{
int keys[MAX_COMMAND_KEYS];
void command_dump_keys(void);
int check_key_bindings(command_definition_t *cmds, char *buf, size_t size);
-int write_key_bindings(FILE *f);
+int write_key_bindings(FILE *f, int all);
char *key2str(int key);
char *get_key_description(command_t command);
command_t get_key_command_from_name(char *name);
int assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]);
+int my_wgetch(WINDOW *w);
command_t get_keyboard_command(void);
command_t get_keyboard_command_with_timeout(int milliseconds);
diff --git a/src/conf.c b/src/conf.c
index f1f1223a3e10d839b4f8ffac0847e752e476a8aa..b31b7b1735c8fb09e82152f75c0e88a38400e51a 100644 (file)
--- a/src/conf.c
+++ b/src/conf.c
#define CONF_AUDIBLE_BELL "audible-bell"
#define CONF_VISIBLE_BELL "visible-bell"
#define CONF_XTERM_TITLE "set-xterm-title"
-#define CONF_MOUSE_EVENTS "enable-mouse"
+#define CONF_ENABLE_MOUSE "enable-mouse"
typedef enum {
KEY_PARSER_UNKNOWN,
{
options->enable_xterm_title = str2bool(value);
}
- else if( !strcasecmp(CONF_MOUSE_EVENTS, name) )
+ else if( !strcasecmp(CONF_ENABLE_MOUSE, name) )
{
- options->enable_mouse_events = str2bool(value);
+ options->enable_mouse = str2bool(value);
}
else
{
diff --git a/src/main.c b/src/main.c
index 19dad29873463bf1deeec23a8921ad19d40bde4d..1cba667bf2eec3b33e09813208acdfc7e6b4ec5c 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#include <unistd.h>
#include <signal.h>
#include <string.h>
+#include <ncurses.h>
#include <glib.h>
#include "config.h"
diff --git a/src/ncmpc.h b/src/ncmpc.h
index dec530dc2987c3e95d5aca86504a0398b2a04a63..7c1d519584594eb00145dc3cc416c7be84d28e19 100644 (file)
--- a/src/ncmpc.h
+++ b/src/ncmpc.h
/* song format - list window */
#define DEFAULT_LIST_FORMAT "%name%|[%artist% - ]%title%|%shortfile%"
-#define LIST_FORMAT (options.list_format ? options.list_format : DEFAULT_LIST_FORMAT)
+#define LIST_FORMAT (options.list_format ? options.list_format : \
+ DEFAULT_LIST_FORMAT)
/* song format - status window */
#define DEFAULT_STATUS_FORMAT "[%artist% - ]%title%|%shortfile%"
-#define STATUS_FORMAT (options.status_format ? options.status_format : DEFAULT_STATUS_FORMAT)
-
-/* sigstop key (Ctrl-Z) */
-#define KEY_SIGSTOP 26
-
-/* send SIGSTOP */
-void sigstop(void);
+#define STATUS_FORMAT (options.status_format ? options.status_format : \
+ DEFAULT_STATUS_FORMAT)
#endif /* NCMPC_H */
diff --git a/src/options.c b/src/options.c
index 94da5b8369dee552f5e7ea8559995e68c7ee642b..514ba544bba1b6f7853b50ee889655e33b46c86a 100644 (file)
--- a/src/options.c
+++ b/src/options.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <ncurses.h>
#include <glib.h>
#include "config.h"
#include "ncmpc.h"
#include "support.h"
#include "options.h"
+#include "command.h"
+#include "conf.h"
#define MAX_LONGOPT_LENGTH 32
{ 'V', "version", NULL, "Display version information" },
{ 'c', "colors", NULL, "Enable colors" },
{ 'C', "no-colors", NULL, "Disable colors" },
+#ifdef HAVE_GETMOUSE
+ { 'm', "mouse", NULL, "Enable mouse" },
+ { 'M', "no-mouse", NULL, "Disable mouse" },
+#endif
{ 'e', "exit", NULL, "Exit on connection errors" },
{ 'p', "port", "PORT", "Connect to server on port [" DEFAULT_PORT_STR "]" },
{ 'h', "host", "HOST", "Connect to server on host [" DEFAULT_HOST "]" },
{ 'f', "config", "FILE", "Read configuration from file" },
{ 'k', "key-file","FILE", "Read configuration from file" },
#ifdef DEBUG
+ { 'K', "dump-keys", NULL, "Dump key bindings to stdout" },
{ 'D', "debug", NULL, "Enable debug output on stderr" },
#endif
{ 0, NULL, NULL, NULL },
display_help();
exit(EXIT_SUCCESS);
case 'V': /* --version */
- printf("Version %s\n", VERSION);
+ printf("%s version: %s\n", PACKAGE, VERSION);
+ printf("build options:");
+#ifdef DEBUG
+ printf(" debug");
+#endif
+#ifdef ENABLE_NLS
+ printf(" nls");
+#endif
+#ifdef ENABLE_KEYDEF_SCREEN
+ printf(" key-screen");
+#endif
+#ifdef ENABLE_CLOCK_SCREEN
+ printf(" clock-screen");
+#endif
+ printf("\n");
exit(EXIT_SUCCESS);
case 'c': /* --colors */
options.enable_colors = TRUE;
case 'C': /* --no-colors */
options.enable_colors = FALSE;
break;
+ case 'm': /* --mouse */
+ options.enable_mouse = TRUE;
+ break;
+ case 'M': /* --no-mouse */
+ options.enable_mouse = FALSE;
+ break;
case 'e': /* --exit */
options.reconnect = FALSE;
break;
g_free(options.key_file);
options.key_file = g_strdup(arg);
break;
+#ifdef DEBUG
+ case 'K': /* --dump-keys */
+ read_configuration(&options);
+ write_key_bindings(stdout, KEYDEF_WRITE_ALL | KEYDEF_COMMENT_ALL);
+ exit(EXIT_SUCCESS);
+ break;
case 'D': /* --debug */
options.debug = TRUE;
break;
+#endif
default:
fprintf(stderr,"Unknown Option %c = %s\n", c, arg);
break;
diff --git a/src/options.h b/src/options.h
index 9cbe38675dcd0170a75cd578adb85433592bfbd3..1a4e4b61e7b4d8ecc0d1b89ba3c505392e77e896 100644 (file)
--- a/src/options.h
+++ b/src/options.h
gboolean audible_bell;
gboolean visible_bell;
gboolean enable_xterm_title;
- gboolean enable_mouse_events;
+ gboolean enable_mouse;
} options_t;
diff --git a/src/screen.c b/src/screen.c
index 9ea46f739c36bcd237e7552770e3214d127f1cfb..f7145be6b03ffe80e4b435e9e235a0b442dd9288 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
timeout(SCREEN_TIMEOUT);
/* initialize mouse support */
#ifdef HAVE_GETMOUSE
- if( options.enable_mouse_events )
+ if( options.enable_mouse )
mousemask(ALL_MOUSE_EVENTS, NULL);
#endif
mode_fn->open(screen, c);
/* initialize wreadln */
- wrln_resize_callback = screen_resize;
+ wrln_wgetch = my_wgetch;
wrln_max_history_length = 16;
return 0;
diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index 7ea8c3fdb03589141c6ee7256b65ed09f9edf525..4ed30dfccbaad50d3a43ae07a989fa67aeef4694 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
g_free(filename);
return -1;
}
- if( write_key_bindings(f) )
+ if( write_key_bindings(f, KEYDEF_WRITE_HEADER) )
screen_status_printf(_("Error: %s - %s"), filename, strerror(errno));
else
screen_status_printf(_("Wrote %s"), filename);
diff --git a/src/screen_utils.c b/src/screen_utils.c
index cd3fc1ed073960593aa30c0bf11799e35904944c..9870fc33a3a1bb02260e5b8052adb2957073ec92 100644 (file)
--- a/src/screen_utils.c
+++ b/src/screen_utils.c
curs_set(1);
timeout(-1);
- while( (key=wgetch(w)) == ERR )
+ while( (key=my_wgetch(w)) == ERR )
;
-#ifdef ENABLE_RAW_MODE
- if( key==KEY_SIGSTOP )
- sigstop();
-#endif
-
#ifdef HAVE_GETMOUSE
/* ignore mouse events */
if( key==KEY_MOUSE )
return screen_getch(w, prompt);
#endif
- if( key==KEY_RESIZE )
- {
- screen_resize();
- }
-
noecho();
curs_set(0);
timeout(SCREEN_TIMEOUT);
diff --git a/src/wreadln.c b/src/wreadln.c
index d0204329e8707c7921e02d4904a8223900965606..700769bd158175ebb1bd7644526fe3abccd1b776 100644 (file)
--- a/src/wreadln.c
+++ b/src/wreadln.c
unsigned int wrln_max_line_size = WRLN_MAX_LINE_SIZE;
unsigned int wrln_max_history_length = WRLN_MAX_HISTORY_LENGTH;
-GVoidFunc wrln_resize_callback = NULL;
+wrln_wgetch_fn_t wrln_wgetch = 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);
-extern void sigstop(void);
char *
wreadln(WINDOW *w,
while( key!=13 && key!='\n' )
{
- key = wgetch(w);
+ if( wrln_wgetch )
+ key = wrln_wgetch(w);
+ else
+ key = wgetch(w);
/* check if key is a function key */
for(i=0; i<63; i++)
switch (key)
{
-#ifdef HAVE_GETMOUSE
case KEY_MOUSE: /* ignore mouse events */
-#endif
case ERR: /* ingnore errors */
break;
-#ifdef ENABLE_RAW_MODE
- case 26:
- sigstop();
- break;
-#endif
case KEY_RESIZE:
- /* a resize event -> call an external callback function */
- if( wrln_resize_callback )
- wrln_resize_callback();
+ /* a resize event */
if( x1>COLS )
{
x1=COLS;
diff --git a/src/wreadln.h b/src/wreadln.h
index 520ba2a6a9ebfae981699db32c1e6760f6233b8a..55c24b91f48563e5c077bfd09bc0f8d185ef333d 100644 (file)
--- a/src/wreadln.h
+++ b/src/wreadln.h
/* max items stored in the history list */
extern unsigned int wrln_max_history_length;
-/* a callback function for KEY_RESIZE */
-extern GVoidFunc wrln_resize_callback;
+/* custom wgetch function */
+typedef int (*wrln_wgetch_fn_t) (WINDOW *w);
+extern wrln_wgetch_fn_t wrln_wgetch;
/* called after TAB is pressed but before g_completion_complete */
typedef void (*wrln_gcmp_pre_cb_t) (GCompletion *gcmp, gchar *buf);