@@ -546,6 +546,7 @@ contains |
| 546 | 546 | type(tab_state), pointer :: tab |
| 547 | 547 | character(len=1024) :: selected_path |
| 548 | 548 | integer :: status |
| 549 | + integer(c_int) :: idle_id |
| 549 | 550 | |
| 550 | 551 | print *, "Open Directory button clicked!" |
| 551 | 552 | |
@@ -559,12 +560,12 @@ contains |
| 559 | 560 | ! Call helper to show native file picker |
| 560 | 561 | call show_native_directory_picker(selected_path, status) |
| 561 | 562 | |
| 562 | | - ! Restore window focus after dialog (native dialogs steal focus on macOS) |
| 563 | | - if (c_associated(main_window_ptr)) then |
| 564 | | - call gtk_window_present(main_window_ptr) |
| 565 | | - end if |
| 566 | | - |
| 567 | 563 | if (status == 0 .and. len_trim(selected_path) > 0) then |
| 564 | + ! Restore window focus after dialog using idle callback |
| 565 | + ! (deferred to let macOS finish cleaning up osascript dialog) |
| 566 | + if (c_associated(main_window_ptr)) then |
| 567 | + idle_id = g_idle_add(c_funloc(restore_window_focus), c_null_ptr) |
| 568 | + end if |
| 568 | 569 | print *, "Selected directory: ", trim(selected_path) |
| 569 | 570 | |
| 570 | 571 | ! Update tab scan path (but don't scan yet) |
@@ -1683,6 +1684,21 @@ contains |
| 1683 | 1684 | end if |
| 1684 | 1685 | end subroutine sniffly_update_status |
| 1685 | 1686 | |
| 1687 | + ! Idle callback to restore window focus after native dialogs |
| 1688 | + function restore_window_focus(user_data) bind(c) result(continue) |
| 1689 | + type(c_ptr), value :: user_data |
| 1690 | + integer(c_int) :: continue |
| 1691 | + |
| 1692 | + ! Restore window focus |
| 1693 | + if (.not. app_is_shutting_down .and. c_associated(main_window_ptr)) then |
| 1694 | + call gtk_window_present(main_window_ptr) |
| 1695 | + print *, "Window focus restored after dialog" |
| 1696 | + end if |
| 1697 | + |
| 1698 | + ! Return 0 to indicate the idle callback should not repeat (one-shot) |
| 1699 | + continue = 0_c_int |
| 1700 | + end function restore_window_focus |
| 1701 | + |
| 1686 | 1702 | ! Timeout callback to clear status message (called after 5 seconds) |
| 1687 | 1703 | function clear_status_message(user_data) bind(c) result(continue) |
| 1688 | 1704 | type(c_ptr), value :: user_data |