Re: is there a signal for typing at bottom of window?

2018-09-27 Thread Eric Cashon via gtk-app-devel-list
 
You might be able to fiddle around with the newlines at the end of the buffer 
to get something to work with the textview.

Eric


//gcc -Wall text_space1.c -o text_space1 `pkg-config --cflags --libs gtk+-3.0`

#include 

static void value_changed(GtkAdjustment *v_adjust, GtkWidget **widgets)
  {
    static gint s_line=0;

    GtkTextIter iter, end_iter;
    GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(widgets[0]));
    GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert");
    gtk_text_buffer_get_iter_at_mark(buffer, , mark);
    gtk_text_buffer_get_end_iter(buffer, _iter);
    gint line=gtk_text_iter_get_line();
    //Check if cursor line is below a certain line in the buffer.
    gint below=gtk_text_buffer_get_line_count(buffer)-6;
    
    if(s_line!=line&>below)
  {
    g_print("Scroll Line\n");
    gint count=0;
    gint i=0;
    //Check for newlines.
    gtk_text_iter_backward_char(_iter);
    for(i=0;i<4;i++)
  {
    if('\n'==gtk_text_iter_get_char(_iter)) count++;
    if(!gtk_text_iter_backward_char(_iter))
  {
    g_print("Break\n");
    break;
  }
  }
    //Add newlines if needed.
    if(count>0)
  {
    GtkTextMark *mark2=gtk_text_buffer_create_mark(buffer, "back", 
, TRUE);
    gint newlines=4-count;
    gtk_text_buffer_get_end_iter(buffer, _iter);
    gchar string[newlines];
    for(i=0;ihttps://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: is there a signal for typing at bottom of window?

2018-09-27 Thread Doug McCasland
Thanks.
IMO, that's too much to do for this feature :-)

So I will just use a keyboard shortcut to do the scrolling, when the cursor
gets too low in the window.

Meanwhile, I want to make a GTK feature suggestion to have a signal emitted
when the TextView window scrolls to reveal the next line in the buffer, but
only when the scrolling is caused by keyboard input.

What is the procedure for making that suggestion?

thanks

On Wed, Sep 26, 2018 at 12:04 PM Joël Krähemann 
wrote:

> Hi Dough,
>
> You have to handle all possible events. Additionally I would listen to:
>
> g_signal_connect(your_widget, "expose-event",
>   G_CALLBACK(your_expose_event_callback), your_data);
>
> g_signal_connect(your_widget, "configure-event",
>   G_CALLBACK(your_configure_event_callback), your_data);
>
> Note in order to receive those events you have to set events mask first.
>
> gtk_widget_set_events(GTK_WIDGET (automation_edit->drawing_area),
> GDK_EXPOSURE_MASK
>| GDK_POINTER_MOTION_MASK
>| GDK_POINTER_MOTION_HINT_MASK
>| GDK_CONTROL_MASK);
>
> I am not sure if all of above is needed but see here for further
> information:
>
> https://developer.gnome.org/gdk2/stable/gdk2-Events.html#GdkEventMask
> https://developer.gnome.org/gdk3/stable/gdk3-Events.html#GdkEventMask
>
>
> Bests,
> Joël
>
> On Wed, Sep 26, 2018 at 8:21 PM Doug McCasland 
> wrote:
> >
> > Thanks Joël,
> >
> > I don't see how your code reacts to scrolling ? But I used your idea to
> check the buffer length.  That helped filter out a lot of the signals.  But
> other non-keyboard actions can change the buffer length, of course, so it's
> not dependable.  :-/
> >
> >
> > On Tue, Sep 25, 2018 at 10:17 PM Joël Krähemann 
> wrote:
> >>
> >> Hi again,
> >>
> >> For sure you should probably use:
> >>
> >> g_signal_connect_after(your_text_buffer, "changed",
> >>   G_CALLBACK(your_text_buffer_changed_callback), your_data);
> >>
> >> and YOUR_DATA(your_data) just casts to your pointer to a struct or
> >> object containing some information:
> >>
> >> struct _YourData{
> >>   gint last_newline_position;
> >> };
> >>
> >> Well this is it.
> >>
> >> Bests,
> >> Joël
> >>
> >>
> >>
> >> On Wed, Sep 26, 2018 at 7:12 AM Joël Krähemann 
> wrote:
> >> >
> >> > Hi,
> >> >
> >> > g_object_get(your_text_view,
> >> >   "buffer", _text_buffer,
> >> >   NULL);
> >> > g_signal_connect(your_text_buffer, "changed",
> >> >   G_CALLBACK(your_text_buffer_changed_callback), your_data);
> >> >
> >> > void your_text_buffer_changed_callback(GtkTextBuffer
> >> > *your_text_buffer, gpointer your_data)
> >> > {
> >> >   gint line_count;
> >> >
> >> >   line_count = gtk_text_buffer_get_line_count(your_text_buffer);
> >> >
> >> >   if(line_count > YOUR_DATA(your_data)->line_count){
> >> > gchar *your_text;
> >> >
> >> > g_object_get(your_text_buffer,
> >> >   "text", _text,
> >> >   NULL);
> >> >
> >> > if(your_text[strlen(your_text) - 1] == '\n' &&
> >> > YOUR_DATA(your_data)->last_newline_position <
> >> > &(your_text[strlen(your_text) - 1]) - your_text){
> >> >   //TODO:DMC: implement me
> >> > }
> >> >   }
> >> > }
> >> >
> >> > by,
> >> > Joël
> >> >
> >> > On Wed, Sep 26, 2018 at 6:49 AM Doug McCasland 
> wrote:
> >> > >
> >> > > Eric, thanks for the ideas!
> >> > >
> >> > > I tried a bunch of things to distinguish the callbacks, but it got
> too
> >> > > complicated.  Checking for a different line number is a clever
> idea, but
> >> > > PgUp and PgDown also move the cursor which changes the line number.
> >> > >  Similar problems for tracking the char offset in the line (for
> simply
> >> > > typing at the end of the last visible line, not creating a new
> line/para).
> >> > >
> >> > > So, it would be nice if there was a simple signal for this case,
> where the
> >> > > window scrolls because of keyboard input in the last visible line.
> >> > >
> >> > > The reason I want this is, is so my app can scroll the window
> >> > > automatically, so that the cursor insert point becomes centered
> >> > > vertically.  In other words, when I'm typing a long paragraph, and
> it's the
> >> > > last visible line, I want it to scroll up, so I'm now typing in the
> middle
> >> > > of the window (vs. continuing to type on the last visible line).
> >> > >
> >> > > I suppose this is a bit esoteric.
> >> > >
> >> > > I did create a kbd shortcut to do that scroll manually:
> >> > >
> >> > > gtk_text_view_scroll_to_iter(..., 0.0, TRUE, 1.0, 0.5)
> >> > >
> >> > > so I have that to use.
> >> > >
> >> > >
> >> > > On Tue, Sep 25, 2018 at 2:34 PM  wrote:
> >> > >
> >> > > >
> >> > > > Not sure how to go about this myself. I see the extra callbacks
> and it
> >> > > > would be a good thing to limit them. For filtering maybe check if
> the
> >> > > > cursor has changed lines along with the adjustment value change.
> Suspect
> >> > > > there is a better solution for this.
> >> > > >
> >> > > > static void value_changed(GtkAdjustment *v_adjust, gpointer
> textview)
> >> > > >   {
>