is there a signal for typing at bottom of window?

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

is there a signal for typing at bottom of window?

Doug McCasland
GTK app devel list <[hidden email]>
is there a signal for typing at bottom of window?
Hi,

I have a TextView app -- it has:
o main window from gtk_window_new()
o add a box to that
o create a scrolled window
o add scrolled window to box
o create a textview object
o add textview to scrolled window
oo

When I type in the last visible text line, at the of that line,
then the window scrolls one line, as expected, to reveal the next
visible line.

Question: I would like to take an action when this one-line scroll
happens.  But I don't see any signal for it.  (I've tried catching
edge-reached and child-scroll, but those are for other things.)

How can I set a signal for this?



thanks!


--
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: is there a signal for typing at bottom of window?

Gtk+ - Apps Dev mailing list
 
Hi Doug,

Try getting the vertical adjustment of the scrolled window and connect to "value-changed". See if that will work. Something like

...
static void value_changed(GtkAdjustment *v_adjust, gpointer user_data)
  {
  }
...
GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
GtkAdjustment *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll));
g_signal_connect(v_adjust, "value-changed", G_CALLBACK(value_changed), NULL);
...

Eric
 
 

_______________________________________________
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: is there a signal for typing at bottom of window?

Doug McCasland
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 <[hidden email]> 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)
>   {
>     static gint s_line=0;
>     GtkTextIter iter;
>     GtkTextBuffer
> *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
>     GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert");
>     gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
>     gint line=gtk_text_iter_get_line(&iter);
>     if(s_line!=line)
>       {
>         g_print("Scroll Line\n");
>         s_line=line;
>       }
>   }
>
> Eric
>
>
> -----Original Message-----
> From: Doug McCasland <[hidden email]>
> To: cecashon <[hidden email]>
> Sent: Tue, Sep 25, 2018 2:10 pm
> Subject: Re: is there a signal for typing at bottom of window?
>
> Actually I get 11 signals with a different setting of:
> gtk_text_view_set_pixels_inside_wrap()
>
> So it's one signal per vertical pixel perhaps?   I can code for that.
>
> But I also I get those signals during any scrolling (scrollbar or
> mousewheel).  How can I distinguish between automatic scrolling at bottom
> and user-commanded scrolling?
>
> thanks
>
>
>
>
>
> On Tue, Sep 25, 2018 at 1:47 PM Doug McCasland <[hidden email]>
> wrote:
>
> Woo-hoo, that works!
>
> BUT, I get 12 signals for each line that is auto-scrolled.  I can code for
> this, but why 12?  Will it always be 12?
>
>
> On Tue, Sep 25, 2018 at 11:46 AM <[hidden email]> wrote:
>
>
> Hi Doug,
>
> Try getting the vertical adjustment of the scrolled window and connect to
> "value-changed". See if that will work. Something like
>
> ...
> static void value_changed(GtkAdjustment *v_adjust, gpointer user_data)
>   {
>   }
> ...
> GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
> GtkAdjustment
> *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll));
> g_signal_connect(v_adjust, "value-changed", G_CALLBACK(value_changed),
> NULL);
> ...
>
> Eric
>
>
>
>
>
> --
> Doug McCasland   <[hidden email]>
>
>
>
> --
> Doug McCasland   <[hidden email]>
>


--
Doug McCasland   <[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: is there a signal for typing at bottom of window?

Gtk+ - Apps Dev mailing list
Hi,

g_object_get(your_text_view,
  "buffer", &your_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", &your_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 <[hidden email]> 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 <[hidden email]> 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)
> >   {
> >     static gint s_line=0;
> >     GtkTextIter iter;
> >     GtkTextBuffer
> > *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
> >     GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert");
> >     gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
> >     gint line=gtk_text_iter_get_line(&iter);
> >     if(s_line!=line)
> >       {
> >         g_print("Scroll Line\n");
> >         s_line=line;
> >       }
> >   }
> >
> > Eric
> >
> >
> > -----Original Message-----
> > From: Doug McCasland <[hidden email]>
> > To: cecashon <[hidden email]>
> > Sent: Tue, Sep 25, 2018 2:10 pm
> > Subject: Re: is there a signal for typing at bottom of window?
> >
> > Actually I get 11 signals with a different setting of:
> > gtk_text_view_set_pixels_inside_wrap()
> >
> > So it's one signal per vertical pixel perhaps?   I can code for that.
> >
> > But I also I get those signals during any scrolling (scrollbar or
> > mousewheel).  How can I distinguish between automatic scrolling at bottom
> > and user-commanded scrolling?
> >
> > thanks
> >
> >
> >
> >
> >
> > On Tue, Sep 25, 2018 at 1:47 PM Doug McCasland <[hidden email]>
> > wrote:
> >
> > Woo-hoo, that works!
> >
> > BUT, I get 12 signals for each line that is auto-scrolled.  I can code for
> > this, but why 12?  Will it always be 12?
> >
> >
> > On Tue, Sep 25, 2018 at 11:46 AM <[hidden email]> wrote:
> >
> >
> > Hi Doug,
> >
> > Try getting the vertical adjustment of the scrolled window and connect to
> > "value-changed". See if that will work. Something like
> >
> > ...
> > static void value_changed(GtkAdjustment *v_adjust, gpointer user_data)
> >   {
> >   }
> > ...
> > GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
> > GtkAdjustment
> > *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll));
> > g_signal_connect(v_adjust, "value-changed", G_CALLBACK(value_changed),
> > NULL);
> > ...
> >
> > Eric
> >
> >
> >
> >
> >
> > --
> > Doug McCasland   <[hidden email]>
> >
> >
> >
> > --
> > Doug McCasland   <[hidden email]>
> >
>
>
> --
> Doug McCasland   <[hidden email]>
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
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: is there a signal for typing at bottom of window?

