Skip to content

gtk4-prep: replace direct GdkEvent struct access with accessor functions#21544

Open
Arecsu wants to merge 1 commit into
darktable-org:masterfrom
Arecsu:gtk4/no-gdk-event-direct-access
Open

gtk4-prep: replace direct GdkEvent struct access with accessor functions#21544
Arecsu wants to merge 1 commit into
darktable-org:masterfrom
Arecsu:gtk4/no-gdk-event-direct-access

Conversation

@Arecsu

@Arecsu Arecsu commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Replace all direct GdkEvent struct member accesses:

  • event->type
  • event->button
  • event->x
  • event->y
  • event->state
  • event->keyval
  • event->time
  • event->window
  • event->scroll.direction
  • event->delta_x/event->delta_y
  • event->direction
  • event->hardware_keycode
  • etc.

With the corresponding gdk_event_get_*() accessor functions via thin inline wrappers in src/common/gdk_event_utils.h.

The wrapper functions (dt_gdk_event_get_*) accept const void* so any typed event pointer (GdkEventButton*, GdkEventKey*, etc.) can be passed without an explicit cast. They return the field value directly instead of using out-parameters.

This removes ~500 direct struct accesses across 65 files. Remaining direct accesses are limited to:

  • Synthetic event construction (writing to gdk_event_new() events)
  • Event mutation before forwarding
  • Fields without GTK3 accessor functions (configure.width/configure.height, crossing.mode/crossing.detail, key.is_modifier)

See https://docs.gtk.org/gtk4/migrating-3to4.html

Stop using direct access to GdkEvent structs

In GTK 4, event structs are opaque and immutable. Many fields already have accessors in GTK 3, and you should use those to reduce the amount of porting work you have to do at the time of the switch.

Related: "Stop using direct access to GdkEvent structs" #15920 #20433

Replace all direct GdkEvent struct member accesses (`event->type`, `event->button`, `event->x`, `event->y`, `event->state`, `event->keyval`, `event->time`, `event->window`, `event->scroll.direction`, `event->delta_x`/`event->delta_y`, `event->direction`, `event->hardware_keycode`, etc.) with the corresponding `gdk_event_get_*()` accessor functions via thin inline wrappers in `src/common/gdk_event_utils.h`.

The wrapper functions (`dt_gdk_event_get_*`) accept `const void*` so any typed event pointer (`GdkEventButton*`, `GdkEventKey*`, etc.) can be passed without an explicit cast. They return the field value directly instead of using out-parameters.

This removes ~500 direct struct accesses across 65 files. Remaining direct accesses are limited to:
- Synthetic event construction (writing to `gdk_event_new()` events)
- Event mutation before forwarding
- Fields without GTK3 accessor functions (`configure.width`/`configure.height`, `crossing.mode`/`crossing.detail`, `key.is_modifier`)

See https://docs.gtk.org/gtk4/migrating-3to4.html
@ralfbrown ralfbrown added the gtk4 label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants