comparison src/event-msw.c @ 308:33bdb3d4b97f r21-0b52

Import from CVS: tag r21-0b52
author cvs
date Mon, 13 Aug 2007 10:42:44 +0200
parents 70ad99077275
children 341dac730539
comparison
equal deleted inserted replaced
307:42d630fd9bd8 308:33bdb3d4b97f
96 static struct event_stream *mswindows_event_stream; 96 static struct event_stream *mswindows_event_stream;
97 97
98 #ifdef HAVE_MSG_SELECT 98 #ifdef HAVE_MSG_SELECT
99 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask; 99 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
100 extern SELECT_TYPE process_only_mask, tty_only_mask; 100 extern SELECT_TYPE process_only_mask, tty_only_mask;
101 SELECT_TYPE zero_mask;
101 extern int signal_event_pipe_initialized; 102 extern int signal_event_pipe_initialized;
102 int windows_fd; 103 int windows_fd;
103 #endif 104 #endif
104 105
105 /* 106 /*
1292 { 1293 {
1293 EMACS_SET_SECS_USECS (sometime, 0, 0); 1294 EMACS_SET_SECS_USECS (sometime, 0, 0);
1294 EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block); 1295 EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block);
1295 pointer_to_this = &select_time_to_block; 1296 pointer_to_this = &select_time_to_block;
1296 } 1297 }
1298
1299 /* select() is slow and buggy so if we don't have any processes
1300 just wait as normal */
1301 if (memcmp (&process_only_mask, &zero_mask, sizeof(SELECT_TYPE))==0)
1302 {
1303 /* Now try getting a message or process event */
1304 active = MsgWaitForMultipleObjects (0, mswindows_waitable_handles,
1305 FALSE, badly_p ? INFINITE : 0,
1306 QS_ALLINPUT);
1307
1308 if (active == WAIT_TIMEOUT)
1309 {
1310 /* No luck trying - just return what we've already got */
1311 return;
1312 }
1313 else if (active == WAIT_OBJECT_0)
1314 {
1315 /* Got your message, thanks */
1316 mswindows_drain_windows_queue ();
1317 continue;
1318 }
1319 }
1320
1297 active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this); 1321 active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this);
1298 1322
1299 if (active == 0) 1323 if (active == 0)
1300 { 1324 {
1301 return; /* timeout */ 1325 return; /* timeout */
1570 case WM_CLOSE: 1594 case WM_CLOSE:
1571 fobj = mswindows_find_frame (hwnd); 1595 fobj = mswindows_find_frame (hwnd);
1572 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt)); 1596 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
1573 break; 1597 break;
1574 1598
1599 case WM_KEYUP:
1600 case WM_SYSKEYUP:
1601 /* See Win95 comment under WM_KEYDOWN */
1602 {
1603 BYTE keymap[256];
1604
1605 if (wParam == VK_CONTROL)
1606 {
1607 GetKeyboardState (keymap);
1608 keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] &= ~0x80;
1609 SetKeyboardState (keymap);
1610 }
1611 else if (wParam == VK_MENU)
1612 {
1613 GetKeyboardState (keymap);
1614 keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] &= ~0x80;
1615 SetKeyboardState (keymap);
1616 }
1617 };
1618 goto defproc;
1619
1575 case WM_KEYDOWN: 1620 case WM_KEYDOWN:
1576 case WM_SYSKEYDOWN: 1621 case WM_SYSKEYDOWN:
1622 /* In some locales the right-hand Alt key is labelled AltGr. This key
1623 * should produce alternative charcaters when combined with another key.
1624 * eg on a German keyboard pressing AltGr+q should produce '@'.
1625 * AltGr generates exactly the same keystrokes as LCtrl+RAlt. But if
1626 * TranslateMessage() is called with *any* combination of Ctrl+Alt down,
1627 * it translates as if AltGr were down.
1628 * We get round this by removing all modifiers from the keymap before
1629 * calling TranslateMessage() unless AltGr is *really* down. */
1577 { 1630 {
1578 BYTE keymap[256]; 1631 BYTE keymap[256];
1579 int has_AltGr = mswindows_current_layout_has_AltGr (); 1632 int has_AltGr = mswindows_current_layout_has_AltGr ();
1580 int mods; 1633 int mods;
1581 Lisp_Object keysym; 1634 Lisp_Object keysym;
1582 1635
1583 GetKeyboardState (keymap); 1636 GetKeyboardState (keymap);
1584 mods = mswindows_modifier_state (keymap, has_AltGr); 1637 mods = mswindows_modifier_state (keymap, has_AltGr);
1585 1638
1586 /* Handle those keys that TranslateMessage won't generate a WM_CHAR for */ 1639 /* Handle those keys for which TranslateMessage won't generate a WM_CHAR */
1587 if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods))) 1640 if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods)))
1588 mswindows_enqueue_keypress_event (hwnd, keysym, mods); 1641 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
1589 else 1642 else
1590 { 1643 {
1591 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd))); 1644 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
1592 BYTE keymap_orig[256]; 1645 BYTE keymap_orig[256];
1593 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), (GetMessagePos()) }; 1646 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), (GetMessagePos()) };
1647
1648 /* GetKeyboardState() does not work as documented on Win95. We have
1649 * to loosely track Left and Right modifiers on behalf of the OS,
1650 * without screwing up Windows NT which tracks them properly. */
1651 if (wParam == VK_CONTROL)
1652 keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
1653 else if (wParam == VK_MENU)
1654 keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] |= 0x80;
1655
1594 memcpy (keymap_orig, keymap, 256); 1656 memcpy (keymap_orig, keymap, 256);
1595 1657
1596 /* Remove shift modifier from an ascii character */ 1658 /* Remove shift modifier from an ascii character */
1597 mods &= ~MOD_SHIFT; 1659 mods &= ~MOD_SHIFT;
1598 1660
1599 /* Clear control and alt modifiers out of the keymap */ 1661 /* Clear control and alt modifiers unless AltGr is pressed */
1600 keymap [VK_RCONTROL] = 0; 1662 keymap [VK_RCONTROL] = 0;
1601 keymap [VK_LMENU] = 0; 1663 keymap [VK_LMENU] = 0;
1602 if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80)) 1664 if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80))
1603 { 1665 {
1604 keymap [VK_LCONTROL] = 0; 1666 keymap [VK_LCONTROL] = 0;
1606 keymap [VK_RMENU] = 0; 1668 keymap [VK_RMENU] = 0;
1607 keymap [VK_MENU] = 0; 1669 keymap [VK_MENU] = 0;
1608 } 1670 }
1609 SetKeyboardState (keymap); 1671 SetKeyboardState (keymap);
1610 1672
1611 /* Have some WM_[SYS]CHARS in the queue */ 1673 /* Maybe generate some WM_[SYS]CHARs in the queue */
1612 TranslateMessage (&msg); 1674 TranslateMessage (&msg);
1613 1675
1614 while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE) 1676 while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
1615 || PeekMessage (&msg, hwnd, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE)) 1677 || PeekMessage (&msg, hwnd, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE))
1616 { 1678 {
2776 { 2838 {
2777 #ifdef HAVE_MSG_SELECT 2839 #ifdef HAVE_MSG_SELECT
2778 windows_fd = open("/dev/windows", O_RDONLY | O_NONBLOCK, 0); 2840 windows_fd = open("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
2779 assert (windows_fd>=0); 2841 assert (windows_fd>=0);
2780 FD_SET (windows_fd, &input_wait_mask); 2842 FD_SET (windows_fd, &input_wait_mask);
2781 /* for some reason I get blocks on the signal event pipe, which is 2843 FD_ZERO(&zero_mask);
2782 bad...
2783 signal_event_pipe_initialized = 0; */
2784 #endif 2844 #endif
2785 2845
2786 event_stream = mswindows_event_stream; 2846 event_stream = mswindows_event_stream;
2787 2847
2788 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE); 2848 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);