Sponsored by IST Limited
Formerly MW3: Motif on the World Wide Web [MW3 Logo]
Last Updated
November 18, 2002

X-Designer - The Leading X/Motif GUI Builder - Click to download a FREE evaluation
About the site
Bulletin Board
News Archive
OpenGroup News
Frequently Asked Questions
The Motif FAQ
X/Motif FAQs
General FAQs
Ask Antony
Latest Q & A
All Q & As
Submit Question
Tips & Pointers
Code Examples
Widget Sets
GUI Toolkits & Libraries
Motif suppliers
Non-commercial S/W
Commercial Software
Docs & Pubs
X/Motif Newsgroups
Feedback Form

Why does pressing a toggle button that is already selected cause the callback to be called twice?

4-Jan-02 14:00 GMT
Question: I have an application containing an XmRadioBox with two XmToggleButtons. If I press a toggle button that is already selected my value changed callback gets called twice.

The behavior, confusing as it looks, is actually correct.

The value changed callbacks are called twice as follows:

  • once for the previous toggle going off
  • once for the new toggle going on

Now if you press a toggle that is already on in a radio box, the old and the new toggle are the same, so the callback goes off for the same object.

Fortunately you can distinguish what is going on by looking at the callback data.

For the old toggle, the "event" element of the XmToggleButtonCallbackStruct will be NULL. The "set" element will also be zero, except if the same toggle has been pressed twice. For the new toggle, the "event" element will be properly set to point to some XButtonPressedEvent structure, and the "set" element will be true.


  • event is NULL, set is TRUE
    - hold on, another callback is coming for this toggle - it has been pressed again
  • event is NULL, set is FALSE
    - this was the previous selection - user has chosen a different toggle
  • event is not null, set is TRUE
    - this is the new toggle
  • event is not null, set is FALSE
    - only possible in a radio box if XmNradioAlwaysOne is FALSE. In which case, there are now no toggles set as the user has turned off the only selection.

It is also important to note that Motif 2.1 introduces an additional toggle state called indeterminate. When coding for Motif 2.1 this fact needs to be taken into consideration in the callback.

Hence if you want to process things only once, when a toggle is turned on, then this is the correct form of the callback:

void toggle_changed_callback(Widget w, XtPointer client, XtPointer call)
	 XmToggleButtonCallbackStruct *tp = (XmToggleButtonCallbackStruct *) call ;

	 if ((tp->event != (XEvent *) 0)) {
		 // do application action

#if (XmVERSION > 1)
		 /* Motif 2.1 */

		 if (tp->set == XmSET) {
			 // toggle is ON
		 else if (tp->set == XmINDETERMINATE) {
			 // toggle is in third indeterminate state
		 else if (tp->set == XmUNSET) {
			// toggle is OFF
#else /* (XmVERSION > 1) */
		 /* Motif 1.2 */

		 if (tp->set) {
			 // toggle is ON
		 else {
			 // toggle is OFF
#endif /* (XmVERSION > 1) */


Sponsored by X-Designer - The Leading X/Motif GUI Builder - Click to download a FREE evaluation


Goto top of page


[IST Limited]
IST Limited is the
proud sponsor of

Thanks to all the contributors to these pages.

Privacy Policy

"Motif" is a registered trademark of The Open Group. All other trademarks are the property of their respective owners.

Some articles/papers here have their own copyright notice. All other information is copyright ©1999-2008 IST Limited

[CommerceOne] MW3 site originally by Ken Sall of Commerce One (formerly Century Computing).