Re: Make "old esc mode" key timeout configurable



Hi Leonard,

Please CC me directly (use "Reply to all").
I read a lot of mailing lists. Mails which are not addressed
explicitly to me are often overlooked/lost.

On Tuesday 01 August 2006 23:22, Leonard den Ottolander wrote:
> > diff -urp mc-4.6.0.orig/src/key.c mc-4.6.0/src/key.c
> 
> > -#define ESCMODE_TIMEOUT 1000000
> > +#define ESCMODE_TIMEOUT keyboard_key_timeout
> 
> Why do you keep this define around if it is substituted for a global
> variable? Just get rid of that define and substitute it with the
> variable.

ok

> > +    char *kt = (char *)getenv("KEYBOARD_KEY_TIMEOUT_US");
> 
> Please conform to the used coding style. I agree the extra spaces are
> ugly but its even uglier mixing styles.
> 
> > +    if (kt != NULL)
> > +       keyboard_key_timeout = atoi(kt);

ok

> What about a multiplier (1000) so the environment variable is in ms? And

Why? I want to accomodate even those mad people who insist on,
say, 500 microsecond delay. There is no downside in doing it.

> should there be a sanity check here for invalid input (= 0) and/or too
> small (10ms?) and too large (10s?) values?

No. 0 and 10 seconds are not invalid.

0 means that ESC will immediately be taken as a separate key,
even if the rest of key sequence will be received with no delay.
Not very useful? Maybe.

10 seconds means that you will need to wait 10 seconds for single ESC
to be considered separate key. Silly? Well, for me, even old
default of 1 second delay was too big. So it varies from
person to person.

Updated patch is attached. Please apply.
--
vda
diff -urpN mc-4.6.1.org/src/key.c mc-4.6.1.key_timeout/src/key.c
--- mc-4.6.1.org/src/key.c	2005-06-08 14:27:19.000000000 +0200
+++ mc-4.6.1.key_timeout/src/key.c	2006-08-07 12:56:28.000000000 +0200
@@ -72,9 +72,6 @@
 #define DIF_TIME(t1,t2) ((t2.tv_sec -t1.tv_sec) *1000+ \
 			 (t2.tv_usec-t1.tv_usec)/1000)
 			 
-/* timeout for old_esc_mode in usec */
-#define ESCMODE_TIMEOUT 1000000
-
 /* Linux console keyboard modifiers */
 #define SHIFT_PRESSED 1
 #define ALTR_PRESSED 2
@@ -85,6 +82,8 @@
 int mou_auto_repeat = 100;
 int double_click_speed = 250;
 int old_esc_mode = 0;
+/* timeout for old_esc_mode in usec */
+int keyboard_key_timeout = 1000000;	/* settable via env */
 
 int use_8th_bit_as_meta = 0;
 
@@ -426,6 +425,9 @@ void
 init_key (void)
 {
     const char *term = getenv ("TERM");
+    char *kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
+    if (kt != NULL)
+	keyboard_key_timeout = atoi (kt);
 
     /* This has to be the first define_sequence */
     /* So, we can assume that the first keys member has ESC */
@@ -805,8 +807,8 @@ int get_key_code (int no_delay)
                 if (esctime.tv_sec == -1)
                     return -1;
                 GET_TIME (current);
-                timeout.tv_sec = ESCMODE_TIMEOUT / 1000000 + esctime.tv_sec;
-                timeout.tv_usec = ESCMODE_TIMEOUT % 1000000 + esctime.tv_usec;
+                timeout.tv_sec = keyboard_key_timeout / 1000000 + esctime.tv_sec;
+                timeout.tv_usec = keyboard_key_timeout % 1000000 + esctime.tv_usec;
                 if (timeout.tv_usec > 1000000) {
                     timeout.tv_usec -= 1000000;
                     timeout.tv_sec++;
@@ -1133,8 +1135,8 @@ static int xgetch_second (void)
     int c;
     struct timeval timeout;
 
-    timeout.tv_sec = ESCMODE_TIMEOUT / 1000000;
-    timeout.tv_usec = ESCMODE_TIMEOUT % 1000000;
+    timeout.tv_sec = keyboard_key_timeout / 1000000;
+    timeout.tv_usec = keyboard_key_timeout % 1000000;
     nodelay (stdscr, TRUE);
     FD_ZERO (&Read_FD_Set);
     FD_SET (input_fd, &Read_FD_Set);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]