Skip to content

Commit ada3b77

Browse files
BoulangerAdrienBoulanger
authored andcommitted
Add handler to deactivate hyperlink when changing workspace
On Ubuntu 22.04, when changing workspace using "CTRL+ALT+Arrow" the Hyperlink mode is never deactivated. Thus when going back to GS, all action are using CTRL modifier until the CTRL has been released once manually. Monitor Focus_Out on the main window to deactivate hyperlink mode.
1 parent 67b94f3 commit ada3b77

File tree

2 files changed

+57
-12
lines changed

2 files changed

+57
-12
lines changed

src_editor/src/src_editor_view-hyper_mode.adb

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
283324
end Src_Editor_View.Hyper_Mode;

src_editor/src/src_editor_view.ads

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,21 +375,25 @@ private
375375

376376
-- Handling of hyper mode
377377

378-
Hyper_Mode : Boolean := False;
378+
Hyper_Mode : Boolean := False;
379379

380-
Hyper_Mode_Motion_Handler : Gtk.Handlers.Handler_Id :=
381-
(Gtk.Handlers.Null_Handler_Id, null);
380+
Hyper_Mode_Motion_Handler : Gtk.Handlers.Handler_Id :=
381+
(Gtk.Handlers.Null_Handler_Id, null);
382382
-- The handler id for the callback that reacts to the motion
383383

384-
Hyper_Mode_Button_Handler : Gtk.Handlers.Handler_Id :=
385-
(Gtk.Handlers.Null_Handler_Id, null);
384+
Hyper_Mode_Button_Handler : Gtk.Handlers.Handler_Id :=
385+
(Gtk.Handlers.Null_Handler_Id, null);
386386
-- The handler id for the callback that reacts to mouse button presses
387387

388-
Cursor_Needs_Change : Boolean := False;
388+
Hyper_Mode_Toplevel_Focus_Handler : Gtk.Handlers.Handler_Id :=
389+
(Gtk.Handlers.Null_Handler_Id, null);
390+
-- The handler id for the callback that reacts to toplevel focus out
391+
392+
Cursor_Needs_Change : Boolean := False;
389393
-- Whether we just entered hyper mode, and the cursor aspect needs
390394
-- to be changed.
391395

392-
Source_Buffer_Handlers : Handlers_Array (1 .. 5);
396+
Source_Buffer_Handlers : Handlers_Array (1 .. 5);
393397
end record;
394398

395399
end Src_Editor_View;

0 commit comments

Comments
 (0)