213
|
1 /* The mswindows event_stream interface.
|
|
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
4 Copyright (C) 1996 Ben Wing.
|
|
5 Copyright (C) 1997 Jonathan Harris.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 /* Authorship:
|
|
27
|
|
28 Ultimately based on FSF.
|
|
29 Rewritten by Ben Wing.
|
|
30 Rewritten for mswindows by Jonathan Harris, November 1997 for 20.4.
|
|
31 */
|
|
32
|
|
33 #include <config.h>
|
|
34 #include "lisp.h"
|
|
35
|
|
36 #include "device.h"
|
|
37 #include "console-msw.h"
|
227
|
38 #include "emacsfns.h"
|
213
|
39 #include "events.h"
|
|
40 #include "frame.h"
|
|
41 #include "process.h"
|
227
|
42 #include "redisplay.h"
|
213
|
43 #include "sysproc.h"
|
|
44 #include "syswait.h"
|
|
45 #include "systime.h"
|
|
46
|
|
47 #include "event-msw.h"
|
|
48
|
|
49 static struct event_stream *mswindows_event_stream;
|
223
|
50
|
|
51 /*
|
|
52 * Two separate queues, for efficiency, one (_u_) for user events, and
|
|
53 * another (_s_) for non-user ones. We always return events out of the
|
|
54 * first one until it is empty and only then proceed with the second
|
|
55 * one.
|
|
56 */
|
|
57 static Lisp_Object mswindows_u_dispatch_event_queue, mswindows_u_dispatch_event_queue_tail;
|
|
58 static Lisp_Object mswindows_s_dispatch_event_queue, mswindows_s_dispatch_event_queue_tail;
|
213
|
59
|
|
60 /*
|
|
61 * List of mswindows waitable handles.
|
|
62 * Apart from the dispatch queue semaphore, all of these handles may be waited
|
219
|
63 * on multiple times in emacs_mswindows_next_event before being processed and so
|
|
64 * must be manual-reset events.
|
213
|
65 */
|
|
66 static HANDLE mswindows_waitable[MAX_WAITABLE];
|
|
67
|
|
68 /* random emacs info associated with each of the wait handles */
|
|
69 static mswindows_waitable_info_type mswindows_waitable_info[MAX_WAITABLE];
|
|
70
|
223
|
71 /* Count of quit chars currently in the queue */
|
|
72 /* Incremented in WM_CHAR handler in msw-proc.c
|
|
73 Decremented in mswindows_dequeue_dispatch_event() */
|
|
74 int mswindows_quit_chars_count = 0;
|
|
75
|
|
76 /* These are Lisp integers; see DEFVARS in this file for description. */
|
|
77 int mswindows_dynamic_frame_resize;
|
|
78 int mswindows_num_mouse_buttons;
|
|
79 int mswindows_button2_max_skew_x;
|
|
80 int mswindows_button2_max_skew_y;
|
|
81 int mswindows_button2_chord_time;
|
|
82
|
219
|
83 /* Number of wait handles */
|
|
84 static mswindows_waitable_count=0;
|
|
85
|
227
|
86 /* This is the event signaled by the event pump.
|
|
87 See mswindows_pump_outstanding_events for comments */
|
231
|
88 static Lisp_Object mswindows_error_caught_in_modal_loop;
|
|
89 static int mswindows_in_modal_loop;
|
227
|
90
|
|
91 /* Count of wound timers */
|
|
92 static int mswindows_pending_timers_count;
|
|
93
|
223
|
94 static int
|
|
95 mswindows_user_event_p (struct Lisp_Event* sevt)
|
|
96 {
|
|
97 return (sevt->event_type == key_press_event
|
|
98 || sevt->event_type == button_press_event
|
225
|
99 || sevt->event_type == button_release_event);
|
223
|
100 }
|
|
101
|
219
|
102 /*
|
223
|
103 * Add an emacs event to the proper dispatch queue
|
219
|
104 */
|
213
|
105 void
|
|
106 mswindows_enqueue_dispatch_event (Lisp_Object event)
|
|
107 {
|
223
|
108 int user_p = mswindows_user_event_p (XEVENT(event));
|
|
109 enqueue_event (event,
|
|
110 user_p ? &mswindows_u_dispatch_event_queue :
|
|
111 &mswindows_s_dispatch_event_queue,
|
|
112 user_p ? &mswindows_u_dispatch_event_queue_tail :
|
|
113 &mswindows_s_dispatch_event_queue_tail);
|
|
114
|
|
115 /* This one does not go to window procedure, hence does not
|
|
116 generate XM_BUMPQUEUE magic event! */
|
|
117 PostMessage (NULL, XM_BUMPQUEUE, 0, 0);
|
213
|
118 }
|
|
119
|
219
|
120 /*
|
223
|
121 * Remove and return the first emacs event on the dispatch queue.
|
|
122 * Give a preference to user events over non-user ones.
|
219
|
123 */
|
213
|
124 static Lisp_Object
|
223
|
125 mswindows_dequeue_dispatch_event ()
|
213
|
126 {
|
|
127 Lisp_Object event;
|
223
|
128 struct Lisp_Event* sevt;
|
|
129
|
|
130 assert (!NILP(mswindows_u_dispatch_event_queue) ||
|
|
131 !NILP(mswindows_s_dispatch_event_queue));
|
|
132
|
|
133 event = dequeue_event (
|
|
134 NILP(mswindows_u_dispatch_event_queue) ?
|
|
135 &mswindows_s_dispatch_event_queue :
|
|
136 &mswindows_u_dispatch_event_queue,
|
|
137 NILP(mswindows_u_dispatch_event_queue) ?
|
|
138 &mswindows_s_dispatch_event_queue_tail :
|
|
139 &mswindows_u_dispatch_event_queue_tail);
|
|
140
|
|
141 sevt = XEVENT(event);
|
|
142 if (sevt->event_type == key_press_event
|
|
143 && (sevt->event.key.modifiers & FAKE_MOD_QUIT))
|
|
144 {
|
|
145 sevt->event.key.modifiers &= ~FAKE_MOD_QUIT;
|
|
146 --mswindows_quit_chars_count;
|
|
147 }
|
|
148
|
213
|
149 return event;
|
|
150 }
|
|
151
|
|
152 /*
|
219
|
153 * Remove and return the first emacs event on the dispatch queue that matches
|
223
|
154 * the supplied event
|
|
155 * Timeout event matches if interval_id equals to that of the given event.
|
|
156 * Keypress event matches if logical AND between modifiers bitmask of the
|
|
157 * event in the queue and that of the given event is non-zero
|
|
158 * For all other event types, this function asserts.
|
219
|
159 */
|
223
|
160
|
219
|
161 Lisp_Object
|
223
|
162 mswindows_cancel_dispatch_event (struct Lisp_Event* match)
|
219
|
163 {
|
|
164 Lisp_Object event;
|
|
165 Lisp_Object previous_event=Qnil;
|
223
|
166 int user_p = mswindows_user_event_p (match);
|
|
167 Lisp_Object* head = user_p ? &mswindows_u_dispatch_event_queue :
|
|
168 &mswindows_s_dispatch_event_queue;
|
|
169 Lisp_Object* tail = user_p ? &mswindows_u_dispatch_event_queue_tail :
|
|
170 &mswindows_s_dispatch_event_queue_tail;
|
219
|
171
|
223
|
172 assert (match->event_type == timeout_event
|
|
173 || match->event_type == key_press_event);
|
219
|
174
|
223
|
175 EVENT_CHAIN_LOOP (event, *head)
|
|
176 {
|
|
177 int found = 1;
|
|
178 if (XEVENT_TYPE (event) != match->event_type)
|
|
179 found = 0;
|
|
180 if (found && match->event_type == timeout_event
|
|
181 && (XEVENT(event)->event.timeout.interval_id !=
|
|
182 match->event.timeout.interval_id))
|
|
183 found = 0;
|
|
184 if (found && match->event_type == key_press_event
|
|
185 && ((XEVENT(event)->event.key.modifiers &
|
|
186 match->event.key.modifiers) == 0))
|
|
187 found = 0;
|
|
188
|
|
189 if (found)
|
|
190 {
|
|
191 if (NILP (previous_event))
|
|
192 dequeue_event (head, tail);
|
|
193 else
|
|
194 {
|
|
195 XSET_EVENT_NEXT (previous_event, XEVENT_NEXT (event));
|
|
196 if (EQ (*tail, event))
|
|
197 *tail = previous_event;
|
|
198 }
|
|
199
|
|
200 return event;
|
|
201 }
|
219
|
202 previous_event = event;
|
223
|
203 }
|
219
|
204 }
|
|
205
|
231
|
206 static Lisp_Object
|
|
207 mswindows_modal_loop_error_handler (Lisp_Object cons_sig_data,
|
|
208 Lisp_Object u_n_u_s_e_d)
|
|
209 {
|
|
210 mswindows_error_caught_in_modal_loop = cons_sig_data;
|
|
211 return Qunbound;
|
|
212 }
|
|
213
|
|
214 Lisp_Object
|
|
215 mswindows_protect_modal_loop (Lisp_Object (*bfun) (Lisp_Object barg),
|
|
216 Lisp_Object barg)
|
|
217 {
|
|
218 Lisp_Object tmp;
|
|
219
|
|
220 ++mswindows_in_modal_loop;
|
|
221 tmp = condition_case_1 (Qt,
|
|
222 bfun, barg,
|
|
223 mswindows_modal_loop_error_handler, Qnil);
|
|
224 --mswindows_in_modal_loop;
|
|
225
|
|
226 return tmp;
|
|
227 }
|
|
228
|
|
229 void
|
|
230 mswindows_unmodalize_signal_maybe (void)
|
|
231 {
|
|
232 if (!NILP (mswindows_error_caught_in_modal_loop))
|
|
233 {
|
|
234 /* Got an error while messages were pumped while
|
|
235 in window procedure - have to resignal */
|
|
236 Lisp_Object sym = XCAR (mswindows_error_caught_in_modal_loop);
|
|
237 Lisp_Object data = XCDR (mswindows_error_caught_in_modal_loop);
|
|
238 mswindows_error_caught_in_modal_loop = Qnil;
|
|
239 Fsignal (sym, data);
|
|
240 }
|
|
241 }
|
|
242
|
219
|
243 /*
|
227
|
244 * This is an unsafe part of event pump, guarded by
|
|
245 * condition_case. See mswindows_pump_outstanding_events
|
|
246 */
|
|
247 static Lisp_Object
|
|
248 mswindows_unsafe_pump_events (Lisp_Object u_n_u_s_e_d)
|
|
249 {
|
|
250 /* This function can call lisp */
|
|
251 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
252 struct gcpro gcpro1;
|
|
253 int do_redisplay = 0;
|
|
254 GCPRO1 (event);
|
|
255
|
|
256 while (detect_input_pending ())
|
|
257 {
|
|
258 Fnext_event (event, Qnil);
|
|
259 Fdispatch_event (event);
|
|
260 do_redisplay = 1;
|
|
261 }
|
|
262
|
|
263 if (do_redisplay)
|
|
264 redisplay ();
|
|
265
|
|
266 Fdeallocate_event (event);
|
|
267 UNGCPRO;
|
|
268
|
|
269 /* Qt becomes return value of mswindows_pump_outstanding_events
|
|
270 once we get here */
|
|
271 return Qt;
|
|
272 }
|
|
273
|
|
274 /*
|
|
275 * This function pumps emacs events, while available, by using
|
|
276 * next_message/dispatch_message loop. Errors are trapped around
|
|
277 * the loop so the function always returns.
|
|
278 *
|
|
279 * Windows message queue is not looked into during the call,
|
|
280 * neither are waitable handles checked. The function pumps
|
|
281 * thus only dispatch events already queued, as well as those
|
|
282 * resulted in dispatching thereof. This is done by setting
|
231
|
283 * module local variable mswidows_in_modal_loop to nonzero.
|
227
|
284 *
|
231
|
285 * Return value is Qt if no errors was trapped, or Qunbound if
|
227
|
286 * there was an error.
|
|
287 *
|
|
288 * In case of error, a cons representing the error, in the
|
|
289 * form (SIGNAL . DATA), is stored in the module local variable
|
231
|
290 * mswindows_error_caught_in_modal_loop. This error is signaled
|
227
|
291 * again when DispatchMessage returns. Thus, Windows internal
|
|
292 * modal loops are protected against throws, which are proven
|
|
293 * to corrupt internal Windows structures.
|
|
294 *
|
231
|
295 * In case of success, mswindows_error_caught_in_modal_loop is
|
227
|
296 * assigned Qnil.
|
|
297 *
|
231
|
298 * If the value of mswindows_error_caught_in_modal_loop is not
|
227
|
299 * nil already upon entry, the function just returns non-nil.
|
|
300 * This situation means that a new event has been queued while
|
|
301 * cancleng mode. The event will be dequeued on the next regular
|
|
302 * call of next-event; the pump is off since error is caught.
|
|
303 * The caller must *unconditionally* cancel modal loop if the
|
|
304 * value returned by this function is nil. Otherwise, everything
|
|
305 * will become frozen until the modal loop exits under normal
|
|
306 * condition (scrollbar drag is released, menu closed etc.)
|
|
307 */
|
|
308 Lisp_Object
|
|
309 mswindows_pump_outstanding_events (void)
|
|
310 {
|
|
311 /* This function can call lisp */
|
|
312
|
|
313 Lisp_Object result = Qt;
|
|
314
|
231
|
315 if (NILP(mswindows_error_caught_in_modal_loop))
|
|
316 result = mswindows_protect_modal_loop (mswindows_unsafe_pump_events, Qnil);
|
227
|
317 return result;
|
|
318 }
|
|
319
|
|
320 /*
|
213
|
321 * Find a free waitable slot
|
|
322 */
|
|
323 static int
|
|
324 mswindows_find_free_waitable(void)
|
|
325 {
|
|
326 int i;
|
|
327 for (i=0; i<mswindows_waitable_count; i++)
|
|
328 if (mswindows_waitable_info[i].type == mswindows_waitable_type_none)
|
|
329 return i;
|
|
330 assert (mswindows_waitable_count < MAX_WAITABLE);
|
|
331 return mswindows_waitable_count++;
|
|
332 }
|
|
333
|
|
334 /*
|
|
335 * Create a new waitable using the type and data passed in by the info structure
|
|
336 * Returns a pointer to the info associated with the assigned waitable object
|
|
337 */
|
|
338 mswindows_waitable_info_type *
|
|
339 mswindows_add_waitable(mswindows_waitable_info_type *info)
|
|
340 {
|
|
341 int waitable;
|
|
342
|
|
343 switch (info->type)
|
|
344 {
|
|
345 case mswindows_waitable_type_dispatch:
|
223
|
346 assert (0); /* kkm - should not get here */
|
213
|
347 /* Can only have one waitable for the dispatch queue, and it's the first one */
|
|
348 assert (mswindows_waitable_count++ == 0);
|
|
349 waitable=0;
|
231
|
350 #if 0
|
|
351 InitializeCriticalSection(&mswindows_dispatch_crit);
|
|
352 #endif
|
213
|
353 assert (mswindows_waitable[0] = CreateSemaphore (NULL, 0, 0x7fffffff, NULL));
|
|
354 return mswindows_waitable_info+0;
|
|
355
|
|
356 default:
|
|
357 assert(0);
|
|
358 }
|
|
359 mswindows_waitable_info[waitable].type = info->type;
|
|
360 return mswindows_waitable_info+waitable;
|
|
361 }
|
|
362
|
|
363 /*
|
|
364 * Remove a waitable using the type and data passed in by the info structure.
|
|
365 */
|
|
366 void
|
|
367 mswindows_remove_waitable(mswindows_waitable_info_type *info)
|
|
368 {
|
|
369 int waitable;
|
|
370
|
|
371 switch (info->type)
|
|
372 {
|
|
373
|
|
374 default:
|
|
375 assert(0);
|
|
376 }
|
|
377
|
|
378 CloseHandle(mswindows_waitable[waitable]);
|
|
379 mswindows_waitable[waitable] = 0;
|
|
380 mswindows_waitable_info[waitable].type = mswindows_waitable_type_none;
|
|
381 if (waitable == mswindows_waitable_count-1)
|
|
382 --mswindows_waitable_count;
|
|
383 }
|
|
384
|
223
|
385 /*
|
|
386 * Callback procedure for synchronous timer messages
|
|
387 */
|
|
388 static void CALLBACK
|
|
389 mswindows_wm_timer_callback (HWND hwnd, UINT umsg, UINT id_timer, DWORD dwtime)
|
|
390 {
|
|
391 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
392 struct Lisp_Event *event = XEVENT (emacs_event);
|
|
393
|
233
|
394 if (KillTimer (NULL, id_timer))
|
|
395 --mswindows_pending_timers_count;
|
223
|
396
|
|
397 event->channel = Qnil;
|
|
398 event->timestamp = dwtime;
|
|
399 event->event_type = timeout_event;
|
|
400 event->event.timeout.interval_id = id_timer;
|
|
401
|
|
402 mswindows_enqueue_dispatch_event (emacs_event);
|
|
403 }
|
|
404
|
|
405 static void
|
|
406 mswindows_drain_windows_queue ()
|
|
407 {
|
|
408 MSG msg;
|
|
409 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
|
227
|
410 {
|
|
411 DispatchMessage (&msg);
|
231
|
412 mswindows_unmodalize_signal_maybe ();
|
227
|
413 }
|
|
414 }
|
|
415
|
|
416 /*
|
|
417 * This is a special flavour of the mswindows_need_event function,
|
|
418 * used while in event pump. Actually, there is only kind of events
|
|
419 * allowed while in event pump: a timer. An attempt to fetch any
|
|
420 * other event leads to a dealock, as there's no source of user input
|
|
421 * ('cause event pump mirrors windows modal loop, which is a sole
|
|
422 * owner of thread message queue).
|
|
423 *
|
|
424 * To detect this, we use a counter of active timers, and allow
|
|
425 * fetching WM_TIMER messages. Instead of trying to fetch a WM_TIMER
|
|
426 * which will never come when there are no pending timers, which leads
|
|
427 * to deadlock, we simply signal an error.
|
|
428 *
|
|
429 * The implementation does not honor user_p by design.
|
|
430 */
|
|
431 static void
|
231
|
432 mswindows_need_event_in_modal_loop (int user_p, int badly_p)
|
227
|
433 {
|
|
434 MSG msg;
|
|
435
|
|
436 /* Check if already have one */
|
|
437 if (!NILP (mswindows_u_dispatch_event_queue)
|
|
438 || !NILP (mswindows_s_dispatch_event_queue))
|
|
439 return;
|
|
440
|
|
441 /* No event is ok */
|
|
442 if (!badly_p)
|
|
443 return;
|
|
444
|
|
445 /* We do not check the _u_ queue, because timers go to _s_ */
|
|
446 while (NILP (mswindows_s_dispatch_event_queue))
|
|
447 {
|
|
448 /* We'll deadlock if go waiting */
|
|
449 if (mswindows_pending_timers_count == 0)
|
|
450 error ("Deadlock due to an attempt to call next-event in a wrong context");
|
|
451
|
|
452 /* Fetch and dispatch any pending timers */
|
|
453 GetMessage (&msg, NULL, WM_TIMER, WM_TIMER);
|
|
454 DispatchMessage (&msg);
|
|
455 }
|
223
|
456 }
|
|
457
|
|
458 /*
|
|
459 * This drains the event queue and fills up two internal queues until
|
|
460 * an event of a type specified by USER_P is retrieved.
|
|
461 *
|
|
462 * If user_p, then the function drains until the first user event, or
|
|
463 * the first non-user event if there no user events. Otherwise, If
|
|
464 * not user_p, it does not give preference to user events.
|
|
465 *
|
|
466 * If badly_p, then the function does not return until an event is
|
|
467 * available.
|
|
468 *
|
|
469 * The code does not rely on MsgWaitForMultipleObjects preference for
|
|
470 * messages over waitable handles.
|
|
471 *
|
|
472 * Used by emacs_mswindows_event_pending_p and emacs_mswindows_next_event
|
|
473 */
|
|
474 static void
|
|
475 mswindows_need_event (int user_p, int badly_p)
|
|
476 {
|
|
477 int active;
|
|
478
|
231
|
479 if (mswindows_in_modal_loop)
|
227
|
480 {
|
231
|
481 mswindows_need_event_in_modal_loop (user_p, badly_p);
|
227
|
482 return;
|
|
483 }
|
|
484
|
223
|
485 /* Have to drain Windows message queue first, otherwise, we may miss
|
|
486 quit char when called from quit_p */
|
|
487 mswindows_drain_windows_queue ();
|
|
488
|
|
489 while (NILP (mswindows_u_dispatch_event_queue) &&
|
|
490 (user_p || NILP (mswindows_s_dispatch_event_queue)))
|
|
491 {
|
|
492 /* If we already have an event, we've got someting to return - no wait! */
|
|
493 if (!NILP (mswindows_u_dispatch_event_queue)
|
|
494 || !NILP (mswindows_s_dispatch_event_queue))
|
|
495 badly_p = 0;
|
|
496
|
|
497 /* Now try getting a message */
|
|
498 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
|
|
499 mswindows_waitable,
|
|
500 FALSE, badly_p ? INFINITE : 0,
|
|
501 QS_ALLINPUT);
|
|
502
|
|
503 /* This will assert if handle being waited for becomes abandoned.
|
|
504 Not the case currently tho */
|
|
505 assert ((!badly_p && active == WAIT_TIMEOUT) ||
|
|
506 (active >= WAIT_OBJECT_0 &&
|
|
507 active <= WAIT_OBJECT_0 + mswindows_waitable_count));
|
|
508
|
|
509 if (active == WAIT_TIMEOUT)
|
|
510 {
|
|
511 /* No luck trying - just return what we've already got */
|
|
512 return;
|
|
513 }
|
|
514 else if (active == WAIT_OBJECT_0 + mswindows_waitable_count)
|
|
515 {
|
|
516 /* Got your message, thanks */
|
|
517 mswindows_drain_windows_queue ();
|
|
518 }
|
|
519 else
|
|
520 {
|
|
521 /* XXX FIXME: We should do some kind of round-robin scheme to ensure fairness */
|
|
522 int waitable = active - WAIT_OBJECT_0;
|
|
523 mswindows_waitable_info_type *info = mswindows_waitable_info + waitable;
|
|
524
|
|
525 switch (info->type)
|
|
526 {
|
|
527 /* XXX FIXME: Should enque subprocess event here so that it is not lost */
|
|
528 default:
|
|
529 assert(0);
|
|
530 }
|
|
531 }
|
|
532 } /* while */
|
|
533
|
|
534 return;
|
|
535 }
|
|
536
|
213
|
537
|
|
538 /************************************************************************/
|
|
539 /* methods */
|
|
540 /************************************************************************/
|
|
541
|
|
542 static int
|
|
543 emacs_mswindows_add_timeout (EMACS_TIME thyme)
|
|
544 {
|
223
|
545 int milliseconds;
|
213
|
546 EMACS_TIME current_time;
|
|
547 EMACS_GET_TIME (current_time);
|
|
548 EMACS_SUB_TIME (thyme, thyme, current_time);
|
223
|
549 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
550 (EMACS_USECS (thyme) + 500) / 1000;
|
213
|
551 if (milliseconds < 1)
|
|
552 milliseconds = 1;
|
227
|
553 ++mswindows_pending_timers_count;
|
223
|
554 return SetTimer (NULL, 0, milliseconds, mswindows_wm_timer_callback);
|
213
|
555 }
|
|
556
|
|
557 static void
|
|
558 emacs_mswindows_remove_timeout (int id)
|
|
559 {
|
223
|
560 struct Lisp_Event match_against;
|
|
561 Lisp_Object emacs_event;
|
|
562
|
233
|
563 if (KillTimer (NULL, id))
|
|
564 --mswindows_pending_timers_count;
|
223
|
565
|
|
566 /* If there is a dispatch event generated by this
|
|
567 timeout in the queue, we have to remove it too. */
|
|
568 match_against.event_type = timeout_event;
|
|
569 match_against.event.timeout.interval_id = id;
|
|
570 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
571 if (!NILP (emacs_event))
|
|
572 Fdeallocate_event(emacs_event);
|
213
|
573 }
|
|
574
|
219
|
575 /* If `user_p' is false, then return whether there are any win32, timeout,
|
|
576 * or subprocess events pending (that is, whether
|
|
577 * emacs_mswindows_next_event() would return immediately without blocking).
|
|
578 *
|
|
579 * if `user_p' is true, then return whether there are any *user generated*
|
|
580 * events available (that is, whether there are keyboard or mouse-click
|
|
581 * events ready to be read). This also implies that
|
|
582 * emacs_mswindows_next_event() would not block.
|
|
583 */
|
213
|
584 static int
|
|
585 emacs_mswindows_event_pending_p (int user_p)
|
|
586 {
|
223
|
587 mswindows_need_event (user_p, 0);
|
219
|
588
|
223
|
589 return (!NILP (mswindows_u_dispatch_event_queue)
|
|
590 || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
|
213
|
591 }
|
|
592
|
|
593 /*
|
|
594 * Return the next event
|
|
595 */
|
|
596 static void
|
|
597 emacs_mswindows_next_event (struct Lisp_Event *emacs_event)
|
|
598 {
|
223
|
599 Lisp_Object event, event2;
|
|
600
|
|
601 /* Give strong preference to user events */
|
|
602 mswindows_need_event (1, 1);
|
213
|
603
|
223
|
604 /* XXX Copied from event-Xt.c */
|
|
605 event = mswindows_dequeue_dispatch_event (!NILP(mswindows_u_dispatch_event_queue));
|
|
606 XSETEVENT (event2, emacs_event);
|
|
607 Fcopy_event (event, event2);
|
|
608 Fdeallocate_event (event);
|
213
|
609 }
|
|
610
|
|
611 /*
|
|
612 * Handle a magic event off the dispatch queue.
|
|
613 */
|
|
614 static void
|
|
615 emacs_mswindows_handle_magic_event (struct Lisp_Event *emacs_event)
|
|
616 {
|
|
617 #if 0
|
|
618 stderr_out("magic %x, (%d,%d), (%d,%d)\n",
|
|
619 EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event),
|
|
620 rect->left, rect->top, rect->right, rect->bottom);
|
|
621 #endif
|
|
622 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event))
|
|
623 {
|
|
624 case WM_SETFOCUS:
|
|
625 case WM_KILLFOCUS:
|
|
626 {
|
223
|
627 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
628 struct frame *f = XFRAME (frame);
|
213
|
629 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS);
|
|
630 Lisp_Object conser;
|
223
|
631
|
213
|
632 /* struct gcpro gcpro1; */
|
|
633
|
|
634 /* Clear sticky modifiers here (if we had any) */
|
|
635
|
|
636 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
|
637 /* GCPRO1 (conser); XXX Not necessary? */
|
|
638 emacs_handle_focus_change_preliminary (conser);
|
|
639 /* Under X the stuff up to here is done in the X event handler.
|
|
640 I Don't know why */
|
|
641 emacs_handle_focus_change_final (conser);
|
|
642 /* UNGCPRO; */
|
223
|
643
|
213
|
644 }
|
|
645 break;
|
|
646
|
223
|
647 case XM_BUMPQUEUE:
|
|
648 /* This is a nice event, when we're in need to queue *something* */
|
|
649 break;
|
|
650
|
|
651 case XM_MAPFRAME:
|
|
652 case XM_UNMAPFRAME:
|
|
653 {
|
|
654 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
655 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)
|
|
656 == XM_MAPFRAME ?
|
|
657 Qmap_frame_hook : Qunmap_frame_hook,
|
|
658 1, frame);
|
|
659 }
|
|
660 break;
|
|
661
|
|
662 /* XXX What about Enter & Leave */
|
213
|
663 #if 0
|
|
664 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
|
|
665 Qmouse_leave_frame_hook, 1, frame);
|
|
666 #endif
|
|
667
|
|
668 default:
|
|
669 assert(0);
|
|
670 }
|
|
671 }
|
|
672
|
|
673 static void
|
|
674 emacs_mswindows_select_process (struct Lisp_Process *process)
|
|
675 {
|
|
676 }
|
|
677
|
|
678 static void
|
|
679 emacs_mswindows_unselect_process (struct Lisp_Process *process)
|
|
680 {
|
|
681 }
|
|
682
|
|
683 static void
|
|
684 emacs_mswindows_select_console (struct console *con)
|
|
685 {
|
|
686 }
|
|
687
|
|
688 static void
|
|
689 emacs_mswindows_unselect_console (struct console *con)
|
|
690 {
|
|
691 }
|
|
692
|
|
693 static void
|
|
694 emacs_mswindows_quit_p (void)
|
|
695 {
|
223
|
696 mswindows_need_event (1, 0);
|
|
697
|
|
698 if (mswindows_quit_chars_count > 0)
|
|
699 {
|
|
700 /* Yes there's a hidden one... Throw it away */
|
|
701 struct Lisp_Event match_against;
|
|
702 Lisp_Object emacs_event;
|
|
703
|
|
704 match_against.event_type = key_press_event;
|
|
705 match_against.event.key.modifiers = FAKE_MOD_QUIT;
|
|
706
|
|
707 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
708 assert (!NILP (emacs_event));
|
|
709
|
|
710 Vquit_flag = (XEVENT(emacs_event)->event.key.modifiers & MOD_SHIFT
|
|
711 ? Qcritical : Qt);
|
|
712
|
|
713 Fdeallocate_event(emacs_event);
|
|
714 --mswindows_quit_chars_count;
|
|
715 }
|
213
|
716 }
|
|
717
|
|
718 /* This is called from GC when a process object is about to be freed.
|
|
719 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
720 */
|
|
721 void
|
|
722 debug_process_finalization (struct Lisp_Process *p)
|
|
723 {
|
|
724 #if 0 /* #### */
|
|
725 int i;
|
|
726 int infd, outfd;
|
|
727 get_process_file_descriptors (p, &infd, &outfd);
|
|
728 /* if it still has fds, then it hasn't been killed yet. */
|
|
729 assert (infd < 0);
|
|
730 assert (outfd < 0);
|
|
731 /* Better not still be in the "with input" table; we know it's got no fds. */
|
|
732 for (i = 0; i < MAXDESC; i++)
|
|
733 {
|
|
734 Lisp_Object process = filedesc_fds_with_input [i];
|
|
735 assert (!PROCESSP (process) || XPROCESS (process) != p);
|
|
736 }
|
|
737 #endif
|
|
738 }
|
|
739
|
|
740 /************************************************************************/
|
|
741 /* initialization */
|
|
742 /************************************************************************/
|
|
743
|
|
744 void
|
|
745 vars_of_event_mswindows (void)
|
|
746 {
|
223
|
747 mswindows_u_dispatch_event_queue = Qnil;
|
|
748 staticpro (&mswindows_u_dispatch_event_queue);
|
|
749 mswindows_u_dispatch_event_queue_tail = Qnil;
|
|
750
|
|
751 mswindows_s_dispatch_event_queue = Qnil;
|
|
752 staticpro (&mswindows_s_dispatch_event_queue);
|
|
753 mswindows_s_dispatch_event_queue_tail = Qnil;
|
213
|
754
|
231
|
755 mswindows_error_caught_in_modal_loop = Qnil;
|
|
756 staticpro (&mswindows_error_caught_in_modal_loop);
|
|
757 mswindows_in_modal_loop = 0;
|
227
|
758 mswindows_pending_timers_count = 0;
|
|
759
|
213
|
760 mswindows_event_stream = xnew (struct event_stream);
|
|
761
|
|
762 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
|
223
|
763 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
|
213
|
764 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
|
|
765 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
|
|
766 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
|
|
767 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
|
223
|
768 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
|
213
|
769 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
|
223
|
770 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
|
213
|
771 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
|
223
|
772
|
225
|
773 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /*
|
223
|
774 *Controls redrawing frame contents during mouse-drag or keyboard resize
|
|
775 operation. When non-nil, the frame is redrawn while being resized. When
|
|
776 nil, frame is not redrawn, and exposed areas are filled with default
|
|
777 MDI application background color. Note that this option only has effect
|
|
778 if "Show window contents while dragging" is on in system Display/Plus!
|
|
779 settings.
|
|
780 Default is t on fast machines, nil on slow.
|
|
781 */ );
|
|
782
|
|
783 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
225
|
784 DEFVAR_INT ("mswindows-mouse-button-tolerance", &mswindows_button2_chord_time /*
|
223
|
785 *Analogue of double click interval for faking middle mouse events.
|
|
786 The value is the minimum time in milliseconds that must elapse between
|
|
787 left/right button down events before they are considered distinct events.
|
|
788 If both mouse buttons are depressed within this interval, a middle mouse
|
|
789 button down event is generated instead.
|
|
790 If negative or zero, currently set system default is used instead.
|
|
791 */ );
|
|
792
|
|
793 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
225
|
794 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
|
223
|
795 Number of physical mouse buttons.
|
|
796 */ );
|
|
797
|
225
|
798 DEFVAR_INT ("mswindows-mouse-button-max-skew-x", &mswindows_button2_max_skew_x /*
|
223
|
799 *Maximum horizontal distance in pixels between points in which left and
|
|
800 right button clicks occured for them to be translated into single
|
|
801 middle button event. Clicks must occur in time not longer than defined
|
225
|
802 by the variable mswindows-mouse-button-tolerance.
|
223
|
803 If negative or zero, currently set system default is used instead.
|
|
804 */ );
|
|
805
|
225
|
806 DEFVAR_INT ("mswindows-mouse-button-max-skew-y", &mswindows_button2_max_skew_y /*
|
223
|
807 *Maximum vertical distance in pixels between points in which left and
|
|
808 right button clicks occured for them to be translated into single
|
|
809 middle button event. Clicks must occur in time not longer than defined
|
225
|
810 by the variable mswindows-mouse-button-tolerance.
|
223
|
811 If negative or zero, currently set system default is used instead.
|
|
812 */ );
|
|
813
|
|
814 mswindows_button2_max_skew_x = 0;
|
|
815 mswindows_button2_max_skew_y = 0;
|
|
816 mswindows_button2_chord_time = 0;
|
213
|
817 }
|
|
818
|
|
819 void
|
|
820 syms_of_event_mswindows (void)
|
|
821 {
|
|
822 }
|
|
823
|
|
824 void
|
|
825 init_event_mswindows_late (void)
|
|
826 {
|
|
827 event_stream = mswindows_event_stream;
|
223
|
828
|
|
829 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
|
|
830 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
|
213
|
831 }
|