Skip to content

remove gtk_dialog_run#715

Open
lidaobing wants to merge 1 commit intomainfrom
bf_remove_gtk_dialog_run
Open

remove gtk_dialog_run#715
lidaobing wants to merge 1 commit intomainfrom
bf_remove_gtk_dialog_run

Conversation

@lidaobing
Copy link
Member

@lidaobing lidaobing commented Feb 1, 2026

Summary by Sourcery

Enhancements:

  • Make information and warning dialogs non-blocking by destroying them via response signal handlers instead of gtk_dialog_run.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 1, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors informational and warning dialog helpers to use non-blocking GTK dialog handling by showing the dialog and destroying it on response instead of using gtk_dialog_run.

Sequence diagram for nonblocking info and warning dialogs

sequenceDiagram
  actor User
  participant Application
  participant UiHelper
  participant GTKDialog

  Application->>UiHelper: pop_info(parent, format, ...)
  activate UiHelper
  UiHelper->>GTKDialog: create GtkMessageDialog(parent, message)
  UiHelper->>GTKDialog: gtk_message_dialog_set_markup(msg)
  UiHelper->>GTKDialog: gtk_window_set_title("Information")
  UiHelper->>GTKDialog: g_signal_connect("response", gtk_widget_destroy)
  UiHelper->>GTKDialog: gtk_widget_show()
  deactivate UiHelper
  note right of Application: Application continues

  User->>GTKDialog: Clicks response button
  GTKDialog-->>GTKDialog: emit response signal
  GTKDialog-->>GTKDialog: gtk_widget_destroy(dialog)
  destroy GTKDialog
Loading

File-Level Changes

Change Details Files
Switch message dialogs from blocking gtk_dialog_run to signal-based asynchronous destruction on response.
  • Remove synchronous gtk_dialog_run invocation for information dialog helper.
  • Remove explicit immediate gtk_widget_destroy following dialog_run.
  • Connect dialog "response" signal to gtk_widget_destroy callback to clean up when user responds.
  • Show the dialogs explicitly with gtk_widget_show so they appear without blocking the main loop.
src/iptux/UiHelper.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • If these dialogs are expected to remain modal like they were with gtk_dialog_run, consider explicitly setting them as modal/transient for the parent (e.g., gtk_window_set_modal / gtk_window_set_transient_for) to preserve the original interaction behavior.
  • If the dialog contains additional child widgets (buttons, labels, etc.), you may want to use gtk_widget_show_all(dialog) instead of gtk_widget_show(dialog) to ensure all content becomes visible in non-blocking mode.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- If these dialogs are expected to remain modal like they were with `gtk_dialog_run`, consider explicitly setting them as modal/transient for the parent (e.g., `gtk_window_set_modal` / `gtk_window_set_transient_for`) to preserve the original interaction behavior.
- If the dialog contains additional child widgets (buttons, labels, etc.), you may want to use `gtk_widget_show_all(dialog)` instead of `gtk_widget_show(dialog)` to ensure all content becomes visible in non-blocking mode.

## Individual Comments

### Comment 1
<location> `src/iptux/UiHelper.cpp:189` </location>
<code_context>
   gtk_window_set_title(GTK_WINDOW(dialog), _("Information"));
-  gtk_dialog_run(GTK_DIALOG(dialog));
-  gtk_widget_destroy(dialog);
+  g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
+  gtk_widget_show(dialog);
 }
</code_context>

<issue_to_address>
**issue (bug_risk):** The response handler signature no longer matches gtk_widget_destroy.

"response" handlers receive (GtkDialog*, gint), but gtk_widget_destroy takes only a GtkWidget*. With this direct connection the gint will be treated as a pointer, causing undefined behavior or crashes. Instead, either use g_signal_connect_swapped with the dialog as user data, or create a wrapper callback matching the response signature that calls gtk_widget_destroy(dialog).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

gtk_window_set_title(GTK_WINDOW(dialog), _("Information"));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): The response handler signature no longer matches gtk_widget_destroy.

"response" handlers receive (GtkDialog*, gint), but gtk_widget_destroy takes only a GtkWidget*. With this direct connection the gint will be treated as a pointer, causing undefined behavior or crashes. Instead, either use g_signal_connect_swapped with the dialog as user data, or create a wrapper callback matching the response signature that calls gtk_widget_destroy(dialog).

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the blocking gtk_dialog_run() usage from the pop_info() and pop_warning() helper dialogs, switching them to a signal-driven, non-blocking display pattern.

Changes:

  • Replace gtk_dialog_run() + immediate destroy with a "response" handler that destroys the dialog.
  • Show the dialog via gtk_widget_show() instead of entering a nested modal loop.

Comment on lines +189 to +190
g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
gtk_widget_show(dialog);
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

The "response" signal has the signature (GtkDialog*, gint response_id, gpointer), but gtk_widget_destroy takes only a single GtkWidget*. Connecting it directly relies on undefined behavior/calling convention quirks. Use g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog) or a small wrapper callback with the proper signature that destroys the dialog.

Copilot uses AI. Check for mistakes.
Comment on lines +219 to +220
g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
gtk_widget_show(dialog);
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

Removing gtk_dialog_run makes this dialog non-blocking; any callers that expect the warning to be shown/acknowledged before continuing will break. For example, Application::onActivate (src/iptux/Application.cpp:221-226) calls pop_warning() and then immediately quits the application, so the warning dialog may never be presented. Either keep pop_warning synchronous (e.g., run a local main loop until response) or refactor callers to perform follow-up actions (like quitting) from the dialog's response handler.

Suggested change
g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
gtk_widget_show(dialog);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Feb 1, 2026

Test Results

69 tests  ±0   69 ✅ ±0   3s ⏱️ ±0s
32 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 1411b40. ± Comparison against base commit 5a63f29.

@codecov
Copy link

codecov bot commented Feb 1, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.75%. Comparing base (5a63f29) to head (1411b40).

Files with missing lines Patch % Lines
src/iptux/UiHelper.cpp 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #715   +/-   ##
=======================================
  Coverage   51.75%   51.75%           
=======================================
  Files          64       64           
  Lines        8704     8704           
=======================================
  Hits         4505     4505           
  Misses       4199     4199           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments