diff options
| author | Gerd Möllmann | 2024-10-23 12:59:09 +0200 |
|---|---|---|
| committer | Gerd Möllmann | 2024-10-23 12:59:09 +0200 |
| commit | 9b8d1e0addeca9b508324537e7743d0af508a630 (patch) | |
| tree | e250263903ee1b5681d77ae83957b4a57ed7e1d1 /src | |
| parent | d1fd1d8fba8a6cfe774f6982bb6ad6c874d0c960 (diff) | |
| download | emacs-9b8d1e0addeca9b508324537e7743d0af508a630.tar.gz emacs-9b8d1e0addeca9b508324537e7743d0af508a630.zip | |
Handle obscured cursor differently
This also fixes an error made when porting this to savannah.
* src/dispnew.c (abs_cursor_pos, (is_cursor_obscured)
(terminal_cursor_magic): Port correctly and fix.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dispnew.c | 73 |
1 files changed, 60 insertions, 13 deletions
diff --git a/src/dispnew.c b/src/dispnew.c index 6a6f983a2ce..2afd2cd3c5a 100644 --- a/src/dispnew.c +++ b/src/dispnew.c | |||
| @@ -3807,25 +3807,68 @@ update_tty_frame (struct frame *f, bool force_p) | |||
| 3807 | return false; | 3807 | return false; |
| 3808 | } | 3808 | } |
| 3809 | 3809 | ||
| 3810 | static void | 3810 | /* Return the cursor position of the selected window of frame F, in |
| 3811 | absolute coordinates in *X and *Y. Note that if F is a child frame, | ||
| 3812 | its cursor may be clipped, i.e. outside of the bounds of the terminal | ||
| 3813 | window. Value is false if the selected window of F doesn't have | ||
| 3814 | valid cursor position info. */ | ||
| 3815 | |||
| 3816 | static bool | ||
| 3811 | abs_cursor_pos (struct frame *f, int *x, int *y) | 3817 | abs_cursor_pos (struct frame *f, int *x, int *y) |
| 3812 | { | 3818 | { |
| 3813 | frame_pos_abs (f, x, y); | ||
| 3814 | struct window *w = XWINDOW (f->selected_window); | 3819 | struct window *w = XWINDOW (f->selected_window); |
| 3815 | *x += w->cursor.x; | 3820 | if (w->cursor.vpos >= 0 |
| 3816 | *y += w->cursor.y; | 3821 | /* The cursor vpos may be temporarily out of bounds |
| 3822 | in the following situation: There is one window, | ||
| 3823 | with the cursor in the lower half of it. The window | ||
| 3824 | is split, and a message causes a redisplay before | ||
| 3825 | a new cursor position has been computed. */ | ||
| 3826 | && w->cursor.vpos < WINDOW_TOTAL_LINES (w)) | ||
| 3827 | { | ||
| 3828 | int wx = WINDOW_TO_FRAME_HPOS (w, w->cursor.hpos); | ||
| 3829 | int wy = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos); | ||
| 3830 | |||
| 3831 | wx += max (0, w->left_margin_cols); | ||
| 3832 | |||
| 3833 | int fx, fy; | ||
| 3834 | frame_pos_abs (f, &fx, &fy); | ||
| 3835 | *x = fx + wx; | ||
| 3836 | *y = fy + wy; | ||
| 3837 | return true; | ||
| 3838 | } | ||
| 3839 | |||
| 3840 | *x = *y = 0; | ||
| 3841 | return false; | ||
| 3842 | } | ||
| 3843 | |||
| 3844 | static bool | ||
| 3845 | is_in_matrix (struct frame *f, int x, int y) | ||
| 3846 | { | ||
| 3847 | struct frame *root = root_frame (f); | ||
| 3848 | if (x < 0 || x >= root->current_matrix->matrix_w || y < 0 | ||
| 3849 | || y >= root->current_matrix->matrix_h) | ||
| 3850 | return false; | ||
| 3851 | return true; | ||
| 3817 | } | 3852 | } |
| 3818 | 3853 | ||
| 3819 | /* Is the terminal cursor of frame F obscured by a child frame? */ | 3854 | /* Is the terminal cursor of the selected frame obscured by a child |
| 3855 | frame? */ | ||
| 3820 | 3856 | ||
| 3821 | static bool | 3857 | static bool |
| 3822 | is_cursor_obscured (void) | 3858 | is_cursor_obscured (void) |
| 3823 | { | 3859 | { |
| 3860 | /* Give up if we can't tell where the cursor currently is. */ | ||
| 3824 | int x, y; | 3861 | int x, y; |
| 3825 | abs_cursor_pos (SELECTED_FRAME (), &x, &y); | 3862 | if (!abs_cursor_pos (SELECTED_FRAME (), &x, &y)) |
| 3863 | return false; | ||
| 3864 | |||
| 3865 | /* (x, y) may be outside of the root frame in case the selected frame is a | ||
| 3866 | child frame which is clipped. */ | ||
| 3826 | struct frame *root = root_frame (SELECTED_FRAME ()); | 3867 | struct frame *root = root_frame (SELECTED_FRAME ()); |
| 3868 | if (!is_in_matrix (root, x, y)) | ||
| 3869 | return true; | ||
| 3870 | |||
| 3827 | struct glyph_row *cursor_row = MATRIX_ROW (root->current_matrix, y); | 3871 | struct glyph_row *cursor_row = MATRIX_ROW (root->current_matrix, y); |
| 3828 | eassert (x < root->current_matrix->matrix_w); | ||
| 3829 | struct glyph *cursor_glyph = cursor_row->glyphs[0] + x; | 3872 | struct glyph *cursor_glyph = cursor_row->glyphs[0] + x; |
| 3830 | return cursor_glyph->frame != SELECTED_FRAME (); | 3873 | return cursor_glyph->frame != SELECTED_FRAME (); |
| 3831 | } | 3874 | } |
| @@ -3854,14 +3897,18 @@ terminal_cursor_magic (struct frame *root, struct frame *topmost_child) | |||
| 3854 | Lisp_Object frame; | 3897 | Lisp_Object frame; |
| 3855 | XSETFRAME (frame, topmost_child); | 3898 | XSETFRAME (frame, topmost_child); |
| 3856 | 3899 | ||
| 3900 | int x, y; | ||
| 3857 | Lisp_Object cursor = Fframe_parameter (frame, Qtty_non_selected_cursor); | 3901 | Lisp_Object cursor = Fframe_parameter (frame, Qtty_non_selected_cursor); |
| 3858 | if (!NILP (cursor)) | 3902 | if (!NILP (cursor) && abs_cursor_pos (topmost_child, &x, &y)) |
| 3859 | { | 3903 | { |
| 3860 | int x, y; | 3904 | if (is_in_matrix (root, x, y)) |
| 3861 | abs_cursor_pos (topmost_child, &x, &y); | 3905 | { |
| 3862 | cursor_to (root, y, x); | 3906 | cursor_to (root, y, x); |
| 3863 | tty_show_cursor (FRAME_TTY (topmost_child)); | 3907 | tty_show_cursor (FRAME_TTY (topmost_child)); |
| 3864 | } | 3908 | } |
| 3909 | else | ||
| 3910 | tty_hide_cursor (FRAME_TTY (root)); | ||
| 3911 | } | ||
| 3865 | } | 3912 | } |
| 3866 | } | 3913 | } |
| 3867 | 3914 | ||