Sign up

DrawingArea focus

I'm having trouble getting a DrawingArea to have focus. I've set up all of the properties that I could find related to focus:

drawingArea.addEvents(GdkEventMask.ALL_EVENTS_MASK);
drawingArea.setCanFocus(true);
drawingArea.setFocusOnClick(true);
drawingArea.setReceivesDefault(true);
drawingArea.grabFocus();

Indeed, when the window opens the DrawingArea has focus, which I can see because the drawing handler checks the focus with hasFocus and conditionally draws a line. But once I click some other control that captures focus (e.g. a TreeView) the focus never returns to the DrawingArea.

I thought that the DrawingArea might be rejecting the focus, so I tried adding handlers for addOnFocus and addOnFocusIn that returned true to prevent any other further event handling, but that didn't work either.

Any ideas?

Re: DrawingArea focus

On 09-02-18 16:44, Luís Marques wrote:

I'm having trouble getting a DrawingArea to have focus. I've set up all of the properties that I could find related to focus:

drawingArea.addEvents(GdkEventMask.ALL_EVENTS_MASK);
drawingArea.setCanFocus(true);
drawingArea.setFocusOnClick(true);
drawingArea.setReceivesDefault(true);
drawingArea.grabFocus();

Indeed, when the window opens the DrawingArea has focus, which I can see because the drawing handler checks the focus with hasFocus and conditionally draws a line. But once I click some other control that captures focus (e.g. a TreeView) the focus never returns to the DrawingArea.

I thought that the DrawingArea might be rejecting the focus, so I tried adding handlers for addOnFocus and addOnFocusIn that returned true to prevent any other further event handling, but that didn't work either.

Any ideas?

Is the drawing handler actually called? you may need to invalidate the
DrawingArea by calling queueDraw in the OnFocusIn handler.

Re: DrawingArea focus

On Fri, 9 Feb 2018 23:11:13 +0100, Mike Wey wrote:

Is the drawing handler actually called? you may need to invalidate the
DrawingArea by calling queueDraw in the OnFocusIn handler.

Yes. I'm sure about that.

Re: DrawingArea focus

On Fri, 09 Feb 2018 22:30:24 GMT, Luís Marques wrote:

On Fri, 9 Feb 2018 23:11:13 +0100, Mike Wey wrote:

Is the drawing handler actually called? you may need to invalidate the
DrawingArea by calling queueDraw in the OnFocusIn handler.

Yes. I'm sure about that.

Any more ideas?

Re: DrawingArea focus

On 10-02-18 17:47, Luís Marques wrote:

On Fri, 09 Feb 2018 22:30:24 GMT, Luís Marques wrote:

On Fri, 9 Feb 2018 23:11:13 +0100, Mike Wey wrote:

Is the drawing handler actually called? you may need to invalidate the
DrawingArea by calling queueDraw in the OnFocusIn handler.

Yes. I'm sure about that.

Any more ideas?

Unfortunately no not currently.

Re: DrawingArea focus

On Sat, 10 Feb 2018 18:05:54 +0100, Mike Wey wrote:

On 10-02-18 17:47, Luís Marques wrote:

Any more ideas?

Unfortunately no not currently.

I had one more idea, but no cigar:

auto focusChain = new ListG(null);
focusChain.append(drawingArea.getWidgetStruct);
mainPaned.setFocusChain(focusChain);

Re: DrawingArea focus

On Fri, 09 Feb 2018 15:44:44 GMT, Luís Marques wrote:

Any ideas?

From what I can tell, despite the misleading presence of the method setFocusOnClick, you have to manualy do a grabFocus on the click event handler of the DrawingArea widget. Also, you have to intercept the keyboard events to not lose focus after a key click, and whatever else that might influence the focus. Lame.