comparison src/w32inevt.c @ 49600:23a1cea22d13

Trailing whitespace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 14:56:31 +0000
parents 863817d7e734
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49599:5ade352e8d1c 49600:23a1cea22d13
80 /* Event queue */ 80 /* Event queue */
81 #define EVENT_QUEUE_SIZE 50 81 #define EVENT_QUEUE_SIZE 50
82 static INPUT_RECORD event_queue[EVENT_QUEUE_SIZE]; 82 static INPUT_RECORD event_queue[EVENT_QUEUE_SIZE];
83 static INPUT_RECORD *queue_ptr = event_queue, *queue_end = event_queue; 83 static INPUT_RECORD *queue_ptr = event_queue, *queue_end = event_queue;
84 84
85 static int 85 static int
86 fill_queue (BOOL block) 86 fill_queue (BOOL block)
87 { 87 {
88 BOOL rc; 88 BOOL rc;
89 DWORD events_waiting; 89 DWORD events_waiting;
90 90
91 if (queue_ptr < queue_end) 91 if (queue_ptr < queue_end)
92 return queue_end-queue_ptr; 92 return queue_end-queue_ptr;
93 93
94 if (!block) 94 if (!block)
95 { 95 {
96 /* Check to see if there are some events to read before we try 96 /* Check to see if there are some events to read before we try
97 because we can't block. */ 97 because we can't block. */
98 if (!GetNumberOfConsoleInputEvents (keyboard_handle, &events_waiting)) 98 if (!GetNumberOfConsoleInputEvents (keyboard_handle, &events_waiting))
99 return -1; 99 return -1;
100 if (events_waiting == 0) 100 if (events_waiting == 0)
101 return 0; 101 return 0;
102 } 102 }
103 103
104 rc = ReadConsoleInput (keyboard_handle, event_queue, EVENT_QUEUE_SIZE, 104 rc = ReadConsoleInput (keyboard_handle, event_queue, EVENT_QUEUE_SIZE,
105 &events_waiting); 105 &events_waiting);
106 if (!rc) 106 if (!rc)
107 return -1; 107 return -1;
108 queue_ptr = event_queue; 108 queue_ptr = event_queue;
112 112
113 /* In a generic, multi-frame world this should take a console handle 113 /* In a generic, multi-frame world this should take a console handle
114 and return the frame for it 114 and return the frame for it
115 115
116 Right now, there's only one frame so return it. */ 116 Right now, there's only one frame so return it. */
117 static FRAME_PTR 117 static FRAME_PTR
118 get_frame (void) 118 get_frame (void)
119 { 119 {
120 return SELECTED_FRAME (); 120 return SELECTED_FRAME ();
121 } 121 }
122 122
123 /* Translate console modifiers to emacs modifiers. 123 /* Translate console modifiers to emacs modifiers.
124 German keyboard support (Kai Morgan Zeise 2/18/95). */ 124 German keyboard support (Kai Morgan Zeise 2/18/95). */
125 int 125 int
126 w32_kbd_mods_to_emacs (DWORD mods, WORD key) 126 w32_kbd_mods_to_emacs (DWORD mods, WORD key)
127 { 127 {
128 int retval = 0; 128 int retval = 0;
129 129
130 /* If we recognize right-alt and left-ctrl as AltGr, and it has been 130 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
131 pressed, first remove those modifiers. */ 131 pressed, first remove those modifiers. */
132 if (!NILP (Vw32_recognize_altgr) 132 if (!NILP (Vw32_recognize_altgr)
133 && (mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED)) 133 && (mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
134 == (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED)) 134 == (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
135 mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED); 135 mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED);
136 136
137 if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) 137 if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
138 retval = ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier); 138 retval = ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier);
139 139
140 if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) 140 if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
141 { 141 {
142 retval |= ctrl_modifier; 142 retval |= ctrl_modifier;
143 if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) 143 if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
144 == (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) 144 == (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
145 retval |= meta_modifier; 145 retval |= meta_modifier;
146 } 146 }
147 147
148 if (mods & LEFT_WIN_PRESSED) 148 if (mods & LEFT_WIN_PRESSED)
210 { 210 {
211 event->uChar.AsciiChar = ansi_code[2]; 211 event->uChar.AsciiChar = ansi_code[2];
212 isdead = 0; 212 isdead = 0;
213 return 1; 213 return 1;
214 } 214 }
215 if (event->uChar.AsciiChar != 0) 215 if (event->uChar.AsciiChar != 0)
216 return 1; 216 return 1;
217 217
218 memset (keystate, 0, sizeof (keystate)); 218 memset (keystate, 0, sizeof (keystate));
219 keystate[key_code] = 0x80; 219 keystate[key_code] = 0x80;
220 if (mods & SHIFT_PRESSED) 220 if (mods & SHIFT_PRESSED)
221 keystate[VK_SHIFT] = 0x80; 221 keystate[VK_SHIFT] = 0x80;
222 if (mods & CAPSLOCK_ON) 222 if (mods & CAPSLOCK_ON)
223 keystate[VK_CAPITAL] = 1; 223 keystate[VK_CAPITAL] = 1;
224 /* If we recognize right-alt and left-ctrl as AltGr, set the key 224 /* If we recognize right-alt and left-ctrl as AltGr, set the key
225 states accordingly before invoking ToAscii. */ 225 states accordingly before invoking ToAscii. */
226 if (!NILP (Vw32_recognize_altgr) 226 if (!NILP (Vw32_recognize_altgr)
227 && (mods & LEFT_CTRL_PRESSED) && (mods & RIGHT_ALT_PRESSED)) 227 && (mods & LEFT_CTRL_PRESSED) && (mods & RIGHT_ALT_PRESSED))
270 { 270 {
271 isdead = ToAscii (event->wVirtualKeyCode, event->wVirtualScanCode, 271 isdead = ToAscii (event->wVirtualKeyCode, event->wVirtualScanCode,
272 keystate, (LPWORD) ansi_code, 0); 272 keystate, (LPWORD) ansi_code, 0);
273 } 273 }
274 274
275 if (isdead == 0) 275 if (isdead == 0)
276 return 0; 276 return 0;
277 event->uChar.AsciiChar = ansi_code[0]; 277 event->uChar.AsciiChar = ansi_code[0];
278 return isdead; 278 return isdead;
279 } 279 }
280 280
281 281
282 extern char *lispy_function_keys[]; 282 extern char *lispy_function_keys[];
283 283
284 static int faked_key = 0; 284 static int faked_key = 0;
285 285
286 /* return code -1 means that event_queue_ptr won't be incremented. 286 /* return code -1 means that event_queue_ptr won't be incremented.
287 In other word, this event makes two key codes. (by himi) */ 287 In other word, this event makes two key codes. (by himi) */
288 int 288 int
289 key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead) 289 key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead)
290 { 290 {
291 static int mod_key_state = 0; 291 static int mod_key_state = 0;
292 int wParam; 292 int wParam;
293 293
504 504
505 return cur_state; 505 return cur_state;
506 } 506 }
507 507
508 /* Mouse position hook. */ 508 /* Mouse position hook. */
509 void 509 void
510 w32_console_mouse_position (FRAME_PTR *f, 510 w32_console_mouse_position (FRAME_PTR *f,
511 int insist, 511 int insist,
512 Lisp_Object *bar_window, 512 Lisp_Object *bar_window,
513 enum scroll_bar_part *part, 513 enum scroll_bar_part *part,
514 Lisp_Object *x, 514 Lisp_Object *x,
521 521
522 *f = get_frame (); 522 *f = get_frame ();
523 *bar_window = Qnil; 523 *bar_window = Qnil;
524 *part = 0; 524 *part = 0;
525 SELECTED_FRAME ()->mouse_moved = 0; 525 SELECTED_FRAME ()->mouse_moved = 0;
526 526
527 *x = movement_pos.X; 527 *x = movement_pos.X;
528 *y = movement_pos.Y; 528 *y = movement_pos.Y;
529 *time = movement_time; 529 *time = movement_time;
530 530
531 UNBLOCK_INPUT; 531 UNBLOCK_INPUT;
532 } 532 }
533 533
534 /* Remember mouse motion and notify emacs. */ 534 /* Remember mouse motion and notify emacs. */
535 static void 535 static void
536 mouse_moved_to (int x, int y) 536 mouse_moved_to (int x, int y)
537 { 537 {
538 /* If we're in the same place, ignore it */ 538 /* If we're in the same place, ignore it */
539 if (x != movement_pos.X || y != movement_pos.Y) 539 if (x != movement_pos.X || y != movement_pos.Y)
540 { 540 {
561 static int emacs_button_translation[NUM_TRANSLATED_MOUSE_BUTTONS] = 561 static int emacs_button_translation[NUM_TRANSLATED_MOUSE_BUTTONS] =
562 { 562 {
563 0, 2, 1 563 0, 2, 1
564 }; 564 };
565 565
566 static int 566 static int
567 do_mouse_event (MOUSE_EVENT_RECORD *event, 567 do_mouse_event (MOUSE_EVENT_RECORD *event,
568 struct input_event *emacs_ev) 568 struct input_event *emacs_ev)
569 { 569 {
570 static DWORD button_state = 0; 570 static DWORD button_state = 0;
571 DWORD but_change, mask; 571 DWORD but_change, mask;
572 int i; 572 int i;
573 573
574 if (event->dwEventFlags == MOUSE_MOVED) 574 if (event->dwEventFlags == MOUSE_MOVED)
575 { 575 {
576 /* For movement events we just note that the mouse has moved 576 /* For movement events we just note that the mouse has moved
577 so that emacs will generate drag events. */ 577 so that emacs will generate drag events. */
578 mouse_moved_to (event->dwMousePosition.X, event->dwMousePosition.Y); 578 mouse_moved_to (event->dwMousePosition.X, event->dwMousePosition.Y);
579 return 0; 579 return 0;
580 } 580 }
581 581
582 /* It looks like the console code sends us a mouse event with 582 /* It looks like the console code sends us a mouse event with
583 dwButtonState == 0 when a window is activated. Ignore this case. */ 583 dwButtonState == 0 when a window is activated. Ignore this case. */
584 if (event->dwButtonState == button_state) 584 if (event->dwButtonState == button_state)
585 return 0; 585 return 0;
586 586
587 emacs_ev->kind = MOUSE_CLICK_EVENT; 587 emacs_ev->kind = MOUSE_CLICK_EVENT;
588 588
589 /* Find out what button has changed state since the last button event. */ 589 /* Find out what button has changed state since the last button event. */
590 but_change = button_state ^ event->dwButtonState; 590 but_change = button_state ^ event->dwButtonState;
591 mask = 1; 591 mask = 1;
592 for (i = 0; mask; i++, mask <<= 1) 592 for (i = 0; mask; i++, mask <<= 1)
593 if (but_change & mask) 593 if (but_change & mask)
601 601
602 button_state = event->dwButtonState; 602 button_state = event->dwButtonState;
603 emacs_ev->timestamp = GetTickCount (); 603 emacs_ev->timestamp = GetTickCount ();
604 emacs_ev->modifiers = w32_kbd_mods_to_emacs (event->dwControlKeyState, 0) | 604 emacs_ev->modifiers = w32_kbd_mods_to_emacs (event->dwControlKeyState, 0) |
605 ((event->dwButtonState & mask) ? down_modifier : up_modifier); 605 ((event->dwButtonState & mask) ? down_modifier : up_modifier);
606 606
607 XSETFASTINT (emacs_ev->x, event->dwMousePosition.X); 607 XSETFASTINT (emacs_ev->x, event->dwMousePosition.X);
608 XSETFASTINT (emacs_ev->y, event->dwMousePosition.Y); 608 XSETFASTINT (emacs_ev->y, event->dwMousePosition.Y);
609 /* for Mule 2.2 (Based on Emacs 19.28 */ 609 /* for Mule 2.2 (Based on Emacs 19.28 */
610 #ifdef MULE 610 #ifdef MULE
611 XSET (emacs_ev->frame_or_window, Lisp_Frame, get_frame ()); 611 XSET (emacs_ev->frame_or_window, Lisp_Frame, get_frame ());
612 #else 612 #else
613 XSETFRAME (emacs_ev->frame_or_window, get_frame ()); 613 XSETFRAME (emacs_ev->frame_or_window, get_frame ());
614 #endif 614 #endif
615 615
616 return 1; 616 return 1;
617 } 617 }
618 618
619 static void 619 static void
620 resize_event (WINDOW_BUFFER_SIZE_RECORD *event) 620 resize_event (WINDOW_BUFFER_SIZE_RECORD *event)
621 { 621 {
622 FRAME_PTR f = get_frame (); 622 FRAME_PTR f = get_frame ();
623 623
624 change_frame_size (f, event->dwSize.Y, event->dwSize.X, 0, 1); 624 change_frame_size (f, event->dwSize.Y, event->dwSize.X, 0, 1);
625 SET_FRAME_GARBAGED (f); 625 SET_FRAME_GARBAGED (f);
626 } 626 }
627 627
628 static void 628 static void
639 1 + info.srWindow.Bottom - info.srWindow.Top, 639 1 + info.srWindow.Bottom - info.srWindow.Top,
640 1 + info.srWindow.Right - info.srWindow.Left, 640 1 + info.srWindow.Right - info.srWindow.Left,
641 0, 0); 641 0, 0);
642 } 642 }
643 643
644 int 644 int
645 w32_console_read_socket (int sd, struct input_event *bufp, int numchars, 645 w32_console_read_socket (int sd, struct input_event *bufp, int numchars,
646 int expected) 646 int expected)
647 { 647 {
648 BOOL no_events = TRUE; 648 BOOL no_events = TRUE;
649 int nev, ret = 0, add; 649 int nev, ret = 0, add;
652 if (interrupt_input_blocked) 652 if (interrupt_input_blocked)
653 { 653 {
654 interrupt_input_pending = 1; 654 interrupt_input_pending = 1;
655 return -1; 655 return -1;
656 } 656 }
657 657
658 interrupt_input_pending = 0; 658 interrupt_input_pending = 0;
659 BLOCK_INPUT; 659 BLOCK_INPUT;
660 660
661 for (;;) 661 for (;;)
662 { 662 {
663 nev = fill_queue (0); 663 nev = fill_queue (0);
664 if (nev <= 0) 664 if (nev <= 0)
665 { 665 {
675 switch (queue_ptr->EventType) 675 switch (queue_ptr->EventType)
676 { 676 {
677 case KEY_EVENT: 677 case KEY_EVENT:
678 add = key_event (&queue_ptr->Event.KeyEvent, bufp, &isdead); 678 add = key_event (&queue_ptr->Event.KeyEvent, bufp, &isdead);
679 if (add == -1) /* 95.7.25 by himi */ 679 if (add == -1) /* 95.7.25 by himi */
680 { 680 {
681 queue_ptr--; 681 queue_ptr--;
682 add = 1; 682 add = 1;
683 } 683 }
684 bufp += add; 684 bufp += add;
685 ret += add; 685 ret += add;
695 695
696 case WINDOW_BUFFER_SIZE_EVENT: 696 case WINDOW_BUFFER_SIZE_EVENT:
697 if (w32_use_full_screen_buffer) 697 if (w32_use_full_screen_buffer)
698 resize_event (&queue_ptr->Event.WindowBufferSizeEvent); 698 resize_event (&queue_ptr->Event.WindowBufferSizeEvent);
699 break; 699 break;
700 700
701 case MENU_EVENT: 701 case MENU_EVENT:
702 case FOCUS_EVENT: 702 case FOCUS_EVENT:
703 /* Internal event types, ignored. */ 703 /* Internal event types, ignored. */
704 break; 704 break;
705 } 705 }
706 706
707 queue_ptr++; 707 queue_ptr++;
708 nev--; 708 nev--;
709 } 709 }
710 710
711 if (ret > 0 || expected == 0) 711 if (ret > 0 || expected == 0)