Gtk+ - Apps Dev mailing list
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 <[hidden email]> wrote:

>
> Hi,
>
> g_object_get(your_text_view,
>   "buffer", &your_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", &your_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 <[hidden email]> 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 <[hidden email]> 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)
> > >   {
> > >     static gint s_line=0;
> > >     GtkTextIter iter;
> > >     GtkTextBuffer
> > > *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
> > >     GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert");
> > >     gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
> > >     gint line=gtk_text_iter_get_line(&iter);
> > >     if(s_line!=line)
> > >       {
> > >         g_print("Scroll Line\n");
> > >         s_line=line;
> > >       }
> > >   }
> > >
> > > Eric
> > >
> > >
> > > -----Original Message-----
> > > From: Doug McCasland <[hidden email]>
> > > To: cecashon <[hidden email]>
> > > Sent: Tue, Sep 25, 2018 2:10 pm
> > > Subject: Re: is there a signal for typing at bottom of window?
> > >
> > > Actually I get 11 signals with a different setting of:
> > > gtk_text_view_set_pixels_inside_wrap()
> > >
> > > So it's one signal per vertical pixel perhaps?   I can code for that.
> > >
> > > But I also I get those signals during any scrolling (scrollbar or
> > > mousewheel).  How can I distinguish between automatic scrolling at bottom
> > > and user-commanded scrolling?
> > >
> > > thanks
> > >
> > >
> > >
> > >
> > >
> > > On Tue, Sep 25, 2018 at 1:47 PM Doug McCasland <[hidden email]>
> > > wrote:
> > >
> > > Woo-hoo, that works!
> > >
> > > BUT, I get 12 signals for each line that is auto-scrolled.  I can code for
> > > this, but why 12?  Will it always be 12?
> > >
> > >
> > > On Tue, Sep 25, 2018 at 11:46 AM <[hidden email]> wrote:
> > >
> > >
> > > Hi Doug,
> > >
> > > Try getting the vertical adjustment of the scrolled window and connect to
> > > "value-changed". See if that will work. Something like
> > >
> > > ...
> > > static void value_changed(GtkAdjustment *v_adjust, gpointer user_data)
> > >   {
> > >   }
> > > ...
> > > GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
> > > GtkAdjustment
> > > *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll));
> > > g_signal_connect(v_adjust, "value-changed", G_CALLBACK(value_changed),
> > > NULL);
> > > ...
> > >
> > > Eric
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Doug McCasland   <[hidden email]>
> > >
> > >
> > >
> > > --
> > > Doug McCasland   <[hidden email]>
> > >
> >
> >
> > --
> > Doug McCasland   <[hidden email]>
> > _______________________________________________
> > gtk-app-devel-list mailing list
> > [hidden email]
> > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
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: is there a signal for typing at bottom of window?

