Skip to content

Commit 63fd6c9

Browse files
zevlgEli-Zaretskii
authored andcommitted
Support for (box . SIZE) 'cursor-type'
This allows control of the minimum size of a masked image under which the box cursor becomes hollow. * buffer.c (cursor-type): Add commentary about (box . SIZE) 'cursor-type'. * xdisp.c (get_specified_cursor_type): Check for 'cursor-type' of the form (box . SIZE). (get_window_cursor_type): Check masked image size for (box . SIZE) 'cursor-type'. * doc/emacs/display.texi (Cursor Display): * doc/emacs/display.texi (Cursor Parameters): Add description of (box . SIZE) 'cursor-type'. * etc/NEWS: Mention the new (box . SIZE) 'cursor-type'.
1 parent c4be801 commit 63fd6c9

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

doc/emacs/display.texi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,8 @@ Customization}). (The other attributes of this face have no effect;
16541654
the text shown under the cursor is drawn using the frame's background
16551655
color.) To change its shape, customize the buffer-local variable
16561656
@code{cursor-type}; possible values are @code{box} (the default),
1657+
@code{(box . @var{SIZE})} (box cursor becoming a hollow box under
1658+
masked images larger than @var{SIZE} pixels in either dimension),
16571659
@code{hollow} (a hollow box), @code{bar} (a vertical bar), @code{(bar
16581660
. @var{n})} (a vertical bar @var{n} pixels wide), @code{hbar} (a
16591661
horizontal bar), @code{(hbar . @var{n})} (a horizontal bar @var{n}

doc/lispref/frames.texi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,9 @@ How to display the cursor. Legitimate values are:
22202220
@table @code
22212221
@item box
22222222
Display a filled box. (This is the default.)
2223+
@item (box . @var{SIZE})
2224+
Display a filled box. However, display it as a hollow box if point is
2225+
under masked image larger than @var{SIZE} pixels in either dimension.
22232226
@item hollow
22242227
Display a hollow box.
22252228
@item nil

etc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ It was declared obsolete in Emacs 27.1.
6464

6565
* Changes in Emacs 28.1
6666

67+
** Support for '(box . SIZE)' cursor-type.
68+
By default, 'box' cursor always has a filled box shape. Unless you
69+
specify cursor-type to be '(box . SIZE)'. In such case, cursor
70+
becomes a hollow box if the point is under masked image larger than
71+
'SIZE' pixels in any dimension.
72+
6773

6874
* Editing Changes in Emacs 28.1
6975

src/buffer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6247,6 +6247,9 @@ Values are interpreted as follows:
62476247
t use the cursor specified for the frame
62486248
nil don't display a cursor
62496249
box display a filled box cursor
6250+
(box . SIZE) display a filled box cursor, but make it
6251+
hollow if cursor is under masked image larger than
6252+
SIZE pixels in either dimension.
62506253
hollow display a hollow box cursor
62516254
bar display a vertical bar cursor with default width
62526255
(bar . WIDTH) display a vertical bar cursor with width WIDTH

src/xdisp.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30741,26 +30741,23 @@ get_specified_cursor_type (Lisp_Object arg, int *width)
3074130741
return BAR_CURSOR;
3074230742
}
3074330743

30744-
if (CONSP (arg)
30745-
&& EQ (XCAR (arg), Qbar)
30746-
&& RANGED_FIXNUMP (0, XCDR (arg), INT_MAX))
30747-
{
30748-
*width = XFIXNUM (XCDR (arg));
30749-
return BAR_CURSOR;
30750-
}
30751-
3075230744
if (EQ (arg, Qhbar))
3075330745
{
3075430746
*width = 2;
3075530747
return HBAR_CURSOR;
3075630748
}
3075730749

3075830750
if (CONSP (arg)
30759-
&& EQ (XCAR (arg), Qhbar)
3076030751
&& RANGED_FIXNUMP (0, XCDR (arg), INT_MAX))
3076130752
{
3076230753
*width = XFIXNUM (XCDR (arg));
30763-
return HBAR_CURSOR;
30754+
30755+
if (EQ (XCAR (arg), Qbox))
30756+
return FILLED_BOX_CURSOR;
30757+
else if (EQ (XCAR (arg), Qbar))
30758+
return BAR_CURSOR;
30759+
else if (EQ (XCAR (arg), Qhbar))
30760+
return HBAR_CURSOR;
3076430761
}
3076530762

3076630763
/* Treat anything unknown as "hollow box cursor".
@@ -30898,12 +30895,15 @@ get_window_cursor_type (struct window *w, struct glyph *glyph, int *width,
3089830895
struct image *img = IMAGE_OPT_FROM_ID (f, glyph->u.img_id);
3089930896
if (img != NULL && IMAGEP (img->spec))
3090030897
{
30901-
/* Arbitrarily, interpret "Large" as >32x32 and >NxN
30898+
/* Interpret "large" as >SIZExSIZE and >NxN
30899+
where SIZE is the value from cursor-type in form (box . SIZE),
3090230900
where N = size of default frame font size.
30903-
This should cover most of the "tiny" icons people may use. */
30901+
So, setting cursor-type to (box . 32) should cover most of
30902+
the "tiny" icons people may use. */
3090430903
if (!img->mask
30905-
|| img->width > max (32, WINDOW_FRAME_COLUMN_WIDTH (w))
30906-
|| img->height > max (32, WINDOW_FRAME_LINE_HEIGHT (w)))
30904+
|| (CONSP (BVAR (b, cursor_type))
30905+
&& img->width > max (*width, WINDOW_FRAME_COLUMN_WIDTH (w))
30906+
&& img->height > max (*width, WINDOW_FRAME_LINE_HEIGHT (w))))
3090730907
cursor_type = HOLLOW_BOX_CURSOR;
3090830908
}
3090930909
}

0 commit comments

Comments
 (0)