From dff5f0dd4004751e4453c6efa405f2c0c29b562e Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 26 Mar 2012 19:03:19 +0200 Subject: [PATCH 1/1] Make routine to probe shift keys The code to probe Alt keys was taken out of MoveTypeInProc, and extended to probing Ctrl and Shift keys too. These are now returned in the 6 LSB of an int by ShiftKeys(). --- dialogs.h | 1 + xboard.c | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/dialogs.h b/dialogs.h index 0bc429f..d7d763f 100644 --- a/dialogs.h +++ b/dialogs.h @@ -60,6 +60,7 @@ void SendText P((int n)); void InitDrawingParams P(()); // in xboard.c void ErrorPopUp P((char *title, char *text, int modal)); +int ShiftKeys P((void)); void BoxAutoPopUp P((char *buf)); void IcsKey P((int n)); diff --git a/xboard.c b/xboard.c index b21441a..4b7f3fe 100644 --- a/xboard.c +++ b/xboard.c @@ -4233,22 +4233,30 @@ QuitWrapper (Widget w, XEvent *event, String *prms, Cardinal *nprms) QuitProc(); } +int +ShiftKeys () +{ // bassic primitive for determining if modifier keys are pressed + long int codes[] = { XK_Meta_L, XK_Meta_R, XK_Control_L, XK_Control_R, XK_Shift_L, XK_Shift_R }; + char keys[32]; + int i,j, k=0; + XQueryKeymap(xDisplay,keys); + for(i=0; i<6; i++) { + k <<= 1; + j = XKeysymToKeycode(xDisplay, codes[i]); + k += ( (keys[j>>3]&1<<(j&7)) != 0 ); + } + return k; +} + static void MoveTypeInProc (Widget widget, caddr_t unused, XEvent *event) { - char buf[10], keys[32]; + char buf[10]; KeySym sym; - KeyCode metaL, metaR; //, ctrlL, ctrlR; int n = XLookupString(&(event->xkey), buf, 10, &sym, NULL); - XQueryKeymap(xDisplay,keys); - metaL = XKeysymToKeycode(xDisplay, XK_Meta_L); - metaR = XKeysymToKeycode(xDisplay, XK_Meta_R); -// ctrlL = XKeysymToKeycode(xDisplay, XK_Control_L); -// ctrlR = XKeysymToKeycode(xDisplay, XK_Control_R); if ( n == 1 && *buf >= 32 // printable - && !(keys[metaL>>3]&1<<(metaL&7)) && !(keys[metaR>>3]&1<<(metaR&7)) // no alt key pressed -// && !(keys[ctrlL>>3]&1<<(ctrlL&7)) && !(keys[ctrlR>>3]&1<<(ctrlR&7)) // no ctrl key pressed - ) BoxAutoPopUp (buf); + && !(ShiftKeys() & 0x3C) // no Alt, Ctrl + ) BoxAutoPopUp (buf); } static void -- 1.7.0.4