Fix initial GTK4 API compatibility issues in main-window.c, curve.c, and ds-marker.c

Co-authored-by: speed47 <218502+speed47@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-09-16 14:52:10 +00:00
parent 53ad97fe5a
commit 2a9da5806b
3 changed files with 35 additions and 26 deletions

View File

@@ -135,10 +135,16 @@ int GuiCurveLogY(Curve *curve, gdouble y) /* not really a log */
***/
void GuiUpdateCurveGeometry(Curve *curve, char *largest_left_label, int right_padding)
{ GtkAllocation a = {0};
{ graphene_rect_t bounds;
int w,h;
gtk_widget_get_allocation(curve->widget, &a);
if (!gtk_widget_compute_bounds(curve->widget, curve->widget, &bounds)) {
/* Fallback if compute_bounds fails */
bounds.origin.x = 0;
bounds.origin.y = 0;
bounds.size.width = 640;
bounds.size.height = 480;
}
/* Top and bottom margins */
@@ -146,13 +152,13 @@ void GuiUpdateCurveGeometry(Curve *curve, char *largest_left_label, int right_pa
curve->topY = h + 10;
GuiSetText(curve->layout, "0123456789", &w, &h);
curve->bottomY = a.height - h - 10;
curve->bottomY = bounds.size.height - h - 10;
/* Left and right margins */
GuiSetText(curve->layout, largest_left_label, &w, &h);
curve->leftX = 5 + 6 + 3 + w;
curve->rightX = a.width - right_padding;
curve->rightX = bounds.size.width - right_padding;
/* Add space for the lograithmic curve */
@@ -181,9 +187,9 @@ void GuiRedrawAxes(cairo_t *cr, Curve *curve)
/* Get foreground and grid colors */
GdkRGBA fg = {0};
GdkRGBA fg = {0.0, 0.0, 0.0, 1.0}; /* Default to black */
GtkStyleContext *context = gtk_widget_get_style_context(curve->widget);
gtk_style_context_get_color(context, gtk_widget_get_state_flags(curve->widget), &fg);
gtk_style_context_get_color(context, &fg);
GdkRGBA grid = fg;
grid.alpha = 0.25;

View File

@@ -265,9 +265,8 @@ int CheckForMissingSectors(unsigned char *buf, guint64 sector,
#ifdef WITH_GUI_YES
static void insert_buttons(GtkDialog *dialog)
{
gtk_dialog_add_buttons(dialog,
_utf("Stop reporting these errors"), 1,
_utf("Continue reporting"), 0, NULL);
gtk_dialog_add_button(dialog, _utf("Stop reporting these errors"), 1);
gtk_dialog_add_button(dialog, _utf("Continue reporting"), 0);
}
#endif

View File

@@ -256,14 +256,14 @@ static GtkWidget *create_button(char *label, char *icon, gint scale)
button = gtk_button_new();
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_LARGE_TOOLBAR);
image = gtk_image_new_from_icon_name(icon);
lab = gtk_label_new(utf_label);
g_free(utf_label);
gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), lab, FALSE, FALSE, 0);
gtk_box_append(GTK_BOX(box), image);
gtk_box_append(GTK_BOX(box), lab);
gtk_container_add(GTK_CONTAINER(button), box);
gtk_button_set_child(GTK_BUTTON(button), box);
// gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
return button;
@@ -343,7 +343,7 @@ static GtkWidget* create_action_bar(GtkNotebook *notebook)
wid = create_button(_("button|Stop"), "stop", scale);
g_signal_connect(G_OBJECT(wid), "clicked", G_CALLBACK(action_cb), (gpointer)ACTION_STOP);
gtk_box_pack_end(GTK_BOX(vbox), wid, FALSE, FALSE, 0);
gtk_box_append(GTK_BOX(vbox), wid);
GuiAttachTooltip(wid, _("tooltip|Abort action"),
_("Aborts an ongoing action."));
@@ -406,23 +406,26 @@ void GuiCreateMainWindow(int *argc, char ***argv)
char title[80];
int sig_okay = TRUE;
/* Ignore argc/argv parameters as GTK4 gtk_init() doesn't need them */
/*** Initialize GTK+ */
gtk_init(argc, argv);
gtk_init();
/*** Set path to our icons */
gtk_icon_theme_add_resource_path(gtk_icon_theme_get_default(), "/dvdisaster/");
gtk_icon_theme_add_resource_path(gtk_icon_theme_get_for_display(gdk_display_get_default()), "/dvdisaster/");
/*** Open the main window */
g_snprintf(title, 80, "dvdisaster-%s", Closure->cookedVersion);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
window = gtk_window_new();
gtk_window_set_title(GTK_WINDOW(window), title);
if(sig_okay)
gtk_window_set_default_size(GTK_WINDOW(window), -1, 550);
gtk_window_set_icon(GTK_WINDOW(window), Closure->windowIcon);
/* gtk_window_set_icon is deprecated in GTK4 - use gtk_window_set_icon_name instead */
gtk_window_set_icon_name(GTK_WINDOW(window), "dvdisaster");
Closure->window = GTK_WINDOW(window);
/* Connect with the close button from the window manager */
@@ -483,28 +486,29 @@ void GuiCreateMainWindow(int *argc, char ***argv)
Closure->status = gtk_label_new(NULL);
gtk_label_set_ellipsize(GTK_LABEL(Closure->status), PANGO_ELLIPSIZE_END);
gtk_label_set_xalign(GTK_LABEL(Closure->status), 0.0);
gtk_box_pack_start(GTK_BOX(status_box), GTK_WIDGET(Closure->status), TRUE, TRUE, 5);
gtk_box_append(GTK_BOX(status_box), GTK_WIDGET(Closure->status));
button = gtk_button_new();
gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
gtk_box_pack_end(GTK_BOX(status_box), button, FALSE, FALSE, 5);
/* gtk_button_set_relief is deprecated in GTK4 */
gtk_box_append(GTK_BOX(status_box), button);
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(log_cb), NULL);
GuiAttachTooltip(button,
_("tooltip|Protocol for current action"),
_("Displays additional information created during the current or last action."));
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add(GTK_CONTAINER(button), box);
gtk_button_set_child(GTK_BUTTON(button), box);
icon = gtk_image_new_from_icon_name("log", GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_box_pack_start(GTK_BOX(box), icon, FALSE, FALSE, 2);
icon = gtk_image_new_from_icon_name("log");
gtk_box_append(GTK_BOX(box), icon);
wid = gtk_label_new(_utf("View log"));
gtk_box_pack_start(GTK_BOX(box), wid, FALSE, FALSE, 0);
gtk_box_append(GTK_BOX(box), wid);
/* And enter the main loop */
gtk_widget_show_all(window);
gtk_widget_show(window);
/* gtk_main is deprecated in GTK4, but keeping it for now - will need to refactor to GtkApplication later */
gtk_main();
}
#endif /* WITH_GUI_YES */