From: Matthias Clasen Date: Sun, 9 Apr 2023 12:28:26 +0000 (-0400) Subject: gtk-demo: Work without stylus X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~4^2~10^2~31 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=4e340afce07097b4459b6ee16934cce76201c14b;p=gtk4.git gtk-demo: Work without stylus In the paint demo, don't assume that the event backlog contains pressure. It won't, if we are working with a plain old mouse. --- diff --git a/demos/gtk-demo/paint.c b/demos/gtk-demo/paint.c index 59561ed7b4..b9fb350215 100644 --- a/demos/gtk-demo/paint.c +++ b/demos/gtk-demo/paint.c @@ -263,7 +263,7 @@ drawing_area_apply_stroke (DrawingArea *area, double y, double pressure) { - if (gdk_device_tool_get_tool_type (tool) == GDK_DEVICE_TOOL_TYPE_ERASER) + if (tool && gdk_device_tool_get_tool_type (tool) == GDK_DEVICE_TOOL_TYPE_ERASER) { cairo_set_line_width (area->cr, 10 * pressure * area->brush_size); cairo_set_operator (area->cr, CAIRO_OPERATOR_DEST_OUT); @@ -314,7 +314,9 @@ stylus_gesture_motion (GtkGestureStylus *gesture, drawing_area_apply_stroke (area, tool, backlog[i].axes[GDK_AXIS_X], backlog[i].axes[GDK_AXIS_Y], - backlog[i].axes[GDK_AXIS_PRESSURE]); + backlog[i].flags & GDK_AXIS_FLAG_PRESSURE + ? backlog[i].axes[GDK_AXIS_PRESSURE] + : 1); } g_free (backlog);