After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 79585 - GtkTextView API to change cursor color
GtkTextView API to change cursor color
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
2.0.x
Other other
: Normal enhancement
: Small API
Assigned To: gtk-bugs
gtk-bugs
: 84548 97698 100577 102114 105840 108492 118953 312139 (view as bug list)
Depends on:
Blocks: 97663 119922
 
 
Reported: 2002-04-23 08:27 UTC by Paolo Maggi
Modified: 2007-06-13 18:56 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
patch (799 bytes, patch)
2007-05-27 21:03 UTC, Yevgen Muntyan
none Details | Review
patch (3.23 KB, patch)
2007-05-28 08:25 UTC, Yevgen Muntyan
none Details | Review
patch (1.99 KB, patch)
2007-05-28 08:27 UTC, Yevgen Muntyan
none Details | Review
gtk_rc_style_set_rc_property() (GtkTextView API to change cursor color) (7.22 KB, patch)
2007-06-01 07:36 UTC, Yevgen Muntyan
none Details | Review
gtk_widget_style_set* (GtkTextView API to change cursor color) (14.77 KB, patch)
2007-06-01 19:48 UTC, Yevgen Muntyan
none Details | Review
patch (8.50 KB, patch)
2007-06-04 07:55 UTC, Yevgen Muntyan
accepted-commit_now Details | Review

Description Paolo Maggi 2002-04-23 08:27:41 UTC
Cursor does not show if the background is black, shows
fine if background is other color. 

The problem here is that the cursor is
black, no matter what the background color is.

A possible solution could be to have the cursor of the same color of the text
(when not using default theme colors)

I think it is not a good idea to add a "Cursor color" setting.

