textview buffers and primary clipboard issue

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

textview buffers and primary clipboard issue

Doug McCasland
Hi,

I have a GTK3 app that uses Notebook with a TextView buffer for
each page.  At startup, I call:
|  tagset_atom_serialize =
|         gtk_text_buffer_register_serialize_tagset(buf[i], "myapp");
| tagset_atom_deserialize =
|         gtk_text_buffer_register_deserialize_tagset(buf[i], "myapp");

for each buffer.

Then I read and write files with:
|  gtk_text_buffer_deserialize_set_can_create_tags(buf[i],
|         tagset_atom_deserialize, FALSE);
| gtk_text_buffer_deserialize(buf[i], buf[i],
|         tagset_atom_deserialize,  
|         &iter, fdata, (gsize )len, &error);

and
|  serialized = gtk_text_buffer_serialize(buf[i],
|         buf[i], tagset_atom_serialize,
|         &start, &end, &len);

All of that works.  Now here's the problem.  I can select text
with the mouse in Buffer 1 and use middle button to paste it in
Buffer 2 (ie, via the Primary clipboard).  BUT if there is a PixBuf
in Buffer1, below the selected text, then somehow the pixbuf and
many lines below it are put on the Primary clipboard, even though
I did not select any of that with the mouse.  So when I paste
it into Buffer 2 using the middle button, I see the selected text
plus image(s) and extra junk.  Okay, that's bad enough ☺, but
when I save that buffer (ie, serialize code above), the whole
process hangs and I have to kill it with SIGKILL!  No error messages
on stdout from the process.

I can work around this by using Ctrl-C to copy a mouse selection
and Ctrl-V to paste, and that works as expected.

Here is the output of the xclip command, after selecting "baz"
with the mouse (note the extra stuff put on the clipboard):
|  PRIMARY contents
| GTKTEXTBUFFERCONTENTS-0001. . . .<text_view_markup>
|  <tags>
|  </tags>
| <text>baz
| <pixbuf index="0" />
|
| <pixbuf index="1" />
|
| </text>
| </text_view_markup>
| GTKTEXTBUFFERPIXBDATA-00. .. .

and here is the secondary clipboard when using Ctrl-C on the same
mouse selection:
|  clipboard contents
| GTKTEXTBUFFERCONTENTS-0001J <text_view_markup>
|  <tags>
|  </tags>
| <text>baz</text>
| </text_view_markup>


Any ideas on what I'm doing wrong and how to make middle-click
paste work between buffers, when there is a pixbuf in the source
buffer?

--
Doug McCasland, San Francisco  <[hidden email]>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: textview buffers and primary clipboard issue

Doug McCasland

Some add'l info:

This is using GTK 3.24 in Lubuntu 18.10.

When I select with the mouse and use middle-click to paste in
the *same* buffer -- with an image below the text, as described
above -- it does work normally.  So in that case, even though
the Primary clipboard incorrectly contains non-selected image
data, TextView is not pasting all of what's on the Primary clipboard,
apparently.  

--
Doug McCasland, San Francisco  <[hidden email]>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: textview buffers and primary clipboard issue

Doug McCasland
In reply to this post by Doug McCasland
Well I played with some tag table calls and now things work correctly.

Previously I was using:
|  gtk_text_view_new()

which creates a TextView and a buffer, then
|  buf[i] = gtk_text_view_get_buffer()

to get the buffer object.  Then for each new tag in each buffer:

|  gtk_text_buffer_create_tag(buf[i],....)

That was very inefficient, since I wanted each buffer to have
all the same tags.  So I re-worked the code so it only created
the tags once in the first buffer and then I created subsequent
buffers using that tag set.  Here are the basics of what I did:
|  GtkTextTagTable *main_tag_table;
| tv[0] = gtk_text_view_new();
| buf[0] = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tv[0]);
| main_tag_table = gtk_text_buffer_get_tag_table(buf[0]);

For subsequent buffers:
|  buf[i] = gtk_text_buffer_new(main_tag_table);
| tv[i] = gtk_text_view_new_with_buffer(buf[i]);

Then create new tags only in the first buffer:
|  gtk_text_buffer_create_tag(buf[0], ..., ....);

I still called:
|  gtk_text_buffer_register_serialize_tagset()

and
|  gtk_text_buffer_register_deserialize_tagset()

in each buffer.

So there's something about not sharing that tag table that makes
middle-button paste act strangely.  Might have been a GTK bug,
or some part of my code (always more likely ☺).  However, the
Primary clipboard after selecting text that is followed by an
image (in a TextView buffer, that is) still has all that unselected
image data.  But somehow it doesn't get pasted by middle-button
click, so that's odd.
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list