diff --git a/curses.h b/curses.h index 1b8633b2..5a98f6a5 100644 --- a/curses.h +++ b/curses.h @@ -28,7 +28,7 @@ Defined by this header: **man-end****************************************************************/ #define PDCURSES 1 /* PDCurses-only routines */ -#define PDC_BUILD 3808 +#define PDC_BUILD 3809 #define PDC_VER_MAJOR 3 #define PDC_VER_MINOR 8 #define PDC_VERDOT "3.8" @@ -339,6 +339,8 @@ typedef struct to be preserved */ int _restore; /* specifies if screen background to be restored, and how */ + unsigned long key_modifiers; /* key modifiers (SHIFT, CONTROL, etc.) + on last key press */ bool save_key_modifiers; /* TRUE if each key modifiers saved with each key press */ bool return_key_modifiers; /* TRUE if modifier keys are diff --git a/curspriv.h b/curspriv.h index 43f501a6..6f57e182 100644 --- a/curspriv.h +++ b/curspriv.h @@ -43,7 +43,6 @@ typedef struct /* structure for ripped off lines */ #define _DLCHAR 0x15 /* Delete Line char (^U) */ extern FILE *pdc_dbfp; /* tracing file pointer (NULL = off) */ -extern unsigned long pdc_key_modifiers; extern MOUSE_STATUS pdc_mouse_status; /*----------------------------------------------------------------------*/ diff --git a/dos/pdckbd.c b/dos/pdckbd.c index 25c88578..a57963cb 100644 --- a/dos/pdckbd.c +++ b/dos/pdckbd.c @@ -79,8 +79,6 @@ static short key_table[] = ALT_PADSLASH, ALT_TAB, ALT_PADENTER, -1 }; -unsigned long pdc_key_modifiers = 0L; - static struct {unsigned short pressed, released;} button[3]; static bool mouse_avail = FALSE, mouse_vis = FALSE, mouse_moved = FALSE, @@ -314,7 +312,7 @@ int PDC_get_key(void) PDCREGS regs; int key, scan; - pdc_key_modifiers = 0; + SP->key_modifiers = 0; if (mouse_vis && (mouse_scroll || mouse_button || mouse_moved)) return _process_mouse_events(); @@ -369,16 +367,16 @@ int PDC_get_key(void) if (SP->save_key_modifiers) { if (shift_status & 3) - pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; + SP->key_modifiers |= PDC_KEY_MODIFIER_SHIFT; if (shift_status & 4) - pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; + SP->key_modifiers |= PDC_KEY_MODIFIER_CONTROL; if (shift_status & 8) - pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT; + SP->key_modifiers |= PDC_KEY_MODIFIER_ALT; if (shift_status & 0x20) - pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; + SP->key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; } if (scan == 0x1c && key == 0x0a) /* ^Enter */ diff --git a/os2/pdckbd.c b/os2/pdckbd.c index f66abfd1..a24b17f9 100644 --- a/os2/pdckbd.c +++ b/os2/pdckbd.c @@ -86,8 +86,6 @@ static short key_table[] = ALT_PADSLASH, ALT_TAB, ALT_PADENTER, -1 }; -unsigned long pdc_key_modifiers = 0L; - unsigned long PDC_get_input_fd(void) { PDC_LOG(("PDC_get_input_fd() - called\n")); @@ -285,7 +283,7 @@ int PDC_get_key(void) int key, scan; KBDKEYINFO keyInfo = {0}; - pdc_key_modifiers = 0L; + SP->key_modifiers = 0L; if (mouse_handle && mouse_events) return _process_mouse_events(); @@ -334,16 +332,16 @@ int PDC_get_key(void) if (SP->save_key_modifiers) { if (keyInfo.fsState & KBDSTF_ALT) - pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT; + SP->key_modifiers |= PDC_KEY_MODIFIER_ALT; if (keyInfo.fsState & KBDSTF_CONTROL) - pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; + SP->key_modifiers |= PDC_KEY_MODIFIER_CONTROL; if (keyInfo.fsState & KBDSTF_NUMLOCK_ON) - pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; + SP->key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; if (keyInfo.fsState & (KBDSTF_LEFTSHIFT|KBDSTF_RIGHTSHIFT)) - pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; + SP->key_modifiers |= PDC_KEY_MODIFIER_SHIFT; } if (scan == 0x1c && key == 0x0a) /* ^Enter */ diff --git a/pdcurses/getch.c b/pdcurses/getch.c index 63b21bcc..203b5e94 100644 --- a/pdcurses/getch.c +++ b/pdcurses/getch.c @@ -349,7 +349,10 @@ unsigned long PDC_get_key_modifiers(void) { PDC_LOG(("PDC_get_key_modifiers() - called\n")); - return pdc_key_modifiers; + if (!SP) + return ERR; + + return SP->key_modifiers; } int PDC_save_key_modifiers(bool flag) diff --git a/pdcurses/initscr.c b/pdcurses/initscr.c index dad33efa..115e7c7e 100644 --- a/pdcurses/initscr.c +++ b/pdcurses/initscr.c @@ -138,6 +138,7 @@ WINDOW *Xinitscr(int argc, char *argv[]) SP->raw_out = FALSE; /* tty I/O modes */ SP->raw_inp = FALSE; /* tty I/O modes */ SP->cbreak = TRUE; + SP->key_modifiers = 0L; SP->save_key_modifiers = FALSE; SP->return_key_modifiers = FALSE; SP->echo = TRUE; diff --git a/sdl1/pdckbd.c b/sdl1/pdckbd.c index fc84817a..ff22376b 100644 --- a/sdl1/pdckbd.c +++ b/sdl1/pdckbd.c @@ -24,8 +24,6 @@ pdckbd #include -unsigned long pdc_key_modifiers = 0L; - static SDL_Event event; static SDLKey oldkey; static MOUSE_STATUS old_mouse_status; @@ -127,7 +125,7 @@ static int _process_key_event(void) { int i, key = 0; - pdc_key_modifiers = 0L; + SP->key_modifiers = 0L; SP->key_code = FALSE; if (event.type == SDL_KEYUP) @@ -165,16 +163,16 @@ static int _process_key_event(void) if (SP->save_key_modifiers) { if (event.key.keysym.mod & KMOD_NUM) - pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; + SP->key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; if (event.key.keysym.mod & KMOD_SHIFT) - pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; + SP->key_modifiers |= PDC_KEY_MODIFIER_SHIFT; if (event.key.keysym.mod & KMOD_CTRL) - pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; + SP->key_modifiers |= PDC_KEY_MODIFIER_CONTROL; if (event.key.keysym.mod & KMOD_ALT) - pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT; + SP->key_modifiers |= PDC_KEY_MODIFIER_ALT; } for (i = 0; key_table[i].keycode; i++) diff --git a/sdl2/pdckbd.c b/sdl2/pdckbd.c index 8bac0137..e74e59f2 100644 --- a/sdl2/pdckbd.c +++ b/sdl2/pdckbd.c @@ -25,8 +25,6 @@ pdckbd #include #include -unsigned long pdc_key_modifiers = 0L; - static SDL_Event event; static SDL_Keycode oldkey; static MOUSE_STATUS old_mouse_status; @@ -177,12 +175,12 @@ static int _handle_alt_keys(int key) if (key > 0x7f) return key; - if (pdc_key_modifiers & PDC_KEY_MODIFIER_CONTROL) + if (SP->key_modifiers & PDC_KEY_MODIFIER_CONTROL) { if (key >= 'A' && key <= 'Z') key -= 64; if (key >= 'a' && key <= 'z') key -= 96; } - else if (pdc_key_modifiers & PDC_KEY_MODIFIER_ALT) + else if (SP->key_modifiers & PDC_KEY_MODIFIER_ALT) { if (key >= 'A' && key <= 'Z') { @@ -218,20 +216,20 @@ static int _process_key_event(void) { case SDLK_LCTRL: case SDLK_RCTRL: - pdc_key_modifiers &= ~PDC_KEY_MODIFIER_CONTROL; + SP->key_modifiers &= ~PDC_KEY_MODIFIER_CONTROL; break; case SDLK_LALT: case SDLK_RALT: - pdc_key_modifiers &= ~PDC_KEY_MODIFIER_ALT; + SP->key_modifiers &= ~PDC_KEY_MODIFIER_ALT; break; case SDLK_LSHIFT: case SDLK_RSHIFT: - pdc_key_modifiers &= ~PDC_KEY_MODIFIER_SHIFT; + SP->key_modifiers &= ~PDC_KEY_MODIFIER_SHIFT; break; } if (!(SDL_GetModState() & KMOD_NUM)) - pdc_key_modifiers &= ~PDC_KEY_MODIFIER_NUMLOCK; + SP->key_modifiers &= ~PDC_KEY_MODIFIER_NUMLOCK; if (SP->return_key_modifiers && event.key.keysym.sym == oldkey) { @@ -281,21 +279,21 @@ static int _process_key_event(void) oldkey = event.key.keysym.sym; if (SDL_GetModState() & KMOD_NUM) - pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; + SP->key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; switch (event.key.keysym.sym) { case SDLK_LCTRL: case SDLK_RCTRL: - pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; + SP->key_modifiers |= PDC_KEY_MODIFIER_CONTROL; break; case SDLK_LALT: case SDLK_RALT: - pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT; + SP->key_modifiers |= PDC_KEY_MODIFIER_ALT; break; case SDLK_LSHIFT: case SDLK_RSHIFT: - pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; + SP->key_modifiers |= PDC_KEY_MODIFIER_SHIFT; break; case SDLK_RETURN: return 0x0d; @@ -332,7 +330,7 @@ static int _process_key_event(void) } /* SDL with TextInput ignores keys with CTRL */ - if (key && pdc_key_modifiers & PDC_KEY_MODIFIER_CONTROL) + if (key && SP->key_modifiers & PDC_KEY_MODIFIER_CONTROL) return _handle_alt_keys(key); return -1; } diff --git a/wincon/pdckbd.c b/wincon/pdckbd.c index 203a3eb1..5edcd55e 100644 --- a/wincon/pdckbd.c +++ b/wincon/pdckbd.c @@ -22,8 +22,6 @@ pdckbd **man-end****************************************************************/ -unsigned long pdc_key_modifiers = 0L; - /* These variables are used to store information about the next Input Event. */ @@ -369,16 +367,16 @@ static int _process_key_event(void) if (SP->save_key_modifiers) { if (state & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) - pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT; + SP->key_modifiers |= PDC_KEY_MODIFIER_ALT; if (state & SHIFT_PRESSED) - pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; + SP->key_modifiers |= PDC_KEY_MODIFIER_SHIFT; if (state & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) - pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; + SP->key_modifiers |= PDC_KEY_MODIFIER_CONTROL; if (state & NUMLOCK_ON) - pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; + SP->key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; } /* Handle modifier keys hit by themselves */ @@ -606,7 +604,7 @@ static int _process_mouse_event(void) int PDC_get_key(void) { - pdc_key_modifiers = 0L; + SP->key_modifiers = 0L; if (!key_count) { diff --git a/x11/pdckbd.c b/x11/pdckbd.c index 20de4a7f..332d6c54 100644 --- a/x11/pdckbd.c +++ b/x11/pdckbd.c @@ -56,8 +56,7 @@ int PDC_get_key(void) if (XC_read_socket(xc_key_sock, &newkey, sizeof(unsigned long)) < 0) XCursesExitCursesProcess(2, "exiting from PDC_get_key"); - pdc_key_modifiers = (newkey >> 24) & 0xFF; - key = (int)(newkey & 0x00FFFFFF); + key = (int)newkey; if (key == KEY_MOUSE && SP->key_code) { diff --git a/x11/x11.c b/x11/x11.c index 6bac006e..5ef4767e 100644 --- a/x11/x11.c +++ b/x11/x11.c @@ -203,8 +203,6 @@ static struct #define BITMAPDEPTH 1 -unsigned long pdc_key_modifiers = 0L; - static GC normal_gc, rect_cursor_gc, italic_gc, bold_gc, border_gc; static int font_height, font_width, font_ascent, font_descent, window_width, window_height; @@ -1133,7 +1131,7 @@ static void XCursesKeyPress(Widget w, XEvent *event, String *params, if (key) { - key |= (modifier << 24); + SP->key_modifiers = modifier; _send_key_to_curses(key, NULL, key_code); } diff --git a/x11new/pdckbd.c b/x11new/pdckbd.c index a25fc596..acad6f70 100644 --- a/x11new/pdckbd.c +++ b/x11new/pdckbd.c @@ -50,8 +50,7 @@ int PDC_get_key(void) if ((unsigned long)(-1) == newkey) return -1; - pdc_key_modifiers = (newkey >> 24) & 0xFF; - key = (int)(newkey & 0x00FFFFFF); + key = (int)newkey; PDC_LOG(("%s:PDC_get_key() - key %d returned\n", XCLOGMSG, key)); diff --git a/x11new/x11.c b/x11new/x11.c index 1923d293..c199a97b 100644 --- a/x11new/x11.c +++ b/x11new/x11.c @@ -201,8 +201,6 @@ static struct #define BITMAPDEPTH 1 -unsigned long pdc_key_modifiers = 0L; - static GC normal_gc, rect_cursor_gc, italic_gc, bold_gc, border_gc; static int font_height, font_width, font_ascent, font_descent, window_width, window_height; @@ -1132,7 +1130,7 @@ unsigned long XCursesKeyPress(XEvent *event) if (key) { - key |= (modifier << 24); + SP->key_modifiers = modifier; SP->key_code = key_code; return key;