Skip to content

Commit ba6b787

Browse files
committed
lint, better style
1 parent bbbe951 commit ba6b787

File tree

3 files changed

+25
-34
lines changed

3 files changed

+25
-34
lines changed

lib/FocusController.vala

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,32 @@
66
*/
77

88
public 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

lib/Focusable.vala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Authored by: Leonhard Kargl <[email protected]>
66
*/
77

8-
public interface Gala.Focusable : Clutter.Actor{
8+
public interface Gala.Focusable : Clutter.Actor {
99
public enum FocusDirection {
1010
UP,
1111
DOWN,
@@ -180,9 +180,11 @@ public interface Gala.Focusable : Clutter.Actor{
180180
return false;
181181
}
182182

183-
get_stage ().set_key_focus (this);
184-
notify_visible_focus_changed ();
185-
key_focus_out.connect (notify_visible_focus_changed);
183+
var stage = get_stage ();
184+
stage.set_key_focus (this);
185+
focus_changed ();
186+
key_focus_out.connect (focus_changed);
187+
FocusController.get_for_stage (stage).notify["focus-visible"].connect (focus_changed);
186188

187189
return true;
188190
}
@@ -191,9 +193,9 @@ public interface Gala.Focusable : Clutter.Actor{
191193
return false;
192194
}
193195

194-
internal void notify_visible_focus_changed () {
196+
private void focus_changed () {
195197
var stage = get_stage ();
196-
update_focus (stage?.get_key_focus () == this && FocusController.get_default (stage).focus_visible);
198+
update_focus (stage?.get_key_focus () == this && FocusController.get_for_stage (stage).focus_visible);
197199
}
198200

199201
protected virtual void update_focus (bool has_visible_focus) { }

src/Widgets/MultitaskingView/MultitaskingView.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class Gala.MultitaskingView : ActorTarget, RootTarget, ActivatableCompone
5656
reactive = true;
5757
clip_to_allocation = true;
5858

59-
FocusController.get_default (wm.stage).register_root (this);
59+
FocusController.get_for_stage (wm.stage).register_root (this);
6060

6161
opened = false;
6262
display = wm.get_display ();

0 commit comments

Comments
 (0)