66 */
77
88public class Gala.FocusController : Object {
9- public static FocusController get_default (Clutter .Stage stage ) {
10- return instance. once (() = > new FocusController (stage));
11- }
9+ private static HashTable<Clutter . Stage , FocusController > instances;
1210
13- public Clutter . Stage stage { get ; construct; }
11+ static construct {
12+ instances = new HashTable<Clutter . Stage , FocusController > (null , null );
13+ }
1414
15- private bool _focus_visible = false ;
16- public bool focus_visible {
17- get { return _focus_visible; }
18- private set {
19- _focus_visible = value ;
20- if (stage. get_key_focus () is Focusable ) {
21- ((Focusable ) stage. get_key_focus ()). notify_visible_focus_changed ();
22- }
15+ public static FocusController get_for_stage (Clutter .Stage stage ) {
16+ if (! instances. contains (stage)) {
17+ instances[stage] = new FocusController (stage);
2318 }
19+ return instances[stage];
2420 }
2521
26- private static GLib . Once<FocusController > instance;
27-
28- private Gee . List<unowned Focusable > root_focusables;
22+ public Clutter . Stage stage { get ; construct; }
23+ public bool focus_visible { get ; private set ; default = false ; }
2924
25+ private Gee . List<weak Focusable > root_focusables;
3026 private uint timeout_id = 0 ;
3127
32- public FocusController (Clutter .Stage stage ) {
28+ private FocusController (Clutter .Stage stage ) {
3329 Object (stage: stage);
3430 }
3531
3632 construct {
3733 root_focusables = new Gee .LinkedList<unowned Focusable > ();
38- stage. key_press_event. connect (on_key_press_event );
34+ stage. key_press_event. connect (handle_key_event );
3935 }
4036
4137 public void register_root (Focusable root ) {
@@ -48,15 +44,6 @@ public class Gala.FocusController : Object {
4844 root. weak_ref ((obj) = > root_focusables. remove ((Focusable ) obj));
4945 }
5046
51- private bool on_key_press_event (Clutter .Event event ) {
52- if (handle_key_event (event) == Clutter . EVENT_STOP ) {
53- show_focus ();
54- return Clutter . EVENT_STOP ;
55- }
56-
57- return Clutter . EVENT_PROPAGATE ;
58- }
59-
6047 private bool handle_key_event (Clutter .Event event ) {
6148 Focusable ? mapped_root = null ;
6249 foreach (var root_focusable in root_focusables) {
@@ -72,14 +59,16 @@ public class Gala.FocusController : Object {
7259 return Clutter . EVENT_PROPAGATE ;
7360 }
7461
75- if (! mapped_root. focus (direction)) {
62+ if (! mapped_root. focus (direction)) {
7663#if HAS_MUTTER47
7764 stage. context. get_backend (). get_default_seat (). bell_notify ();
7865#else
7966 Clutter . get_default_backend (). get_default_seat (). bell_notify ();
8067#endif
8168 }
8269
70+ show_focus ();
71+
8372 return Clutter . EVENT_STOP ;
8473 }
8574
0 commit comments