ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
short version of question:
Is there some way to tell in a GtkAdjustment value_changed callback if the change was caused by the user taking action (with the mouse) or if the value was changed by the program itself (for instance using gtk_adjustment_set_value())?
I have an application written using another GUI that I am considering porting to the GTK+ GUI. In testing, GTK+, I have noticed an interaction which will cause trouble unless I can find a work-around.
The application does an astrodynamic computation in 3 variables, each of which may be set using a slider (a gtk_hscale, for instance), and displays the resulting satellite orbit in an OpenGL drawing.
However, the situation may equally well be described by 3 OTHER variables. So I have 3 additional sliders showing these values. When I change any one of the first 3 sliders, typically all three of the second set of sliders need to move to reflect new values. Similary, if any one of the second set of sliders is changed, all three of the first sliders need to move to show new values.
The probem stems from the GtkAdjustment callbacks and the fact that converting between the two sets of variables is quite complex. The complexity of the computation leads to slight rounding and truncation errors, so converting value set A to value set B and back to value set A does not exactly result in the original values.
Call the two sets of sliders A and B. Here is what happens:
1. Move a slider in set A.
2. A value_changed callback occurs, and I compute and set values for each slider in set B.
3. Next, because the sliders in set B have changed, I get three value_changed callbacks, each of which causes a recomputation of values for slider set A and causes their values to be reset
4. Because the sliders in set A have changed, I get more callbacks which recompute and set the sliders in set B.
5. Because the sliders in set B have changed, I get more callbacks which recompute and set the sliders in set A.
6. etc. ...
It will just loop forever.
So I need to be able to distinguish between a callback caused by the user and one caused by the program itself. I would act on the former and ignore the latter and the problem would be solved.