Figure event windowbuttondownfcn callback function empty currentposition in handle and also empty type

is this intended non-implemented behaviour or a bug.

DPH = figure(1,"windowbuttondownfcn", {@mycallback}); imshow(DPIMG);
function mycallback (h, evt)
  set(h)
endfunction

I would assume the h would be the caller figure handle, ie, same as DPH value, but the h does not give even type of “figure”. was trying to get the currentposition of the mouse in a click or mouse move. but: evt gives 1,2 or 3 for the mouse button index, so it at least partially works, not fully, smh.

win 11, octave 7.1.0

Works for me with this slightly modified example (functions must be defined before they are used in Octave):

function mycallback (h, evt)
h
endfunction
DPH = figure(1,"windowbuttondownfcn", {@mycallback});

Each time, I click on the figure h = 1 is printed in the command window.

just used what the documentation stated, where the functions can be after.

and yes h=1 will be printed, but set(h) will not contain currentpoint.
ie, the order of the function and main does not change outcome.
no mouse coordinates on the figure, if not it does not work.

octave does not complain about the function callback being after, btw.
do you use something else than win11 or 7.1.0.

edit:
in this official documentation the function is defined after. I guess the definition is implicit on the call.
Callbacks (GNU Octave (version 7.1.0))

it seems like the callback does not have access to the figure data properly, or the currentpoint in mouse pressed does not work properly.

edit 2: after restarting octave, it now complains about the “error: invalid function handle, unable to find function for @mycallback”, right. do you keep compatibility to matlab at 100% or have you considered c-style header function definitions. the current position property is not accessible as documentation promises, still.

scratch that, get() instead of set(), case closed, but documentation instructs putting the function definitions after, maybe update to make it clear

was only getting the set options for the option parameters, with the set(h, property-name).

Works for me:

function mycallback (h, evt)
h
get(h, 'CurrentPoint')
evt
endfunction
DPH = figure(1,"windowbuttondownfcn", @mycallback);

When I click at random positions inside the figure, I see:

h = 1
ans =

   314   332

evt = 3
h = 1
ans =

   300   163

evt = 3
h = 1
ans =

   178   273

evt = 2
h = 1
ans =

   385   138

evt = 2

I agree that the current documentation isn’t very clear about that. Maybe that is meant to indicate that the callback is defined as a local function inside a function file (in which case it needs to be defined after the “main” function). But that is not clear to me from the context given in the documentation either.

If you have suggestions how to be clearer about that, please help us improve the docstring.

This is correct. Most callback functions are local functions written as part of a larger m-file and thus appear after the main function which must take the name of the file itself.

Using a function defined on the command line in this instance just isn’t a natural coding style, although it can be made to work by defining the function before using it.