This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch submission for AltGr handling


Hi, Again, Corinna! :)

On Mon, 5 Mar 2001, Corinna Vinschen wrote:

> Could you please resubmit a patch which doesn't introduce another
> CYGWIN option but instead uses automatic recognition of the current
> keyboard setting? For example the expression

> if (PRIMARYLANGID (LOWORD (GetKeyboardLayout (0)) == LANG_ENGLISH)
>
> should work.

It does indeed.  I've provided the patch and changelog info at the
bottom of this message.  I did rudimentary testing to show that AltGr
is interpreted as META on a US English keyboard; I then set my default
keyboard to German (Standard) and verified that the
GetKeyboardLayout() call worked appropriately and that AltGr was *not*
interpreted as META.  So far, so good!

I hope that others with access to international keyboards will find
that this patch does not interfere with their needs.  Thanks again for
the help.

---Jason Tiller
jtiller@sjm.com
Sonos

Here are the diffs (fhandler.h, fhandler_console.cc and autoload.cc):

--- fhandler.h-orig	Mon Jan 29 18:36:10 2001
+++ fhandler.h	Mon Mar  5 15:42:24 2001
@@ -615,6 +615,10 @@ private:
   int input_tcsetattr (int a, const struct termios *t);
   void set_cursor_maybe ();

+  // Used to determine if an input keystroke should be modified with
+  // META.
+  int meta_mask;
+
 public:

   fhandler_console (const char *name);


--- fhandler_console.cc-orig	Mon Jan 29 18:36:12 2001
+++ fhandler_console.cc	Mon Mar  5 17:47:30 2001
@@ -220,10 +220,11 @@ fhandler_console::read (void *pv, size_t
 		 converting a CTRL-U. */
 	      if ((unsigned char)ich > 0x7f && current_codepage == ansi_cp)
 		OemToCharBuff (tmp + 1, tmp + 1, 1);
-	      if (!(input_rec.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED))
+              // Determine if the keystroke is modified by META.
+	      if (!(input_rec.Event.KeyEvent.dwControlKeyState & meta_mask))
 		toadd = tmp + 1;
 	      else
-		{
+                { // Yup.
 		  tmp[0] = '\033';
 		  tmp[1] = cyg_tolower (tmp[1]);
 		  toadd = tmp;
@@ -720,6 +721,20 @@ fhandler_console::fhandler_console (cons
 {
   set_cb (sizeof *this);
   state_ = normal;
+
+  // Set the mask that determines if an input keystroke is modified by
+  // META.  We set this based on the keyboard layout language loaded
+  // for the current thread.  The left <ALT> key always generates
+  // META, but the right <ALT> key only generates META if we are using
+  // an English keyboard because many "international" keyboards
+  // replace common shell symbols ('[', '{', etc.) with accented
+  // language-specific characters (umlaut, accent grave, etc.).  On
+  // these keyboards right <ALT> (called AltGr) is used to produce the
+  // shell symbols and should not be interpreted as META.
+  meta_mask = LEFT_ALT_PRESSED;
+  if( PRIMARYLANGID (LOWORD (GetKeyboardLayout (0))) == LANG_ENGLISH )
+     meta_mask |= RIGHT_ALT_PRESSED;
+
   set_need_fork_fixup ();
 }



--- autoload.cc-orig	Mon Mar  5 16:59:44 2001
+++ autoload.cc	Mon Mar  5 17:01:00 2001
@@ -255,6 +255,7 @@ LoadDLLfunc (DefWindowProcA, 16, user32)
 LoadDLLfunc (DispatchMessageA, 4, user32)
 LoadDLLfunc (FindWindowA, 8, user32)
 LoadDLLfunc (GetClipboardData, 4, user32)
+LoadDLLfunc (GetKeyboardLayout, 4, user32)
 LoadDLLfunc (GetMessageA, 16, user32)
 LoadDLLfunc (GetProcessWindowStation, 0, user32)
 LoadDLLfunc (GetThreadDesktop, 4, user32)


Here are the ChangeLog entries:

     * auto_load.cc: Add "GetKeyboardLayout" entry in the list of
       Win32 User32.DLL exports to provide.
     * fhandler.h (class fhandler_console): Add meta_mask private
       member to remember which keystroke modifiers should generate
       META.
     * fhandler_console.cc (fhandler_console::read): Modify code that
       tests a keystroke for a META-escaped key to use the 'meta_mask'
       variable.
       (fhandler_console::fhandler_console): Add definition for
       variable "meta_mask" used to determine if a keystroke should be
       preceded by META in the client console stream.  Set meta_mask
       based on whether or not user's keyboard language is English -
       non-English keyboards pass AltGr (right <ALT>) unmolested,
       whereas English keyboards now interpret left- and right-<ALT>
       as META.


That's it.  Once again, thanks for considering this patch.

---Jason Tiller
jtiller@sjm.com
Sonos


--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]