Skip to content

Commit 9ace03c

Browse files
committed
Port ActiveShape and WindowSwitcherIcon
1 parent 00032fa commit 9ace03c

File tree

3 files changed

+47
-75
lines changed

3 files changed

+47
-75
lines changed

data/shaders/rounded-corners.vert

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,5 @@ void main () {
5050
vec2 texture_coord = cogl_tex_coord0_in.xy * actor_size;
5151
float res = rounded_rect_coverage (texture_coord);
5252

53-
cogl_color_out = sample * cogl_color_in;
54-
cogl_color_out.a *= res;
53+
cogl_color_out = sample * cogl_color_in * res;
5554
}

src/Widgets/MultitaskingView/WindowClone.vala

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
4141
*/
4242
public bool active {
4343
set {
44+
active_shape.update_color ();
45+
4446
active_shape.save_easing_state ();
4547
active_shape.set_easing_duration (Utils.get_animation_duration (FADE_ANIMATION_DURATION));
4648
active_shape.opacity = value ? 255 : 0;
@@ -122,8 +124,9 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
122124
add_action (drag_action);
123125
}
124126

125-
active_shape = new ActiveShape ();
126-
active_shape.opacity = 0;
127+
active_shape = new ActiveShape () {
128+
opacity = 0
129+
};
127130

128131
clone_container = new Clutter.Actor () {
129132
pivot_point = { 0.5f, 0.5f }
@@ -687,33 +690,22 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
687690
/**
688691
* Border to show around the selected window when using keyboard navigation.
689692
*/
690-
private class ActiveShape : CanvasActor {
693+
private class ActiveShape : Clutter.Actor {
691694
private const int BORDER_RADIUS = 16;
692695
private const double COLOR_OPACITY = 0.8;
693696

694697
construct {
695-
notify["opacity"].connect (invalidate);
696-
}
697-
698-
public void invalidate () {
699-
content.invalidate ();
698+
add_effect (new RoundedCornersEffect (BORDER_RADIUS, 1.0f));
700699
}
701700

702-
protected override void draw (Cairo.Context cr, int width, int height) {
703-
if (!visible || opacity == 0) {
704-
return;
705-
}
706-
707-
var color = Drawing.StyleManager.get_instance ().theme_accent_color;
708-
709-
cr.save ();
710-
cr.set_operator (Cairo.Operator.CLEAR);
711-
cr.paint ();
712-
cr.restore ();
713-
714-
Drawing.Utilities.cairo_rounded_rectangle (cr, 0, 0, width, height, BORDER_RADIUS);
715-
cr.set_source_rgba (color.red, color.green, color.blue, COLOR_OPACITY);
716-
cr.fill ();
701+
public void update_color () {
702+
var accent_color = Drawing.StyleManager.get_instance ().theme_accent_color;
703+
background_color = {
704+
(uint8) (accent_color.red * uint8.MAX),
705+
(uint8) (accent_color.green * uint8.MAX),
706+
(uint8) (accent_color.blue * uint8.MAX),
707+
(uint8) (COLOR_OPACITY * uint8.MAX)
708+
};
717709
}
718710
}
719711
}

src/Widgets/WindowSwitcher/WindowSwitcherIcon.vala

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,48 @@
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
55

6-
public class Gala.WindowSwitcherIcon : CanvasActor {
6+
public class Gala.WindowSwitcherIcon : Clutter.Actor {
77
private const int WRAPPER_BORDER_RADIUS = 3;
88

99
public Meta.Window window { get; construct; }
1010

1111
private WindowIcon icon;
12+
private RoundedCornersEffect rounded_corners_effect;
1213

13-
private bool _selected = false;
1414
public bool selected {
15-
get {
16-
return _selected;
17-
}
1815
set {
19-
_selected = value;
20-
content.invalidate ();
16+
if (value) {
17+
var accent_color = Drawing.StyleManager.get_instance ().theme_accent_color;
18+
background_color = {
19+
(uint8) (accent_color.red * uint8.MAX),
20+
(uint8) (accent_color.green * uint8.MAX),
21+
(uint8) (accent_color.blue * uint8.MAX),
22+
(uint8) (accent_color.alpha * uint8.MAX)
23+
};
24+
} else {
25+
#if HAS_MUTTER47
26+
background_color = Cogl.Color.from_4f (0, 0, 0, 0);
27+
#else
28+
background_color = Clutter.Color.alloc ();
29+
#endif
30+
}
31+
32+
get_accessible ().notify_state_change (Atk.StateType.SELECTED, value);
33+
get_accessible ().notify_state_change (Atk.StateType.FOCUSED, value);
34+
35+
queue_redraw ();
2136
}
2237
}
2338

24-
private float _scale_factor = 1.0f;
2539
public float scale_factor {
26-
get {
27-
return _scale_factor;
28-
}
2940
set {
30-
_scale_factor = value;
41+
var indicator_size = Utils.scale_to_int (
42+
(WindowSwitcher.ICON_SIZE + WindowSwitcher.WRAPPER_PADDING * 2),
43+
value
44+
);
45+
set_size (indicator_size, indicator_size);
3146

32-
update_size ();
47+
rounded_corners_effect.monitor_scale = value;
3348
}
3449
}
3550

@@ -40,48 +55,14 @@ public class Gala.WindowSwitcherIcon : CanvasActor {
4055
icon.add_constraint (new Clutter.AlignConstraint (this, Clutter.AlignAxis.BOTH, 0.5f));
4156
add_child (icon);
4257

58+
rounded_corners_effect = new RoundedCornersEffect (WRAPPER_BORDER_RADIUS, scale_factor);
59+
add_effect (rounded_corners_effect);
60+
4361
get_accessible ().accessible_name = window.title;
4462
get_accessible ().accessible_role = LIST_ITEM;
4563
get_accessible ().notify_state_change (Atk.StateType.FOCUSABLE, true);
4664

4765
reactive = true;
48-
4966
this.scale_factor = scale_factor;
5067
}
51-
52-
private void update_size () {
53-
var indicator_size = Utils.scale_to_int (
54-
(WindowSwitcher.ICON_SIZE + WindowSwitcher.WRAPPER_PADDING * 2),
55-
scale_factor
56-
);
57-
set_size (indicator_size, indicator_size);
58-
}
59-
60-
protected override void draw (Cairo.Context ctx, int width, int height) {
61-
ctx.save ();
62-
ctx.set_operator (Cairo.Operator.CLEAR);
63-
ctx.paint ();
64-
ctx.clip ();
65-
ctx.reset_clip ();
66-
67-
if (selected) {
68-
// draw rect
69-
var rgba = Drawing.StyleManager.get_instance ().theme_accent_color;
70-
ctx.set_source_rgba (
71-
rgba.red,
72-
rgba.green,
73-
rgba.blue,
74-
rgba.alpha
75-
);
76-
var rect_radius = Utils.scale_to_int (WRAPPER_BORDER_RADIUS, scale_factor);
77-
Drawing.Utilities.cairo_rounded_rectangle (ctx, 0, 0, width, height, rect_radius);
78-
ctx.set_operator (Cairo.Operator.SOURCE);
79-
ctx.fill ();
80-
81-
ctx.restore ();
82-
}
83-
84-
get_accessible ().notify_state_change (Atk.StateType.SELECTED, selected);
85-
get_accessible ().notify_state_change (Atk.StateType.FOCUSED, selected);
86-
}
8768
}

0 commit comments

Comments
 (0)