Skip to content

Commit 42ab42a

Browse files
tintoudanirabbit
andauthored
Start the port to Mutter 48 (#2231)
Co-authored-by: Danielle Foré <[email protected]>
1 parent 4eaed40 commit 42ab42a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1842
-110
lines changed

lib/CloseButton.vala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public class Gala.CloseButton : Clutter.Actor {
3333
var pixbuf = get_close_button_pixbuf (scale);
3434
if (pixbuf != null) {
3535
try {
36-
var image = new Clutter.Image ();
37-
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
38-
image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
39-
36+
var image = new Gala.Image.from_pixbuf (pixbuf);
4037
pixbuf_actor.set_content (image);
4138
pixbuf_actor.set_size (pixbuf.width, pixbuf.height);
4239
set_size (pixbuf.width, pixbuf.height);

lib/DragDropAction.vala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,11 @@ namespace Gala {
313313
event.get_coords (out x, out y);
314314

315315
if (!dragging && clicked) {
316+
#if HAS_MUTTER47
317+
var drag_threshold = actor.context.get_settings ().dnd_drag_threshold;
318+
#else
316319
var drag_threshold = Clutter.Settings.get_default ().dnd_drag_threshold;
320+
#endif
317321
if (Math.fabsf (last_x - x) > drag_threshold || Math.fabsf (last_y - y) > drag_threshold) {
318322
handle = drag_begin (last_x, last_y);
319323
if (handle == null) {

lib/Image.vala

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2015 Corentin Noël
3+
* Copyright 2025 elementary, Inc. <https://elementary.io>
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
#if !HAS_MUTTER48
8+
public class Gala.Image : Clutter.Image {
9+
public Image.from_pixbuf (Gdk.Pixbuf pixbuf) {
10+
Object ();
11+
12+
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
13+
try {
14+
set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
15+
} catch (Error e) {}
16+
}
17+
}
18+
#else
19+
public class Gala.Image : GLib.Object, Clutter.Content {
20+
Gdk.Pixbuf? pixbuf;
21+
Cogl.Texture? texture;
22+
uint width;
23+
uint height;
24+
25+
public Image.from_pixbuf (Gdk.Pixbuf pixbuf) {
26+
this.pixbuf = pixbuf;
27+
width = pixbuf.width;
28+
height = pixbuf.height;
29+
invalidate ();
30+
}
31+
32+
public bool get_preferred_size (out float width, out float height) {
33+
if (texture == null) {
34+
width = 0;
35+
height = 0;
36+
return false;
37+
}
38+
39+
width = texture.get_width ();
40+
height = texture.get_height ();
41+
return true;
42+
}
43+
44+
public void paint_content (Clutter.Actor actor, Clutter.PaintNode node, Clutter.PaintContext paint_context) {
45+
if (pixbuf != null && texture == null) {
46+
var cogl_context = actor.context.get_backend ().get_cogl_context ();
47+
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
48+
try {
49+
texture = new Cogl.Texture2D.from_data (cogl_context, pixbuf.width, pixbuf.height, pixel_format, pixbuf.rowstride, pixbuf.get_pixels ());
50+
if (width != texture.get_width () || height != texture.get_height ()) {
51+
width = texture.get_width ();
52+
height = texture.get_height ();
53+
invalidate_size ();
54+
}
55+
} catch (Error e) {
56+
critical (e.message);
57+
}
58+
}
59+
60+
if (texture == null)
61+
return;
62+
63+
var content_node = actor.create_texture_paint_node (texture);
64+
content_node.set_static_name ("Image Content");
65+
node.add_child (content_node);
66+
}
67+
68+
public void invalidate () {
69+
texture = null;
70+
}
71+
72+
public void invalidate_size () {
73+
}
74+
}
75+
#endif

lib/Utils.vala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,9 @@ namespace Gala {
385385
texture.reactive = true;
386386

387387
if (pixbuf != null) {
388-
try {
389-
var image = new Clutter.Image ();
390-
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
391-
image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
392-
texture.set_content (image);
393-
texture.set_size (pixbuf.width, pixbuf.height);
394-
} catch (Error e) {}
388+
var image = new Gala.Image.from_pixbuf (pixbuf);
389+
texture.set_content (image);
390+
texture.set_size (pixbuf.width, pixbuf.height);
395391
} else {
396392
// we'll just make this red so there's at least something as an
397393
// indicator that loading failed. Should never happen and this

lib/WindowIcon.vala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ public class Gala.WindowIcon : Clutter.Actor {
4646
height = icon_size * scale;
4747

4848
var pixbuf = Gala.Utils.get_icon_for_window (window, icon_size, scale);
49-
try {
50-
var image = new Clutter.Image ();
51-
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
52-
image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
53-
set_content (image);
54-
} catch (Error e) {}
49+
var image = new Gala.Image.from_pixbuf (pixbuf);
50+
set_content (image);
5551
}
5652
}

lib/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ gala_lib_sources = files(
1313
'Drawing/Color.vala',
1414
'Drawing/StyleManager.vala',
1515
'Drawing/Utilities.vala',
16+
'Image.vala',
1617
'Plugin.vala',
1718
'ShadowEffect.vala',
1819
'Utils.vala',

meson.build

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ if mutter47_dep.found()
137137
vala_flags = ['--define', 'HAS_MUTTER43', '--define', 'HAS_MUTTER44', '--define', 'HAS_MUTTER45', '--define', 'HAS_MUTTER46', '--define', 'HAS_MUTTER47']
138138
endif
139139

140+
mutter48_dep = dependency('libmutter-16', version: ['>= 48', '< 49'], required: false)
141+
if mutter48_dep.found()
142+
libmutter_dep = dependency('libmutter-16', version: '>= 48')
143+
mutter_dep = [
144+
libmutter_dep,
145+
dependency('mutter-mtk-16'), dependency('mutter-cogl-16'),
146+
dependency('mutter-clutter-16')
147+
]
148+
vala_flags = ['--define', 'HAS_MUTTER43', '--define', 'HAS_MUTTER44', '--define', 'HAS_MUTTER45', '--define', 'HAS_MUTTER46', '--define', 'HAS_MUTTER47', '--define', 'HAS_MUTTER48']
149+
endif
150+
140151
if mutter_dep.length() == 0
141152
error ('No supported mutter library found!')
142153
endif

plugins/pip/Main.vala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
137137

138138
private Meta.WindowActor? get_window_actor_at (int x, int y) {
139139
unowned Meta.Display display = wm.get_display ();
140+
#if HAS_MUTTER48
141+
unowned List<Meta.WindowActor> actors = display.get_compositor ().get_window_actors ();
142+
#else
140143
unowned List<Meta.WindowActor> actors = display.get_window_actors ();
144+
#endif
141145

142146
var copy = actors.copy ();
143147
copy.reverse ();
@@ -161,7 +165,11 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
161165

162166
private Meta.WindowActor? get_active_window_actor () {
163167
unowned Meta.Display display = wm.get_display ();
168+
#if HAS_MUTTER48
169+
unowned List<Meta.WindowActor> actors = display.get_compositor ().get_window_actors ();
170+
#else
164171
unowned List<Meta.WindowActor> actors = display.get_window_actors ();
172+
#endif
165173

166174
var copy = actors.copy ();
167175
copy.reverse ();

plugins/pip/PopupWindow.vala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
201201
}
202202

203203
private Clutter.Actor on_move_begin () {
204+
#if HAS_MUTTER48
205+
display.set_cursor (Meta.Cursor.MOVE);
206+
#else
204207
display.set_cursor (Meta.Cursor.DND_IN_DRAG);
208+
#endif
205209

206210
return this;
207211
}
@@ -304,7 +308,11 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
304308
opacity = 0;
305309
restore_easing_state ();
306310

311+
#if HAS_MUTTER48
312+
GLib.Timeout.add (duration, () => {
313+
#else
307314
Clutter.Threads.Timeout.add (duration, () => {
315+
#endif
308316
closed ();
309317
return Source.REMOVE;
310318
});

src/ColorFilters/ColorblindnessCorrectionEffect.vala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ public class Gala.ColorblindnessCorrectionEffect : Clutter.ShaderEffect {
3232

3333
public ColorblindnessCorrectionEffect (int mode, double strength) {
3434
Object (
35+
#if HAS_MUTTER48
36+
shader_type: Cogl.ShaderType.FRAGMENT,
37+
#else
3538
shader_type: Clutter.ShaderType.FRAGMENT_SHADER,
39+
#endif
3640
mode: mode,
3741
strength: strength
3842
);

0 commit comments

Comments
 (0)