@@ -53,6 +53,10 @@ package body Src_Editor_View.Hyper_Mode is
5353 (Widget : access Gtk_Widget_Record'Class;
5454 Event : Gdk_Event) return Boolean;
5555
56+ function Toplevel_Focus_Out_Event_Cb
57+ (Widget : access Gtk_Widget_Record'Class;
58+ Event : Gdk_Event) return Boolean;
59+
5660 -- ---------------------
5761 -- Local subprograms --
5862 -- ---------------------
@@ -102,18 +106,26 @@ package body Src_Editor_View.Hyper_Mode is
102106 View.Hyper_Mode_Motion_Handler :=
103107 Return_Callback.Connect
104108 (View, Signal_Motion_Notify_Event,
105- Marsh => Return_Callback.To_Marshaller
106- (Motion_Notify_Event_Cb'Access ),
109+ Marsh =>
110+ Return_Callback.To_Marshaller (Motion_Notify_Event_Cb'Access ),
107111 After => False);
108112
109113 -- Connect to a button press on the view
110-
111114 View.Hyper_Mode_Button_Handler :=
112115 Return_Callback.Connect
113116 (View, Signal_Button_Press_Event,
114- Marsh => Return_Callback.To_Marshaller
115- (Button_Press_Event_Cb'Access ),
117+ Marsh =>
118+ Return_Callback.To_Marshaller (Button_Press_Event_Cb'Access ),
116119 After => False);
120+
121+ -- Monitor focus event on the toplevel
122+ View.Hyper_Mode_Toplevel_Focus_Handler :=
123+ Return_Callback.Object_Connect
124+ (View.Get_Toplevel,
125+ Signal_Focus_Out_Event,
126+ Return_Callback.To_Marshaller (Toplevel_Focus_Out_Event_Cb'Access ),
127+ Slot_Object => View,
128+ After => False);
117129 end Hyper_Mode_Enter ;
118130
119131 -- --------------------
@@ -160,6 +172,12 @@ package body Src_Editor_View.Hyper_Mode is
160172 Gtk.Handlers.Disconnect (View, View.Hyper_Mode_Button_Handler);
161173 View.Hyper_Mode_Button_Handler :=
162174 (Gtk.Handlers.Null_Handler_Id, null );
175+
176+ -- Disconnect the focus handler from the toplevel
177+ Gtk.Handlers.Disconnect
178+ (View.Get_Toplevel, View.Hyper_Mode_Toplevel_Focus_Handler);
179+ View.Hyper_Mode_Toplevel_Focus_Handler :=
180+ (Gtk.Handlers.Null_Handler_Id, null );
163181 end Hyper_Mode_Leave ;
164182
165183 -- -----------------------
@@ -280,4 +298,27 @@ package body Src_Editor_View.Hyper_Mode is
280298 return False;
281299 end Motion_Notify_Event_Cb ;
282300
301+ -- -------------------------------
302+ -- Toplevel_Focus_Out_Event_Cb --
303+ -- -------------------------------
304+
305+ function Toplevel_Focus_Out_Event_Cb
306+ (Widget : access Gtk_Widget_Record'Class;
307+ Event : Gdk_Event) return Boolean
308+ is
309+ pragma Unreferenced (Event);
310+ View : constant Source_View := Source_View (Widget);
311+ begin
312+ if Active (Me) then
313+ Trace (Me, " Focus Out " & Name (View));
314+ end if ;
315+
316+ Hyper_Mode_Leave (Widget);
317+ return False;
318+ exception
319+ when E : others =>
320+ Trace (Me, E);
321+ return False;
322+ end Toplevel_Focus_Out_Event_Cb ;
323+
283324end Src_Editor_View.Hyper_Mode ;
0 commit comments