#ifdef HAVE_MSG_SELECT
extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
extern SELECT_TYPE process_only_mask, tty_only_mask;
+SELECT_TYPE zero_mask;
extern int signal_event_pipe_initialized;
int windows_fd;
#endif
/* This structure is allocated by the main thread, and is deallocated
in the thread upon exit. There are situations when a thread
remains blocked for a long time, much longer than the lstream
- exists. For exmaple, "start notepad" command is issued from the
+ exists. For example, "start notepad" command is issued from the
shell, then the shell is closed by C-c C-d. Although the shell
process exits, its output pipe will not get closed until the
notepad process exits also, because it inherits the pipe form the
sizeof (struct ntpipe_slurp_stream));
/* This function is thread-safe, and is called from either thread
- context. It serializes freeing shared dtata structure */
+ context. It serializes freeing shared data structure */
static void
slurper_free_shared_data_maybe (struct ntpipe_slurp_stream_shared_data* s)
{
if (s->die_p)
break;
- /* Block until the client finishes with retireving the rest of
+ /* Block until the client finishes with retrieving the rest of
pipe data */
WaitForSingleObject (s->hev_thread, INFINITE);
}
OVERLAPPED ov; /* Overlapped I/O structure */
void* buffer; /* Buffer. Allocated for input stream only */
unsigned int bufsize; /* Number of bytes last read */
- unsigned int bufpos; /* Psition in buffer for next fetch */
+ unsigned int bufpos; /* Position in buffer for next fetch */
unsigned int error_p :1; /* I/O Error seen */
unsigned int eof_p :1; /* EOF Error seen */
unsigned int pending_p :1; /* There is a pending I/O operation */
{
ResetEvent (str->ov.hEvent);
-
- if (WriteFile ((HANDLE)str->s, data, size, NULL, &str->ov)
+
+ /* Docs indicate that 4th parameter to WriteFile can be NULL since this is
+ * an overlapped operation. This fails on Win95 with winsock 1.x so we
+ * supply a spare address which is ignored by Win95 anyway. Sheesh. */
+ if (WriteFile ((HANDLE)str->s, data, size, (LPDWORD)&str->buffer, &str->ov)
|| GetLastError() == ERROR_IO_PENDING)
str->pending_p = 1;
else
* neither are waitable handles checked. The function pumps
* thus only dispatch events already queued, as well as those
* resulted in dispatching thereof. This is done by setting
- * module local variable mswidows_in_modal_loop to nonzero.
+ * module local variable mswindows_in_modal_loop to nonzero.
*
* Return value is Qt if no errors was trapped, or Qunbound if
* there was an error.
* If the value of mswindows_error_caught_in_modal_loop is not
* nil already upon entry, the function just returns non-nil.
* This situation means that a new event has been queued while
- * cancleng mode. The event will be dequeued on the next regular
+ * in cancel mode. The event will be dequeued on the next regular
* call of next-event; the pump is off since error is caught.
* The caller must *unconditionally* cancel modal loop if the
* value returned by this function is nil. Otherwise, everything
}
/*
- * This is a special flavour of the mswindows_need_event function,
+ * This is a special flavor of the mswindows_need_event function,
* used while in event pump. Actually, there is only kind of events
* allowed while in event pump: a timer. An attempt to fetch any
- * other event leads to a dealock, as there's no source of user input
+ * other event leads to a deadlock, as there's no source of user input
* ('cause event pump mirrors windows modal loop, which is a sole
* owner of thread message queue).
*
EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block);
pointer_to_this = &select_time_to_block;
}
+
+ /* select() is slow and buggy so if we don't have any processes
+ just wait as normal */
+ if (memcmp (&process_only_mask, &zero_mask, sizeof(SELECT_TYPE))==0)
+ {
+ /* Now try getting a message or process event */
+ active = MsgWaitForMultipleObjects (0, mswindows_waitable_handles,
+ FALSE, badly_p ? INFINITE : 0,
+ QS_ALLINPUT);
+
+ if (active == WAIT_TIMEOUT)
+ {
+ /* No luck trying - just return what we've already got */
+ return;
+ }
+ else if (active == WAIT_OBJECT_0)
+ {
+ /* Got your message, thanks */
+ mswindows_drain_windows_queue ();
+ continue;
+ }
+ }
+
active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this);
if (active == 0)
{
if (errno != EINTR)
{
- /* something bad happended */
+ /* something bad happened */
assert(0);
}
}
else
{
int ix = active - WAIT_OBJECT_0;
- /* First, try to find which process' ouptut has signaled */
+ /* First, try to find which process' output has signaled */
struct Lisp_Process *p =
get_process_from_usid (HANDLE_TO_USID (mswindows_waitable_handles[ix]));
if (p != NULL)
else
{
/* None. This means that the process handle itself has signaled.
- Remove the handle from the wait vector, and make status_ntoify
+ Remove the handle from the wait vector, and make status_notify
note the exited process */
mswindows_waitable_handles [ix] =
mswindows_waitable_handles [--mswindows_waitable_count];
event->timestamp = dwtime;
event->event_type = timeout_event;
event->event.timeout.interval_id = id_timer;
+ event->event.timeout.function = Qnil;
+ event->event.timeout.object = Qnil;
mswindows_enqueue_dispatch_event (emacs_event);
}
LRESULT WINAPI
mswindows_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- /* Note: Remember to initialise emacs_event and event before use.
+ /* Note: Remember to initialize emacs_event and event before use.
This code calls code that can GC. You must GCPRO before calling such code. */
Lisp_Object emacs_event = Qnil;
Lisp_Object fobj = Qnil;
mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
break;
+ case WM_KEYUP:
+ case WM_SYSKEYUP:
+ /* See Win95 comment under WM_KEYDOWN */
+ {
+ BYTE keymap[256];
+
+ if (wParam == VK_CONTROL)
+ {
+ GetKeyboardState (keymap);
+ keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] &= ~0x80;
+ SetKeyboardState (keymap);
+ }
+ else if (wParam == VK_MENU)
+ {
+ GetKeyboardState (keymap);
+ keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] &= ~0x80;
+ SetKeyboardState (keymap);
+ }
+ };
+ goto defproc;
+
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
+ /* In some locales the right-hand Alt key is labelled AltGr. This key
+ * should produce alternative charcaters when combined with another key.
+ * eg on a German keyboard pressing AltGr+q should produce '@'.
+ * AltGr generates exactly the same keystrokes as LCtrl+RAlt. But if
+ * TranslateMessage() is called with *any* combination of Ctrl+Alt down,
+ * it translates as if AltGr were down.
+ * We get round this by removing all modifiers from the keymap before
+ * calling TranslateMessage() unless AltGr is *really* down. */
{
BYTE keymap[256];
int has_AltGr = mswindows_current_layout_has_AltGr ();
GetKeyboardState (keymap);
mods = mswindows_modifier_state (keymap, has_AltGr);
- /* Handle those keys that TranslateMessage won't generate a WM_CHAR for */
+ /* Handle those keys for which TranslateMessage won't generate a WM_CHAR */
if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods)))
mswindows_enqueue_keypress_event (hwnd, keysym, mods);
else
int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
BYTE keymap_orig[256];
MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), (GetMessagePos()) };
+
+ /* GetKeyboardState() does not work as documented on Win95. We have
+ * to loosely track Left and Right modifiers on behalf of the OS,
+ * without screwing up Windows NT which tracks them properly. */
+ if (wParam == VK_CONTROL)
+ keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
+ else if (wParam == VK_MENU)
+ keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] |= 0x80;
+
memcpy (keymap_orig, keymap, 256);
/* Remove shift modifier from an ascii character */
mods &= ~MOD_SHIFT;
- /* Clear control and alt modifiers out of the keymap */
+ /* Clear control and alt modifiers unless AltGr is pressed */
keymap [VK_RCONTROL] = 0;
keymap [VK_LMENU] = 0;
if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80))
}
SetKeyboardState (keymap);
- /* Have some WM_[SYS]CHARS in the queue */
+ /* Maybe generate some WM_[SYS]CHARs in the queue */
TranslateMessage (&msg);
while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
break;
case WM_MOUSEMOVE:
- /* Optimization: don't report mouse movement while size is changind */
+ /* Optimization: don't report mouse movement while size is changing */
msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
if (!msframe->sizing)
{
/* When waiting for the second mouse button to finish
button2 emulation, and have moved too far, just pretend
- as if timer has expired. This impoves drag-select feedback */
+ as if timer has expired. This improves drag-select feedback */
if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
&& !mswindows_button2_near_enough (msframe->last_click_point,
MAKEPOINTS (lParam)))
DEFVAR_INT ("mswindows-mouse-button-max-skew-x", &mswindows_mouse_button_max_skew_x /*
*Maximum horizontal distance in pixels between points in which left and
-right button clicks occured for them to be translated into single
+right button clicks occurred for them to be translated into single
middle button event. Clicks must occur in time not longer than defined
by the variable `mswindows-mouse-button-tolerance'.
If negative or zero, currently set system default is used instead.
DEFVAR_INT ("mswindows-mouse-button-max-skew-y", &mswindows_mouse_button_max_skew_y /*
*Maximum vertical distance in pixels between points in which left and
-right button clicks occured for them to be translated into single
+right button clicks occurred for them to be translated into single
middle button event. Clicks must occur in time not longer than defined
by the variable `mswindows-mouse-button-tolerance'.
If negative or zero, currently set system default is used instead.
windows_fd = open("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
assert (windows_fd>=0);
FD_SET (windows_fd, &input_wait_mask);
- /* for some reason I get blocks on the signal event pipe, which is
- bad...
- signal_event_pipe_initialized = 0; */
+ FD_ZERO(&zero_mask);
#endif
event_stream = mswindows_event_stream;