Re: Can A Drawable Canvas Receive Key Events?

2007-04-02 Thread Mike Melanson
Mike Melanson wrote:
> I found that when I put a big text widget inside the XEmbed'ed GtkPlug 
> container instead of a big drawable canvas, it was able to receive 
> focus. Digging into the GTK source code, I noticed that it calls 
> gtk_widget_grab_focus() when it receives a button press event. So I did 
> the same for my canvas widget when the user clicks in it, and it seems 
> to work. The widget retains focus until the user clicks outside of the 
> window.

I missed a crucial step here. You also need to specify that the 
ordinarily non-focusable widget can receive focus by setting its 
"can-focus" property:

   GTK_WIDGET_SET_FLAGS (GTK_WIDGET(my_widget), GTK_CAN_FOCUS);

-- 
-Mike Melanson
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Can A Drawable Canvas Receive Key Events?

2007-04-02 Thread Mike Melanson
Mike Melanson wrote:
> Tristan Van Berkom wrote:
>> Did you add the events to the event mask before the widget was
>> realized ?
>>
>> Does the widget in question have keyboard focus at the time
>> you want to recieve the keyboard events ?
>>
>> Is the widget in question marked to be focus-capable ?
>> (i.e. the can-focus bit/property)
> 
> This last item did the trick. I set the can-focus property and the 
> GtkDrawingArea now registers key presses and releases. Thanks.
> 
> Now that it works in the contrived standalone app, I need to figure out 
> how to get key events in an XEmbed'ed application. I apply the same 
> can-focus property change but I'm afraid I might be fighting with the 
> hosting app for the key events.

Answering my own question since I know there are interested people out 
there...

I found that when I put a big text widget inside the XEmbed'ed GtkPlug 
container instead of a big drawable canvas, it was able to receive 
focus. Digging into the GTK source code, I noticed that it calls 
gtk_widget_grab_focus() when it receives a button press event. So I did 
the same for my canvas widget when the user clicks in it, and it seems 
to work. The widget retains focus until the user clicks outside of the 
window.

Wow, I can't believe that looking at the source actually helped. :)

-- 
-Mike Melanson
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Can A Drawable Canvas Receive Key Events?

2007-03-31 Thread Mike Melanson
Tristan Van Berkom wrote:
> Did you add the events to the event mask before the widget was
> realized ?
> 
> Does the widget in question have keyboard focus at the time
> you want to recieve the keyboard events ?
> 
> Is the widget in question marked to be focus-capable ?
> (i.e. the can-focus bit/property)

This last item did the trick. I set the can-focus property and the 
GtkDrawingArea now registers key presses and releases. Thanks.

Now that it works in the contrived standalone app, I need to figure out 
how to get key events in an XEmbed'ed application. I apply the same 
can-focus property change but I'm afraid I might be fighting with the 
hosting app for the key events.

-- 
-Mike Melanson
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Can A Drawable Canvas Receive Key Events?

2007-03-30 Thread Tristan Van Berkom
On Fri, 2007-03-30 at 13:02 -0700, Mike Melanson wrote:
> Hi,
> 
> I have a standalone test app that has nothing inside the main window but 
> a big, drawable RGB canvas (GtkDrawingArea). I can receive nearly any 
> kind of event via the canvas: Expose, mouse motion, button 
> press/release, scroll wheel, etc. However, I *cannot* figure out how to 
> get key press events. I even added the key up/down events to the 
> widget's event list using the GDK_KEY_PRESS_MASK and 
> GDK_KEY_RELEASE_MASK flags passed to gtk_widget_add_events().
> 

Did you add the events to the event mask before the widget was
realized ?

Does the widget in question have keyboard focus at the time
you want to recieve the keyboard events ?

Is the widget in question marked to be focus-capable ?
(i.e. the can-focus bit/property)

Cheers,
 -Tristan


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Can A Drawable Canvas Receive Key Events?

2007-03-30 Thread Mike Melanson
Hi,

I have a standalone test app that has nothing inside the main window but 
a big, drawable RGB canvas (GtkDrawingArea). I can receive nearly any 
kind of event via the canvas: Expose, mouse motion, button 
press/release, scroll wheel, etc. However, I *cannot* figure out how to 
get key press events. I even added the key up/down events to the 
widget's event list using the GDK_KEY_PRESS_MASK and 
GDK_KEY_RELEASE_MASK flags passed to gtk_widget_add_events().

Is it even supposed to be possible to get key events for the canvas? Is 
a non-text widget forbidden from receiving key events? When I swap the 
canvas out for a more text-oriented widget, I get all the key events I want.

Thanks...
-- 
-Mike Melanson
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list