Question

How can I register a callback to get mouse right button down and up events?

Background: The xload application that comes standard with many UNIX flavors is almost handy. It draws a graph of system load by time. It uses a simple StripChart widget that is flawed; it draws the grid wrong. I've fixed that, but now I want to be able to click on the strip chart graph and get the time corresponding to that load.

The source is here: http://learjeff.net/forums/xload .

The main sets things up and calls XtAppMainLoop. I want to know how to register (for the child StripChart panel) a handler to get mouse up-down events, and how to find the mouse location in the panel on the down events. I'm not an X11 programmer; I'm just hacking an existing program. The last time I did GUI programming was pre-X11 (SunWindows). I did once modify X11 to run over OSI TP4, but that didn't require much knowledge of widgets. Any and all help appreciated, including pointers to the right functions to look up. Thanks!

Meanwhile, feel free to use my modified xload app. You'll have to guess what the numbers on the label mean.

Was it helpful?

Solution

The program is written using X Toolkit Intrinsics and Xaw.

You want to add one or more actions to the widget in question (the actions field in the core of struct stripChartClassRec) and one or more translations (the tm_table field).

Actions are C functions called in response to abstract events that you, the widget writer, define (like e.g. startDragging() or pageDown()). Translations map these abstract events to concrete events that Xt understands (like e.g. <Btn1Down> or <Key>KP_PageUp).

Inside the action you have access to the XEvent struct that has triggered the action, and from there you can get mouse coordinates or whatever.

To see how actions and translations are set up, look at one of the existing Xaw widgets, e.g. Panner. You can download the Xaw source here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top