Changing the text cursor (caret) size and color

Moderator: Forum moderators

Post Reply
User avatar
Subito Piano
Posts: 75
Joined: Fri Sep 04, 2020 6:08 pm
Location: UPSTATE New York
Has thanked: 17 times
Been thanked: 11 times
Contact:

Changing the text cursor (caret) size and color

Post by Subito Piano »

WHATTA PAIN figuring this out! Hopefully, posting this saves someone else several hours of searching... It may also help those with some vision limitations -- ??

I like semi-dark (gray) themes BUT want my text applications to have black text on a white background (as in good old Elementary Studio). When GTK-3 came along, I had trouble finding a semi-dark theme that consistently gave me black text/white background.. When I found a usable theme, the blinking text cursor (i.e., the "caret") was invisible! Of course, it was a white cursor on a white page background. How to change it to bigger and black -- or red, which would show on either a dark or light background?

This is what I found:

TO CHANGE COLOR
(from the "Text caret properties" section of https://docs.gtk.org/gtk3/css-properties.html)
In the gtk-3.0 folder of my theme, I opened the gtk.css file. This was the top section:

Code: Select all

* { padding: 0; -GtkToolButton-icon-spacing: 4; -GtkTextView-error-underline-color: #cc0000; -GtkScrolledWindow-scrollbar-spacing: 0; 
-GtkToolItemGroup-expander-size: 11; -GtkWidget-text-handle-width: 20; -GtkWidget-text-handle-height: 24; -GtkDialog-button-spacing: 4; 
-GtkDialog-action-area-border: 0; outline-color: alpha(currentColor,0.3); outline-style: dashed; outline-offset: -3px; outline-width: 1px; 
-gtk-outline-radius: 2px; -gtk-secondary-caret-color: #398ee7; }

I inserted

Code: Select all

caret-color: #bf0000; 

just before " -gtk-secondary-caret-color: #398ee7; };" — leaving a space after each semicolon. This gave a nice deep red; for black, of course, make it "caret-color: #000000"
NOTE: form GTK-3.2 and newer you probably need to insert this instead:

Code: Select all

str = "GtkTextView {caret-color: rgb(255,0,80);}";

...but refer to the web page above for more info.

TO CHANGE THICKNESS (from https://askubuntu.com/questions/1027877/libreoffice-writer-typing-cursor-appearance-not-mouse-pointer)

In newer configurations with compiled gtk themes, you just need to add this to ~/.config/gtk-3.0/gtk.css. (Create the file if it doesn't exist.)

Code: Select all

* { -GtkWidget-cursor-aspect-ratio: 0.2; }

So that's what I did, adding it just under serveral about the cursor-handle. After the semicolon in that section, i skipped a line, entered the line above, then entered another empty line. Note that the lines above and below this entry did resemble the coding of this added line, but it works! This is for quite a think caret; for a medium thickness, use the value 0.1, i.e., insert this instead:

Code: Select all

* { -GtkWidget-cursor-aspect-ratio: 0.1; }

Your gtk.css file (if you have one) may be different; if so, refer to the links above. If you don't have that file, you can try making the file with that one entry - backup your theme folder first! Some themes seem to have a totally different construction (as mentioned in one of the links), IDK if this will work with those.

Cheers!

"God is love" - I John 4:16
Member since 2007. Currently running Fossa on a 2012 MacBook Air.
Still using Xenial 32 on my trusty 2007 IBM T60 warhorse. ♥
(A/V Linux for live softsynth needs)

vrgovinda
Posts: 1
Joined: Fri Apr 28, 2023 6:33 am

Re: Change text cursor (caret) size and color

Post by vrgovinda »

I am using Xfce 4.16, gtk-3. I did the above mentioned steps.Only LibreOffice, Firefox changed the caret size but not in Xfce DE apps such as MousePad, WhiskerMenu, Application Finder, CatFish etc. Any workaround??

User avatar
Subito Piano
Posts: 75
Joined: Fri Sep 04, 2020 6:08 pm
Location: UPSTATE New York
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Changing the text cursor (caret) size and color

Post by Subito Piano »

Hi vrgovinda,

I don't use XFCE, let me see if I can look into this the coming weekend. If I can, I'll reply.

Cheers,

SP

"God is love" - I John 4:16
Member since 2007. Currently running Fossa on a 2012 MacBook Air.
Still using Xenial 32 on my trusty 2007 IBM T60 warhorse. ♥
(A/V Linux for live softsynth needs)

Post Reply

Return to “Tips & Tweaks”