1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
11 * ui.c: functions that handle the user interface.
12 * 1. Keyboard input stuff, and a bit of windowing stuff. These are called
13 * before the machine specific stuff (mch_*) so that we can call the GUI
14 * stuff instead if the GUI is running.
16 * 3. Input buffer stuff.
27 if (gui
.in_use
&& !gui
.dying
&& !gui
.starting
)
31 gui_wait_for_chars(p_wd
);
36 /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */
37 if (!(silent_mode
&& p_verbose
== 0))
40 char_u
*tofree
= NULL
;
42 if (output_conv
.vc_type
!= CONV_NONE
)
44 /* Convert characters from 'encoding' to 'termencoding'. */
45 tofree
= string_convert(&output_conv
, s
, &len
);
54 if (output_conv
.vc_type
!= CONV_NONE
)
61 #if defined(UNIX) || defined(VMS) || defined(PROTO)
63 * When executing an external program, there may be some typed characters that
64 * are not consumed by it. Give them back to ui_inchar() and they are stored
65 * here for the next call.
67 static char_u
*ta_str
= NULL
;
68 static int ta_off
; /* offset for next char to use when ta_str != NULL */
69 static int ta_len
; /* length of ta_str when it's not NULL*/
72 ui_inchar_undo(s
, len
)
81 newlen
+= ta_len
- ta_off
;
87 mch_memmove(new, ta_str
+ ta_off
, (size_t)(ta_len
- ta_off
));
88 mch_memmove(new + ta_len
- ta_off
, s
, (size_t)len
);
92 mch_memmove(new, s
, (size_t)len
);
101 * ui_inchar(): low level input funcion.
102 * Get characters from the keyboard.
103 * Return the number of characters that are available.
104 * If "wtime" == 0 do not wait for characters.
105 * If "wtime" == -1 wait forever for characters.
106 * If "wtime" > 0 wait "wtime" milliseconds for a character.
108 * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into
109 * it. When typebuf.tb_change_cnt changes (e.g., when a message is received
110 * from a remote client) "buf" can no longer be used. "tb_change_cnt" is NULL
114 ui_inchar(buf
, maxlen
, wtime
, tb_change_cnt
)
117 long wtime
; /* don't use "time", MIPS cannot handle it */
122 #if defined(FEAT_GUI) && (defined(UNIX) || defined(VMS))
124 * Use the typeahead if there is any.
128 if (maxlen
>= ta_len
- ta_off
)
130 mch_memmove(buf
, ta_str
+ ta_off
, (size_t)ta_len
);
135 mch_memmove(buf
, ta_str
+ ta_off
, (size_t)maxlen
);
142 if (do_profiling
== PROF_YES
&& wtime
!= 0)
146 #ifdef NO_CONSOLE_INPUT
147 /* Don't wait for character input when the window hasn't been opened yet.
148 * Do try reading, this works when redirecting stdin from a file.
149 * Must return something, otherwise we'll loop forever. If we run into
150 * this very often we probably got stuck, exit Vim. */
151 if (no_console_input())
153 static int count
= 0;
156 retval
= mch_inchar(buf
, maxlen
, (wtime
>= 0 && wtime
< 10)
157 ? 10L : wtime
, tb_change_cnt
);
158 if (retval
> 0 || typebuf_changed(tb_change_cnt
) || wtime
>= 0)
161 if (wtime
== -1 && ++count
== 1000)
169 /* If we are going to wait for some time or block... */
170 if (wtime
== -1 || wtime
> 100L)
172 /* ... allow signals to kill us. */
173 (void)vim_handle_signal(SIGNAL_UNBLOCK
);
175 /* ... there is no need for CTRL-C to interrupt something, don't let
176 * it set got_int when it was mapped. */
178 ctrl_c_interrupts
= FALSE
;
184 if (gui_wait_for_chars(wtime
) && !typebuf_changed(tb_change_cnt
))
185 retval
= read_from_input_buf(buf
, (long)maxlen
);
193 retval
= mch_inchar(buf
, maxlen
, wtime
, tb_change_cnt
);
197 if (wtime
== -1 || wtime
> 100L)
198 /* block SIGHUP et al. */
199 (void)vim_handle_signal(SIGNAL_BLOCK
);
201 ctrl_c_interrupts
= TRUE
;
203 #ifdef NO_CONSOLE_INPUT
207 if (do_profiling
== PROF_YES
&& wtime
!= 0)
214 * return non-zero if a character is available
223 return input_available();
227 # ifdef NO_CONSOLE_INPUT
228 if (no_console_input())
231 return mch_char_avail();
238 * Delay for the given number of milliseconds. If ignoreinput is FALSE then we
239 * cancel the delay if a key is hit.
242 ui_delay(msec
, ignoreinput
)
247 if (gui
.in_use
&& !ignoreinput
)
248 gui_wait_for_chars(msec
);
251 mch_delay(msec
, ignoreinput
);
255 * If the machine has job control, use it to suspend the program,
256 * otherwise fake it by starting a new shell.
257 * When running the GUI iconify the window.
272 #if !defined(UNIX) || !defined(SIGTSTP) || defined(PROTO) || defined(__BEOS__)
274 * When the OS can't really suspend, call this function to start a shell.
275 * This is never called in the GUI.
281 EMSG(_(e_shellempty
));
284 MSG_PUTS(_("new shell started\n"));
291 * Try to get the current Vim shell size. Put the result in Rows and Columns.
292 * Use the new sizes as defaults for 'columns' and 'lines'.
293 * Return OK when size could be determined, FAIL otherwise.
302 retval
= gui_get_shellsize();
305 retval
= mch_get_shellsize();
309 /* adjust the default for 'lines' and 'columns' */
312 set_number_default("lines", Rows
);
313 set_number_default("columns", Columns
);
319 * Set the size of the Vim shell according to Rows and Columns, if possible.
320 * The gui_set_shellsize() or mch_set_shellsize() function will try to set the
321 * new size. If this is not possible, it will adjust Rows and Columns.
325 ui_set_shellsize(mustset
)
326 int mustset
; /* set by the user */
330 gui_set_shellsize(mustset
,
343 * Called when Rows and/or Columns changed. Adjust scroll region and mouse
349 if (full_screen
&& !exiting
)
371 /*****************************************************************************
372 * Functions for copying and pasting text between applications.
373 * This is always included in a GUI version, but may also be included when the
374 * clipboard and mouse is available to a terminal version such as xterm.
375 * Note: there are some more functions in ops.c that handle selection stuff.
377 * Also note that the majority of functions here deal with the X 'primary'
378 * (visible - for Visual mode use) selection, and only that. There are no
379 * versions of these for the 'clipboard' selection, as Visual mode has no use
383 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
386 * Selection stuff using Visual mode, for cutting and pasting text to other
391 * Call this to initialise the clipboard. Pass it FALSE if the clipboard code
392 * is included, but the clipboard can not be used, or TRUE if the clipboard can
393 * be used. Eg unix may call this with FALSE, then call it again with TRUE if
405 cb
->available
= can_use
;
411 cb
->state
= SELECT_CLEARED
;
413 if (cb
== &clip_plus
)
420 * Check whether the VIsual area has changed, and if so try to become the owner
421 * of the selection, and free any old converted selection we may still have
422 * lying around. If the VIsual mode has ended, make a copy of what was
423 * selected so we can still give it to others. Will probably have to make sure
424 * this is called whenever VIsual mode is ended.
427 clip_update_selection()
431 /* If visual mode is only due to a redo command ("."), then ignore it */
432 if (!redo_VIsual_busy
&& VIsual_active
&& (State
& NORMAL
))
434 if (lt(VIsual
, curwin
->w_cursor
))
437 end
= curwin
->w_cursor
;
440 end
.col
+= (*mb_ptr2len
)(ml_get_cursor()) - 1;
445 start
= curwin
->w_cursor
;
448 if (!equalpos(clip_star
.start
, start
)
449 || !equalpos(clip_star
.end
, end
)
450 || clip_star
.vmode
!= VIsual_mode
)
452 clip_clear_selection();
453 clip_star
.start
= start
;
455 clip_star
.vmode
= VIsual_mode
;
456 clip_free_selection(&clip_star
);
457 clip_own_selection(&clip_star
);
458 clip_gen_set_selection(&clip_star
);
464 clip_own_selection(cbd
)
468 * Also want to check somehow that we are reading from the keyboard rather
469 * than a mapping etc.
471 if (!cbd
->owned
&& cbd
->available
)
473 cbd
->owned
= (clip_gen_own_selection(cbd
) == OK
);
475 if (cbd
== &clip_star
)
477 /* May have to show a different kind of highlighting for the
478 * selected area. There is no specific redraw command for this,
479 * just redraw all windows on the current buffer. */
481 && (get_real_state() == VISUAL
482 || get_real_state() == SELECTMODE
)
484 && hl_attr(HLF_V
) != hl_attr(HLF_VNC
))
485 redraw_curbuf_later(INVERTED_ALL
);
492 clip_lose_selection(cbd
)
496 int was_owned
= cbd
->owned
;
498 int visual_selection
= (cbd
== &clip_star
);
500 clip_free_selection(cbd
);
502 if (visual_selection
)
503 clip_clear_selection();
504 clip_gen_lose_selection(cbd
);
506 if (visual_selection
)
508 /* May have to show a different kind of highlighting for the selected
509 * area. There is no specific redraw command for this, just redraw all
510 * windows on the current buffer. */
512 && (get_real_state() == VISUAL
513 || get_real_state() == SELECTMODE
)
515 && hl_attr(HLF_V
) != hl_attr(HLF_VNC
))
517 update_curbuf(INVERTED_ALL
);
523 gui_update_cursor(TRUE
, FALSE
);
531 clip_copy_selection()
533 if (VIsual_active
&& (State
& NORMAL
) && clip_star
.available
)
535 if (clip_isautosel())
536 clip_update_selection();
537 clip_free_selection(&clip_star
);
538 clip_own_selection(&clip_star
);
540 clip_get_selection(&clip_star
);
541 clip_gen_set_selection(&clip_star
);
546 * Called when Visual mode is ended: update the selection.
551 if (clip_isautosel())
552 clip_copy_selection();
556 * Return TRUE if automatic selection of Visual area is desired.
563 gui
.in_use
? (vim_strchr(p_go
, GO_ASEL
) != NULL
) :
570 * Stuff for general mouse selection, without using Visual mode.
573 static int clip_compare_pos
__ARGS((int row1
, int col1
, int row2
, int col2
));
574 static void clip_invert_area
__ARGS((int, int, int, int, int how
));
575 static void clip_invert_rectangle
__ARGS((int row
, int col
, int height
, int width
, int invert
));
576 static void clip_get_word_boundaries
__ARGS((VimClipboard
*, int, int));
577 static int clip_get_line_end
__ARGS((int));
578 static void clip_update_modeless_selection
__ARGS((VimClipboard
*, int, int,
581 /* flags for clip_invert_area() */
584 #define CLIP_TOGGLE 3
587 * Start, continue or end a modeless selection. Used when editing the
588 * command-line and in the cmdline window.
591 clip_modeless(button
, is_click
, is_drag
)
598 repeat
= ((clip_star
.mode
== SELECT_MODE_CHAR
599 || clip_star
.mode
== SELECT_MODE_LINE
)
600 && (mod_mask
& MOD_MASK_2CLICK
))
601 || (clip_star
.mode
== SELECT_MODE_WORD
602 && (mod_mask
& MOD_MASK_3CLICK
));
603 if (is_click
&& button
== MOUSE_RIGHT
)
605 /* Right mouse button: If there was no selection, start one.
606 * Otherwise extend the existing selection. */
607 if (clip_star
.state
== SELECT_CLEARED
)
608 clip_start_selection(mouse_col
, mouse_row
, FALSE
);
609 clip_process_selection(button
, mouse_col
, mouse_row
, repeat
);
612 clip_start_selection(mouse_col
, mouse_row
, repeat
);
615 /* Don't try extending a selection if there isn't one. Happens when
616 * button-down is in the cmdline and them moving mouse upwards. */
617 if (clip_star
.state
!= SELECT_CLEARED
)
618 clip_process_selection(button
, mouse_col
, mouse_row
, repeat
);
621 clip_process_selection(MOUSE_RELEASE
, mouse_col
, mouse_row
, FALSE
);
625 * Compare two screen positions ala strcmp()
628 clip_compare_pos(row1
, col1
, row2
, col2
)
634 if (row1
> row2
) return(1);
635 if (row1
< row2
) return(-1);
636 if (col1
> col2
) return(1);
637 if (col1
< col2
) return(-1);
642 * Start the selection
645 clip_start_selection(col
, row
, repeated_click
)
650 VimClipboard
*cb
= &clip_star
;
652 if (cb
->state
== SELECT_DONE
)
653 clip_clear_selection();
655 row
= check_row(row
);
656 col
= check_col(col
);
658 col
= mb_fix_col(col
, row
);
661 cb
->start
.lnum
= row
;
664 cb
->origin_row
= (short_u
)cb
->start
.lnum
;
665 cb
->state
= SELECT_IN_PROGRESS
;
669 if (++cb
->mode
> SELECT_MODE_LINE
)
670 cb
->mode
= SELECT_MODE_CHAR
;
673 cb
->mode
= SELECT_MODE_CHAR
;
676 /* clear the cursor until the selection is made */
683 case SELECT_MODE_CHAR
:
684 cb
->origin_start_col
= cb
->start
.col
;
685 cb
->word_end_col
= clip_get_line_end((int)cb
->start
.lnum
);
688 case SELECT_MODE_WORD
:
689 clip_get_word_boundaries(cb
, (int)cb
->start
.lnum
, cb
->start
.col
);
690 cb
->origin_start_col
= cb
->word_start_col
;
691 cb
->origin_end_col
= cb
->word_end_col
;
693 clip_invert_area((int)cb
->start
.lnum
, cb
->word_start_col
,
694 (int)cb
->end
.lnum
, cb
->word_end_col
, CLIP_SET
);
695 cb
->start
.col
= cb
->word_start_col
;
696 cb
->end
.col
= cb
->word_end_col
;
699 case SELECT_MODE_LINE
:
700 clip_invert_area((int)cb
->start
.lnum
, 0, (int)cb
->start
.lnum
,
701 (int)Columns
, CLIP_SET
);
703 cb
->end
.col
= Columns
;
707 cb
->prev
= cb
->start
;
709 #ifdef DEBUG_SELECTION
710 printf("Selection started at (%u,%u)\n", cb
->start
.lnum
, cb
->start
.col
);
715 * Continue processing the selection
718 clip_process_selection(button
, col
, row
, repeated_click
)
722 int_u repeated_click
;
724 VimClipboard
*cb
= &clip_star
;
726 int slen
= 1; /* cursor shape width */
728 if (button
== MOUSE_RELEASE
)
730 /* Check to make sure we have something selected */
731 if (cb
->start
.lnum
== cb
->end
.lnum
&& cb
->start
.col
== cb
->end
.col
)
735 gui_update_cursor(FALSE
, FALSE
);
737 cb
->state
= SELECT_CLEARED
;
741 #ifdef DEBUG_SELECTION
742 printf("Selection ended: (%u,%u) to (%u,%u)\n", cb
->start
.lnum
,
743 cb
->start
.col
, cb
->end
.lnum
, cb
->end
.col
);
748 gui
.in_use
? (vim_strchr(p_go
, GO_ASELML
) != NULL
) :
751 clip_copy_modeless_selection(FALSE
);
754 gui_update_cursor(FALSE
, FALSE
);
757 cb
->state
= SELECT_DONE
;
761 row
= check_row(row
);
762 col
= check_col(col
);
764 col
= mb_fix_col(col
, row
);
767 if (col
== (int)cb
->prev
.col
&& row
== cb
->prev
.lnum
&& !repeated_click
)
771 * When extending the selection with the right mouse button, swap the
772 * start and end if the position is before half the selection
774 if (cb
->state
== SELECT_DONE
&& button
== MOUSE_RIGHT
)
777 * If the click is before the start, or the click is inside the
778 * selection and the start is the closest side, set the origin to the
779 * end of the selection.
781 if (clip_compare_pos(row
, col
, (int)cb
->start
.lnum
, cb
->start
.col
) < 0
782 || (clip_compare_pos(row
, col
,
783 (int)cb
->end
.lnum
, cb
->end
.col
) < 0
784 && (((cb
->start
.lnum
== cb
->end
.lnum
785 && cb
->end
.col
- col
> col
- cb
->start
.col
))
786 || ((diff
= (cb
->end
.lnum
- row
) -
787 (row
- cb
->start
.lnum
)) > 0
788 || (diff
== 0 && col
< (int)(cb
->start
.col
+
789 cb
->end
.col
) / 2)))))
791 cb
->origin_row
= (short_u
)cb
->end
.lnum
;
792 cb
->origin_start_col
= cb
->end
.col
- 1;
793 cb
->origin_end_col
= cb
->end
.col
;
797 cb
->origin_row
= (short_u
)cb
->start
.lnum
;
798 cb
->origin_start_col
= cb
->start
.col
;
799 cb
->origin_end_col
= cb
->start
.col
;
801 if (cb
->mode
== SELECT_MODE_WORD
&& !repeated_click
)
802 cb
->mode
= SELECT_MODE_CHAR
;
805 /* set state, for when using the right mouse button */
806 cb
->state
= SELECT_IN_PROGRESS
;
808 #ifdef DEBUG_SELECTION
809 printf("Selection extending to (%d,%d)\n", row
, col
);
812 if (repeated_click
&& ++cb
->mode
> SELECT_MODE_LINE
)
813 cb
->mode
= SELECT_MODE_CHAR
;
817 case SELECT_MODE_CHAR
:
818 /* If we're on a different line, find where the line ends */
819 if (row
!= cb
->prev
.lnum
)
820 cb
->word_end_col
= clip_get_line_end(row
);
822 /* See if we are before or after the origin of the selection */
823 if (clip_compare_pos(row
, col
, cb
->origin_row
,
824 cb
->origin_start_col
) >= 0)
826 if (col
>= (int)cb
->word_end_col
)
827 clip_update_modeless_selection(cb
, cb
->origin_row
,
828 cb
->origin_start_col
, row
, (int)Columns
);
832 if (has_mbyte
&& mb_lefthalve(row
, col
))
835 clip_update_modeless_selection(cb
, cb
->origin_row
,
836 cb
->origin_start_col
, row
, col
+ slen
);
843 && mb_lefthalve(cb
->origin_row
, cb
->origin_start_col
))
846 if (col
>= (int)cb
->word_end_col
)
847 clip_update_modeless_selection(cb
, row
, cb
->word_end_col
,
848 cb
->origin_row
, cb
->origin_start_col
+ slen
);
850 clip_update_modeless_selection(cb
, row
, col
,
851 cb
->origin_row
, cb
->origin_start_col
+ slen
);
855 case SELECT_MODE_WORD
:
856 /* If we are still within the same word, do nothing */
857 if (row
== cb
->prev
.lnum
&& col
>= (int)cb
->word_start_col
858 && col
< (int)cb
->word_end_col
&& !repeated_click
)
861 /* Get new word boundaries */
862 clip_get_word_boundaries(cb
, row
, col
);
864 /* Handle being after the origin point of selection */
865 if (clip_compare_pos(row
, col
, cb
->origin_row
,
866 cb
->origin_start_col
) >= 0)
867 clip_update_modeless_selection(cb
, cb
->origin_row
,
868 cb
->origin_start_col
, row
, cb
->word_end_col
);
870 clip_update_modeless_selection(cb
, row
, cb
->word_start_col
,
871 cb
->origin_row
, cb
->origin_end_col
);
874 case SELECT_MODE_LINE
:
875 if (row
== cb
->prev
.lnum
&& !repeated_click
)
878 if (clip_compare_pos(row
, col
, cb
->origin_row
,
879 cb
->origin_start_col
) >= 0)
880 clip_update_modeless_selection(cb
, cb
->origin_row
, 0, row
,
883 clip_update_modeless_selection(cb
, row
, 0, cb
->origin_row
,
891 #ifdef DEBUG_SELECTION
892 printf("Selection is: (%u,%u) to (%u,%u)\n", cb
->start
.lnum
,
893 cb
->start
.col
, cb
->end
.lnum
, cb
->end
.col
);
899 * Called after an Expose event to redraw the selection
902 clip_redraw_selection(x
, y
, w
, h
)
908 VimClipboard
*cb
= &clip_star
;
909 int row1
, col1
, row2
, col2
;
914 if (cb
->state
== SELECT_CLEARED
)
917 row1
= check_row(Y_2_ROW(y
));
918 col1
= check_col(X_2_COL(x
));
919 row2
= check_row(Y_2_ROW(y
+ h
- 1));
920 col2
= check_col(X_2_COL(x
+ w
- 1));
922 /* Limit the rows that need to be re-drawn */
923 if (cb
->start
.lnum
> row1
)
924 row1
= cb
->start
.lnum
;
925 if (cb
->end
.lnum
< row2
)
928 /* Look at each row that might need to be re-drawn */
929 for (row
= row1
; row
<= row2
; row
++)
931 /* For the first selection row, use the starting selection column */
932 if (row
== cb
->start
.lnum
)
933 start
= cb
->start
.col
;
937 /* For the last selection row, use the ending selection column */
938 if (row
== cb
->end
.lnum
)
950 gui_mch_invert_rectangle(row
, start
, 1, end
- start
);
955 # if defined(FEAT_GUI) || defined(PROTO)
957 * Redraw part of the selection if character at "row,col" is inside of it.
958 * Only used for the GUI.
961 clip_may_redraw_selection(row
, col
, len
)
968 if (clip_star
.state
!= SELECT_CLEARED
969 && row
>= clip_star
.start
.lnum
970 && row
<= clip_star
.end
.lnum
)
972 if (row
== clip_star
.start
.lnum
&& start
< (int)clip_star
.start
.col
)
973 start
= clip_star
.start
.col
;
974 if (row
== clip_star
.end
.lnum
&& end
> (int)clip_star
.end
.col
)
975 end
= clip_star
.end
.col
;
977 clip_invert_area(row
, start
, row
, end
, 0);
983 * Called from outside to clear selected region from the display
986 clip_clear_selection()
988 VimClipboard
*cb
= &clip_star
;
990 if (cb
->state
== SELECT_CLEARED
)
993 clip_invert_area((int)cb
->start
.lnum
, cb
->start
.col
, (int)cb
->end
.lnum
,
994 cb
->end
.col
, CLIP_CLEAR
);
995 cb
->state
= SELECT_CLEARED
;
999 * Clear the selection if any lines from "row1" to "row2" are inside of it.
1002 clip_may_clear_selection(row1
, row2
)
1005 if (clip_star
.state
== SELECT_DONE
1006 && row2
>= clip_star
.start
.lnum
1007 && row1
<= clip_star
.end
.lnum
)
1008 clip_clear_selection();
1012 * Called before the screen is scrolled up or down. Adjusts the line numbers
1013 * of the selection. Call with big number when clearing the screen.
1016 clip_scroll_selection(rows
)
1017 int rows
; /* negative for scroll down */
1021 if (clip_star
.state
== SELECT_CLEARED
)
1024 lnum
= clip_star
.start
.lnum
- rows
;
1026 clip_star
.start
.lnum
= 0;
1027 else if (lnum
>= screen_Rows
) /* scrolled off of the screen */
1028 clip_star
.state
= SELECT_CLEARED
;
1030 clip_star
.start
.lnum
= lnum
;
1032 lnum
= clip_star
.end
.lnum
- rows
;
1033 if (lnum
< 0) /* scrolled off of the screen */
1034 clip_star
.state
= SELECT_CLEARED
;
1035 else if (lnum
>= screen_Rows
)
1036 clip_star
.end
.lnum
= screen_Rows
- 1;
1038 clip_star
.end
.lnum
= lnum
;
1042 * Invert a region of the display between a starting and ending row and column
1044 * CLIP_CLEAR: undo inversion
1045 * CLIP_SET: set inversion
1046 * CLIP_TOGGLE: set inversion if pos1 < pos2, undo inversion otherwise.
1047 * 0: invert (GUI only).
1050 clip_invert_area(row1
, col1
, row2
, col2
, how
)
1059 if (how
== CLIP_SET
)
1062 /* Swap the from and to positions so the from is always before */
1063 if (clip_compare_pos(row1
, col1
, row2
, col2
) > 0)
1065 int tmp_row
, tmp_col
;
1074 else if (how
== CLIP_TOGGLE
)
1077 /* If all on the same line, do it the easy way */
1080 clip_invert_rectangle(row1
, col1
, 1, col2
- col1
, invert
);
1084 /* Handle a piece of the first line */
1087 clip_invert_rectangle(row1
, col1
, 1, (int)Columns
- col1
, invert
);
1091 /* Handle a piece of the last line */
1092 if (col2
< Columns
- 1)
1094 clip_invert_rectangle(row2
, 0, 1, col2
, invert
);
1098 /* Handle the rectangle thats left */
1100 clip_invert_rectangle(row1
, 0, row2
- row1
+ 1, (int)Columns
,
1106 * Invert or un-invert a rectangle of the screen.
1107 * "invert" is true if the result is inverted.
1110 clip_invert_rectangle(row
, col
, height
, width
, invert
)
1119 gui_mch_invert_rectangle(row
, col
, height
, width
);
1122 screen_draw_rectangle(row
, col
, height
, width
, invert
);
1126 * Copy the currently selected area into the '*' register so it will be
1127 * available for pasting.
1128 * When "both" is TRUE also copy to the '+' register.
1132 clip_copy_modeless_selection(both
)
1141 int add_newline_flag
= FALSE
;
1146 int row1
= clip_star
.start
.lnum
;
1147 int col1
= clip_star
.start
.col
;
1148 int row2
= clip_star
.end
.lnum
;
1149 int col2
= clip_star
.end
.col
;
1151 /* Can't use ScreenLines unless initialized */
1152 if (ScreenLines
== NULL
)
1156 * Make sure row1 <= row2, and if row1 == row2 that col1 <= col2.
1160 row
= row1
; row1
= row2
; row2
= row
;
1161 row
= col1
; col1
= col2
; col2
= row
;
1163 else if (row1
== row2
&& col1
> col2
)
1165 row
= col1
; col1
= col2
; col2
= row
;
1168 /* correct starting point for being on right halve of double-wide char */
1169 p
= ScreenLines
+ LineOffset
[row1
];
1171 col1
-= (*mb_head_off
)(p
, p
+ col1
);
1172 else if (enc_utf8
&& p
[col1
] == 0)
1176 /* Create a temporary buffer for storing the text */
1177 len
= (row2
- row1
+ 1) * Columns
+ 1;
1180 len
*= 2; /* max. 2 bytes per display cell */
1184 buffer
= lalloc((long_u
)len
, TRUE
);
1185 if (buffer
== NULL
) /* out of memory */
1188 /* Process each row in the selection */
1189 for (bufp
= buffer
, row
= row1
; row
<= row2
; row
++)
1201 line_end_col
= clip_get_line_end(row
);
1203 /* See if we need to nuke some trailing whitespace */
1204 if (end_col
>= Columns
&& (row
< row2
|| end_col
> line_end_col
))
1206 /* Get rid of trailing whitespace */
1207 end_col
= line_end_col
;
1208 if (end_col
< start_col
)
1209 end_col
= start_col
;
1211 /* If the last line extended to the end, add an extra newline */
1213 add_newline_flag
= TRUE
;
1216 /* If after the first row, we need to always add a newline */
1217 if (row
> row1
&& !LineWraps
[row
- 1])
1220 if (row
< screen_Rows
&& end_col
<= screen_Columns
)
1227 p
= ScreenLines
+ LineOffset
[row
];
1228 for (i
= start_col
; i
< end_col
; ++i
)
1229 if (enc_dbcs
== DBCS_JPNU
&& p
[i
] == 0x8e)
1231 /* single-width double-byte char */
1233 *bufp
++ = ScreenLines2
[LineOffset
[row
] + i
];
1238 if (MB_BYTE2LEN(p
[i
]) == 2)
1248 off
= LineOffset
[row
];
1249 for (i
= start_col
; i
< end_col
; ++i
)
1251 /* The base character is either in ScreenLinesUC[] or
1253 if (ScreenLinesUC
[off
+ i
] == 0)
1254 *bufp
++ = ScreenLines
[off
+ i
];
1257 bufp
+= utf_char2bytes(ScreenLinesUC
[off
+ i
], bufp
);
1258 for (ci
= 0; ci
< Screen_mco
; ++ci
)
1260 /* Add a composing character. */
1261 if (ScreenLinesC
[ci
][off
+ i
] == 0)
1263 bufp
+= utf_char2bytes(ScreenLinesC
[ci
][off
+ i
],
1267 /* Skip right halve of double-wide character. */
1268 if (ScreenLines
[off
+ i
+ 1] == 0)
1275 STRNCPY(bufp
, ScreenLines
+ LineOffset
[row
] + start_col
,
1276 end_col
- start_col
);
1277 bufp
+= end_col
- start_col
;
1282 /* Add a newline at the end if the selection ended there */
1283 if (add_newline_flag
)
1286 /* First cleanup any old selection and become the owner. */
1287 clip_free_selection(&clip_star
);
1288 clip_own_selection(&clip_star
);
1290 /* Yank the text into the '*' register. */
1291 clip_yank_selection(MCHAR
, buffer
, (long)(bufp
- buffer
), &clip_star
);
1293 /* Make the register contents available to the outside world. */
1294 clip_gen_set_selection(&clip_star
);
1299 /* Do the same for the '+' register. */
1300 clip_free_selection(&clip_plus
);
1301 clip_own_selection(&clip_plus
);
1302 clip_yank_selection(MCHAR
, buffer
, (long)(bufp
- buffer
), &clip_plus
);
1303 clip_gen_set_selection(&clip_plus
);
1310 * Find the starting and ending positions of the word at the given row and
1311 * column. Only white-separated words are recognized here.
1313 #define CHAR_CLASS(c) (c <= ' ' ? ' ' : vim_iswordc(c))
1316 clip_get_word_boundaries(cb
, row
, col
)
1328 if (row
>= screen_Rows
|| col
>= screen_Columns
|| ScreenLines
== NULL
)
1331 p
= ScreenLines
+ LineOffset
[row
];
1333 /* Correct for starting in the right halve of a double-wide char */
1335 col
-= dbcs_screen_head_off(p
, p
+ col
);
1336 else if (enc_utf8
&& p
[col
] == 0)
1339 start_class
= CHAR_CLASS(p
[col
]);
1342 for ( ; temp_col
> 0; temp_col
--)
1345 && (mboff
= dbcs_screen_head_off(p
, p
+ temp_col
- 1)) > 0)
1349 if (CHAR_CLASS(p
[temp_col
- 1]) != start_class
1351 && !(enc_utf8
&& p
[temp_col
- 1] == 0)
1355 cb
->word_start_col
= temp_col
;
1358 for ( ; temp_col
< screen_Columns
; temp_col
++)
1360 if (enc_dbcs
!= 0 && dbcs_ptr2cells(p
+ temp_col
) == 2)
1364 if (CHAR_CLASS(p
[temp_col
]) != start_class
1366 && !(enc_utf8
&& p
[temp_col
] == 0)
1370 cb
->word_end_col
= temp_col
;
1374 * Find the column position for the last non-whitespace character on the given
1378 clip_get_line_end(row
)
1383 if (row
>= screen_Rows
|| ScreenLines
== NULL
)
1385 for (i
= screen_Columns
; i
> 0; i
--)
1386 if (ScreenLines
[LineOffset
[row
] + i
- 1] != ' ')
1392 * Update the currently selected region by adding and/or subtracting from the
1393 * beginning or end and inverting the changed area(s).
1396 clip_update_modeless_selection(cb
, row1
, col1
, row2
, col2
)
1403 /* See if we changed at the beginning of the selection */
1404 if (row1
!= cb
->start
.lnum
|| col1
!= (int)cb
->start
.col
)
1406 clip_invert_area(row1
, col1
, (int)cb
->start
.lnum
, cb
->start
.col
,
1408 cb
->start
.lnum
= row1
;
1409 cb
->start
.col
= col1
;
1412 /* See if we changed at the end of the selection */
1413 if (row2
!= cb
->end
.lnum
|| col2
!= (int)cb
->end
.col
)
1415 clip_invert_area((int)cb
->end
.lnum
, cb
->end
.col
, row2
, col2
,
1417 cb
->end
.lnum
= row2
;
1423 clip_gen_own_selection(cbd
)
1426 #ifdef FEAT_XCLIPBOARD
1429 return clip_mch_own_selection(cbd
);
1432 return clip_xterm_own_selection(cbd
);
1434 return clip_mch_own_selection(cbd
);
1439 clip_gen_lose_selection(cbd
)
1442 #ifdef FEAT_XCLIPBOARD
1445 clip_mch_lose_selection(cbd
);
1448 clip_xterm_lose_selection(cbd
);
1450 clip_mch_lose_selection(cbd
);
1455 clip_gen_set_selection(cbd
)
1458 #ifdef FEAT_XCLIPBOARD
1461 clip_mch_set_selection(cbd
);
1464 clip_xterm_set_selection(cbd
);
1466 clip_mch_set_selection(cbd
);
1471 clip_gen_request_selection(cbd
)
1474 #ifdef FEAT_XCLIPBOARD
1477 clip_mch_request_selection(cbd
);
1480 clip_xterm_request_selection(cbd
);
1482 clip_mch_request_selection(cbd
);
1486 #endif /* FEAT_CLIPBOARD */
1488 /*****************************************************************************
1489 * Functions that handle the input buffer.
1490 * This is used for any GUI version, and the unix terminal version.
1492 * For Unix, the input characters are buffered to be able to check for a
1493 * CTRL-C. This should be done with signals, but I don't know how to do that
1494 * in a portable way for a tty in RAW mode.
1496 * For the client-server code in the console the received keys are put in the
1500 #if defined(USE_INPUT_BUF) || defined(PROTO)
1503 * Internal typeahead buffer. Includes extra space for long key code
1504 * descriptions which would otherwise overflow. The buffer is considered full
1505 * when only this extra space (or part of it) remains.
1507 #if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG) \
1508 || defined(FEAT_CLIENTSERVER)
1510 * Sun WorkShop and NetBeans stuff debugger commands into the input buffer.
1511 * This requires a larger buffer...
1512 * (Madsen) Go with this for remote input as well ...
1514 # define INBUFLEN 4096
1516 # define INBUFLEN 250
1519 static char_u inbuf
[INBUFLEN
+ MAX_KEY_CODE_LEN
];
1520 static int inbufcount
= 0; /* number of chars in inbuf[] */
1523 * vim_is_input_buf_full(), vim_is_input_buf_empty(), add_to_input_buf(), and
1524 * trash_input_buf() are functions for manipulating the input buffer. These
1525 * are used by the gui_* calls when a GUI is used to handle keyboard input.
1529 vim_is_input_buf_full()
1531 return (inbufcount
>= INBUFLEN
);
1535 vim_is_input_buf_empty()
1537 return (inbufcount
== 0);
1540 #if defined(FEAT_OLE) || defined(PROTO)
1542 vim_free_in_input_buf()
1544 return (INBUFLEN
- inbufcount
);
1548 #if defined(FEAT_GUI_GTK) || defined(PROTO)
1550 vim_used_in_input_buf()
1556 #if defined(FEAT_EVAL) || defined(FEAT_EX_EXTRA) || defined(PROTO)
1558 * Return the current contents of the input buffer and make it empty.
1559 * The returned pointer must be passed to set_input_buf() later.
1566 /* We use a growarray to store the data pointer and the length. */
1567 gap
= (garray_T
*)alloc((unsigned)sizeof(garray_T
));
1570 /* Add one to avoid a zero size. */
1571 gap
->ga_data
= alloc((unsigned)inbufcount
+ 1);
1572 if (gap
->ga_data
!= NULL
)
1573 mch_memmove(gap
->ga_data
, inbuf
, (size_t)inbufcount
);
1574 gap
->ga_len
= inbufcount
;
1577 return (char_u
*)gap
;
1581 * Restore the input buffer with a pointer returned from get_input_buf().
1582 * The allocated memory is freed, this only works once!
1588 garray_T
*gap
= (garray_T
*)p
;
1592 if (gap
->ga_data
!= NULL
)
1594 mch_memmove(inbuf
, gap
->ga_data
, gap
->ga_len
);
1595 inbufcount
= gap
->ga_len
;
1596 vim_free(gap
->ga_data
);
1603 #if defined(FEAT_GUI) \
1604 || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE) \
1605 || defined(FEAT_XCLIPBOARD) || defined(VMS) \
1606 || defined(FEAT_SNIFF) || defined(FEAT_CLIENTSERVER) \
1609 * Add the given bytes to the input buffer
1610 * Special keys start with CSI. A real CSI must have been translated to
1611 * CSI KS_EXTRA KE_CSI. K_SPECIAL doesn't require translation.
1614 add_to_input_buf(s
, len
)
1618 if (inbufcount
+ len
> INBUFLEN
+ MAX_KEY_CODE_LEN
)
1619 return; /* Shouldn't ever happen! */
1621 #ifdef FEAT_HANGULIN
1622 if ((State
& (INSERT
|CMDLINE
)) && hangul_input_state_get())
1623 if ((len
= hangul_input_process(s
, len
)) == 0)
1628 inbuf
[inbufcount
++] = *s
++;
1632 #if ((defined(FEAT_XIM) || defined(FEAT_DND)) && defined(FEAT_GUI_GTK)) \
1633 || defined(FEAT_GUI_MSWIN) \
1634 || defined(FEAT_GUI_MAC) \
1635 || (defined(FEAT_MBYTE) && defined(FEAT_MBYTE_IME)) \
1636 || (defined(FEAT_GUI) && (!defined(USE_ON_FLY_SCROLL) \
1637 || defined(FEAT_MENU))) \
1640 * Add "str[len]" to the input buffer while escaping CSI bytes.
1643 add_to_input_buf_csi(char_u
*str
, int len
)
1648 for (i
= 0; i
< len
; ++i
)
1650 add_to_input_buf(str
+ i
, 1);
1653 /* Turn CSI into K_CSI. */
1655 buf
[1] = (int)KE_CSI
;
1656 add_to_input_buf(buf
, 2);
1662 #if defined(FEAT_HANGULIN) || defined(PROTO)
1664 push_raw_key (s
, len
)
1669 inbuf
[inbufcount
++] = *s
++;
1673 #if defined(FEAT_GUI) || defined(FEAT_EVAL) || defined(FEAT_EX_EXTRA) \
1675 /* Remove everything from the input buffer. Called when ^C is found */
1684 * Read as much data from the input buffer as possible up to maxlen, and store
1686 * Note: this function used to be Read() in unix.c
1689 read_from_input_buf(buf
, maxlen
)
1693 if (inbufcount
== 0) /* if the buffer is empty, fill it */
1694 fill_input_buf(TRUE
);
1695 if (maxlen
> inbufcount
)
1696 maxlen
= inbufcount
;
1697 mch_memmove(buf
, inbuf
, (size_t)maxlen
);
1698 inbufcount
-= maxlen
;
1700 mch_memmove(inbuf
, inbuf
+ maxlen
, (size_t)inbufcount
);
1706 fill_input_buf(exit_on_error
)
1709 #if defined(UNIX) || defined(OS2) || defined(VMS) || defined(MACOS_X_UNIX)
1712 static int did_read_something
= FALSE
;
1714 static char_u
*rest
= NULL
; /* unconverted rest of previous read */
1715 static int restlen
= 0;
1722 # ifdef NO_CONSOLE_INPUT
1723 /* Don't use the GUI input when the window hasn't been opened yet.
1724 * We get here from ui_inchar() when we should try reading from stdin. */
1725 && !no_console_input()
1733 #if defined(UNIX) || defined(OS2) || defined(VMS) || defined(MACOS_X_UNIX)
1734 if (vim_is_input_buf_full())
1737 * Fill_input_buf() is only called when we really need a character.
1738 * If we can't get any, but there is some in the buffer, just return.
1739 * If we can't get any, and there isn't any in the buffer, we give up and
1744 * On the BeBox version (for now), all input is secretly performed within
1745 * beos_select() which is called from RealWaitForChar().
1747 while (!vim_is_input_buf_full() && RealWaitForChar(read_cmd_fd
, 0, NULL
))
1754 if (sniff_request_waiting
)
1756 add_to_input_buf((char_u
*)"\233sniff",6); /* results in K_SNIFF */
1757 sniff_request_waiting
= 0;
1758 want_sniff_request
= 0;
1766 /* Use remainder of previous call, starts with an invalid character
1767 * that may become valid when reading more. */
1768 if (restlen
> INBUFLEN
- inbufcount
)
1769 unconverted
= INBUFLEN
- inbufcount
;
1771 unconverted
= restlen
;
1772 mch_memmove(inbuf
+ inbufcount
, rest
, unconverted
);
1773 if (unconverted
== restlen
)
1780 restlen
-= unconverted
;
1781 mch_memmove(rest
, rest
+ unconverted
, restlen
);
1783 inbufcount
+= unconverted
;
1789 len
= 0; /* to avoid gcc warning */
1790 for (try = 0; try < 100; ++try)
1795 len
= read(read_cmd_fd
,
1797 (char *)inbuf
+ inbufcount
, (size_t)((INBUFLEN
- inbufcount
)
1799 / input_conv
.vc_factor
1803 ) /* avoid syntax highlight error */
1806 if (len
> 0 || got_int
)
1809 * If reading stdin results in an error, continue reading stderr.
1810 * This helps when using "foo | xargs vim".
1812 if (!did_read_something
&& !isatty(read_cmd_fd
) && read_cmd_fd
== 0)
1816 /* We probably set the wrong file descriptor to raw mode. Switch
1817 * back to cooked mode, use another descriptor and set the mode to
1819 settmode(TMODE_COOK
);
1821 /* Use stderr for stdin, also works for shell commands. */
1825 read_cmd_fd
= 2; /* read from stderr instead of stdin */
1833 if (len
<= 0 && !got_int
)
1836 did_read_something
= TRUE
;
1839 /* Interrupted, pretend a CTRL-C was typed. */
1847 * May perform conversion on the input characters.
1848 * Include the unconverted rest of the previous call.
1849 * If there is an incomplete char at the end it is kept for the next
1850 * time, reading more bytes should make conversion possible.
1851 * Don't do this in the unlikely event that the input buffer is too
1852 * small ("rest" still contains more bytes).
1854 if (input_conv
.vc_type
!= CONV_NONE
)
1856 inbufcount
-= unconverted
;
1857 len
= convert_input_safe(inbuf
+ inbufcount
,
1858 len
+ unconverted
, INBUFLEN
- inbufcount
,
1859 rest
== NULL
? &rest
: NULL
, &restlen
);
1865 * if a CTRL-C was typed, remove it from the buffer and set got_int
1867 if (inbuf
[inbufcount
] == 3 && ctrl_c_interrupts
)
1869 /* remove everything typed before the CTRL-C */
1870 mch_memmove(inbuf
, inbuf
+ inbufcount
, (size_t)(len
+ 1));
1877 #endif /* UNIX or OS2 or VMS*/
1879 #endif /* defined(UNIX) || defined(FEAT_GUI) || defined(OS2) || defined(VMS) */
1882 * Exit because of an input read error.
1887 if (silent_mode
) /* Normal way to exit for "ex -s" */
1889 STRCPY(IObuff
, _("Vim: Error reading input, exiting...\n"));
1893 #if defined(CURSOR_SHAPE) || defined(PROTO)
1895 * May update the shape of the cursor.
1902 gui_update_cursor_later();
1905 term_cursor_shape();
1907 # ifdef MCH_CURSOR_SHAPE
1908 mch_update_cursor();
1913 #if defined(FEAT_CLIPBOARD) || defined(FEAT_GUI) || defined(FEAT_RIGHTLEFT) \
1914 || defined(FEAT_MBYTE) || defined(PROTO)
1916 * Check bounds for column number
1924 if (col
>= (int)screen_Columns
)
1925 return (int)screen_Columns
- 1;
1930 * Check bounds for row number
1938 if (row
>= (int)screen_Rows
)
1939 return (int)screen_Rows
- 1;
1945 * Stuff for the X clipboard. Shared between VMS and Unix.
1948 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) || defined(PROTO)
1949 # include <X11/Xatom.h>
1950 # include <X11/Intrinsic.h>
1953 * Open the application context (if it hasn't been opened yet).
1954 * Used for Motif and Athena GUI and the xterm clipboard.
1959 if (app_context
== NULL
)
1961 XtToolkitInitialize();
1962 app_context
= XtCreateApplicationContext();
1966 static Atom vim_atom
; /* Vim's own special selection format */
1968 static Atom vimenc_atom
; /* Vim's extended selection format */
1970 static Atom compound_text_atom
;
1971 static Atom text_atom
;
1972 static Atom targets_atom
;
1975 x11_setup_atoms(dpy
)
1978 vim_atom
= XInternAtom(dpy
, VIM_ATOM_NAME
, False
);
1980 vimenc_atom
= XInternAtom(dpy
, VIMENC_ATOM_NAME
,False
);
1982 compound_text_atom
= XInternAtom(dpy
, "COMPOUND_TEXT", False
);
1983 text_atom
= XInternAtom(dpy
, "TEXT", False
);
1984 targets_atom
= XInternAtom(dpy
, "TARGETS", False
);
1985 clip_star
.sel_atom
= XA_PRIMARY
;
1986 clip_plus
.sel_atom
= XInternAtom(dpy
, "CLIPBOARD", False
);
1990 * X Selection stuff, for cutting and pasting text to other windows.
1993 static void clip_x11_request_selection_cb
__ARGS((Widget
, XtPointer
, Atom
*, Atom
*, XtPointer
, long_u
*, int *));
1997 clip_x11_request_selection_cb(w
, success
, sel_atom
, type
, value
, length
,
2010 char **text_list
= NULL
;
2013 char_u
*tmpbuf
= NULL
;
2016 if (*sel_atom
== clip_plus
.sel_atom
)
2021 if (value
== NULL
|| *length
== 0)
2023 clip_free_selection(cbd
); /* nothing received, clear register */
2024 *(int *)success
= FALSE
;
2027 motion_type
= MCHAR
;
2028 p
= (char_u
*)value
;
2030 if (*type
== vim_atom
)
2037 else if (*type
== vimenc_atom
)
2050 /* If the encoding of the text is different from 'encoding', attempt
2052 conv
.vc_type
= CONV_NONE
;
2053 convert_setup(&conv
, enc
, p_enc
);
2054 if (conv
.vc_type
!= CONV_NONE
)
2056 convlen
= len
; /* Need to use an int here. */
2057 tmpbuf
= string_convert(&conv
, p
, &convlen
);
2061 convert_setup(&conv
, NULL
, NULL
);
2066 else if (*type
== compound_text_atom
|| (
2070 *type
== text_atom
))
2072 XTextProperty text_prop
;
2076 text_prop
.value
= (unsigned char *)value
;
2077 text_prop
.encoding
= *type
;
2078 text_prop
.format
= *format
;
2079 text_prop
.nitems
= len
;
2080 status
= XmbTextPropertyToTextList(X_DISPLAY
, &text_prop
,
2081 &text_list
, &n_text
);
2082 if (status
!= Success
|| n_text
< 1)
2084 *(int *)success
= FALSE
;
2087 p
= (char_u
*)text_list
[0];
2090 clip_yank_selection(motion_type
, p
, (long)len
, cbd
);
2092 if (text_list
!= NULL
)
2093 XFreeStringList(text_list
);
2097 XtFree((char *)value
);
2098 *(int *)success
= TRUE
;
2102 clip_x11_request_selection(myShell
, dpy
, cbd
)
2114 int timed_out
= FALSE
;
2127 case 0: type
= vimenc_atom
; break;
2129 case 1: type
= vim_atom
; break;
2130 case 2: type
= compound_text_atom
; break;
2131 case 3: type
= text_atom
; break;
2132 default: type
= XA_STRING
;
2135 XtGetSelectionValue(myShell
, cbd
->sel_atom
, type
,
2136 clip_x11_request_selection_cb
, (XtPointer
)&success
, CurrentTime
);
2138 /* Make sure the request for the selection goes out before waiting for
2143 * Wait for result of selection request, otherwise if we type more
2144 * characters, then they will appear before the one that requested the
2145 * paste! Don't worry, we will catch up with any other events later.
2147 start_time
= time(NULL
);
2148 while (success
== MAYBE
)
2150 if (XCheckTypedEvent(dpy
, SelectionNotify
, &event
)
2151 || XCheckTypedEvent(dpy
, SelectionRequest
, &event
)
2152 || XCheckTypedEvent(dpy
, PropertyNotify
, &event
))
2154 /* This is where clip_x11_request_selection_cb() should be
2155 * called. It may actually happen a bit later, so we loop
2156 * until "success" changes.
2157 * We may get a SelectionRequest here and if we don't handle
2158 * it we hang. KDE klipper does this, for example.
2159 * We need to handle a PropertyNotify for large selections. */
2160 XtDispatchEvent(&event
);
2164 /* Time out after 2 to 3 seconds to avoid that we hang when the
2165 * other process doesn't respond. Note that the SelectionNotify
2166 * event may still come later when the selection owner comes back
2167 * to life and the text gets inserted unexpectedly. Don't know
2168 * why that happens or how to avoid that :-(. */
2169 if (time(NULL
) > start_time
+ 2)
2175 /* Do we need this? Probably not. */
2178 /* Wait for 1 msec to avoid that we eat up all CPU time. */
2182 if (success
== TRUE
)
2185 /* don't do a retry with another type after timing out, otherwise we
2186 * hang for 15 seconds. */
2191 /* Final fallback position - use the X CUT_BUFFER0 store */
2192 buffer
= (char_u
*)XFetchBuffer(dpy
, &nbytes
, 0);
2196 clip_yank_selection(MCHAR
, buffer
, (long)nbytes
, cbd
);
2197 XFree((void *)buffer
);
2199 verb_msg((char_u
*)_("Used CUT_BUFFER0 instead of empty selection"));
2203 static Boolean clip_x11_convert_selection_cb
__ARGS((Widget
, Atom
*, Atom
*, Atom
*, XtPointer
*, long_u
*, int *));
2207 clip_x11_convert_selection_cb(w
, sel_atom
, target
, type
, value
, length
, format
)
2222 if (*sel_atom
== clip_plus
.sel_atom
)
2228 return False
; /* Shouldn't ever happen */
2230 /* requestor wants to know what target types we support */
2231 if (*target
== targets_atom
)
2235 if ((array
= (Atom
*)XtMalloc((unsigned)(sizeof(Atom
) * 6))) == NULL
)
2237 *value
= (XtPointer
)array
;
2239 array
[i
++] = XA_STRING
;
2240 array
[i
++] = targets_atom
;
2242 array
[i
++] = vimenc_atom
;
2244 array
[i
++] = vim_atom
;
2245 array
[i
++] = text_atom
;
2246 array
[i
++] = compound_text_atom
;
2248 /* This used to be: *format = sizeof(Atom) * 8; but that caused
2249 * crashes on 64 bit machines. (Peter Derr) */
2255 if ( *target
!= XA_STRING
2257 && *target
!= vimenc_atom
2259 && *target
!= vim_atom
2260 && *target
!= text_atom
2261 && *target
!= compound_text_atom
)
2264 clip_get_selection(cbd
);
2265 motion_type
= clip_convert_selection(&string
, length
, cbd
);
2266 if (motion_type
< 0)
2269 /* For our own format, the first byte contains the motion type */
2270 if (*target
== vim_atom
)
2274 /* Our own format with encoding: motion 'encoding' NUL text */
2275 if (*target
== vimenc_atom
)
2276 *length
+= STRLEN(p_enc
) + 2;
2279 *value
= XtMalloc((Cardinal
)*length
);
2280 result
= (char_u
*)*value
;
2287 if (*target
== XA_STRING
)
2289 mch_memmove(result
, string
, (size_t)(*length
));
2292 else if (*target
== compound_text_atom
2293 || *target
== text_atom
)
2295 XTextProperty text_prop
;
2296 char *string_nt
= (char *)alloc((unsigned)*length
+ 1);
2298 /* create NUL terminated string which XmbTextListToTextProperty wants */
2299 mch_memmove(string_nt
, string
, (size_t)*length
);
2300 string_nt
[*length
] = NUL
;
2301 XmbTextListToTextProperty(X_DISPLAY
, (char **)&string_nt
, 1,
2302 XCompoundTextStyle
, &text_prop
);
2303 vim_free(string_nt
);
2304 XtFree(*value
); /* replace with COMPOUND text */
2305 *value
= (XtPointer
)(text_prop
.value
); /* from plain text */
2306 *length
= text_prop
.nitems
;
2307 *type
= compound_text_atom
;
2311 else if (*target
== vimenc_atom
)
2313 int l
= STRLEN(p_enc
);
2315 result
[0] = motion_type
;
2316 STRCPY(result
+ 1, p_enc
);
2317 mch_memmove(result
+ l
+ 2, string
, (size_t)(*length
- l
- 2));
2318 *type
= vimenc_atom
;
2324 result
[0] = motion_type
;
2325 mch_memmove(result
+ 1, string
, (size_t)(*length
- 1));
2328 *format
= 8; /* 8 bits per char */
2333 static void clip_x11_lose_ownership_cb
__ARGS((Widget
, Atom
*));
2337 clip_x11_lose_ownership_cb(w
, sel_atom
)
2341 if (*sel_atom
== clip_plus
.sel_atom
)
2342 clip_lose_selection(&clip_plus
);
2344 clip_lose_selection(&clip_star
);
2348 clip_x11_lose_selection(myShell
, cbd
)
2352 XtDisownSelection(myShell
, cbd
->sel_atom
, CurrentTime
);
2356 clip_x11_own_selection(myShell
, cbd
)
2360 if (XtOwnSelection(myShell
, cbd
->sel_atom
, CurrentTime
,
2361 clip_x11_convert_selection_cb
, clip_x11_lose_ownership_cb
,
2368 * Send the current selection to the clipboard. Do nothing for X because we
2369 * will fill in the selection only when requested by another app.
2373 clip_x11_set_selection(cbd
)
2379 #if defined(FEAT_MOUSE) || defined(PROTO)
2382 * Move the cursor to the specified row and column on the screen.
2383 * Change current window if necessary. Returns an integer with the
2384 * CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
2386 * The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column.
2387 * The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column.
2389 * If flags has MOUSE_FOCUS, then the current window will not be changed, and
2390 * if the mouse is outside the window then the text will scroll, or if the
2391 * mouse was previously on a status line, then the status line may be dragged.
2393 * If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
2394 * cursor is moved unless the cursor was on a status line.
2395 * This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or
2396 * IN_SEP_LINE depending on where the cursor was clicked.
2398 * If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
2399 * the mouse is on the status line of the same window.
2401 * If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
2404 * If flags has MOUSE_SETPOS, nothing is done, only the current position is
2408 jump_to_mouse(flags
, inclusive
, which_button
)
2410 int *inclusive
; /* used for inclusive operator, can be NULL */
2411 int which_button
; /* MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE */
2413 static int on_status_line
= 0; /* #lines below bottom of window */
2414 #ifdef FEAT_VERTSPLIT
2415 static int on_sep_line
= 0; /* on separator right of window */
2417 static int prev_row
= -1;
2418 static int prev_col
= -1;
2419 static win_T
*dragwin
= NULL
; /* window being dragged */
2420 static int did_drag
= FALSE
; /* drag was noticed */
2422 win_T
*wp
, *old_curwin
;
2426 int row
= mouse_row
;
2427 int col
= mouse_col
;
2432 mouse_past_bottom
= FALSE
;
2433 mouse_past_eol
= FALSE
;
2435 if (flags
& MOUSE_RELEASED
)
2437 /* On button release we may change window focus if positioned on a
2438 * status line and no dragging happened. */
2439 if (dragwin
!= NULL
&& !did_drag
)
2440 flags
&= ~(MOUSE_FOCUS
| MOUSE_DID_MOVE
);
2445 if ((flags
& MOUSE_DID_MOVE
)
2446 && prev_row
== mouse_row
2447 && prev_col
== mouse_col
)
2450 /* before moving the cursor for a left click which is NOT in a status
2451 * line, stop Visual mode */
2453 return IN_STATUS_LINE
;
2454 #ifdef FEAT_VERTSPLIT
2459 if (flags
& MOUSE_MAY_STOP_VIS
)
2462 redraw_curbuf_later(INVERTED
); /* delete the inversion */
2465 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD)
2466 /* Continue a modeless selection in another window. */
2467 if (cmdwin_type
!= 0 && row
< W_WINROW(curwin
))
2468 return IN_OTHER_WIN
;
2473 prev_row
= mouse_row
;
2474 prev_col
= mouse_col
;
2476 if (flags
& MOUSE_SETPOS
)
2477 goto retnomove
; /* ugly goto... */
2480 /* Remember the character under the mouse, it might be a '-' or '+' in the
2482 if (row
>= 0 && row
< Rows
&& col
>= 0 && col
<= Columns
2483 && ScreenLines
!= NULL
)
2484 mouse_char
= ScreenLines
[LineOffset
[row
] + col
];
2489 old_curwin
= curwin
;
2490 old_cursor
= curwin
->w_cursor
;
2492 if (!(flags
& MOUSE_FOCUS
))
2494 if (row
< 0 || col
< 0) /* check if it makes sense */
2498 /* find the window where the row is in */
2499 wp
= mouse_find_win(&row
, &col
);
2505 * winpos and height may change in win_enter()!
2507 if (row
>= wp
->w_height
) /* In (or below) status line */
2509 on_status_line
= row
- wp
->w_height
+ 1;
2514 #ifdef FEAT_VERTSPLIT
2515 if (col
>= wp
->w_width
) /* In separator line */
2517 on_sep_line
= col
- wp
->w_width
+ 1;
2523 /* The rightmost character of the status line might be a vertical
2524 * separator character if there is no connecting window to the right. */
2525 if (on_status_line
&& on_sep_line
)
2527 if (stl_connected(wp
))
2535 /* Before jumping to another buffer, or moving the cursor for a left
2536 * click, stop Visual mode. */
2538 && (wp
->w_buffer
!= curwin
->w_buffer
2540 # ifdef FEAT_VERTSPLIT
2543 # ifdef FEAT_FOLDING
2545 # ifdef FEAT_RIGHTLEFT
2546 wp
->w_p_rl
? col
< W_WIDTH(wp
) - wp
->w_p_fdc
:
2550 + (cmdwin_type
== 0 && wp
== curwin
? 0 : 1)
2554 && (flags
& MOUSE_MAY_STOP_VIS
))))
2557 redraw_curbuf_later(INVERTED
); /* delete the inversion */
2561 if (cmdwin_type
!= 0 && wp
!= curwin
)
2563 /* A click outside the command-line window: Use modeless
2564 * selection if possible. Allow dragging the status line of
2565 * windows just above the command-line window. */
2566 if (wp
->w_winrow
+ wp
->w_height
2567 != curwin
->w_prev
->w_winrow
+ curwin
->w_prev
->w_height
)
2572 # ifdef FEAT_VERTSPLIT
2575 # ifdef FEAT_CLIPBOARD
2577 return IN_STATUS_LINE
;
2578 return IN_OTHER_WIN
;
2581 col
+= wp
->w_wincol
;
2587 /* Only change window focus when not clicking on or dragging the
2588 * status line. Do change focus when releasing the mouse button
2589 * (MOUSE_FOCUS was set above if we dragged first). */
2590 if (dragwin
== NULL
|| (flags
& MOUSE_RELEASED
))
2591 win_enter(wp
, TRUE
); /* can make wp invalid! */
2592 # ifdef CHECK_DOUBLE_CLICK
2593 /* set topline, to be able to check for double click ourselves */
2594 if (curwin
!= old_curwin
)
2595 set_mouse_topline(curwin
);
2598 if (on_status_line
) /* In (or below) status line */
2600 /* Don't use start_arrow() if we're in the same window */
2601 if (curwin
== old_curwin
)
2602 return IN_STATUS_LINE
;
2604 return IN_STATUS_LINE
| CURSOR_MOVED
;
2606 #ifdef FEAT_VERTSPLIT
2607 if (on_sep_line
) /* In (or below) status line */
2609 /* Don't use start_arrow() if we're in the same window */
2610 if (curwin
== old_curwin
)
2613 return IN_SEP_LINE
| CURSOR_MOVED
;
2617 curwin
->w_cursor
.lnum
= curwin
->w_topline
;
2619 /* remember topline, needed for double click */
2620 gui_prev_topline
= curwin
->w_topline
;
2622 gui_prev_topfill
= curwin
->w_topfill
;
2626 else if (on_status_line
&& which_button
== MOUSE_LEFT
)
2629 if (dragwin
!= NULL
)
2631 /* Drag the status line */
2632 count
= row
- dragwin
->w_winrow
- dragwin
->w_height
+ 1
2634 win_drag_status_line(dragwin
, count
);
2638 return IN_STATUS_LINE
; /* Cursor didn't move */
2640 #ifdef FEAT_VERTSPLIT
2641 else if (on_sep_line
&& which_button
== MOUSE_LEFT
)
2643 if (dragwin
!= NULL
)
2645 /* Drag the separator column */
2646 count
= col
- dragwin
->w_wincol
- dragwin
->w_width
+ 1
2648 win_drag_vsep_line(dragwin
, count
);
2651 return IN_SEP_LINE
; /* Cursor didn't move */
2654 else /* keep_window_focus must be TRUE */
2657 /* before moving the cursor for a left click, stop Visual mode */
2658 if (flags
& MOUSE_MAY_STOP_VIS
)
2661 redraw_curbuf_later(INVERTED
); /* delete the inversion */
2665 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD)
2666 /* Continue a modeless selection in another window. */
2667 if (cmdwin_type
!= 0 && row
< W_WINROW(curwin
))
2668 return IN_OTHER_WIN
;
2671 row
-= W_WINROW(curwin
);
2672 #ifdef FEAT_VERTSPLIT
2673 col
-= W_WINCOL(curwin
);
2677 * When clicking beyond the end of the window, scroll the screen.
2678 * Scroll by however many rows outside the window we are.
2683 for (first
= TRUE
; curwin
->w_topline
> 1; )
2686 if (curwin
->w_topfill
< diff_check(curwin
, curwin
->w_topline
))
2690 count
+= plines(curwin
->w_topline
- 1);
2691 if (!first
&& count
> -row
)
2695 hasFolding(curwin
->w_topline
, &curwin
->w_topline
, NULL
);
2698 if (curwin
->w_topfill
< diff_check(curwin
, curwin
->w_topline
))
2699 ++curwin
->w_topfill
;
2703 --curwin
->w_topline
;
2705 curwin
->w_topfill
= 0;
2710 check_topfill(curwin
, FALSE
);
2713 ~(VALID_WROW
|VALID_CROW
|VALID_BOTLINE
|VALID_BOTLINE_AP
);
2714 redraw_later(VALID
);
2717 else if (row
>= curwin
->w_height
)
2720 for (first
= TRUE
; curwin
->w_topline
< curbuf
->b_ml
.ml_line_count
; )
2723 if (curwin
->w_topfill
> 0)
2727 count
+= plines(curwin
->w_topline
);
2728 if (!first
&& count
> row
- curwin
->w_height
+ 1)
2732 if (hasFolding(curwin
->w_topline
, NULL
, &curwin
->w_topline
)
2733 && curwin
->w_topline
== curbuf
->b_ml
.ml_line_count
)
2737 if (curwin
->w_topfill
> 0)
2738 --curwin
->w_topfill
;
2742 ++curwin
->w_topline
;
2745 diff_check_fill(curwin
, curwin
->w_topline
);
2750 check_topfill(curwin
, FALSE
);
2752 redraw_later(VALID
);
2754 ~(VALID_WROW
|VALID_CROW
|VALID_BOTLINE
|VALID_BOTLINE_AP
);
2755 row
= curwin
->w_height
- 1;
2759 /* When dragging the mouse, while the text has been scrolled up as
2760 * far as it goes, moving the mouse in the top line should scroll
2761 * the text down (done later when recomputing w_topline). */
2762 if (mouse_dragging
> 0
2763 && curwin
->w_cursor
.lnum
2764 == curwin
->w_buffer
->b_ml
.ml_line_count
2765 && curwin
->w_cursor
.lnum
== curwin
->w_topline
)
2766 curwin
->w_valid
&= ~(VALID_TOPLINE
);
2771 /* Check for position outside of the fold column. */
2773 # ifdef FEAT_RIGHTLEFT
2774 curwin
->w_p_rl
? col
< W_WIDTH(curwin
) - curwin
->w_p_fdc
:
2776 col
>= curwin
->w_p_fdc
2778 + (cmdwin_type
== 0 ? 0 : 1)
2784 /* compute the position in the buffer line from the posn on the screen */
2785 if (mouse_comp_pos(curwin
, &row
, &col
, &curwin
->w_cursor
.lnum
))
2786 mouse_past_bottom
= TRUE
;
2789 /* Start Visual mode before coladvance(), for when 'sel' != "old" */
2790 if ((flags
& MOUSE_MAY_VIS
) && !VIsual_active
)
2792 check_visual_highlight();
2793 VIsual
= old_cursor
;
2794 VIsual_active
= TRUE
;
2795 VIsual_reselect
= TRUE
;
2796 /* if 'selectmode' contains "mouse", start Select mode */
2797 may_start_select('o');
2799 if (p_smd
&& msg_silent
== 0)
2800 redraw_cmdline
= TRUE
; /* show visual mode later */
2804 curwin
->w_curswant
= col
;
2805 curwin
->w_set_curswant
= FALSE
; /* May still have been TRUE */
2806 if (coladvance(col
) == FAIL
) /* Mouse click beyond end of line */
2808 if (inclusive
!= NULL
)
2810 mouse_past_eol
= TRUE
;
2812 else if (inclusive
!= NULL
)
2816 if (curwin
!= old_curwin
|| curwin
->w_cursor
.lnum
!= old_cursor
.lnum
2817 || curwin
->w_cursor
.col
!= old_cursor
.col
)
2818 count
|= CURSOR_MOVED
; /* Cursor has moved */
2821 if (mouse_char
== '+')
2822 count
|= MOUSE_FOLD_OPEN
;
2823 else if (mouse_char
!= ' ')
2824 count
|= MOUSE_FOLD_CLOSE
;
2831 * Compute the position in the buffer line from the posn on the screen in
2833 * Returns TRUE if the position is below the last line.
2836 mouse_comp_pos(win
, rowp
, colp
, lnump
)
2849 #ifdef FEAT_RIGHTLEFT
2851 col
= W_WIDTH(win
) - 1 - col
;
2854 lnum
= win
->w_topline
;
2859 /* Don't include filler lines in "count" */
2861 # ifdef FEAT_FOLDING
2862 && !hasFoldingWin(win
, lnum
, NULL
, NULL
, TRUE
, NULL
)
2866 if (lnum
== win
->w_topline
)
2867 row
-= win
->w_topfill
;
2869 row
-= diff_check_fill(win
, lnum
);
2870 count
= plines_win_nofill(win
, lnum
, TRUE
);
2874 count
= plines_win(win
, lnum
, TRUE
);
2876 break; /* Position is in this buffer line. */
2878 (void)hasFoldingWin(win
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
2880 if (lnum
== win
->w_buffer
->b_ml
.ml_line_count
)
2883 break; /* past end of file */
2891 /* Compute the column without wrapping. */
2892 off
= win_col_off(win
) - win_col_off2(win
);
2895 col
+= row
* (W_WIDTH(win
) - off
);
2896 /* add skip column (for long wrapping line) */
2897 col
+= win
->w_skipcol
;
2901 col
+= win
->w_leftcol
;
2903 /* skip line number and fold column in front of the line */
2904 col
-= win_col_off(win
);
2907 #ifdef FEAT_NETBEANS_INTG
2909 netbeans_gutter_click(lnum
);
2920 #if defined(FEAT_WINDOWS) || defined(PROTO)
2922 * Find the window at screen position "*rowp" and "*colp". The positions are
2923 * updated to become relative to the top-left of the window.
2927 mouse_find_win(rowp
, colp
)
2934 *rowp
-= firstwin
->w_winrow
;
2937 if (fp
->fr_layout
== FR_LEAF
)
2939 #ifdef FEAT_VERTSPLIT
2940 if (fp
->fr_layout
== FR_ROW
)
2942 for (fp
= fp
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
2944 if (*colp
< fp
->fr_width
)
2946 *colp
-= fp
->fr_width
;
2950 else /* fr_layout == FR_COL */
2952 for (fp
= fp
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
2954 if (*rowp
< fp
->fr_height
)
2956 *rowp
-= fp
->fr_height
;
2964 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined (FEAT_GUI_MAC) \
2965 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \
2966 || defined(FEAT_GUI_PHOTON) || defined(PROTO)
2968 * Translate window coordinates to buffer position without any side effects
2971 get_fpos_of_mouse(mpos
)
2975 int row
= mouse_row
;
2976 int col
= mouse_col
;
2978 if (row
< 0 || col
< 0) /* check if it makes sense */
2982 /* find the window where the row is in */
2983 wp
= mouse_find_win(&row
, &col
);
2988 * winpos and height may change in win_enter()!
2990 if (row
>= wp
->w_height
) /* In (or below) status line */
2991 return IN_STATUS_LINE
;
2992 #ifdef FEAT_VERTSPLIT
2993 if (col
>= wp
->w_width
) /* In vertical separator line */
3000 /* compute the position in the buffer line from the posn on the screen */
3001 if (mouse_comp_pos(curwin
, &row
, &col
, &mpos
->lnum
))
3002 return IN_STATUS_LINE
; /* past bottom */
3004 mpos
->col
= vcol2col(wp
, mpos
->lnum
, col
);
3012 * Convert a virtual (screen) column to a character column.
3013 * The first column is one.
3016 vcol2col(wp
, lnum
, vcol
)
3021 /* try to advance to the specified column */
3026 ptr
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3027 while (count
<= vcol
&& *ptr
!= NUL
)
3030 count
+= win_lbr_chartabsize(wp
, ptr
, count
, NULL
);
3037 #endif /* FEAT_MOUSE */
3039 #if defined(FEAT_GUI) || defined(WIN3264) || defined(PROTO)
3041 * Called when focus changed. Used for the GUI or for systems where this can
3042 * be done in the console (Win32).
3045 ui_focus_change(in_focus
)
3046 int in_focus
; /* TRUE if focus gained. */
3048 static time_t last_time
= (time_t)0;
3049 int need_redraw
= FALSE
;
3051 /* When activated: Check if any file was modified outside of Vim.
3052 * Only do this when not done within the last two seconds (could get
3053 * several events in a row). */
3054 if (in_focus
&& last_time
+ 2 < time(NULL
))
3056 need_redraw
= check_timestamps(
3063 last_time
= time(NULL
);
3068 * Fire the focus gained/lost autocommand.
3070 need_redraw
|= apply_autocmds(in_focus
? EVENT_FOCUSGAINED
3071 : EVENT_FOCUSLOST
, NULL
, NULL
, FALSE
, curbuf
);
3076 /* Something was executed, make sure the cursor is put back where it
3078 need_wait_return
= FALSE
;
3080 if (State
& CMDLINE
)
3082 else if (State
== HITRETURN
|| State
== SETWSIZE
|| State
== ASKMORE
3083 || State
== EXTERNCMD
|| State
== CONFIRM
|| exmode_active
)
3085 else if ((State
& NORMAL
) || (State
& INSERT
))
3087 if (must_redraw
!= 0)
3091 cursor_on(); /* redrawing may have switched it off */
3096 gui_update_cursor(FALSE
, TRUE
);
3097 gui_update_scrollbars(FALSE
);
3102 /* File may have been changed from 'readonly' to 'noreadonly' */
3109 #if defined(USE_IM_CONTROL) || defined(PROTO)
3111 * Save current Input Method status to specified place.
3114 im_save_status(psave
)
3117 /* Don't save when 'imdisable' is set or "xic" is NULL, IM is always
3118 * disabled then (but might start later).
3119 * Also don't save when inside a mapping, vgetc_im_active has not been set
3121 * And don't save when the keys were stuffed (e.g., for a "." command).
3122 * And don't save when the GUI is running but our window doesn't have
3123 * input focus (e.g., when a find dialog is open). */
3124 if (!p_imdisable
&& KeyTyped
&& !KeyStuffed
3129 && (!gui
.in_use
|| gui
.in_focus
)
3133 /* Do save when IM is on, or IM is off and saved status is on. */
3134 if (vgetc_im_active
)
3135 *psave
= B_IMODE_IM
;
3136 else if (*psave
== B_IMODE_IM
)
3137 *psave
= B_IMODE_NONE
;