Skip to content

Commit bfece1b

Browse files
committed
Start the port to Mutter 48
1 parent c36970d commit bfece1b

Some content is hidden

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

42 files changed

+1837
-101
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/Image.vala

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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_MUTTER46
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+
//set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
14+
}
15+
}
16+
#else
17+
public class Gala.Image : GLib.Object, Clutter.Content {
18+
Cogl.Texture? texture;
19+
int width;
20+
int height;
21+
22+
public Image.from_pixbuf (Gdk.Pixbuf pixbuf) {
23+
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
24+
//image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
25+
}
26+
27+
public bool get_preferred_size (out float width, out float height) {
28+
if (texture == null)
29+
return false;
30+
31+
width = texture.get_width ();
32+
height = texture.get_height ();
33+
return true;
34+
}
35+
36+
public void paint_content (Clutter.Actor actor, Clutter.PaintNode node, Clutter.PaintContext paint_context) {
37+
if (texture == null)
38+
return;
39+
40+
var content_node = actor.create_texture_paint_node (texture);
41+
content_node.set_static_name ("Image Content");
42+
node.add_child (content_node);
43+
}
44+
45+
public void invalidate () {
46+
47+
}
48+
49+
public void invalidate_size () {
50+
51+
}
52+
/*
53+
gboolean
54+
st_image_content_set_data (StImageContent *content,
55+
const guint8 *data,
56+
CoglPixelFormat pixel_format,
57+
guint width,
58+
guint height,
59+
guint row_stride,
60+
GError **error)
61+
{
62+
g_return_val_if_fail (ST_IS_IMAGE_CONTENT (content), FALSE);
63+
g_return_val_if_fail (data != NULL, FALSE);
64+
65+
if (content->texture != NULL)
66+
g_object_unref (content->texture);
67+
68+
content->texture = create_texture_from_data (width,
69+
height,
70+
pixel_format,
71+
row_stride,
72+
data,
73+
error);
74+
75+
if (content->texture == NULL)
76+
return FALSE;
77+
78+
clutter_content_invalidate (CLUTTER_CONTENT (content));
79+
update_image_size (content);
80+
81+
return TRUE;
82+
}
83+
84+
85+
set_data (this, data, pixel_format, width, height, row_stride) throws {
86+
backend = Clutter.Backend.get_default();
87+
cogl_context = backend.get_cogl_context ();
88+
this.texture = Cogl.Texture2D.new_from_data (cogl_context, width, height, pixel_format, row_stride, data, error);
89+
90+
if (!this.texture)
91+
return;
92+
93+
this.content_invalidate ();
94+
95+
int width = this.texture.get_width();
96+
int height = this.texture.get_height();
97+
98+
if (this.width == width && this.height == height)
99+
return;
100+
101+
this.width = width;
102+
this.height = height;
103+
this.invalidate_size();
104+
}*/
105+
}
106+
#endif

lib/Utils.vala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,7 @@ namespace Gala {
386386

387387
if (pixbuf != null) {
388388
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);
389+
var image = new Gala.Image.from_pixbuf (pixbuf);
392390
texture.set_content (image);
393391
texture.set_size (pixbuf.width, pixbuf.height);
394392
} catch (Error e) {}

lib/WindowIcon.vala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ public class Gala.WindowIcon : Clutter.Actor {
4747

4848
var pixbuf = Gala.Utils.get_icon_for_window (window, icon_size, scale);
4949
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);
50+
var image = new Gala.Image.from_pixbuf (pixbuf);
5351
set_content (image);
5452
} catch (Error e) {}
5553
}

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
@@ -129,7 +129,11 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
129129

130130
private Meta.WindowActor? get_window_actor_at (int x, int y) {
131131
unowned Meta.Display display = wm.get_display ();
132+
#if HAS_MUTTER48
133+
unowned List<Meta.WindowActor> actors = display.get_compositor ().get_window_actors ();
134+
#else
132135
unowned List<Meta.WindowActor> actors = display.get_window_actors ();
136+
#endif
133137

134138
var copy = actors.copy ();
135139
copy.reverse ();
@@ -153,7 +157,11 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
153157

154158
private Meta.WindowActor? get_active_window_actor () {
155159
unowned Meta.Display display = wm.get_display ();
160+
#if HAS_MUTTER48
161+
unowned List<Meta.WindowActor> actors = display.get_compositor ().get_window_actors ();
162+
#else
156163
unowned List<Meta.WindowActor> actors = display.get_window_actors ();
164+
#endif
157165

158166
var copy = actors.copy ();
159167
copy.reverse ();

plugins/pip/PopupWindow.vala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,11 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
304304
opacity = 0;
305305
restore_easing_state ();
306306

307+
#if HAS_MUTTER48
308+
GLib.Timeout.add (duration, () => {
309+
#else
307310
Clutter.Threads.Timeout.add (duration, () => {
311+
#endif
308312
closed ();
309313
return Source.REMOVE;
310314
});

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
);

src/ColorFilters/MonochromeEffect.vala

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

2525
public MonochromeEffect (double strength) {
2626
Object (
27+
#if HAS_MUTTER48
28+
shader_type: Cogl.ShaderType.FRAGMENT,
29+
#else
2730
shader_type: Clutter.ShaderType.FRAGMENT_SHADER,
31+
#endif
2832
strength: strength
2933
);
3034

0 commit comments

Comments
 (0)