Skip to content

Commit

Permalink
linux: use gtk_widget_get_toplevel
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Sep 18, 2024
1 parent 81239d4 commit d7f8924
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions gral_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,29 +324,29 @@ struct _GralArea {
G_DEFINE_TYPE(GralArea, gral_area, GTK_TYPE_DRAWING_AREA)

static gboolean gral_area_draw(GtkWidget *widget, cairo_t *cr) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
GdkRectangle clip_rectangle;
gdk_cairo_get_clip_rectangle(cr, &clip_rectangle);
window->interface.draw((struct gral_draw_context *)cr, clip_rectangle.x, clip_rectangle.y, clip_rectangle.width, clip_rectangle.height, window->user_data);
return GDK_EVENT_STOP;
}
static void gral_area_size_allocate(GtkWidget *widget, GtkAllocation *allocation) {
GTK_WIDGET_CLASS(gral_area_parent_class)->size_allocate(widget, allocation);
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
window->interface.resize(allocation->width, allocation->height, window->user_data);
}
static gboolean gral_area_enter_notify_event(GtkWidget *widget, GdkEventCrossing *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
window->interface.mouse_enter(window->user_data);
return GDK_EVENT_STOP;
}
static gboolean gral_area_leave_notify_event(GtkWidget *widget, GdkEventCrossing *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
window->interface.mouse_leave(window->user_data);
return GDK_EVENT_STOP;
}
static gboolean gral_area_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
if (window->is_pointer_locked) {
GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(window));
GdkDisplay *display = gdk_screen_get_display(screen);
Expand All @@ -371,7 +371,7 @@ static gboolean gral_area_motion_notify_event(GtkWidget *widget, GdkEventMotion
return GDK_EVENT_STOP;
}
static gboolean gral_area_button_press_event(GtkWidget *widget, GdkEventButton *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
if (event->type == GDK_BUTTON_PRESS) {
window->interface.mouse_button_press(event->x, event->y, event->button, get_modifiers(event->state), window->user_data);
}
Expand All @@ -381,12 +381,12 @@ static gboolean gral_area_button_press_event(GtkWidget *widget, GdkEventButton *
return GDK_EVENT_STOP;
}
static gboolean gral_area_button_release_event(GtkWidget *widget, GdkEventButton *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
window->interface.mouse_button_release(event->x, event->y, event->button, window->user_data);
return GDK_EVENT_STOP;
}
static gboolean gral_area_scroll_event(GtkWidget *widget, GdkEventScroll *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
gdouble delta_x, delta_y;
gdk_event_get_scroll_deltas((GdkEvent *)event, &delta_x, &delta_y);
window->interface.scroll(-delta_x, -delta_y, window->user_data);
Expand Down Expand Up @@ -433,7 +433,7 @@ static int get_key(GdkEventKey *event) {
}
static gboolean gral_area_key_press_event(GtkWidget *widget, GdkEventKey *event) {
GralArea *area = GRAL_AREA(widget);
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
gtk_im_context_filter_keypress(area->im_context, event);
int key = get_key(event);
if (key) {
Expand All @@ -443,7 +443,7 @@ static gboolean gral_area_key_press_event(GtkWidget *widget, GdkEventKey *event)
}
static gboolean gral_area_key_release_event(GtkWidget *widget, GdkEventKey *event) {
GralArea *area = GRAL_AREA(widget);
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
gtk_im_context_filter_keypress(area->im_context, event);
int key = get_key(event);
if (key) {
Expand All @@ -452,16 +452,16 @@ static gboolean gral_area_key_release_event(GtkWidget *widget, GdkEventKey *even
return GDK_EVENT_STOP;
}
static void gral_area_commit(GtkIMContext *context, gchar *str, gpointer user_data) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(GTK_WIDGET(user_data)));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(user_data)));
window->interface.text(str, window->user_data);
}
static gboolean gral_area_focus_in_event(GtkWidget *widget, GdkEventFocus *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
window->interface.focus_enter(window->user_data);
return GDK_EVENT_STOP;
}
static gboolean gral_area_focus_out_event(GtkWidget *widget, GdkEventFocus *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
GralWindow *window = GRAL_WINDOW(gtk_widget_get_toplevel(widget));
window->interface.focus_leave(window->user_data);
return GDK_EVENT_STOP;
}
Expand Down

0 comments on commit d7f8924

Please sign in to comment.