Not all widgets get events. Synthetic events possible?




I started writing a program that will require dragging and layout of
arbitrary GTK+ widgets, and have come to the conclusion that it is not
possible to capture input events for all widget types.  For example,
GtkHBox, a common widget, has a signal for "button_press_event", but
it is unable to ever receive it.  I understand that the reason for
this is that there is no X-window associated with GtkHBox, but that is
not really a good reason.  It seems to me that any widget that does
not have a native X-window should receive synthesized events rather
than direct events.  Any non-window child of a windowed parent should
get a synthesized event if:
    a) the parent gets the event, and
    b) the child has been made sensitive to the event.
Obviously, this would need to be recursive.  Many optimizations are
possible to reduce the depth and frequency of searches through the
widget hierarchy looking for possible synthesized event targets.

Doing this would solve a few problems:
1) Widgets that advertise an event can actually get it.  This is
essentially all non-window widgets right now.
2) OO wrappers on GTK, or even C programs in GTK will be able to treat
widgets consistently, which is currently not possible
3) It would remove much X-centric (pun intended) behaviour from the
GTK+ toolkit, making porting easier
4) It would make it possible to run GTK on top of a primitive graphic
layer that does not provide window system functionality, such as MGL,
OpenGL or DirectX.

As an alternative that may be easier, though less general, could there
be a mechanism to force any/all widgets to declare an X-window so that
they could be made sensitive?

As an example, Photon in QNX has a flag on widgets that tells it
whether there is a window on the widget.  If no window exists, then
the event is synthesized.  In cases where synthesizing the event is
unreasonably costly in CPU, the window is added automatically to the
widget, increasing resource usage but always giving the correct
behaviour.  Widgets like buttons, sliders, labels, do not normally
have a windows, but get one if entry or cursor events are requested.
Button presses do not require a window since they are trivially
synthesized.

Andrew Thomas



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]