82 |
static INPUT_RECORD event_queue[EVENT_QUEUE_SIZE]; |
static INPUT_RECORD event_queue[EVENT_QUEUE_SIZE]; |
83 |
static INPUT_RECORD *queue_ptr = event_queue, *queue_end = event_queue; |
static INPUT_RECORD *queue_ptr = event_queue, *queue_end = event_queue; |
84 |
|
|
85 |
static int |
static int |
86 |
fill_queue (BOOL block) |
fill_queue (BOOL block) |
87 |
{ |
{ |
88 |
BOOL rc; |
BOOL rc; |
89 |
DWORD events_waiting; |
DWORD events_waiting; |
90 |
|
|
91 |
if (queue_ptr < queue_end) |
if (queue_ptr < queue_end) |
92 |
return queue_end-queue_ptr; |
return queue_end-queue_ptr; |
93 |
|
|
94 |
if (!block) |
if (!block) |
95 |
{ |
{ |
96 |
/* Check to see if there are some events to read before we try |
/* Check to see if there are some events to read before we try |
100 |
if (events_waiting == 0) |
if (events_waiting == 0) |
101 |
return 0; |
return 0; |
102 |
} |
} |
103 |
|
|
104 |
rc = ReadConsoleInput (keyboard_handle, event_queue, EVENT_QUEUE_SIZE, |
rc = ReadConsoleInput (keyboard_handle, event_queue, EVENT_QUEUE_SIZE, |
105 |
&events_waiting); |
&events_waiting); |
106 |
if (!rc) |
if (!rc) |
114 |
and return the frame for it |
and return the frame for it |
115 |
|
|
116 |
Right now, there's only one frame so return it. */ |
Right now, there's only one frame so return it. */ |
117 |
static FRAME_PTR |
static FRAME_PTR |
118 |
get_frame (void) |
get_frame (void) |
119 |
{ |
{ |
120 |
return SELECTED_FRAME (); |
return SELECTED_FRAME (); |
121 |
} |
} |
122 |
|
|
123 |
/* Translate console modifiers to emacs modifiers. |
/* Translate console modifiers to emacs modifiers. |
124 |
German keyboard support (Kai Morgan Zeise 2/18/95). */ |
German keyboard support (Kai Morgan Zeise 2/18/95). */ |
125 |
int |
int |
126 |
w32_kbd_mods_to_emacs (DWORD mods, WORD key) |
w32_kbd_mods_to_emacs (DWORD mods, WORD key) |
129 |
|
|
130 |
/* If we recognize right-alt and left-ctrl as AltGr, and it has been |
/* If we recognize right-alt and left-ctrl as AltGr, and it has been |
131 |
pressed, first remove those modifiers. */ |
pressed, first remove those modifiers. */ |
132 |
if (!NILP (Vw32_recognize_altgr) |
if (!NILP (Vw32_recognize_altgr) |
133 |
&& (mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED)) |
&& (mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED)) |
134 |
== (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED)) |
== (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED)) |
135 |
mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED); |
mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED); |
136 |
|
|
137 |
if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) |
if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) |
138 |
retval = ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier); |
retval = ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier); |
139 |
|
|
140 |
if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) |
if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) |
141 |
{ |
{ |
142 |
retval |= ctrl_modifier; |
retval |= ctrl_modifier; |
143 |
if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) |
if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) |
144 |
== (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) |
== (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) |
145 |
retval |= meta_modifier; |
retval |= meta_modifier; |
146 |
} |
} |
212 |
isdead = 0; |
isdead = 0; |
213 |
return 1; |
return 1; |
214 |
} |
} |
215 |
if (event->uChar.AsciiChar != 0) |
if (event->uChar.AsciiChar != 0) |
216 |
return 1; |
return 1; |
217 |
|
|
218 |
memset (keystate, 0, sizeof (keystate)); |
memset (keystate, 0, sizeof (keystate)); |
219 |
keystate[key_code] = 0x80; |
keystate[key_code] = 0x80; |
220 |
if (mods & SHIFT_PRESSED) |
if (mods & SHIFT_PRESSED) |
221 |
keystate[VK_SHIFT] = 0x80; |
keystate[VK_SHIFT] = 0x80; |
222 |
if (mods & CAPSLOCK_ON) |
if (mods & CAPSLOCK_ON) |
223 |
keystate[VK_CAPITAL] = 1; |
keystate[VK_CAPITAL] = 1; |
224 |
/* If we recognize right-alt and left-ctrl as AltGr, set the key |
/* If we recognize right-alt and left-ctrl as AltGr, set the key |
225 |
states accordingly before invoking ToAscii. */ |
states accordingly before invoking ToAscii. */ |
272 |
keystate, (LPWORD) ansi_code, 0); |
keystate, (LPWORD) ansi_code, 0); |
273 |
} |
} |
274 |
|
|
275 |
if (isdead == 0) |
if (isdead == 0) |
276 |
return 0; |
return 0; |
277 |
event->uChar.AsciiChar = ansi_code[0]; |
event->uChar.AsciiChar = ansi_code[0]; |
278 |
return isdead; |
return isdead; |
283 |
|
|
284 |
static int faked_key = 0; |
static int faked_key = 0; |
285 |
|
|
286 |
/* return code -1 means that event_queue_ptr won't be incremented. |
/* return code -1 means that event_queue_ptr won't be incremented. |
287 |
In other word, this event makes two key codes. (by himi) */ |
In other word, this event makes two key codes. (by himi) */ |
288 |
int |
int |
289 |
key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead) |
key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead) |
290 |
{ |
{ |
291 |
static int mod_key_state = 0; |
static int mod_key_state = 0; |
506 |
} |
} |
507 |
|
|
508 |
/* Mouse position hook. */ |
/* Mouse position hook. */ |
509 |
void |
void |
510 |
w32_console_mouse_position (FRAME_PTR *f, |
w32_console_mouse_position (FRAME_PTR *f, |
511 |
int insist, |
int insist, |
512 |
Lisp_Object *bar_window, |
Lisp_Object *bar_window, |
523 |
*bar_window = Qnil; |
*bar_window = Qnil; |
524 |
*part = 0; |
*part = 0; |
525 |
SELECTED_FRAME ()->mouse_moved = 0; |
SELECTED_FRAME ()->mouse_moved = 0; |
526 |
|
|
527 |
*x = movement_pos.X; |
*x = movement_pos.X; |
528 |
*y = movement_pos.Y; |
*y = movement_pos.Y; |
529 |
*time = movement_time; |
*time = movement_time; |
530 |
|
|
531 |
UNBLOCK_INPUT; |
UNBLOCK_INPUT; |
532 |
} |
} |
533 |
|
|
534 |
/* Remember mouse motion and notify emacs. */ |
/* Remember mouse motion and notify emacs. */ |
535 |
static void |
static void |
536 |
mouse_moved_to (int x, int y) |
mouse_moved_to (int x, int y) |
537 |
{ |
{ |
538 |
/* If we're in the same place, ignore it */ |
/* If we're in the same place, ignore it */ |
563 |
0, 2, 1 |
0, 2, 1 |
564 |
}; |
}; |
565 |
|
|
566 |
static int |
static int |
567 |
do_mouse_event (MOUSE_EVENT_RECORD *event, |
do_mouse_event (MOUSE_EVENT_RECORD *event, |
568 |
struct input_event *emacs_ev) |
struct input_event *emacs_ev) |
569 |
{ |
{ |
570 |
static DWORD button_state = 0; |
static DWORD button_state = 0; |
571 |
DWORD but_change, mask; |
DWORD but_change, mask; |
572 |
int i; |
int i; |
573 |
|
|
574 |
if (event->dwEventFlags == MOUSE_MOVED) |
if (event->dwEventFlags == MOUSE_MOVED) |
575 |
{ |
{ |
576 |
/* For movement events we just note that the mouse has moved |
/* For movement events we just note that the mouse has moved |
578 |
mouse_moved_to (event->dwMousePosition.X, event->dwMousePosition.Y); |
mouse_moved_to (event->dwMousePosition.X, event->dwMousePosition.Y); |
579 |
return 0; |
return 0; |
580 |
} |
} |
581 |
|
|
582 |
/* It looks like the console code sends us a mouse event with |
/* It looks like the console code sends us a mouse event with |
583 |
dwButtonState == 0 when a window is activated. Ignore this case. */ |
dwButtonState == 0 when a window is activated. Ignore this case. */ |
584 |
if (event->dwButtonState == button_state) |
if (event->dwButtonState == button_state) |
585 |
return 0; |
return 0; |
586 |
|
|
587 |
emacs_ev->kind = MOUSE_CLICK_EVENT; |
emacs_ev->kind = MOUSE_CLICK_EVENT; |
588 |
|
|
589 |
/* Find out what button has changed state since the last button event. */ |
/* Find out what button has changed state since the last button event. */ |
590 |
but_change = button_state ^ event->dwButtonState; |
but_change = button_state ^ event->dwButtonState; |
591 |
mask = 1; |
mask = 1; |
603 |
emacs_ev->timestamp = GetTickCount (); |
emacs_ev->timestamp = GetTickCount (); |
604 |
emacs_ev->modifiers = w32_kbd_mods_to_emacs (event->dwControlKeyState, 0) | |
emacs_ev->modifiers = w32_kbd_mods_to_emacs (event->dwControlKeyState, 0) | |
605 |
((event->dwButtonState & mask) ? down_modifier : up_modifier); |
((event->dwButtonState & mask) ? down_modifier : up_modifier); |
606 |
|
|
607 |
XSETFASTINT (emacs_ev->x, event->dwMousePosition.X); |
XSETFASTINT (emacs_ev->x, event->dwMousePosition.X); |
608 |
XSETFASTINT (emacs_ev->y, event->dwMousePosition.Y); |
XSETFASTINT (emacs_ev->y, event->dwMousePosition.Y); |
609 |
/* for Mule 2.2 (Based on Emacs 19.28 */ |
/* for Mule 2.2 (Based on Emacs 19.28 */ |
612 |
#else |
#else |
613 |
XSETFRAME (emacs_ev->frame_or_window, get_frame ()); |
XSETFRAME (emacs_ev->frame_or_window, get_frame ()); |
614 |
#endif |
#endif |
615 |
|
|
616 |
return 1; |
return 1; |
617 |
} |
} |
618 |
|
|
619 |
static void |
static void |
620 |
resize_event (WINDOW_BUFFER_SIZE_RECORD *event) |
resize_event (WINDOW_BUFFER_SIZE_RECORD *event) |
621 |
{ |
{ |
622 |
FRAME_PTR f = get_frame (); |
FRAME_PTR f = get_frame (); |
623 |
|
|
624 |
change_frame_size (f, event->dwSize.Y, event->dwSize.X, 0, 1); |
change_frame_size (f, event->dwSize.Y, event->dwSize.X, 0, 1); |
625 |
SET_FRAME_GARBAGED (f); |
SET_FRAME_GARBAGED (f); |
626 |
} |
} |
641 |
0, 0); |
0, 0); |
642 |
} |
} |
643 |
|
|
644 |
int |
int |
645 |
w32_console_read_socket (int sd, struct input_event *bufp, int numchars, |
w32_console_read_socket (int sd, struct input_event *bufp, int numchars, |
646 |
int expected) |
int expected) |
647 |
{ |
{ |
654 |
interrupt_input_pending = 1; |
interrupt_input_pending = 1; |
655 |
return -1; |
return -1; |
656 |
} |
} |
657 |
|
|
658 |
interrupt_input_pending = 0; |
interrupt_input_pending = 0; |
659 |
BLOCK_INPUT; |
BLOCK_INPUT; |
660 |
|
|
661 |
for (;;) |
for (;;) |
662 |
{ |
{ |
663 |
nev = fill_queue (0); |
nev = fill_queue (0); |
677 |
case KEY_EVENT: |
case KEY_EVENT: |
678 |
add = key_event (&queue_ptr->Event.KeyEvent, bufp, &isdead); |
add = key_event (&queue_ptr->Event.KeyEvent, bufp, &isdead); |
679 |
if (add == -1) /* 95.7.25 by himi */ |
if (add == -1) /* 95.7.25 by himi */ |
680 |
{ |
{ |
681 |
queue_ptr--; |
queue_ptr--; |
682 |
add = 1; |
add = 1; |
683 |
} |
} |
697 |
if (w32_use_full_screen_buffer) |
if (w32_use_full_screen_buffer) |
698 |
resize_event (&queue_ptr->Event.WindowBufferSizeEvent); |
resize_event (&queue_ptr->Event.WindowBufferSizeEvent); |
699 |
break; |
break; |
700 |
|
|
701 |
case MENU_EVENT: |
case MENU_EVENT: |
702 |
case FOCUS_EVENT: |
case FOCUS_EVENT: |
703 |
/* Internal event types, ignored. */ |
/* Internal event types, ignored. */ |
704 |
break; |
break; |
705 |
} |
} |
706 |
|
|
707 |
queue_ptr++; |
queue_ptr++; |
708 |
nev--; |
nev--; |
709 |
} |
} |