Doug McCasland
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 <[hidden email]>
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 <[hidden email]>
> wrote:
> >
> > Hi,
> >
> > g_object_get(your_text_view,
> >   "buffer", &your_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", &your_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 <[hidden email]>
> 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 <[hidden email]> 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)
> > > >   {
> > > >     static gint s_line=0;
> > > >     GtkTextIter iter;
> > > >     GtkTextBuffer
> > > > *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
> > > >     GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert");
> > > >     gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
> > > >     gint line=gtk_text_iter_get_line(&iter);
> > > >     if(s_line!=line)
> > > >       {
> > > >         g_print("Scroll Line\n");
> > > >         s_line=line;
> > > >       }
> > > >   }
> > > >
> > > > Eric
> > > >
> > > >
> > > > -----Original Message-----
> > > > From: Doug McCasland <[hidden email]>
> > > > To: cecashon <[hidden email]>
> > > > Sent: Tue, Sep 25, 2018 2:10 pm
> > > > Subject: Re: is there a signal for typing at bottom of window?
> > > >
> > > > Actually I get 11 signals with a different setting of:
> > > > gtk_text_view_set_pixels_inside_wrap()
> > > >
> > > > So it's one signal per vertical pixel perhaps?   I can code for that.
> > > >
> > > > But I also I get those signals during any scrolling (scrollbar or
> > > > mousewheel).  How can I distinguish between automatic scrolling at
> bottom
> > > > and user-commanded scrolling?
> > > >
> > > > thanks
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On Tue, Sep 25, 2018 at 1:47 PM Doug McCasland <[hidden email]>
> > > > wrote:
> > > >
> > > > Woo-hoo, that works!
> > > >
> > > > BUT, I get 12 signals for each line that is auto-scrolled.  I can
> code for
> > > > this, but why 12?  Will it always be 12?
> > > >
> > > >
> > > > On Tue, Sep 25, 2018 at 11:46 AM <[hidden email]> wrote:
> > > >
> > > >
> > > > Hi Doug,
> > > >
> > > > Try getting the vertical adjustment of the scrolled window and
> connect to
> > > > "value-changed". See if that will work. Something like
> > > >
> > > > ...
> > > > static void value_changed(GtkAdjustment *v_adjust, gpointer
> user_data)
> > > >   {
> > > >   }
> > > > ...
> > > > GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
> > > > GtkAdjustment
> > > >
> *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll));
> > > > g_signal_connect(v_adjust, "value-changed",
> G_CALLBACK(value_changed),
> > > > NULL);
> > > > ...
> > > >
> > > > Eric
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Doug McCasland   <[hidden email]>
> > > >
> > > >
> > > >
> > > > --
> > > > Doug McCasland   <[hidden email]>
> > > >
> > >
> > >
> > > --
> > > Doug McCasland   <[hidden email]>
> > > _______________________________________________
> > > gtk-app-devel-list mailing list
> > > [hidden email]
> > > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>


--
Doug McCasland   <[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: is there a signal for typing at bottom of window?

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 <[hidden email]>
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 <[hidden email]>
> 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 <[hidden email]>
> 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 <[hidden email]>
> wrote:
> >> >
> >> > Hi,
> >> >
> >> > g_object_get(your_text_view,
> >> >   "buffer", &your_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", &your_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 <[hidden email]>
> 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 <[hidden email]> 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)
> >> > > >   {
> >> > > >     static gint s_line=0;
> >> > > >     GtkTextIter iter;
> >> > > >     GtkTextBuffer
> >> > > > *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
> >> > > >     GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert");
> >> > > >     gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
> >> > > >     gint line=gtk_text_iter_get_line(&iter);
> >> > > >     if(s_line!=line)
> >> > > >       {
> >> > > >         g_print("Scroll Line\n");
> >> > > >         s_line=line;
> >> > > >       }
> >> > > >   }
> >> > > >
> >> > > > Eric
> >> > > >
> >> > > >
> >> > > > -----Original Message-----
> >> > > > From: Doug McCasland <[hidden email]>
> >> > > > To: cecashon <[hidden email]>
> >> > > > Sent: Tue, Sep 25, 2018 2:10 pm
> >> > > > Subject: Re: is there a signal for typing at bottom of window?
> >> > > >
> >> > > > Actually I get 11 signals with a different setting of:
> >> > > > gtk_text_view_set_pixels_inside_wrap()
> >> > > >
> >> > > > So it's one signal per vertical pixel perhaps?   I can code for
> that.
> >> > > >
> >> > > > But I also I get those signals during any scrolling (scrollbar or
> >> > > > mousewheel).  How can I distinguish between automatic scrolling
> at bottom
> >> > > > and user-commanded scrolling?
> >> > > >
> >> > > > thanks
> >> > > >
> >> > > >
> >> > > >
> >> > > >
> >> > > >
> >> > > > On Tue, Sep 25, 2018 at 1:47 PM Doug McCasland <
> [hidden email]>
> >> > > > wrote:
> >> > > >
> >> > > > Woo-hoo, that works!
> >> > > >
> >> > > > BUT, I get 12 signals for each line that is auto-scrolled.  I can
> code for
> >> > > > this, but why 12?  Will it always be 12?
> >> > > >
> >> > > >
> >> > > > On Tue, Sep 25, 2018 at 11:46 AM <[hidden email]> wrote:
> >> > > >
> >> > > >
> >> > > > Hi Doug,
> >> > > >
> >> > > > Try getting the vertical adjustment of the scrolled window and
> connect to
> >> > > > "value-changed". See if that will work. Something like
> >> > > >
> >> > > > ...
> >> > > > static void value_changed(GtkAdjustment *v_adjust, gpointer
> user_data)
> >> > > >   {
> >> > > >   }
> >> > > > ...
> >> > > > GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
> >> > > > GtkAdjustment
> >> > > >
> *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll));
> >> > > > g_signal_connect(v_adjust, "value-changed",
> G_CALLBACK(value_changed),
> >> > > > NULL);
> >> > > > ...
> >> > > >
> >> > > > Eric
> >> > > >
> >> > > >
> >> > > >
> >> > > >
> >> > > >
> >> > > > --
> >> > > > Doug McCasland   <[hidden email]>
> >> > > >
> >> > > >
> >> > > >
> >> > > > --
> >> > > > Doug McCasland   <[hidden email]>
> >> > > >
> >> > >
> >> > >
> >> > > --
> >> > > Doug McCasland   <[hidden email]>
> >> > > _______________________________________________
> >> > > gtk-app-devel-list mailing list
> >> > > [hidden email]
> >> > > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> >
> >
> >
> > --
> > Doug McCasland   <[hidden email]>
>


