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 */
|
245
|
84 static int mswindows_waitable_count=0;
|
219
|
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 }
|
239
|
204 return Qnil;
|
219
|
205 }
|
|
206
|
231
|
207 static Lisp_Object
|
|
208 mswindows_modal_loop_error_handler (Lisp_Object cons_sig_data,
|
|
209 Lisp_Object u_n_u_s_e_d)
|
|
210 {
|
|
211 mswindows_error_caught_in_modal_loop = cons_sig_data;
|
|
212 return Qunbound;
|
|
213 }
|
|
214
|
|
215 Lisp_Object
|
|
216 mswindows_protect_modal_loop (Lisp_Object (*bfun) (Lisp_Object barg),
|
|
217 Lisp_Object barg)
|
|
218 {
|
|
219 Lisp_Object tmp;
|
|
220
|
|
221 ++mswindows_in_modal_loop;
|
|
222 tmp = condition_case_1 (Qt,
|
|
223 bfun, barg,
|
|
224 mswindows_modal_loop_error_handler, Qnil);
|
|
225 --mswindows_in_modal_loop;
|
|
226
|
|
227 return tmp;
|
|
228 }
|
|
229
|
|
230 void
|
|
231 mswindows_unmodalize_signal_maybe (void)
|
|
232 {
|
|
233 if (!NILP (mswindows_error_caught_in_modal_loop))
|
|
234 {
|
|
235 /* Got an error while messages were pumped while
|
|
236 in window procedure - have to resignal */
|
|
237 Lisp_Object sym = XCAR (mswindows_error_caught_in_modal_loop);
|
|
238 Lisp_Object data = XCDR (mswindows_error_caught_in_modal_loop);
|
|
239 mswindows_error_caught_in_modal_loop = Qnil;
|
|
240 Fsignal (sym, data);
|
|
241 }
|
|
242 }
|
|
243
|
219
|
244 /*
|
227
|
245 * This is an unsafe part of event pump, guarded by
|
|
246 * condition_case. See mswindows_pump_outstanding_events
|
|
247 */
|
|
248 static Lisp_Object
|
|
249 mswindows_unsafe_pump_events (Lisp_Object u_n_u_s_e_d)
|
|
250 {
|
|
251 /* This function can call lisp */
|
|
252 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
253 struct gcpro gcpro1;
|
|
254 int do_redisplay = 0;
|
|
255 GCPRO1 (event);
|
|
256
|
|
257 while (detect_input_pending ())
|
|
258 {
|
|
259 Fnext_event (event, Qnil);
|
|
260 Fdispatch_event (event);
|
|
261 do_redisplay = 1;
|
|
262 }
|
|
263
|
|
264 if (do_redisplay)
|
|
265 redisplay ();
|
|
266
|
|
267 Fdeallocate_event (event);
|
|
268 UNGCPRO;
|
|
269
|
|
270 /* Qt becomes return value of mswindows_pump_outstanding_events
|
|
271 once we get here */
|
|
272 return Qt;
|
|
273 }
|
|
274
|
|
275 /*
|
|
276 * This function pumps emacs events, while available, by using
|
|
277 * next_message/dispatch_message loop. Errors are trapped around
|
|
278 * the loop so the function always returns.
|
|
279 *
|
|
280 * Windows message queue is not looked into during the call,
|
|
281 * neither are waitable handles checked. The function pumps
|
|
282 * thus only dispatch events already queued, as well as those
|
|
283 * resulted in dispatching thereof. This is done by setting
|
231
|
284 * module local variable mswidows_in_modal_loop to nonzero.
|
227
|
285 *
|
231
|
286 * Return value is Qt if no errors was trapped, or Qunbound if
|
227
|
287 * there was an error.
|
|
288 *
|
|
289 * In case of error, a cons representing the error, in the
|
|
290 * form (SIGNAL . DATA), is stored in the module local variable
|
231
|
291 * mswindows_error_caught_in_modal_loop. This error is signaled
|
227
|
292 * again when DispatchMessage returns. Thus, Windows internal
|
|
293 * modal loops are protected against throws, which are proven
|
|
294 * to corrupt internal Windows structures.
|
|
295 *
|
231
|
296 * In case of success, mswindows_error_caught_in_modal_loop is
|
227
|
297 * assigned Qnil.
|
|
298 *
|
231
|
299 * If the value of mswindows_error_caught_in_modal_loop is not
|
227
|
300 * nil already upon entry, the function just returns non-nil.
|
|
301 * This situation means that a new event has been queued while
|
|
302 * cancleng mode. The event will be dequeued on the next regular
|
|
303 * call of next-event; the pump is off since error is caught.
|
|
304 * The caller must *unconditionally* cancel modal loop if the
|
|
305 * value returned by this function is nil. Otherwise, everything
|
|
306 * will become frozen until the modal loop exits under normal
|
|
307 * condition (scrollbar drag is released, menu closed etc.)
|
|
308 */
|
|
309 Lisp_Object
|
|
310 mswindows_pump_outstanding_events (void)
|
|
311 {
|
|
312 /* This function can call lisp */
|
|
313
|
|
314 Lisp_Object result = Qt;
|
|
315
|
231
|
316 if (NILP(mswindows_error_caught_in_modal_loop))
|
|
317 result = mswindows_protect_modal_loop (mswindows_unsafe_pump_events, Qnil);
|
227
|
318 return result;
|
|
319 }
|
|
320
|
|
321 /*
|
213
|
322 * Find a free waitable slot
|
|
323 */
|
245
|
324 #if 0 /* NOTUSED */
|
213
|
325 static int
|
|
326 mswindows_find_free_waitable(void)
|
|
327 {
|
|
328 int i;
|
|
329 for (i=0; i<mswindows_waitable_count; i++)
|
|
330 if (mswindows_waitable_info[i].type == mswindows_waitable_type_none)
|
|
331 return i;
|
|
332 assert (mswindows_waitable_count < MAX_WAITABLE);
|
|
333 return mswindows_waitable_count++;
|
|
334 }
|
245
|
335 #endif
|
213
|
336
|
|
337 /*
|
|
338 * Create a new waitable using the type and data passed in by the info structure
|
|
339 * Returns a pointer to the info associated with the assigned waitable object
|
|
340 */
|
|
341 mswindows_waitable_info_type *
|
|
342 mswindows_add_waitable(mswindows_waitable_info_type *info)
|
|
343 {
|
|
344 int waitable;
|
|
345
|
|
346 switch (info->type)
|
|
347 {
|
|
348 case mswindows_waitable_type_dispatch:
|
223
|
349 assert (0); /* kkm - should not get here */
|
213
|
350 /* Can only have one waitable for the dispatch queue, and it's the first one */
|
|
351 assert (mswindows_waitable_count++ == 0);
|
|
352 waitable=0;
|
231
|
353 #if 0
|
|
354 InitializeCriticalSection(&mswindows_dispatch_crit);
|
|
355 #endif
|
213
|
356 assert (mswindows_waitable[0] = CreateSemaphore (NULL, 0, 0x7fffffff, NULL));
|
|
357 return mswindows_waitable_info+0;
|
|
358
|
|
359 default:
|
|
360 assert(0);
|
|
361 }
|
|
362 mswindows_waitable_info[waitable].type = info->type;
|
|
363 return mswindows_waitable_info+waitable;
|
|
364 }
|
|
365
|
|
366 /*
|
|
367 * Remove a waitable using the type and data passed in by the info structure.
|
|
368 */
|
|
369 void
|
|
370 mswindows_remove_waitable(mswindows_waitable_info_type *info)
|
|
371 {
|
|
372 int waitable;
|
|
373
|
|
374 switch (info->type)
|
|
375 {
|
|
376
|
|
377 default:
|
|
378 assert(0);
|
|
379 }
|
|
380
|
|
381 CloseHandle(mswindows_waitable[waitable]);
|
|
382 mswindows_waitable[waitable] = 0;
|
|
383 mswindows_waitable_info[waitable].type = mswindows_waitable_type_none;
|
|
384 if (waitable == mswindows_waitable_count-1)
|
|
385 --mswindows_waitable_count;
|
|
386 }
|
|
387
|
223
|
388 /*
|
|
389 * Callback procedure for synchronous timer messages
|
|
390 */
|
|
391 static void CALLBACK
|
|
392 mswindows_wm_timer_callback (HWND hwnd, UINT umsg, UINT id_timer, DWORD dwtime)
|
|
393 {
|
|
394 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
395 struct Lisp_Event *event = XEVENT (emacs_event);
|
|
396
|
233
|
397 if (KillTimer (NULL, id_timer))
|
|
398 --mswindows_pending_timers_count;
|
223
|
399
|
|
400 event->channel = Qnil;
|
|
401 event->timestamp = dwtime;
|
|
402 event->event_type = timeout_event;
|
|
403 event->event.timeout.interval_id = id_timer;
|
|
404
|
|
405 mswindows_enqueue_dispatch_event (emacs_event);
|
|
406 }
|
|
407
|
|
408 static void
|
|
409 mswindows_drain_windows_queue ()
|
|
410 {
|
|
411 MSG msg;
|
|
412 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
|
227
|
413 {
|
|
414 DispatchMessage (&msg);
|
231
|
415 mswindows_unmodalize_signal_maybe ();
|
227
|
416 }
|
|
417 }
|
|
418
|
|
419 /*
|
|
420 * This is a special flavour of the mswindows_need_event function,
|
|
421 * used while in event pump. Actually, there is only kind of events
|
|
422 * allowed while in event pump: a timer. An attempt to fetch any
|
|
423 * other event leads to a dealock, as there's no source of user input
|
|
424 * ('cause event pump mirrors windows modal loop, which is a sole
|
|
425 * owner of thread message queue).
|
|
426 *
|
|
427 * To detect this, we use a counter of active timers, and allow
|
|
428 * fetching WM_TIMER messages. Instead of trying to fetch a WM_TIMER
|
|
429 * which will never come when there are no pending timers, which leads
|
|
430 * to deadlock, we simply signal an error.
|
|
431 *
|
|
432 * The implementation does not honor user_p by design.
|
|
433 */
|
|
434 static void
|
231
|
435 mswindows_need_event_in_modal_loop (int user_p, int badly_p)
|
227
|
436 {
|
|
437 MSG msg;
|
|
438
|
|
439 /* Check if already have one */
|
|
440 if (!NILP (mswindows_u_dispatch_event_queue)
|
|
441 || !NILP (mswindows_s_dispatch_event_queue))
|
|
442 return;
|
|
443
|
|
444 /* No event is ok */
|
|
445 if (!badly_p)
|
|
446 return;
|
|
447
|
|
448 /* We do not check the _u_ queue, because timers go to _s_ */
|
|
449 while (NILP (mswindows_s_dispatch_event_queue))
|
|
450 {
|
|
451 /* We'll deadlock if go waiting */
|
|
452 if (mswindows_pending_timers_count == 0)
|
|
453 error ("Deadlock due to an attempt to call next-event in a wrong context");
|
|
454
|
|
455 /* Fetch and dispatch any pending timers */
|
|
456 GetMessage (&msg, NULL, WM_TIMER, WM_TIMER);
|
|
457 DispatchMessage (&msg);
|
|
458 }
|
223
|
459 }
|
|
460
|
|
461 /*
|
|
462 * This drains the event queue and fills up two internal queues until
|
|
463 * an event of a type specified by USER_P is retrieved.
|
|
464 *
|
|
465 * If user_p, then the function drains until the first user event, or
|
|
466 * the first non-user event if there no user events. Otherwise, If
|
|
467 * not user_p, it does not give preference to user events.
|
|
468 *
|
|
469 * If badly_p, then the function does not return until an event is
|
|
470 * available.
|
|
471 *
|
|
472 * The code does not rely on MsgWaitForMultipleObjects preference for
|
|
473 * messages over waitable handles.
|
|
474 *
|
|
475 * Used by emacs_mswindows_event_pending_p and emacs_mswindows_next_event
|
|
476 */
|
|
477 static void
|
|
478 mswindows_need_event (int user_p, int badly_p)
|
|
479 {
|
|
480 int active;
|
|
481
|
231
|
482 if (mswindows_in_modal_loop)
|
227
|
483 {
|
231
|
484 mswindows_need_event_in_modal_loop (user_p, badly_p);
|
227
|
485 return;
|
|
486 }
|
|
487
|
223
|
488 /* Have to drain Windows message queue first, otherwise, we may miss
|
|
489 quit char when called from quit_p */
|
|
490 mswindows_drain_windows_queue ();
|
|
491
|
|
492 while (NILP (mswindows_u_dispatch_event_queue) &&
|
|
493 (user_p || NILP (mswindows_s_dispatch_event_queue)))
|
|
494 {
|
|
495 /* If we already have an event, we've got someting to return - no wait! */
|
|
496 if (!NILP (mswindows_u_dispatch_event_queue)
|
|
497 || !NILP (mswindows_s_dispatch_event_queue))
|
|
498 badly_p = 0;
|
|
499
|
|
500 /* Now try getting a message */
|
|
501 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
|
|
502 mswindows_waitable,
|
|
503 FALSE, badly_p ? INFINITE : 0,
|
|
504 QS_ALLINPUT);
|
|
505
|
|
506 /* This will assert if handle being waited for becomes abandoned.
|
|
507 Not the case currently tho */
|
|
508 assert ((!badly_p && active == WAIT_TIMEOUT) ||
|
|
509 (active >= WAIT_OBJECT_0 &&
|
|
510 active <= WAIT_OBJECT_0 + mswindows_waitable_count));
|
|
511
|
|
512 if (active == WAIT_TIMEOUT)
|
|
513 {
|
|
514 /* No luck trying - just return what we've already got */
|
|
515 return;
|
|
516 }
|
|
517 else if (active == WAIT_OBJECT_0 + mswindows_waitable_count)
|
|
518 {
|
|
519 /* Got your message, thanks */
|
|
520 mswindows_drain_windows_queue ();
|
|
521 }
|
|
522 else
|
|
523 {
|
|
524 /* XXX FIXME: We should do some kind of round-robin scheme to ensure fairness */
|
|
525 int waitable = active - WAIT_OBJECT_0;
|
|
526 mswindows_waitable_info_type *info = mswindows_waitable_info + waitable;
|
|
527
|
|
528 switch (info->type)
|
|
529 {
|
|
530 /* XXX FIXME: Should enque subprocess event here so that it is not lost */
|
|
531 default:
|
|
532 assert(0);
|
|
533 }
|
|
534 }
|
|
535 } /* while */
|
|
536
|
|
537 return;
|
|
538 }
|
|
539
|
213
|
540
|
|
541 /************************************************************************/
|
|
542 /* methods */
|
|
543 /************************************************************************/
|
|
544
|
|
545 static int
|
|
546 emacs_mswindows_add_timeout (EMACS_TIME thyme)
|
|
547 {
|
223
|
548 int milliseconds;
|
213
|
549 EMACS_TIME current_time;
|
|
550 EMACS_GET_TIME (current_time);
|
|
551 EMACS_SUB_TIME (thyme, thyme, current_time);
|
223
|
552 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
553 (EMACS_USECS (thyme) + 500) / 1000;
|
213
|
554 if (milliseconds < 1)
|
|
555 milliseconds = 1;
|
227
|
556 ++mswindows_pending_timers_count;
|
223
|
557 return SetTimer (NULL, 0, milliseconds, mswindows_wm_timer_callback);
|
213
|
558 }
|
|
559
|
|
560 static void
|
|
561 emacs_mswindows_remove_timeout (int id)
|
|
562 {
|
223
|
563 struct Lisp_Event match_against;
|
|
564 Lisp_Object emacs_event;
|
|
565
|
233
|
566 if (KillTimer (NULL, id))
|
|
567 --mswindows_pending_timers_count;
|
223
|
568
|
|
569 /* If there is a dispatch event generated by this
|
|
570 timeout in the queue, we have to remove it too. */
|
|
571 match_against.event_type = timeout_event;
|
|
572 match_against.event.timeout.interval_id = id;
|
|
573 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
574 if (!NILP (emacs_event))
|
|
575 Fdeallocate_event(emacs_event);
|
213
|
576 }
|
|
577
|
219
|
578 /* If `user_p' is false, then return whether there are any win32, timeout,
|
|
579 * or subprocess events pending (that is, whether
|
|
580 * emacs_mswindows_next_event() would return immediately without blocking).
|
|
581 *
|
|
582 * if `user_p' is true, then return whether there are any *user generated*
|
|
583 * events available (that is, whether there are keyboard or mouse-click
|
|
584 * events ready to be read). This also implies that
|
|
585 * emacs_mswindows_next_event() would not block.
|
|
586 */
|
213
|
587 static int
|
|
588 emacs_mswindows_event_pending_p (int user_p)
|
|
589 {
|
223
|
590 mswindows_need_event (user_p, 0);
|
219
|
591
|
223
|
592 return (!NILP (mswindows_u_dispatch_event_queue)
|
|
593 || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
|
213
|
594 }
|
|
595
|
|
596 /*
|
|
597 * Return the next event
|
|
598 */
|
|
599 static void
|
|
600 emacs_mswindows_next_event (struct Lisp_Event *emacs_event)
|
|
601 {
|
223
|
602 Lisp_Object event, event2;
|
|
603
|
|
604 /* Give strong preference to user events */
|
|
605 mswindows_need_event (1, 1);
|
213
|
606
|
223
|
607 /* XXX Copied from event-Xt.c */
|
|
608 event = mswindows_dequeue_dispatch_event (!NILP(mswindows_u_dispatch_event_queue));
|
|
609 XSETEVENT (event2, emacs_event);
|
|
610 Fcopy_event (event, event2);
|
|
611 Fdeallocate_event (event);
|
213
|
612 }
|
|
613
|
|
614 /*
|
|
615 * Handle a magic event off the dispatch queue.
|
|
616 */
|
|
617 static void
|
|
618 emacs_mswindows_handle_magic_event (struct Lisp_Event *emacs_event)
|
|
619 {
|
|
620 #if 0
|
|
621 stderr_out("magic %x, (%d,%d), (%d,%d)\n",
|
|
622 EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event),
|
|
623 rect->left, rect->top, rect->right, rect->bottom);
|
|
624 #endif
|
|
625 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event))
|
|
626 {
|
|
627 case WM_SETFOCUS:
|
|
628 case WM_KILLFOCUS:
|
|
629 {
|
223
|
630 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
631 struct frame *f = XFRAME (frame);
|
213
|
632 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS);
|
|
633 Lisp_Object conser;
|
223
|
634
|
213
|
635 /* struct gcpro gcpro1; */
|
|
636
|
|
637 /* Clear sticky modifiers here (if we had any) */
|
|
638
|
|
639 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
|
640 /* GCPRO1 (conser); XXX Not necessary? */
|
|
641 emacs_handle_focus_change_preliminary (conser);
|
|
642 /* Under X the stuff up to here is done in the X event handler.
|
|
643 I Don't know why */
|
|
644 emacs_handle_focus_change_final (conser);
|
|
645 /* UNGCPRO; */
|
223
|
646
|
213
|
647 }
|
|
648 break;
|
|
649
|
223
|
650 case XM_BUMPQUEUE:
|
|
651 /* This is a nice event, when we're in need to queue *something* */
|
|
652 break;
|
|
653
|
|
654 case XM_MAPFRAME:
|
|
655 case XM_UNMAPFRAME:
|
|
656 {
|
|
657 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
658 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)
|
|
659 == XM_MAPFRAME ?
|
|
660 Qmap_frame_hook : Qunmap_frame_hook,
|
|
661 1, frame);
|
|
662 }
|
|
663 break;
|
|
664
|
|
665 /* XXX What about Enter & Leave */
|
213
|
666 #if 0
|
|
667 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
|
|
668 Qmouse_leave_frame_hook, 1, frame);
|
|
669 #endif
|
|
670
|
|
671 default:
|
|
672 assert(0);
|
|
673 }
|
|
674 }
|
|
675
|
|
676 static void
|
|
677 emacs_mswindows_select_process (struct Lisp_Process *process)
|
|
678 {
|
|
679 }
|
|
680
|
|
681 static void
|
|
682 emacs_mswindows_unselect_process (struct Lisp_Process *process)
|
|
683 {
|
|
684 }
|
|
685
|
|
686 static void
|
|
687 emacs_mswindows_select_console (struct console *con)
|
|
688 {
|
|
689 }
|
|
690
|
|
691 static void
|
|
692 emacs_mswindows_unselect_console (struct console *con)
|
|
693 {
|
|
694 }
|
|
695
|
|
696 static void
|
|
697 emacs_mswindows_quit_p (void)
|
|
698 {
|
223
|
699 mswindows_need_event (1, 0);
|
|
700
|
|
701 if (mswindows_quit_chars_count > 0)
|
|
702 {
|
|
703 /* Yes there's a hidden one... Throw it away */
|
|
704 struct Lisp_Event match_against;
|
|
705 Lisp_Object emacs_event;
|
|
706
|
|
707 match_against.event_type = key_press_event;
|
|
708 match_against.event.key.modifiers = FAKE_MOD_QUIT;
|
|
709
|
|
710 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
711 assert (!NILP (emacs_event));
|
|
712
|
|
713 Vquit_flag = (XEVENT(emacs_event)->event.key.modifiers & MOD_SHIFT
|
|
714 ? Qcritical : Qt);
|
|
715
|
|
716 Fdeallocate_event(emacs_event);
|
|
717 --mswindows_quit_chars_count;
|
|
718 }
|
213
|
719 }
|
|
720
|
|
721 /* This is called from GC when a process object is about to be freed.
|
|
722 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
723 */
|
|
724 void
|
|
725 debug_process_finalization (struct Lisp_Process *p)
|
|
726 {
|
|
727 #if 0 /* #### */
|
|
728 int i;
|
|
729 int infd, outfd;
|
|
730 get_process_file_descriptors (p, &infd, &outfd);
|
|
731 /* if it still has fds, then it hasn't been killed yet. */
|
|
732 assert (infd < 0);
|
|
733 assert (outfd < 0);
|
|
734 /* Better not still be in the "with input" table; we know it's got no fds. */
|
|
735 for (i = 0; i < MAXDESC; i++)
|
|
736 {
|
|
737 Lisp_Object process = filedesc_fds_with_input [i];
|
|
738 assert (!PROCESSP (process) || XPROCESS (process) != p);
|
|
739 }
|
|
740 #endif
|
|
741 }
|
|
742
|
|
743 /************************************************************************/
|
|
744 /* initialization */
|
|
745 /************************************************************************/
|
|
746
|
|
747 void
|
|
748 vars_of_event_mswindows (void)
|
|
749 {
|
223
|
750 mswindows_u_dispatch_event_queue = Qnil;
|
|
751 staticpro (&mswindows_u_dispatch_event_queue);
|
|
752 mswindows_u_dispatch_event_queue_tail = Qnil;
|
|
753
|
|
754 mswindows_s_dispatch_event_queue = Qnil;
|
|
755 staticpro (&mswindows_s_dispatch_event_queue);
|
|
756 mswindows_s_dispatch_event_queue_tail = Qnil;
|
213
|
757
|
231
|
758 mswindows_error_caught_in_modal_loop = Qnil;
|
|
759 staticpro (&mswindows_error_caught_in_modal_loop);
|
|
760 mswindows_in_modal_loop = 0;
|
227
|
761 mswindows_pending_timers_count = 0;
|
|
762
|
213
|
763 mswindows_event_stream = xnew (struct event_stream);
|
|
764
|
|
765 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
|
223
|
766 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
|
213
|
767 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
|
|
768 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
|
|
769 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
|
|
770 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
|
223
|
771 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
|
213
|
772 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
|
223
|
773 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
|
213
|
774 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
|
223
|
775
|
225
|
776 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /*
|
223
|
777 *Controls redrawing frame contents during mouse-drag or keyboard resize
|
|
778 operation. When non-nil, the frame is redrawn while being resized. When
|
|
779 nil, frame is not redrawn, and exposed areas are filled with default
|
|
780 MDI application background color. Note that this option only has effect
|
|
781 if "Show window contents while dragging" is on in system Display/Plus!
|
|
782 settings.
|
|
783 Default is t on fast machines, nil on slow.
|
|
784 */ );
|
|
785
|
|
786 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
225
|
787 DEFVAR_INT ("mswindows-mouse-button-tolerance", &mswindows_button2_chord_time /*
|
223
|
788 *Analogue of double click interval for faking middle mouse events.
|
|
789 The value is the minimum time in milliseconds that must elapse between
|
|
790 left/right button down events before they are considered distinct events.
|
|
791 If both mouse buttons are depressed within this interval, a middle mouse
|
|
792 button down event is generated instead.
|
|
793 If negative or zero, currently set system default is used instead.
|
|
794 */ );
|
|
795
|
|
796 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
225
|
797 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
|
223
|
798 Number of physical mouse buttons.
|
|
799 */ );
|
|
800
|
225
|
801 DEFVAR_INT ("mswindows-mouse-button-max-skew-x", &mswindows_button2_max_skew_x /*
|
223
|
802 *Maximum horizontal distance in pixels between points in which left and
|
|
803 right button clicks occured for them to be translated into single
|
|
804 middle button event. Clicks must occur in time not longer than defined
|
225
|
805 by the variable mswindows-mouse-button-tolerance.
|
223
|
806 If negative or zero, currently set system default is used instead.
|
|
807 */ );
|
|
808
|
225
|
809 DEFVAR_INT ("mswindows-mouse-button-max-skew-y", &mswindows_button2_max_skew_y /*
|
223
|
810 *Maximum vertical distance in pixels between points in which left and
|
|
811 right button clicks occured for them to be translated into single
|
|
812 middle button event. Clicks must occur in time not longer than defined
|
225
|
813 by the variable mswindows-mouse-button-tolerance.
|
223
|
814 If negative or zero, currently set system default is used instead.
|
|
815 */ );
|
|
816
|
|
817 mswindows_button2_max_skew_x = 0;
|
|
818 mswindows_button2_max_skew_y = 0;
|
|
819 mswindows_button2_chord_time = 0;
|
213
|
820 }
|
|
821
|
|
822 void
|
|
823 syms_of_event_mswindows (void)
|
|
824 {
|
|
825 }
|
|
826
|
|
827 void
|
|
828 init_event_mswindows_late (void)
|
|
829 {
|
|
830 event_stream = mswindows_event_stream;
|
223
|
831
|
|
832 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
|
|
833 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
|
213
|
834 }
|