Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

po/colorpicker edit - edit area & point #17051

Merged
merged 3 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gui/gtk.c: Add new routine dt_gui_simulate_button_event.
This Gtk routine can be used to generated a mouse button event
to any widget.
  • Loading branch information
TurboGit committed Nov 15, 2024
commit 7d9600742e42b8483f9352c67800868754afd26a
34 changes: 34 additions & 0 deletions src/gui/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4405,6 +4405,40 @@ void dt_gui_process_events()
continue;
}

void dt_gui_simulate_button_event(GtkWidget *widget,
const GdkEventType eventtype,
const int button)
{
gboolean res = FALSE;

// Create the event GdkEventButton
GdkEventButton event;
memset(&event, 0, sizeof(event));

event.type = eventtype;
event.window = gtk_widget_get_window(widget);
event.send_event = TRUE;
event.time = GDK_CURRENT_TIME;
event.x = 0; // not important in this case
event.y = 0; // not important in this case
event.button = button;
event.device =
gdk_seat_get_pointer(gdk_display_get_default_seat(gdk_display_get_default()));

if (event.window != NULL)
{
g_object_ref(event.window);
}

// send signal
g_signal_emit_by_name(G_OBJECT(widget), "button-press-event", &event, &res, NULL);

if (event.window != NULL)
{
g_object_unref(event.window);
}
}

// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
Expand Down
5 changes: 5 additions & 0 deletions src/gui/gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,11 @@ void dt_gui_cursor_clear_busy();
// (i.e. the current function will do a lot of work before returning)
void dt_gui_process_events();

// Simulate a mouse button event (button is 1, 2, 3 - mouse button) sent to a Widget
void dt_gui_simulate_button_event(GtkWidget *widget,
const GdkEventType eventtype,
const int button);

#ifdef __cplusplus
} // extern "C"
#endif /* __cplusplus */
Expand Down