--
Doug McCasland   <[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: is there a signal for typing at bottom of window?

Gtk+ - Apps Dev mailing 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 <gtk/gtk.h>

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, &iter, mark);
    gtk_text_buffer_get_end_iter(buffer, &end_iter);
    gint line=gtk_text_iter_get_line(&iter);
    //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&&line>below)
      {
        g_print("Scroll Line\n");
        gint count=0;
        gint i=0;
        //Check for newlines.
        gtk_text_iter_backward_char(&end_iter);
        for(i=0;i<4;i++)
          {
            if('\n'==gtk_text_iter_get_char(&end_iter)) count++;
            if(!gtk_text_iter_backward_char(&end_iter))
              {
                g_print("Break\n");
                break;
              }
          }
        //Add newlines if needed.
        if(count>0)
          {
            GtkTextMark *mark2=gtk_text_buffer_create_mark(buffer, "back", &iter, TRUE);
            gint newlines=4-count;
            gtk_text_buffer_get_end_iter(buffer, &end_iter);
            gchar string[newlines];
            for(i=0;i<newlines;i++) string[i]='\n';
            gtk_text_buffer_insert(buffer, &end_iter, string, newlines);
            gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark2);
            gtk_text_buffer_place_cursor(buffer, &iter);
            gtk_range_set_value(GTK_RANGE(widgets[1]), gtk_adjustment_get_upper(v_adjust));
            gtk_text_buffer_delete_mark(buffer, mark2);
          }
        s_line=line;
      }
  }
int main(int argc, char *argv[])
  {
    gtk_init(&argc, &argv);

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Text Space");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 20);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget *textview=gtk_text_view_new();
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_CHAR);
    gtk_widget_set_hexpand(textview, TRUE);
    gtk_widget_set_vexpand(textview, TRUE);

    GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
    GtkTextIter iter;
    gtk_text_buffer_get_end_iter(buffer, &iter);
    GtkTextMark *mark=gtk_text_buffer_create_mark(buffer, "back", &iter, TRUE);
    //Append 4 newlines to the buffer.
    gtk_text_buffer_insert(buffer, &iter, "\n\n\n\n", -1);
    gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
    gtk_text_buffer_place_cursor(buffer, &iter);
    gtk_text_buffer_delete_mark(buffer, mark);

    GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
    GtkAdjustment *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll));
    gtk_container_add(GTK_CONTAINER(scroll), textview);

    GtkWidget *range=gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(scroll));
    GtkWidget *widgets[2]={textview, range};
    g_signal_connect(v_adjust, "value-changed", G_CALLBACK(value_changed), widgets);

    GtkWidget *grid=gtk_grid_new();
    gtk_grid_attach(GTK_GRID(grid), scroll, 0, 0, 1, 1);

    gtk_container_add(GTK_CONTAINER(window), grid);

    gtk_widget_show_all(window);
   
    gtk_main();

    return 0;
  }


 

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list