Skip to content

Commit 57f8ec2

Browse files
authored
Merge branch 'main' into lenemter/inline-windowiconactor
2 parents cd30adb + 42443b2 commit 57f8ec2

File tree

1 file changed

+123
-137
lines changed

1 file changed

+123
-137
lines changed

src/Widgets/PointerLocator.vala

Lines changed: 123 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,151 @@
1-
//
2-
// Copyright 2020 elementary, Inc. (https://elementary.io)
3-
//
4-
// This program is free software: you can redistribute it and/or modify
5-
// it under the terms of the GNU General Public License as published by
6-
// the Free Software Foundation, either version 3 of the License, or
7-
// (at your option) any later version.
8-
//
9-
// This program is distributed in the hope that it will be useful,
10-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
// GNU General Public License for more details.
13-
//
14-
// You should have received a copy of the GNU General Public License
15-
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
//
17-
18-
namespace Gala {
19-
public class PointerLocator : Clutter.Actor, Clutter.Animatable {
20-
private const int WIDTH_PX = 300;
21-
private const int HEIGHT_PX = 300;
22-
private const int ANIMATION_TIME_MS = 300;
23-
24-
private const int BORDER_WIDTH_PX = 1;
25-
26-
private const double BACKGROUND_OPACITY = 0.7;
27-
28-
public Meta.Display display { get; construct; }
29-
30-
private float scaling_factor = 1.0f;
31-
private int surface_width = WIDTH_PX;
32-
private int surface_height = HEIGHT_PX;
33-
34-
private GLib.Settings settings;
35-
private Cogl.Pipeline pipeline;
36-
private Cairo.ImageSurface surface;
37-
private Cairo.Pattern stroke_color;
38-
private Cairo.Pattern fill_color;
39-
40-
public PointerLocator (Meta.Display display) {
41-
Object (display: display);
42-
}
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2020-2025 elementary, Inc. (https://elementary.io)
4+
*/
5+
6+
public class Gala.PointerLocator : Clutter.Actor, Clutter.Animatable {
7+
private const int WIDTH_PX = 300;
8+
private const int HEIGHT_PX = 300;
9+
private const int ANIMATION_TIME_MS = 300;
10+
11+
private const int BORDER_WIDTH_PX = 1;
12+
13+
private const double BACKGROUND_OPACITY = 0.7;
4314

44-
construct {
45-
visible = false;
46-
reactive = false;
15+
public Meta.Display display { get; construct; }
16+
17+
private float scaling_factor = 1.0f;
18+
private int surface_width = WIDTH_PX;
19+
private int surface_height = HEIGHT_PX;
20+
21+
private GLib.Settings settings;
22+
private Cogl.Pipeline pipeline;
23+
private Cairo.ImageSurface surface;
24+
private Cairo.Pattern stroke_color;
25+
private Cairo.Pattern fill_color;
26+
27+
public PointerLocator (Meta.Display display) {
28+
Object (display: display);
29+
}
4730

48-
settings = new GLib.Settings ("org.gnome.desktop.interface");
31+
construct {
32+
visible = false;
33+
reactive = false;
34+
35+
settings = new GLib.Settings ("org.gnome.desktop.interface");
4936

5037
#if HAS_MUTTER47
51-
unowned var ctx = context.get_backend ().get_cogl_context ();
38+
unowned var ctx = context.get_backend ().get_cogl_context ();
5239
#else
53-
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
40+
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
5441
#endif
55-
pipeline = new Cogl.Pipeline (ctx);
42+
pipeline = new Cogl.Pipeline (ctx);
5643

57-
var pivot = Graphene.Point ();
58-
pivot.init (0.5f, 0.5f);
59-
pivot_point = pivot;
60-
}
44+
var pivot = Graphene.Point ();
45+
pivot.init (0.5f, 0.5f);
46+
pivot_point = pivot;
47+
}
6148

62-
private void update_surface (float cur_scale) {
63-
if (surface == null || cur_scale != scaling_factor) {
64-
scaling_factor = cur_scale;
65-
surface_width = InternalUtils.scale_to_int (WIDTH_PX, scaling_factor);
66-
surface_height = InternalUtils.scale_to_int (HEIGHT_PX, scaling_factor);
49+
private void update_surface (float cur_scale) {
50+
if (surface == null || cur_scale != scaling_factor) {
51+
scaling_factor = cur_scale;
52+
surface_width = InternalUtils.scale_to_int (WIDTH_PX, scaling_factor);
53+
surface_height = InternalUtils.scale_to_int (HEIGHT_PX, scaling_factor);
6754

68-
surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, surface_width, surface_height);
55+
surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, surface_width, surface_height);
6956

70-
set_size (surface_width, surface_height);
71-
}
57+
set_size (surface_width, surface_height);
7258
}
59+
}
7360

74-
public override void paint (Clutter.PaintContext context) {
75-
var radius = int.min (surface_width / 2, surface_height / 2);
61+
public override void paint (Clutter.PaintContext context) {
62+
var radius = int.min (surface_width / 2, surface_height / 2);
7663

77-
var cr = new Cairo.Context (surface);
78-
var border_width = InternalUtils.scale_to_int (BORDER_WIDTH_PX, scaling_factor);
64+
var cr = new Cairo.Context (surface);
65+
var border_width = InternalUtils.scale_to_int (BORDER_WIDTH_PX, scaling_factor);
7966

80-
// Clear the surface
81-
cr.save ();
82-
cr.set_source_rgba (0, 0, 0, 0);
83-
cr.set_operator (Cairo.Operator.SOURCE);
84-
cr.paint ();
85-
cr.restore ();
67+
// Clear the surface
68+
cr.save ();
69+
cr.set_source_rgba (0, 0, 0, 0);
70+
cr.set_operator (Cairo.Operator.SOURCE);
71+
cr.paint ();
72+
cr.restore ();
8673

87-
cr.set_line_cap (Cairo.LineCap.ROUND);
88-
cr.set_line_join (Cairo.LineJoin.ROUND);
89-
cr.translate (surface_width / 2, surface_height / 2);
74+
cr.set_line_cap (Cairo.LineCap.ROUND);
75+
cr.set_line_join (Cairo.LineJoin.ROUND);
76+
cr.translate (surface_width / 2, surface_height / 2);
9077

91-
cr.move_to (radius - BORDER_WIDTH_PX, 0);
92-
cr.arc (0, 0, radius - border_width, 0, 2 * Math.PI);
93-
cr.close_path ();
78+
cr.move_to (radius - BORDER_WIDTH_PX, 0);
79+
cr.arc (0, 0, radius - border_width, 0, 2 * Math.PI);
80+
cr.close_path ();
9481

95-
cr.set_line_width (0);
96-
cr.set_source (fill_color);
97-
cr.fill_preserve ();
82+
cr.set_line_width (0);
83+
cr.set_source (fill_color);
84+
cr.fill_preserve ();
9885

99-
cr.set_line_width (border_width);
100-
cr.set_source (stroke_color);
101-
cr.stroke ();
86+
cr.set_line_width (border_width);
87+
cr.set_source (stroke_color);
88+
cr.stroke ();
10289

103-
var cogl_context = context.get_framebuffer ().get_context ();
90+
var cogl_context = context.get_framebuffer ().get_context ();
10491

105-
try {
106-
var texture = new Cogl.Texture2D.from_data (cogl_context, surface_width, surface_height,
107-
Cogl.PixelFormat.BGRA_8888_PRE, surface.get_stride (), surface.get_data ());
92+
try {
93+
var texture = new Cogl.Texture2D.from_data (cogl_context, surface_width, surface_height,
94+
Cogl.PixelFormat.BGRA_8888_PRE, surface.get_stride (), surface.get_data ());
10895

109-
pipeline.set_layer_texture (0, texture);
96+
pipeline.set_layer_texture (0, texture);
11097

111-
context.get_framebuffer ().draw_rectangle (pipeline, 0, 0, surface_width, surface_height);
112-
} catch (Error e) {}
98+
context.get_framebuffer ().draw_rectangle (pipeline, 0, 0, surface_width, surface_height);
99+
} catch (Error e) {}
113100

114-
base.paint (context);
101+
base.paint (context);
102+
}
103+
104+
public void show_ripple () {
105+
if (!settings.get_boolean ("locate-pointer")) {
106+
return;
115107
}
116108

117-
public void show_ripple () {
118-
if (!settings.get_boolean ("locate-pointer")) {
119-
return;
120-
}
121-
122-
unowned var old_transition = get_transition ("circle");
123-
if (old_transition != null) {
124-
old_transition.stop ();
125-
}
126-
127-
var transition = new Clutter.TransitionGroup ();
128-
transition.remove_on_complete = true;
129-
var transition_x = new Clutter.PropertyTransition ("scale-x");
130-
var transition_y = new Clutter.PropertyTransition ("scale-y");
131-
var start_val = Value (typeof (double));
132-
start_val.set_double (1);
133-
var stop_val = Value (typeof (double));
134-
stop_val.set_double (0);
135-
transition_x.set_from_value (start_val);
136-
transition_y.set_from_value (start_val);
137-
transition_x.set_to_value (stop_val);
138-
transition_y.set_to_value (stop_val);
139-
transition.progress_mode = Clutter.AnimationMode.EASE_OUT_QUAD;
140-
transition.duration = ANIMATION_TIME_MS;
141-
transition.add_transition (transition_x);
142-
transition.add_transition (transition_y);
143-
transition.stopped.connect (() => { visible = false; });
144-
transition.started.connect (() => { visible = true; });
145-
add_transition ("circle", transition);
146-
147-
var rgba = Drawing.StyleManager.get_instance ().theme_accent_color;
148-
149-
/* Don't use alpha from the stylesheet to ensure contrast */
150-
stroke_color = new Cairo.Pattern.rgb (rgba.red, rgba.green, rgba.blue);
151-
fill_color = new Cairo.Pattern.rgba (rgba.red, rgba.green, rgba.blue, BACKGROUND_OPACITY);
152-
153-
unowned var tracker = display.get_cursor_tracker ();
154-
Graphene.Point coords = {};
155-
tracker.get_pointer (out coords, null);
156-
157-
update_surface (display.get_monitor_scale (display.get_current_monitor ()));
158-
159-
x = coords.x - (width / 2);
160-
y = coords.y - (width / 2);
161-
162-
transition.start ();
109+
unowned var old_transition = get_transition ("circle");
110+
if (old_transition != null) {
111+
old_transition.stop ();
163112
}
113+
114+
var transition = new Clutter.TransitionGroup ();
115+
transition.remove_on_complete = true;
116+
var transition_x = new Clutter.PropertyTransition ("scale-x");
117+
var transition_y = new Clutter.PropertyTransition ("scale-y");
118+
var start_val = Value (typeof (double));
119+
start_val.set_double (1);
120+
var stop_val = Value (typeof (double));
121+
stop_val.set_double (0);
122+
transition_x.set_from_value (start_val);
123+
transition_y.set_from_value (start_val);
124+
transition_x.set_to_value (stop_val);
125+
transition_y.set_to_value (stop_val);
126+
transition.progress_mode = Clutter.AnimationMode.EASE_OUT_QUAD;
127+
transition.duration = ANIMATION_TIME_MS;
128+
transition.add_transition (transition_x);
129+
transition.add_transition (transition_y);
130+
transition.stopped.connect (() => { visible = false; });
131+
transition.started.connect (() => { visible = true; });
132+
add_transition ("circle", transition);
133+
134+
var rgba = Drawing.StyleManager.get_instance ().theme_accent_color;
135+
136+
/* Don't use alpha from the stylesheet to ensure contrast */
137+
stroke_color = new Cairo.Pattern.rgb (rgba.red, rgba.green, rgba.blue);
138+
fill_color = new Cairo.Pattern.rgba (rgba.red, rgba.green, rgba.blue, BACKGROUND_OPACITY);
139+
140+
unowned var tracker = display.get_cursor_tracker ();
141+
Graphene.Point coords = {};
142+
tracker.get_pointer (out coords, null);
143+
144+
update_surface (display.get_monitor_scale (display.get_current_monitor ()));
145+
146+
x = coords.x - (width / 2);
147+
y = coords.y - (width / 2);
148+
149+
transition.start ();
164150
}
165151
}

0 commit comments

Comments
 (0)