comparison src/macterm.c @ 54165:88d1b7a60637

(XTread_socket): Remove bufp_r and numcharsp args. Add hold_quit arg. Rework to use just one, local, inev input_event. Store inev directly in fifo using kbd_buffer_store_event_hold.
author Kim F. Storm <storm@cua.dk>
date Fri, 27 Feb 2004 23:47:13 +0000
parents 6c8849d06ab3
children f84db574fec7 b44978264e1d
comparison
equal deleted inserted replaced
54164:fe5d50158fb4 54165:88d1b7a60637
8014 } 8014 }
8015 8015
8016 /* Emacs calls this whenever it wants to read an input event from the 8016 /* Emacs calls this whenever it wants to read an input event from the
8017 user. */ 8017 user. */
8018 int 8018 int
8019 XTread_socket (int sd, struct input_event *bufp, int numchars, int expected) 8019 XTread_socket (int sd, int expected, struct input_event *hold_quit)
8020 { 8020 {
8021 struct input_event inev;
8021 int count = 0; 8022 int count = 0;
8022 #if USE_CARBON_EVENTS 8023 #if USE_CARBON_EVENTS
8023 OSStatus rneResult; 8024 OSStatus rneResult;
8024 EventRef eventRef; 8025 EventRef eventRef;
8025 EventMouseButton mouseBtn; 8026 EventMouseButton mouseBtn;
8039 interrupt_input_pending = 0; 8040 interrupt_input_pending = 0;
8040 BLOCK_INPUT; 8041 BLOCK_INPUT;
8041 8042
8042 /* So people can tell when we have read the available input. */ 8043 /* So people can tell when we have read the available input. */
8043 input_signal_count++; 8044 input_signal_count++;
8044
8045 if (numchars <= 0)
8046 abort ();
8047 8045
8048 /* Don't poll for events to process (specifically updateEvt) if 8046 /* Don't poll for events to process (specifically updateEvt) if
8049 window update currently already in progress. A call to redisplay 8047 window update currently already in progress. A call to redisplay
8050 (in do_window_update) can be preempted by another call to 8048 (in do_window_update) can be preempted by another call to
8051 redisplay, causing blank regions to be left on the screen and the 8049 redisplay, causing blank regions to be left on the screen and the
8061 8059
8062 /* It is necessary to set this (additional) argument slot of an 8060 /* It is necessary to set this (additional) argument slot of an
8063 event to nil because keyboard.c protects incompletely processed 8061 event to nil because keyboard.c protects incompletely processed
8064 event from being garbage collected by placing them in the 8062 event from being garbage collected by placing them in the
8065 kbd_buffer_gcpro vector. */ 8063 kbd_buffer_gcpro vector. */
8066 bufp->arg = Qnil; 8064 EVENT_INIT (inev);
8065 inev.kind = NO_EVENT;
8066 inev.arg = Qnil;
8067 8067
8068 event_mask = everyEvent; 8068 event_mask = everyEvent;
8069 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop))) 8069 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop)))
8070 event_mask -= highLevelEventMask; 8070 event_mask -= highLevelEventMask;
8071 8071
8099 typeSInt32, NULL, sizeof (SInt32), 8099 typeSInt32, NULL, sizeof (SInt32),
8100 NULL, &delta); 8100 NULL, &delta);
8101 GetEventParameter(eventRef, kEventParamMouseLocation, 8101 GetEventParameter(eventRef, kEventParamMouseLocation,
8102 typeQDPoint, NULL, sizeof (Point), 8102 typeQDPoint, NULL, sizeof (Point),
8103 NULL, &point); 8103 NULL, &point);
8104 bufp->kind = WHEEL_EVENT; 8104 inev.kind = WHEEL_EVENT;
8105 bufp->code = 0; 8105 inev.code = 0;
8106 bufp->modifiers = (mac_event_to_emacs_modifiers(eventRef) 8106 inev.modifiers = (mac_event_to_emacs_modifiers(eventRef)
8107 | ((delta < 0) ? down_modifier 8107 | ((delta < 0) ? down_modifier
8108 : up_modifier)); 8108 : up_modifier));
8109 SetPort (GetWindowPort (window_ptr)); 8109 SetPort (GetWindowPort (window_ptr));
8110 GlobalToLocal (&point); 8110 GlobalToLocal (&point);
8111 XSETINT (bufp->x, point.h); 8111 XSETINT (inev.x, point.h);
8112 XSETINT (bufp->y, point.v); 8112 XSETINT (inev.y, point.v);
8113 XSETFRAME (bufp->frame_or_window, mwp->mFP); 8113 XSETFRAME (inev.frame_or_window, mwp->mFP);
8114 bufp->timestamp = EventTimeToTicks (GetEventTime (eventRef))*(1000/60); 8114 inev.timestamp = EventTimeToTicks (GetEventTime (eventRef))*(1000/60);
8115 count++;
8116 } 8115 }
8117 else 8116 else
8118 SendEventToEventTarget (eventRef, GetEventDispatcherTarget ()); 8117 SendEventToEventTarget (eventRef, GetEventDispatcherTarget ());
8119 8118
8120 break; 8119 break;
8159 #endif 8158 #endif
8160 8159
8161 GlobalToLocal (&mouse_loc); 8160 GlobalToLocal (&mouse_loc);
8162 8161
8163 #if USE_CARBON_EVENTS 8162 #if USE_CARBON_EVENTS
8164 bufp->code = mac_get_mouse_btn (eventRef); 8163 inev.code = mac_get_mouse_btn (eventRef);
8165 #else 8164 #else
8166 bufp_.code = mac_get_emulate_btn (er.modifiers); 8165 inev.code = mac_get_emulate_btn (er.modifiers);
8167 #endif 8166 #endif
8168 bufp->kind = SCROLL_BAR_CLICK_EVENT; 8167 inev.kind = SCROLL_BAR_CLICK_EVENT;
8169 bufp->frame_or_window = tracked_scroll_bar->window; 8168 inev.frame_or_window = tracked_scroll_bar->window;
8170 bufp->part = scroll_bar_handle; 8169 inev.part = scroll_bar_handle;
8171 #if USE_CARBON_EVENTS 8170 #if USE_CARBON_EVENTS
8172 bufp->modifiers = mac_event_to_emacs_modifiers (eventRef); 8171 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
8173 #else 8172 #else
8174 bufp->modifiers = mac_to_emacs_modifiers (er.modifiers); 8173 inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
8175 #endif 8174 #endif
8176 bufp->modifiers |= up_modifier; 8175 inev.modifiers |= up_modifier;
8177 bufp->timestamp = er.when * (1000 / 60); 8176 inev.timestamp = er.when * (1000 / 60);
8178 /* ticks to milliseconds */ 8177 /* ticks to milliseconds */
8179 8178
8180 XSETINT (bufp->x, tracked_scroll_bar->left + 2); 8179 XSETINT (inev.x, tracked_scroll_bar->left + 2);
8181 XSETINT (bufp->y, mouse_loc.v - 24); 8180 XSETINT (inev.y, mouse_loc.v - 24);
8182 tracked_scroll_bar->dragging = Qnil; 8181 tracked_scroll_bar->dragging = Qnil;
8183 mouse_tracking_in_progress = mouse_tracking_none; 8182 mouse_tracking_in_progress = mouse_tracking_none;
8184 tracked_scroll_bar = NULL; 8183 tracked_scroll_bar = NULL;
8185 count++;
8186 break; 8184 break;
8187 } 8185 }
8188 8186
8189 part_code = FindWindow (er.where, &window_ptr); 8187 part_code = FindWindow (er.where, &window_ptr);
8190 8188
8194 if (er.what == mouseDown) 8192 if (er.what == mouseDown)
8195 { 8193 {
8196 struct frame *f = ((mac_output *) 8194 struct frame *f = ((mac_output *)
8197 GetWRefCon (FrontWindow ()))->mFP; 8195 GetWRefCon (FrontWindow ()))->mFP;
8198 saved_menu_event_location = er.where; 8196 saved_menu_event_location = er.where;
8199 bufp->kind = MENU_BAR_ACTIVATE_EVENT; 8197 inev.kind = MENU_BAR_ACTIVATE_EVENT;
8200 XSETFRAME (bufp->frame_or_window, f); 8198 XSETFRAME (inev.frame_or_window, f);
8201 count++;
8202 } 8199 }
8203 break; 8200 break;
8204 8201
8205 case inContent: 8202 case inContent:
8206 if (window_ptr != FrontWindow ()) 8203 if (window_ptr != FrontWindow ())
8227 #else 8224 #else
8228 control_part_code = FindControl (mouse_loc, window_ptr, &ch); 8225 control_part_code = FindControl (mouse_loc, window_ptr, &ch);
8229 #endif 8226 #endif
8230 8227
8231 #if USE_CARBON_EVENTS 8228 #if USE_CARBON_EVENTS
8232 bufp->code = mac_get_mouse_btn (eventRef); 8229 inev.code = mac_get_mouse_btn (eventRef);
8233 #else 8230 #else
8234 bufp_.code = mac_get_emulate_btn (er.modifiers); 8231 inev.code = mac_get_emulate_btn (er.modifiers);
8235 #endif 8232 #endif
8236 XSETINT (bufp->x, mouse_loc.h); 8233 XSETINT (inev.x, mouse_loc.h);
8237 XSETINT (bufp->y, mouse_loc.v); 8234 XSETINT (inev.y, mouse_loc.v);
8238 bufp->timestamp = er.when * (1000 / 60); 8235 inev.timestamp = er.when * (1000 / 60);
8239 /* ticks to milliseconds */ 8236 /* ticks to milliseconds */
8240 8237
8241 #if TARGET_API_MAC_CARBON 8238 #if TARGET_API_MAC_CARBON
8242 if (ch != 0) 8239 if (ch != 0)
8243 #else 8240 #else
8245 #endif 8242 #endif
8246 { 8243 {
8247 struct scroll_bar *bar = (struct scroll_bar *) 8244 struct scroll_bar *bar = (struct scroll_bar *)
8248 GetControlReference (ch); 8245 GetControlReference (ch);
8249 x_scroll_bar_handle_click (bar, control_part_code, &er, 8246 x_scroll_bar_handle_click (bar, control_part_code, &er,
8250 bufp); 8247 &inev);
8251 if (er.what == mouseDown 8248 if (er.what == mouseDown
8252 && control_part_code == kControlIndicatorPart) 8249 && control_part_code == kControlIndicatorPart)
8253 { 8250 {
8254 mouse_tracking_in_progress 8251 mouse_tracking_in_progress
8255 = mouse_tracking_scroll_bar; 8252 = mouse_tracking_scroll_bar;
8262 } 8259 }
8263 } 8260 }
8264 else 8261 else
8265 { 8262 {
8266 Lisp_Object window; 8263 Lisp_Object window;
8267 8264
8268 bufp->kind = MOUSE_CLICK_EVENT; 8265 inev.kind = MOUSE_CLICK_EVENT;
8269 XSETFRAME (bufp->frame_or_window, mwp->mFP); 8266 XSETFRAME (inev.frame_or_window, mwp->mFP);
8270 if (er.what == mouseDown) 8267 if (er.what == mouseDown)
8271 mouse_tracking_in_progress 8268 mouse_tracking_in_progress
8272 = mouse_tracking_mouse_movement; 8269 = mouse_tracking_mouse_movement;
8273 else 8270 else
8274 mouse_tracking_in_progress = mouse_tracking_none; 8271 mouse_tracking_in_progress = mouse_tracking_none;
8275 window = window_from_coordinates (mwp->mFP, bufp->x, bufp->y, 0, 0, 0, 1); 8272 window = window_from_coordinates (mwp->mFP, inev.x, inev.y, 0, 0, 0, 1);
8276 8273
8277 if (EQ (window, mwp->mFP->tool_bar_window)) 8274 if (EQ (window, mwp->mFP->tool_bar_window))
8278 { 8275 {
8279 if (er.what == mouseDown) 8276 if (er.what == mouseDown)
8280 handle_tool_bar_click (mwp->mFP, bufp->x, bufp->y, 1, 0); 8277 handle_tool_bar_click (mwp->mFP, inev.x, inev.y, 1, 0);
8281 else 8278 else
8282 handle_tool_bar_click (mwp->mFP, bufp->x, bufp->y, 0, 8279 handle_tool_bar_click (mwp->mFP, inev.x, inev.y, 0,
8283 #if USE_CARBON_EVENTS 8280 #if USE_CARBON_EVENTS
8284 mac_event_to_emacs_modifiers (eventRef) 8281 mac_event_to_emacs_modifiers (eventRef)
8285 #else 8282 #else
8286 er.modifiers 8283 er.modifiers
8287 #endif 8284 #endif
8289 break; 8286 break;
8290 } 8287 }
8291 } 8288 }
8292 8289
8293 #if USE_CARBON_EVENTS 8290 #if USE_CARBON_EVENTS
8294 bufp->modifiers = mac_event_to_emacs_modifiers (eventRef); 8291 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
8295 #else 8292 #else
8296 bufp->modifiers = mac_to_emacs_modifiers (er.modifiers); 8293 inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
8297 #endif 8294 #endif
8298 8295
8299 switch (er.what) 8296 switch (er.what)
8300 { 8297 {
8301 case mouseDown: 8298 case mouseDown:
8302 bufp->modifiers |= down_modifier; 8299 inev.modifiers |= down_modifier;
8303 break; 8300 break;
8304 case mouseUp: 8301 case mouseUp:
8305 bufp->modifiers |= up_modifier; 8302 inev.modifiers |= up_modifier;
8306 break; 8303 break;
8307 } 8304 }
8308
8309 count++;
8310 } 8305 }
8311 break; 8306 break;
8312 8307
8313 case inDrag: 8308 case inDrag:
8314 #if TARGET_API_MAC_CARBON 8309 #if TARGET_API_MAC_CARBON
8325 break; 8320 break;
8326 8321
8327 case inGoAway: 8322 case inGoAway:
8328 if (TrackGoAway (window_ptr, er.where)) 8323 if (TrackGoAway (window_ptr, er.where))
8329 { 8324 {
8330 bufp->kind = DELETE_WINDOW_EVENT; 8325 inev.kind = DELETE_WINDOW_EVENT;
8331 XSETFRAME (bufp->frame_or_window, 8326 XSETFRAME (inev.frame_or_window,
8332 ((mac_output *) GetWRefCon (window_ptr))->mFP); 8327 ((mac_output *) GetWRefCon (window_ptr))->mFP);
8333 count++;
8334 } 8328 }
8335 break; 8329 break;
8336 8330
8337 /* window resize handling added --ben */ 8331 /* window resize handling added --ben */
8338 case inGrow: 8332 case inGrow:
8397 8391
8398 ObscureCursor (); 8392 ObscureCursor ();
8399 8393
8400 if (keycode_to_xkeysym (keycode, &xkeysym)) 8394 if (keycode_to_xkeysym (keycode, &xkeysym))
8401 { 8395 {
8402 bufp->code = 0xff00 | xkeysym; 8396 inev.code = 0xff00 | xkeysym;
8403 bufp->kind = NON_ASCII_KEYSTROKE_EVENT; 8397 inev.kind = NON_ASCII_KEYSTROKE_EVENT;
8404 } 8398 }
8405 else 8399 else
8406 { 8400 {
8407 if (er.modifiers & (controlKey | 8401 if (er.modifiers & (controlKey |
8408 (NILP (Vmac_command_key_is_meta) ? optionKey 8402 (NILP (Vmac_command_key_is_meta) ? optionKey
8417 int new_modifiers = er.modifiers & 0xe600; 8411 int new_modifiers = er.modifiers & 0xe600;
8418 /* mask off option and command */ 8412 /* mask off option and command */
8419 int new_keycode = keycode | new_modifiers; 8413 int new_keycode = keycode | new_modifiers;
8420 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); 8414 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
8421 unsigned long some_state = 0; 8415 unsigned long some_state = 0;
8422 bufp->code = KeyTranslate (kchr_ptr, new_keycode, 8416 inev.code = KeyTranslate (kchr_ptr, new_keycode,
8423 &some_state) & 0xff; 8417 &some_state) & 0xff;
8424 } 8418 }
8425 else 8419 else
8426 bufp->code = er.message & charCodeMask; 8420 inev.code = er.message & charCodeMask;
8427 bufp->kind = ASCII_KEYSTROKE_EVENT; 8421 inev.kind = ASCII_KEYSTROKE_EVENT;
8428 } 8422 }
8429 } 8423 }
8430 8424
8431 /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil, 8425 /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil,
8432 convert non-ASCII characters typed at the Mac keyboard 8426 convert non-ASCII characters typed at the Mac keyboard
8433 (presumed to be in the Mac Roman encoding) to iso-latin-1 8427 (presumed to be in the Mac Roman encoding) to iso-latin-1
8434 encoding before they are passed to Emacs. This enables the 8428 encoding before they are passed to Emacs. This enables the
8435 Mac keyboard to be used to enter non-ASCII iso-latin-1 8429 Mac keyboard to be used to enter non-ASCII iso-latin-1
8436 characters directly. */ 8430 characters directly. */
8437 if (mac_keyboard_text_encoding != kTextEncodingMacRoman 8431 if (mac_keyboard_text_encoding != kTextEncodingMacRoman
8438 && bufp->kind == ASCII_KEYSTROKE_EVENT && bufp->code >= 128) 8432 && inev.kind == ASCII_KEYSTROKE_EVENT && inev.code >= 128)
8439 { 8433 {
8440 static TECObjectRef converter = NULL; 8434 static TECObjectRef converter = NULL;
8441 OSStatus the_err = noErr; 8435 OSStatus the_err = noErr;
8442 OSStatus convert_status = noErr; 8436 OSStatus convert_status = noErr;
8443 8437
8462 = mac_keyboard_text_encoding; 8456 = mac_keyboard_text_encoding;
8463 } 8457 }
8464 8458
8465 if (the_err == noErr) 8459 if (the_err == noErr)
8466 { 8460 {
8467 unsigned char ch = bufp->code; 8461 unsigned char ch = inev.code;
8468 ByteCount actual_input_length, actual_output_length; 8462 ByteCount actual_input_length, actual_output_length;
8469 unsigned char outch; 8463 unsigned char outch;
8470 8464
8471 convert_status = TECConvertText (converter, &ch, 1, 8465 convert_status = TECConvertText (converter, &ch, 1,
8472 &actual_input_length, 8466 &actual_input_length,
8473 &outch, 1, 8467 &outch, 1,
8474 &actual_output_length); 8468 &actual_output_length);
8475 if (convert_status == noErr 8469 if (convert_status == noErr
8476 && actual_input_length == 1 8470 && actual_input_length == 1
8477 && actual_output_length == 1) 8471 && actual_output_length == 1)
8478 bufp->code = outch; 8472 inev.code = outch;
8479 } 8473 }
8480 } 8474 }
8481 8475
8482 #if USE_CARBON_EVENTS 8476 #if USE_CARBON_EVENTS
8483 bufp->modifiers = mac_event_to_emacs_modifiers (eventRef); 8477 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
8484 #else 8478 #else
8485 bufp->modifiers = mac_to_emacs_modifiers (er.modifiers); 8479 inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
8486 #endif 8480 #endif
8487 8481
8488 { 8482 {
8489 mac_output *mwp 8483 mac_output *mwp
8490 = (mac_output *) GetWRefCon (FrontNonFloatingWindow ()); 8484 = (mac_output *) GetWRefCon (FrontNonFloatingWindow ());
8491 XSETFRAME (bufp->frame_or_window, mwp->mFP); 8485 XSETFRAME (inev.frame_or_window, mwp->mFP);
8492 } 8486 }
8493 8487
8494 bufp->timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ 8488 inev.timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
8495
8496 count++;
8497 break; 8489 break;
8498 8490
8499 case kHighLevelEvent: 8491 case kHighLevelEvent:
8500 drag_and_drop_file_list = Qnil; 8492 drag_and_drop_file_list = Qnil;
8501 8493
8519 } 8511 }
8520 8512
8521 if (wp && is_emacs_window(wp)) 8513 if (wp && is_emacs_window(wp))
8522 f = ((mac_output *) GetWRefCon (wp))->mFP; 8514 f = ((mac_output *) GetWRefCon (wp))->mFP;
8523 8515
8524 bufp->kind = DRAG_N_DROP_EVENT; 8516 inev.kind = DRAG_N_DROP_EVENT;
8525 bufp->code = 0; 8517 inev.code = 0;
8526 bufp->timestamp = er.when * (1000 / 60); 8518 inev.timestamp = er.when * (1000 / 60);
8527 /* ticks to milliseconds */ 8519 /* ticks to milliseconds */
8528 #if USE_CARBON_EVENTS 8520 #if USE_CARBON_EVENTS
8529 bufp->modifiers = mac_event_to_emacs_modifiers (eventRef); 8521 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
8530 #else 8522 #else
8531 bufp->modifiers = mac_to_emacs_modifiers (er.modifiers); 8523 inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
8532 #endif 8524 #endif
8533 8525
8534 XSETINT (bufp->x, 0); 8526 XSETINT (inev.x, 0);
8535 XSETINT (bufp->y, 0); 8527 XSETINT (inev.y, 0);
8536 8528
8537 XSETFRAME (frame, f); 8529 XSETFRAME (frame, f);
8538 bufp->frame_or_window = Fcons (frame, drag_and_drop_file_list); 8530 inev.frame_or_window = Fcons (frame, drag_and_drop_file_list);
8539 8531
8540 /* Regardless of whether Emacs was suspended or in the 8532 /* Regardless of whether Emacs was suspended or in the
8541 foreground, ask it to redraw its entire screen. 8533 foreground, ask it to redraw its entire screen.
8542 Otherwise parts of the screen can be left in an 8534 Otherwise parts of the screen can be left in an
8543 inconsistent state. */ 8535 inconsistent state. */
8550 InvalWindowRect (wp, &r); 8542 InvalWindowRect (wp, &r);
8551 } 8543 }
8552 #else /* not TARGET_API_MAC_CARBON */ 8544 #else /* not TARGET_API_MAC_CARBON */
8553 InvalRect (&(wp->portRect)); 8545 InvalRect (&(wp->portRect));
8554 #endif /* not TARGET_API_MAC_CARBON */ 8546 #endif /* not TARGET_API_MAC_CARBON */
8555
8556 count++;
8557 } 8547 }
8558 default: 8548 default:
8559 break; 8549 break;
8560 } 8550 }
8561 #if USE_CARBON_EVENTS 8551 #if USE_CARBON_EVENTS
8620 } 8610 }
8621 } 8611 }
8622 } 8612 }
8623 } 8613 }
8624 8614
8615 if (inev.kind != NO_EVENT)
8616 {
8617 kbd_buffer_store_event_hold (&inev, hold_quit);
8618 count++;
8619 }
8620
8625 UNBLOCK_INPUT; 8621 UNBLOCK_INPUT;
8626
8627 return count; 8622 return count;
8628 } 8623 }
8629 8624
8630 8625
8631 /* Need to override CodeWarrior's input function so no conversion is 8626 /* Need to override CodeWarrior's input function so no conversion is