3

I am again at the same position, when I had the question What is the correct way to use g_signal_connect() in C++ for dynamic unity quicklists?

There I was informed that the signature for my static method was incorrect and that I had to add a guint argument in front of the others. Now I have the same problem but for the function called for the "scroll-event" signal that I want to make on to my indicator.

More specifically:

//connecting indicator with the scroll-event and altogether with the function indicator_scrolled
g_signal_connect(G_OBJECT(appindicator), "scroll-event", G_CALLBACK(&indicator_scrolled), (gpointer)this);

This is the function indicator_scrolled:

gboolean indicator_scrolled(GtkStatusIcon  *status_icon, GdkEventScroll *event, gpointer data){
    cout << "The indicator was scrolled\n";
    MainWindow* m = (MainWindow*)data;
    m->action_on_scroll();
}

I can see the "Indicator was scrolled" message but then the program crashed. Adding a guint argument in front of the others didn't solved the problem.

So, what is the correct signature for this function so as to make it work? How can I find what is the correct signature each time so as to avoid this kind of questions? (At the other question user George Edison talked about valgrind but he did not clarify)

Please do not advice that AppIndicators are not the correct way to go with Ubuntu+Qt, please see question Make sniqt recognize all tray abilities (or create a working indicator in Qt)

Edit: After tests I coincidentally found that a guint argument needs to be placed between the GtkStatusIcon and GdkEventScroll arguments. But I would really want to know a way to find out what is the correct function signature.

2 Answers 2

3

Have a look at the reference manual: https://web.archive.org/web/20130604060558/http://developer.ubuntu.com/api/ubuntu-12.04/c/appindicator/libappindicator-app-indicator.html#AppIndicator-scroll-event

arg0 : The AppIndicator object
arg1 : How many steps the scroll wheel has taken
arg2 : (type Gdk.ScrollDirection) Which direction the wheel went in
user_data : user data set when the signal handler was connected.
1
  • I had a look at the source code of another application implementing what I wanted to and its arguments were completely different than the ones specified in the link you provided me with. Thanks for this, it works flawlessly :)
    – hytromo
    Commented Jan 2, 2013 at 2:24
1

As of today, after some search-and-try, this is my working scroll-event callback:

static void indicator_scrolled(AppIndicator *indicator, guint steps, GdkScrollDirection direction)
{
    if (direction == GDK_SCROLL_DOWN)
        g_print("DOWN\n");
    else if (direction == GDK_SCROLL_UP)
        g_print("UP\n");
    else if (direction == GDK_SCROLL_SMOOTH)
       g_print("SMOOTH\n");
}

During a scroll I am receiving just one UP/DOWN, and then some SMOOTH (in the same direction).

I have no idea on how to manage the smooth direction, as I should need the GdkEventScroll structure not seen anywhere; I am implementing a volume up/down on my app indicator and I will maintain a global direction flag so the following smooth will be applied on the current direction, but I think this is just a workaround on a messy and poor documented implementation which is libappindicator.

1
  • 1
    Congrats on finding a working callback function for you. Welcome to the site ! Commented May 25, 2018 at 5:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .