Skip to content

Commit b36be97

Browse files
committed
Start the port to Mutter 48
1 parent be515b5 commit b36be97

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

+1227
-123
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
@@ -389,9 +389,7 @@ namespace Gala {
389389

390390
if (pixbuf != null) {
391391
try {
392-
var image = new Clutter.Image ();
393-
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
394-
image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
392+
var image = new Gala.Image.from_pixbuf (pixbuf);
395393
texture.set_content (image);
396394
texture.set_size (pixbuf.width, pixbuf.height);
397395
} 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
@@ -14,6 +14,7 @@ gala_lib_sources = files(
1414
'Drawing/Color.vala',
1515
'Drawing/StyleManager.vala',
1616
'Drawing/Utilities.vala',
17+
'Image.vala',
1718
'Plugin.vala',
1819
'ShadowEffect.vala',
1920
'Utils.vala',

meson.build

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

172+
mutter48_dep = dependency('libmutter-16', version: ['>= 48', '< 49'], required: false)
173+
if mutter48_dep.found()
174+
libmutter_dep = dependency('libmutter-16', version: '>= 48')
175+
mutter_dep = [
176+
libmutter_dep,
177+
dependency('mutter-mtk-16'), dependency('mutter-cogl-16'),
178+
dependency('mutter-clutter-16')
179+
]
180+
vala_flags = ['--define', 'HAS_MUTTER43', '--define', 'HAS_MUTTER44', '--define', 'HAS_MUTTER45', '--define', 'HAS_MUTTER46', '--define', 'HAS_MUTTER47', '--define', 'HAS_MUTTER48']
181+
endif
182+
172183
if mutter_dep.length() == 0
173184
error ('No supported mutter library found!')
174185
endif

plugins/pip/Main.vala

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

134134
private Meta.WindowActor? get_window_actor_at (int x, int y) {
135135
unowned Meta.Display display = wm.get_display ();
136+
#if HAS_MUTTER48
137+
unowned List<Meta.WindowActor> actors = display.get_compositor ().get_window_actors ();
138+
#else
136139
unowned List<Meta.WindowActor> actors = display.get_window_actors ();
140+
#endif
137141

138142
var copy = actors.copy ();
139143
copy.reverse ();
@@ -157,7 +161,11 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
157161

158162
private Meta.WindowActor? get_active_window_actor () {
159163
unowned Meta.Display display = wm.get_display ();
164+
#if HAS_MUTTER48
165+
unowned List<Meta.WindowActor> actors = display.get_compositor ().get_window_actors ();
166+
#else
160167
unowned List<Meta.WindowActor> actors = display.get_window_actors ();
168+
#endif
161169

162170
var copy = actors.copy ();
163171
copy.reverse ();

plugins/pip/PopupWindow.vala

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

319+
#if HAS_MUTTER48
320+
GLib.Timeout.add (duration, () => {
321+
#else
319322
Clutter.Threads.Timeout.add (duration, () => {
323+
#endif
320324
closed ();
321325
return Source.REMOVE;
322326
});

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)