GtkGesture for CAD applications?

GTK4 seems to favor Gestures instead of using plain GDK events. Events seems to still exist, see

but the term “Legacy” seems to indicate that we should avoid it.

Gestures may be simpler to use and may work better on touch devices. I have already played with a Nim version of ~/gtk/examples/drawing.c (formerly known as scribble window.)

But I still wonder if gestures works for applications like InkScape.

I have a simple CAD application which I wrote 10 years ago in Ruby, and rewrote partly in Nim. It is using GTK3 and plain GDK events. For porting to GTK4 I wonder if I should try hard to use only Gestures, or go on using Events with GtkEventControllerLegacy.

Gestures are fine for some operations like moving entities with drag operation. But I have many more operations to support. For example drawing a line is currently done by clicking on start position, moving mouse, clicking on end position. Of course we could do that with a drag gesture, but then we would have to hold the mouse button pressed for the whole operation. And then that gesture could not be used at the same time for moving objects. I would have to switch mode of operation when I want to move objects, or at least use a different mouse button or a keyboard qualifier. What I have for GTK3 is: click, move, click is drawing new line. Press, move, release is move object, i.e. for a line move whole line or move one of its endpoints. All with LMB and without mode switching. I like that mode of operation.

Currently I think that I would have to use GtkEventControllerLegacy, or that I would have to make the user interface more modal, so that user has to select mode of operation often. For touch devices Gestures may be a better solution, but doing CAD on a cellphone with fingers only is difficult. But maybe someone would use a Wacom tablet.

Events vs controllers is not an alternative - you need both to have any input in your application. Event controllers (and gestures) are a replacement for signal handlers connecting to GtkWidget event related signals, turned into objects so they can carry a little bit of state.

The legacy event controller is named that way because it is the equivalent of the ::event signal in GTK3 - even in 3.x, we preferred you using more specific signals like ::motion-notify-event or ::key-press-event. In GTK4, the equivalent of those signals are GtkEventControllerMotion and GtkEventControllerKey.

In any case, there’s nothing wrong with using those event controllers and managing input-related state yourself.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.