"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "sdl2/pdckbd.c" between
PDCurses-3.8.tar.gz and PDCurses-3.9.tar.gz

About: PDCurses is a multiple platforms curses library implementing most of the functions available in X/Open and System V R4 curses.

pdckbd.c  (PDCurses-3.8):pdckbd.c  (PDCurses-3.9)
skipping to change at line 16 skipping to change at line 16
pdckbd pdckbd
------ ------
### Synopsis ### Synopsis
unsigned long PDC_get_input_fd(void); unsigned long PDC_get_input_fd(void);
### Description ### Description
PDC_get_input_fd() returns the file descriptor that PDCurses PDC_get_input_fd() returns the file descriptor that PDCurses reads
reads its input from. It can be used for select(). its input from. It can be used for select().
### Portability ### Portability
X/Open BSD SYS V X/Open ncurses NetBSD
PDC_get_input_fd - - - PDC_get_input_fd - - -
**man-end****************************************************************/ **man-end****************************************************************/
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
unsigned long pdc_key_modifiers = 0L;
static SDL_Event event; static SDL_Event event;
static SDL_Keycode oldkey; static SDL_Keycode oldkey;
static MOUSE_STATUS old_mouse_status; static MOUSE_STATUS old_mouse_status;
static struct static struct
{ {
SDL_Keycode keycode; SDL_Keycode keycode;
bool numkeypad; bool numkeypad;
unsigned short normal; unsigned short normal;
unsigned short shifted; unsigned short shifted;
skipping to change at line 180 skipping to change at line 178
return unicode; return unicode;
} }
#endif #endif
/* Handle ALT and CTRL sequences */ /* Handle ALT and CTRL sequences */
static int _handle_alt_keys(int key) static int _handle_alt_keys(int key)
{ {
if (key > 0x7f) if (key > 0x7f)
return key; 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 -= 64;
if (key >= 'a' && key <= 'z') key -= 96; 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') if (key >= 'A' && key <= 'Z')
{ {
key += ALT_A - 'A'; key += ALT_A - 'A';
SP->key_code = TRUE; SP->key_code = TRUE;
} else if (key >= 'a' && key <= 'z') } else if (key >= 'a' && key <= 'z')
{ {
key += ALT_A - 'a'; key += ALT_A - 'a';
SP->key_code = TRUE; SP->key_code = TRUE;
} else if (key >= '0' && key <= '9') } else if (key >= '0' && key <= '9')
skipping to change at line 221 skipping to change at line 219
#endif #endif
SP->key_code = FALSE; SP->key_code = FALSE;
if (event.type == SDL_KEYUP) if (event.type == SDL_KEYUP)
{ {
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_LCTRL: case SDLK_LCTRL:
case SDLK_RCTRL: case SDLK_RCTRL:
pdc_key_modifiers &= ~PDC_KEY_MODIFIER_CONTROL; SP->key_modifiers &= ~PDC_KEY_MODIFIER_CONTROL;
break; break;
case SDLK_LALT: case SDLK_LALT:
case SDLK_RALT: case SDLK_RALT:
pdc_key_modifiers &= ~PDC_KEY_MODIFIER_ALT; SP->key_modifiers &= ~PDC_KEY_MODIFIER_ALT;
break; break;
case SDLK_LSHIFT: case SDLK_LSHIFT:
case SDLK_RSHIFT: case SDLK_RSHIFT:
pdc_key_modifiers &= ~PDC_KEY_MODIFIER_SHIFT; SP->key_modifiers &= ~PDC_KEY_MODIFIER_SHIFT;
break; break;
} }
if (!(SDL_GetModState() & KMOD_NUM)) 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) if (SP->return_key_modifiers && event.key.keysym.sym == oldkey)
{ {
SP->key_code = TRUE; SP->key_code = TRUE;
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_RSHIFT: case SDLK_RSHIFT:
return KEY_SHIFT_R; return KEY_SHIFT_R;
case SDLK_LSHIFT: case SDLK_LSHIFT:
return KEY_SHIFT_L; return KEY_SHIFT_L;
skipping to change at line 284 skipping to change at line 282
#else #else
key = (unsigned char)event.text.text[0]; key = (unsigned char)event.text.text[0];
memmove(event.text.text, event.text.text + 1, memmove(event.text.text, event.text.text + 1,
strlen(event.text.text)); strlen(event.text.text));
return key > 0x7f ? -1 : _handle_alt_keys(key); return key > 0x7f ? -1 : _handle_alt_keys(key);
#endif #endif
} }
oldkey = event.key.keysym.sym; oldkey = event.key.keysym.sym;
if (SDL_GetModState() & KMOD_NUM) if (SDL_GetModState() & KMOD_NUM)
pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; SP->key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK;
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_LCTRL: case SDLK_LCTRL:
case SDLK_RCTRL: case SDLK_RCTRL:
pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; SP->key_modifiers |= PDC_KEY_MODIFIER_CONTROL;
break; break;
case SDLK_LALT: case SDLK_LALT:
case SDLK_RALT: case SDLK_RALT:
pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT; SP->key_modifiers |= PDC_KEY_MODIFIER_ALT;
break; break;
case SDLK_LSHIFT: case SDLK_LSHIFT:
case SDLK_RSHIFT: case SDLK_RSHIFT:
pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; SP->key_modifiers |= PDC_KEY_MODIFIER_SHIFT;
break; break;
case SDLK_RETURN: case SDLK_RETURN:
return 0x0d; return 0x0d;
default: default:
key = event.key.keysym.sym; key = event.key.keysym.sym;
} }
for (i = 0; key_table[i].keycode; i++) for (i = 0; key_table[i].keycode; i++)
{ {
if (key_table[i].keycode == event.key.keysym.sym) if (key_table[i].keycode == event.key.keysym.sym)
skipping to change at line 335 skipping to change at line 333
/* To get here, we ignore all other modifiers */ /* To get here, we ignore all other modifiers */
key = key_table[i].normal; key = key_table[i].normal;
} }
SP->key_code = (key > 0x100); SP->key_code = (key > 0x100);
return key; return key;
} }
} }
/* SDL with TextInput ignores keys with CTRL */ /* 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 _handle_alt_keys(key);
return -1; return -1;
} }
static int _process_mouse_event(void) static int _process_mouse_event(void)
{ {
SDL_Keymod keymods; SDL_Keymod keymods;
short shift_flags = 0; short shift_flags = 0;
memset(&pdc_mouse_status, 0, sizeof(MOUSE_STATUS)); memset(&SP->mouse_status, 0, sizeof(MOUSE_STATUS));
keymods = SDL_GetModState(); keymods = SDL_GetModState();
if (keymods & KMOD_SHIFT) if (keymods & KMOD_SHIFT)
shift_flags |= BUTTON_SHIFT; shift_flags |= BUTTON_SHIFT;
if (keymods & KMOD_CTRL) if (keymods & KMOD_CTRL)
shift_flags |= BUTTON_CONTROL; shift_flags |= BUTTON_CONTROL;
if (keymods & KMOD_ALT) if (keymods & KMOD_ALT)
shift_flags |= BUTTON_ALT; shift_flags |= BUTTON_ALT;
if (event.type == SDL_MOUSEMOTION) if (event.type == SDL_MOUSEMOTION)
{ {
int i; int i;
pdc_mouse_status.x = event.motion.x / pdc_fwidth; SP->mouse_status.x = (event.motion.x - pdc_xoffset) / pdc_fwidth;
pdc_mouse_status.y = event.motion.y / pdc_fheight; SP->mouse_status.y = (event.motion.y - pdc_yoffset) / pdc_fheight;
if (!event.motion.state || if (!event.motion.state ||
(pdc_mouse_status.x == old_mouse_status.x && (SP->mouse_status.x == old_mouse_status.x &&
pdc_mouse_status.y == old_mouse_status.y)) SP->mouse_status.y == old_mouse_status.y))
return -1; return -1;
pdc_mouse_status.changes = PDC_MOUSE_MOVED; SP->mouse_status.changes = PDC_MOUSE_MOVED;
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
if (event.motion.state & SDL_BUTTON(i + 1)) if (event.motion.state & SDL_BUTTON(i + 1))
{ {
pdc_mouse_status.button[i] = BUTTON_MOVED | shift_flags; SP->mouse_status.button[i] = BUTTON_MOVED | shift_flags;
pdc_mouse_status.changes |= (1 << i); SP->mouse_status.changes |= (1 << i);
} }
} }
} }
else if (event.type == SDL_MOUSEWHEEL) else if (event.type == SDL_MOUSEWHEEL)
{ {
pdc_mouse_status.x = pdc_mouse_status.y = -1; SP->mouse_status.x = SP->mouse_status.y = -1;
if (event.wheel.y > 0) if (event.wheel.y > 0)
pdc_mouse_status.changes = PDC_MOUSE_WHEEL_UP; SP->mouse_status.changes = PDC_MOUSE_WHEEL_UP;
else if (event.wheel.y < 0) else if (event.wheel.y < 0)
pdc_mouse_status.changes = PDC_MOUSE_WHEEL_DOWN; SP->mouse_status.changes = PDC_MOUSE_WHEEL_DOWN;
else if (event.wheel.x > 0) else if (event.wheel.x > 0)
pdc_mouse_status.changes = PDC_MOUSE_WHEEL_RIGHT; SP->mouse_status.changes = PDC_MOUSE_WHEEL_RIGHT;
else if (event.wheel.x < 0) else if (event.wheel.x < 0)
pdc_mouse_status.changes = PDC_MOUSE_WHEEL_LEFT; SP->mouse_status.changes = PDC_MOUSE_WHEEL_LEFT;
else else
return -1; return -1;
SP->key_code = TRUE;
return KEY_MOUSE; return KEY_MOUSE;
} }
else else
{ {
short action = (event.button.state == SDL_PRESSED) ? short action = (event.button.state == SDL_PRESSED) ?
BUTTON_PRESSED : BUTTON_RELEASED; BUTTON_PRESSED : BUTTON_RELEASED;
Uint8 btn = event.button.button; Uint8 btn = event.button.button;
if (btn < 1 || btn > 3) if (btn < 1 || btn > 3)
return -1; return -1;
skipping to change at line 424 skipping to change at line 423
if (SDL_PollEvent(&rel)) if (SDL_PollEvent(&rel))
{ {
if (rel.type == SDL_MOUSEBUTTONUP && rel.button.button == btn) if (rel.type == SDL_MOUSEBUTTONUP && rel.button.button == btn)
action = BUTTON_CLICKED; action = BUTTON_CLICKED;
else else
SDL_PushEvent(&rel); SDL_PushEvent(&rel);
} }
} }
pdc_mouse_status.x = event.button.x / pdc_fwidth; SP->mouse_status.x = (event.button.x - pdc_xoffset) / pdc_fwidth;
pdc_mouse_status.y = event.button.y / pdc_fheight; SP->mouse_status.y = (event.button.y - pdc_yoffset) / pdc_fheight;
btn--; btn--;
pdc_mouse_status.button[btn] = action | shift_flags; SP->mouse_status.button[btn] = action | shift_flags;
pdc_mouse_status.changes = (1 << btn); SP->mouse_status.changes = (1 << btn);
} }
old_mouse_status = pdc_mouse_status; old_mouse_status = SP->mouse_status;
SP->key_code = TRUE;
return KEY_MOUSE; return KEY_MOUSE;
} }
/* return the next available key or mouse event */ /* return the next available key or mouse event */
int PDC_get_key(void) int PDC_get_key(void)
{ {
switch (event.type) switch (event.type)
{ {
case SDL_QUIT: case SDL_QUIT:
exit(1); exit(1);
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
switch (event.window.event) switch (event.window.event)
{ {
case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_WINDOWEVENT_RESIZED: pdc_screen = SDL_GetWindowSurface(pdc_window);
if (pdc_own_window && pdc_sheight = pdc_screen->h - pdc_xoffset;
(event.window.data2 / pdc_fheight != LINES || pdc_swidth = pdc_screen->w - pdc_yoffset;
event.window.data1 / pdc_fwidth != COLS)) touchwin(curscr);
{ wrefresh(curscr);
pdc_sheight = event.window.data2;
pdc_swidth = event.window.data1;
pdc_screen = SDL_GetWindowSurface(pdc_window); if (!SP->resized)
touchwin(curscr); {
wrefresh(curscr); SP->resized = TRUE;
SP->key_code = TRUE;
if (!SP->resized) return KEY_RESIZE;
{
SP->resized = TRUE;
SP->key_code = TRUE;
return KEY_RESIZE;
}
} }
break; break;
case SDL_WINDOWEVENT_RESTORED: case SDL_WINDOWEVENT_RESTORED:
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
SDL_UpdateWindowSurface(pdc_window); SDL_UpdateWindowSurface(pdc_window);
break;
} }
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
SDL_ShowCursor(SDL_ENABLE); SDL_ShowCursor(SDL_ENABLE);
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
oldkey = SDLK_SPACE; oldkey = SDLK_SPACE;
if (SP->_trap_mbe) return _process_mouse_event();
return _process_mouse_event();
break;
case SDL_KEYUP: case SDL_KEYUP:
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
PDC_mouse_set(); PDC_mouse_set();
return _process_key_event(); return _process_key_event();
case SDL_USEREVENT: case SDL_USEREVENT:
PDC_blink_text(); PDC_blink_text();
} }
return -1; return -1;
skipping to change at line 508 skipping to change at line 498
routine for flushinp() */ routine for flushinp() */
void PDC_flushinp(void) void PDC_flushinp(void)
{ {
PDC_LOG(("PDC_flushinp() - called\n")); PDC_LOG(("PDC_flushinp() - called\n"));
while (PDC_check_key()) while (PDC_check_key())
PDC_get_key(); PDC_get_key();
} }
bool PDC_has_mouse(void)
{
return TRUE;
}
int PDC_mouse_set(void) int PDC_mouse_set(void)
{ {
SDL_ShowCursor(SP->_trap_mbe ? SDL_ENABLE : SDL_DISABLE); SDL_ShowCursor(SP->_trap_mbe ? SDL_ENABLE : SDL_DISABLE);
return OK; return OK;
} }
int PDC_modifiers_set(void) int PDC_modifiers_set(void)
{ {
return OK; return OK;
 End of changes. 34 change blocks. 
55 lines changed or deleted 50 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)