Note for me: find out how to change cursor color.
Comment 1 Paolo Maggi 2002-04-24 15:42:52 UTC
<paolo> hp: how can I change the cursor color in a GtkTextView? (I'm
trying to fix bug #79585)
<hp> paolo: I don't think we have that feature, I could be wrong
<paolo> hp: hmmm... then I think I will not fix this buf :-( 
cursor-color is a style property, can this info help me?
<hp> paolo: well it means people can set a cursor color in their gtkrc
anyway

I think at the moment we have no way to fix this bug.

luis: should we fill a bug report against GtkTextView?
Comment 2 Paolo Maggi 2002-04-24 19:56:30 UTC
Since it is not fixable -> normal
Comment 3 Havoc Pennington 2002-05-02 14:45:27 UTC
Moving to GTK until GTK exports a way to set the cursor color, 
or magically picks the right cursor color, or something.
Maybe a tag property for cursor color?
Comment 4 Paolo Maggi 2002-05-02 14:55:05 UTC
I don't think using tags will be a good solution, at least to solve
gedit bug.
I think we should have a function (for example:
gtk_widget_modify_cursor) like gtk_widget_modify_text and family
Comment 5 Paolo Maggi 2002-06-09 09:47:08 UTC
*** Bug 84548 has been marked as a duplicate of this bug. ***
Comment 6 Torbjörn Andersson 2002-06-13 09:42:54 UTC
This has probably already been considered and rejected, but...

One common behaviour on other platforms seems to be to have the cursor
invert whatever is in the area occupied by it, rather than picking
just one colour for the whole thing. Of course, that can make the
cursor hard to spot in some other cases, but surely it would do the
right thing more often than now?

What's annoying is that there seems to be a "cursor-color" property in
GtkWidget but I can't figure out how to change it, or even if I'm
supposed to be able to. I'm still rather new to GTK+ :-)
Comment 7 Havoc Pennington 2002-06-13 13:15:23 UTC
The "cursor-color" property there is intended to be set by the theme,
for the default color.
Comment 8 Paolo Maggi 2002-11-05 15:57:14 UTC
*** Bug 97698 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Sobala 2002-12-07 12:23:31 UTC
*** Bug 100577 has been marked as a duplicate of this bug. ***
Comment 10 Calum Benson 2002-12-13 17:36:52 UTC
I've fixed this for the accessibility themes (see #100330), guess
someone just needs to fix it in the default theme now if it's still
happening :)
Comment 11 Paolo Maggi 2002-12-29 10:00:22 UTC
*** Bug 102114 has been marked as a duplicate of this bug. ***
Comment 12 Paolo Maggi 2003-02-12 11:29:51 UTC
*** Bug 105840 has been marked as a duplicate of this bug. ***
Comment 13 Paolo Maggi 2003-03-16 16:19:43 UTC
*** Bug 108492 has been marked as a duplicate of this bug. ***
Comment 14 Matthias Clasen 2003-08-02 21:17:46 UTC
*** Bug 118953 has been marked as a duplicate of this bug. ***
Comment 15 Owen Taylor 2004-02-29 16:34:50 UTC
You *can* manage to change the cursor color by setting a 
name on the widget and using gtk_rc_parse_string(). Not
nice at all though.
Comment 16 Yevgen Muntyan 2007-05-27 21:03:12 UTC
Created attachment 88907 [details] [review]
patch

Does someone have an idea why cursor uses style->black instead of style->text? If it uses style->text, then modify_text() will correctly change the cursor color along with text color.
Comment 17 Matthias Clasen 2007-05-28 04:37:10 UTC
Hmm, but hardcoding the state here looks a bit wrong. And if you use the actual state of the widget, then the cache ought to keep track of the state as well.

And what about the secondary cursor ? 
Comment 18 Yevgen Muntyan 2007-05-28 05:55:49 UTC
(In reply to comment #17)
> Hmm, but hardcoding the state here looks a bit wrong.

It does look wrong to me too, but it's what actually is done - cursor color is the text color, and the text color is text[GTK_STATE_NORMAL]. Should I make cursor_gc's be created for different states, and fetch appropriate state's gc in draw_insertion_cursor() (I don't think cursor is drawn for GtkTextView and GtkEntry when those are not GTK_STATE_NORMAL or not in focus)?

> And if you use the actual
> state of the widget, then the cache ought to keep track of the state as well.

I thought it's taken care of in gtk_style_real_init_from_rc, cursor gc's are destroyed if text[GTK_STATE_NORMAL] changed. I don't know style mechanics at all though, so I might have guessed wrong.

> And what about the secondary cursor ? 

I wish someone could explain what this secondary cursor is. Perhaps take cursor color and tansform it somehow (whatever it's called, when you make grey of black)?
Comment 19 Matthias Clasen 2007-05-28 06:06:22 UTC
> It does look wrong to me too, but it's what actually is done - cursor color is
> the text color, and the text color is text[GTK_STATE_NORMAL]. Should I make
> cursor_gc's be created for different states, and fetch appropriate state's gc
> in draw_insertion_cursor() (I don't think cursor is drawn for GtkTextView and
> GtkEntry when those are not GTK_STATE_NORMAL or not in focus)?

Hmm, I guess you are right, but at least it is worth a short comment.

I wish someone could explain what this secondary cursor is. Perhaps take cursor
color and tansform it somehow (whatever it's called, when you make grey of
black)?

 
> I wish someone could explain what this secondary cursor is.

If you want to see it in action, go to the entry example in testgtk, first entry,
and move the cursor to the very end. A secondary cursor is shown when insertion of 
LTR and RTL text would happen at different places.
Comment 20 Yevgen Muntyan 2007-05-28 08:25:21 UTC
Created attachment 88927 [details] [review]
patch

Added comments, and made secondary cursor color be average between text and base colors. Don't ask about magical numbers.
Comment 21 Yevgen Muntyan 2007-05-28 08:27:05 UTC
Created attachment 88928 [details] [review]
patch

Oops, unrelated change slipped into the patch.
Comment 22 Benjamin Berg 2007-05-28 12:22:09 UTC
I just want to point out that the patch will not work for themes that set the "cursor-color" or "secondary-cursor-color" style properties.
That said I like the patch as it chooses saner default colors. (A problem we are running into in themes when the user chooses a dark color scheme.)
Comment 23 Yevgen Muntyan 2007-05-28 18:42:55 UTC
Why won't it work? It does work.
Comment 24 Benjamin Berg 2007-05-28 20:03:56 UTC
Ehm, I am saying that it will not work *if* the theme sets the style properties. Because then the color returned by make_cursor_gc will be from the style property and *not* the text color.


For example put the following style into your gtkrc and remove the hack that gedit has to set the cursor-color.

style "blub"
{
        GtkWidget::cursor-color = "#0000ff"
}

class "GtkWidget" style "blub"

The cursor-color is blue, and stays blue, whatever you do to the gedit preferences. Your patch does not make any difference.
Comment 25 Yevgen Muntyan 2007-05-28 20:09:27 UTC
If I understand it correctly, then it works as expected. The patch isn't mean to break themes; if a theme sets cursor color then this set color is used, as it should. Am I missing something?
Comment 26 Benjamin Berg 2007-05-28 20:18:10 UTC
Well, you still end up with a fixed cursor color. This color may not be the desired one with a (user) modified background color. And I thought that was the whole point of this bug.
Comment 27 Yevgen Muntyan 2007-05-28 20:49:26 UTC
Yes, got it now. So it seems we do need api to change cursor color (right now it's problem in GtkSourceView which simply may not use gtkrc trick, since it may not assign widget names and it may not invent its own themes on top of user's).

Matthias, would it be okay to make per-widget style matching, like it's done for widget names? Perhaps something like: when widget's own style is to be modified, create GtkStyle object, attach it with some g_object_set_data(widget, "gtk-widget-personal-style"), and make it participate in theming business?
Comment 28 Benjamin Berg 2007-05-28 21:16:07 UTC
This is what the gtk_widget_modify_* functions do. A GtkRcStyle is attached to the widget, and merged in last, overriding the themes rc styles.

What you said could be done with the current system if if it was possible to not only modify the colors of the rc style, but also set style properties. For this to work one would basically need to make insert_rc_property (from gtkrc.c) public API to make that work.
Comment 29 Yevgen Muntyan 2007-05-28 21:20:19 UTC
(In reply to comment #28)
> This is what the gtk_widget_modify_* functions do. A GtkRcStyle is attached to
> the widget, and merged in last, overriding the themes rc styles.

That's right, and GtkRcStyle won't do style properties.

> What you said could be done with the current system if if it was possible to
> not only modify the colors of the rc style, but also set style properties. For
> this to work one would basically need to make insert_rc_property (from gtkrc.c)
> public API to make that work.

And the question is if it would be okay to do it (it's totally good that it's easier than I thought).
Comment 30 Matthias Clasen 2007-06-01 04:00:13 UTC
I think I am fine with changing get_insertion_cursor_gc() to use 
text[NORMAL] and something between text and base for the secondary cursor.
You can simply use text_aa for that though, considering

      style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
      style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
      style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;

I also think that extending the gtk_widget_modify_... api to allow
setting style properties might be an acceptable way to reduce the perceived
need in apps to muck around with gtk_rc_parse_string()
Comment 31 Yevgen Muntyan 2007-06-01 05:03:20 UTC
Committed this colors thing: use text[GTK_STATE_NORMAL] for primary cursor, and text_aa[GTK_STATE_NORMAL] for secondary cursor.
Comment 32 Yevgen Muntyan 2007-06-01 07:36:53 UTC
Created attachment 89164 [details] [review]
gtk_rc_style_set_rc_property() (GtkTextView API to change cursor color)

<mclasen> muntyan: we could let them jump through one more hoop by confining it to gtk_rc_style_set_property()

Here are gtk_rc_style_set_rc_property() and gtk_rc_style_unset_rc_property(), rather ugly.
Comment 33 Yevgen Muntyan 2007-06-01 19:48:04 UTC
Created attachment 89202 [details] [review]
gtk_widget_style_set* (GtkTextView API to change cursor color)

Here's gtk_widget_style_set* family and gtk_widget_style_unset_property().
Comment 34 Yevgen Muntyan 2007-06-04 07:55:36 UTC
Created attachment 89314 [details] [review]
patch

Or perhaps this one, with gtk_widget_modify_cursor().
Comment 35 Paolo Borelli 2007-06-06 08:27:17 UTC
*** Bug 312139 has been marked as a duplicate of this bug. ***
Comment 36 Matthias Clasen 2007-06-06 15:07:49 UTC
Lets take the modify_cursor approach first and worry about setting other style properties later.

- The docs are missing a "Since: 2.12"

- Please use gdk_color_to_string instead of printf

- Please add the new function to docs/reference/gtk/gtk-sections.txt


Other than that, the patch looks good, please commit with these changes
Comment 37 Yevgen Muntyan 2007-06-06 19:45:37 UTC
Done, with said changes.

2007-06-06  Yevgen Muntyan  <muntyan@tamu.edu>

        * gtk/gtkwidget.c:
        * gtk/gtkwidget.h: new method, gtk_widget_modify_cursor() (#89314).

        * gtkrc.c:
        * gtkrc.h: new functions _gtk_rc_style_set_rc_property() and
        _gtk_rc_style_unset_rc_property().

        * gtk/gtk.symbols: added gtk_widget_modify_cursor.

        * tests/testtext.c (do_cursor_visible_changed):
        * tests/testgtk.c (create_styles): test it.
Comment 38 Richard Hult 2007-06-06 20:04:35 UTC
It's unfortunate that the textview's naming of its cursor clashes with the other more generic concept of a cursor (mouse pointer) used in gdk. Adding API on GtkWidget with cursor in the name sounds more like it has to do with the mouse cursor than a GtkTextView/Entry specific thing, in my opinion. I don't have a better suggestion though.
Comment 39 Yevgen Muntyan 2007-06-06 20:17:16 UTC
Perhaps make it gtk_widget_modify_cursor_color()? I personally like it better, but I made it consistent with other gtk_widget_modify_stuff() names.
Comment 40 Matthias Clasen 2007-06-07 01:23:03 UTC
Hmm. Yes, there is a slight clash in naming, but the use of "cursor" as 
"text cursor/caret" is pretty widespread:

gtk-cursor-blink
cursor-color
gtk-split-cursor
gtk_text_view_move_cursor

I think the consistency with the rest of the gtk_widget_modify_ family
of functions outweigths this concern.