fortrangoingonforty/sniffly / bd09f9e

Browse files

defer window focus restoration after dialog to idle cycle

Co-Authored-By: mfwolffe <wolffemf@dukes.jmu.edu>
Authored by espadonne
SHA
bd09f9ee8edc5a246a7e658c1e1dd3123610d891
Parents
2ec9f67
Tree
63a972f

1 changed file

StatusFile+-
M src/gui/gtk_app.f90 21 5
src/gui/gtk_app.f90modified
@@ -546,6 +546,7 @@ contains
546
     type(tab_state), pointer :: tab
546
     type(tab_state), pointer :: tab
547
     character(len=1024) :: selected_path
547
     character(len=1024) :: selected_path
548
     integer :: status
548
     integer :: status
549
+    integer(c_int) :: idle_id
549
 
550
 
550
     print *, "Open Directory button clicked!"
551
     print *, "Open Directory button clicked!"
551
 
552
 
@@ -559,12 +560,12 @@ contains
559
     ! Call helper to show native file picker
560
     ! Call helper to show native file picker
560
     call show_native_directory_picker(selected_path, status)
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
     if (status == 0 .and. len_trim(selected_path) > 0) then
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
       print *, "Selected directory: ", trim(selected_path)
569
       print *, "Selected directory: ", trim(selected_path)
569
 
570
 
570
       ! Update tab scan path (but don't scan yet)
571
       ! Update tab scan path (but don't scan yet)
@@ -1683,6 +1684,21 @@ contains
1683
     end if
1684
     end if
1684
   end subroutine sniffly_update_status
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
   ! Timeout callback to clear status message (called after 5 seconds)
1702
   ! Timeout callback to clear status message (called after 5 seconds)
1687
   function clear_status_message(user_data) bind(c) result(continue)
1703
   function clear_status_message(user_data) bind(c) result(continue)
1688
     type(c_ptr), value :: user_data
1704
     type(c_ptr), value :: user_data