Skip to content

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

Merged
TurboGit merged 1 commit into
darktable-org:masterfrom
Arecsu:gtk4/no-gdk-event-direct-access
Jul 25, 2026
Merged

gtk4-prep: replace direct GdkEvent struct access with accessor functions#21544
TurboGit merged 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

@ralfbrown ralfbrown added the gtk4 label Jul 14, 2026
@TurboGit TurboGit added this to the 5.8 milestone Jul 16, 2026
@TurboGit

Copy link
Copy Markdown
Member

@Arecsu : This needs a conflict resolution. TIA.

@Arecsu

Arecsu commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@Arecsu : This needs a conflict resolution. TIA.

Done!

@TurboGit

Copy link
Copy Markdown
Member

The policy is to rebase and never merge master into a topic branch. Sorry should have been clear before :) Can you rebase? TIA.

@Arecsu
Arecsu force-pushed the gtk4/no-gdk-event-direct-access branch from 349599a to f2d8507 Compare July 24, 2026 20:49
@Arecsu

Arecsu commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for clarify, I didn't know. Just did it, please check!

@TurboGit TurboGit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested yet, looks good just minor comments.

Comment thread src/common/gdk_event_utils.h Outdated
@Arecsu
Arecsu force-pushed the gtk4/no-gdk-event-direct-access branch from f2d8507 to 421bdee Compare July 25, 2026 06:52
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
@Arecsu
Arecsu force-pushed the gtk4/no-gdk-event-direct-access branch from 421bdee to 53f1ad5 Compare July 25, 2026 06:53
@Arecsu

Arecsu commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Updated copyright headers to 2026 across all changed files. Done!

@TurboGit TurboGit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@TurboGit
TurboGit merged commit 1cf3e70 into darktable-org:master Jul 25, 2026
5 checks passed
@Arecsu
Arecsu deleted the gtk4/no-gdk-event-direct-access branch July 25, 2026 21:29
@TurboGit

Copy link
Copy Markdown
Member

@Arecsu : This introduce a regression, the zoom in/out is broken, both direction of the mouse wheel does zoom-in there is no way to zoom-out (in darkroom, shapes...). Can you fix? If this is not possible before tonight I'll revert this to let you rework this part without pressure. Just let me know, TIA.

@TurboGit

Copy link
Copy Markdown
Member

The issue #21622.

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.

3 participants