Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start the port to Mutter 48 #2231

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/CloseButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ public class Gala.CloseButton : Clutter.Actor {
var pixbuf = get_close_button_pixbuf (scale);
if (pixbuf != null) {
try {
var image = new Clutter.Image ();
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);

var image = new Gala.Image.from_pixbuf (pixbuf);
pixbuf_actor.set_content (image);
pixbuf_actor.set_size (pixbuf.width, pixbuf.height);
set_size (pixbuf.width, pixbuf.height);
Expand Down
106 changes: 106 additions & 0 deletions lib/Image.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2015 Corentin Noël
* Copyright 2025 elementary, Inc. <https://elementary.io>
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#if !HAS_MUTTER46
public class Gala.Image : Clutter.Image {
public Image.from_pixbuf (Gdk.Pixbuf pixbuf) {
Object ();

Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
//set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
}
}
#else
public class Gala.Image : GLib.Object, Clutter.Content {
Cogl.Texture? texture;
int width;
int height;

public Image.from_pixbuf (Gdk.Pixbuf pixbuf) {
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
//image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
}

public bool get_preferred_size (out float width, out float height) {
if (texture == null)
return false;

width = texture.get_width ();
height = texture.get_height ();
return true;
}

public void paint_content (Clutter.Actor actor, Clutter.PaintNode node, Clutter.PaintContext paint_context) {
if (texture == null)
return;

var content_node = actor.create_texture_paint_node (texture);
content_node.set_static_name ("Image Content");
node.add_child (content_node);
}

public void invalidate () {

}

public void invalidate_size () {

}
/*
gboolean
st_image_content_set_data (StImageContent *content,
const guint8 *data,
CoglPixelFormat pixel_format,
guint width,
guint height,
guint row_stride,
GError **error)
{
g_return_val_if_fail (ST_IS_IMAGE_CONTENT (content), FALSE);
g_return_val_if_fail (data != NULL, FALSE);

if (content->texture != NULL)
g_object_unref (content->texture);

content->texture = create_texture_from_data (width,
height,
pixel_format,
row_stride,
data,
error);

if (content->texture == NULL)
return FALSE;

clutter_content_invalidate (CLUTTER_CONTENT (content));
update_image_size (content);

return TRUE;
}


set_data (this, data, pixel_format, width, height, row_stride) throws {
backend = Clutter.Backend.get_default();
cogl_context = backend.get_cogl_context ();
this.texture = Cogl.Texture2D.new_from_data (cogl_context, width, height, pixel_format, row_stride, data, error);

if (!this.texture)
return;

this.content_invalidate ();

int width = this.texture.get_width();
int height = this.texture.get_height();

if (this.width == width && this.height == height)
return;

this.width = width;
this.height = height;
this.invalidate_size();
}*/
}
#endif
4 changes: 1 addition & 3 deletions lib/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ namespace Gala {

if (pixbuf != null) {
try {
var image = new Clutter.Image ();
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
var image = new Gala.Image.from_pixbuf (pixbuf);
texture.set_content (image);
texture.set_size (pixbuf.width, pixbuf.height);
} catch (Error e) {}
Expand Down
4 changes: 1 addition & 3 deletions lib/WindowIcon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public class Gala.WindowIcon : Clutter.Actor {

var pixbuf = Gala.Utils.get_icon_for_window (window, icon_size, scale);
try {
var image = new Clutter.Image ();
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
var image = new Gala.Image.from_pixbuf (pixbuf);
set_content (image);
} catch (Error e) {}
}
Expand Down
1 change: 1 addition & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ gala_lib_sources = files(
'Drawing/Color.vala',
'Drawing/StyleManager.vala',
'Drawing/Utilities.vala',
'Image.vala',
'Plugin.vala',
'ShadowEffect.vala',
'Utils.vala',
Expand Down
11 changes: 11 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ if mutter47_dep.found()
vala_flags = ['--define', 'HAS_MUTTER43', '--define', 'HAS_MUTTER44', '--define', 'HAS_MUTTER45', '--define', 'HAS_MUTTER46', '--define', 'HAS_MUTTER47']
endif

mutter48_dep = dependency('libmutter-16', version: ['>= 48', '< 49'], required: false)
if mutter48_dep.found()
libmutter_dep = dependency('libmutter-16', version: '>= 48')
mutter_dep = [
libmutter_dep,
dependency('mutter-mtk-16'), dependency('mutter-cogl-16'),
dependency('mutter-clutter-16')
]
vala_flags = ['--define', 'HAS_MUTTER43', '--define', 'HAS_MUTTER44', '--define', 'HAS_MUTTER45', '--define', 'HAS_MUTTER46', '--define', 'HAS_MUTTER47', '--define', 'HAS_MUTTER48']
endif

if mutter_dep.length() == 0
error ('No supported mutter library found!')
endif
Expand Down
8 changes: 8 additions & 0 deletions plugins/pip/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {

private Meta.WindowActor? get_window_actor_at (int x, int y) {
unowned Meta.Display display = wm.get_display ();
#if HAS_MUTTER48
unowned List<Meta.WindowActor> actors = display.get_compositor ().get_window_actors ();
#else
unowned List<Meta.WindowActor> actors = display.get_window_actors ();
#endif

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

private Meta.WindowActor? get_active_window_actor () {
unowned Meta.Display display = wm.get_display ();
#if HAS_MUTTER48
unowned List<Meta.WindowActor> actors = display.get_compositor ().get_window_actors ();
#else
unowned List<Meta.WindowActor> actors = display.get_window_actors ();
#endif

var copy = actors.copy ();
copy.reverse ();
Expand Down
4 changes: 4 additions & 0 deletions plugins/pip/PopupWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
opacity = 0;
restore_easing_state ();

#if HAS_MUTTER48
GLib.Timeout.add (duration, () => {
#else
Clutter.Threads.Timeout.add (duration, () => {
#endif
closed ();
return Source.REMOVE;
});
Expand Down
4 changes: 4 additions & 0 deletions src/ColorFilters/ColorblindnessCorrectionEffect.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public class Gala.ColorblindnessCorrectionEffect : Clutter.ShaderEffect {

public ColorblindnessCorrectionEffect (int mode, double strength) {
Object (
#if HAS_MUTTER48
shader_type: Cogl.ShaderType.FRAGMENT,
#else
shader_type: Clutter.ShaderType.FRAGMENT_SHADER,
#endif
mode: mode,
strength: strength
);
Expand Down
4 changes: 4 additions & 0 deletions src/ColorFilters/MonochromeEffect.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public class Gala.MonochromeEffect : Clutter.ShaderEffect {

public MonochromeEffect (double strength) {
Object (
#if HAS_MUTTER48
shader_type: Cogl.ShaderType.FRAGMENT,
#else
shader_type: Clutter.ShaderType.FRAGMENT_SHADER,
#endif
strength: strength
);

Expand Down
8 changes: 8 additions & 0 deletions src/DesktopIntegration.vala
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,18 @@ public class Gala.DesktopIntegration : GLib.Object {

transition.stopped.connect (() => {
notifying = false;
#if HAS_MUTTER48
wm.get_display ().get_compositor ().enable_unredirect ();
#else
wm.get_display ().enable_unredirect ();
#endif
});

#if HAS_MUTTER48
wm.get_display ().get_compositor ().disable_unredirect ();
#else
wm.get_display ().disable_unredirect ();
#endif

((Meta.WindowActor) window.get_compositor_private ()).add_transition ("notify-already-focused", transition);
}
Expand Down
8 changes: 7 additions & 1 deletion src/InternalUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ namespace Gala {

new_window.change_workspace_by_index (index, false);

#if HAS_MUTTER48
unowned List<Meta.WindowActor> actors = new_window.get_display ().get_compositor ().get_window_actors ();
#else
unowned List<Meta.WindowActor> actors = new_window.get_display ().get_window_actors ();
#endif
foreach (unowned Meta.WindowActor actor in actors) {
if (actor.is_destroyed ())
continue;
Expand Down Expand Up @@ -382,7 +386,9 @@ namespace Gala {
}

public static void bell_notify (Meta.Display display) {
#if HAS_MUTTER47
#if HAS_MUTTER48
display.get_compositor ().get_stage ().context.get_backend ().get_default_seat ().bell_notify ();
#elif HAS_MUTTER47
display.get_stage ().context.get_backend ().get_default_seat ().bell_notify ();
#else
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
Expand Down
6 changes: 5 additions & 1 deletion src/ScreenshotManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ namespace Gala {
}

private Cairo.ImageSurface composite_stage_cursor (Cairo.ImageSurface image, Cairo.RectangleInt image_rect) {
unowned Meta.CursorTracker cursor_tracker = wm.get_display ().get_cursor_tracker ();
#if HAS_MUTTER48
unowned var cursor_tracker = wm.get_display ().get_compositor ().get_backend ().get_cursor_tracker ();
#else
unowned var cursor_tracker = wm.get_display ().get_cursor_tracker ();
#endif
Graphene.Point coords = {};
cursor_tracker.get_pointer (out coords, null);

Expand Down
10 changes: 9 additions & 1 deletion src/ShellClients/HideTracker.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public class Gala.HideTracker : Object {
window.unmanaged.connect (schedule_update);
});

var cursor_tracker = display.get_cursor_tracker ();
#if HAS_MUTTER48
unowned var cursor_tracker = display.get_compositor ().get_backend ().get_cursor_tracker ();
#else
unowned var cursor_tracker = display.get_cursor_tracker ();
#endif
cursor_tracker.position_invalidated.connect (() => {
#if HAS_MUTTER45
var has_pointer = panel.window.has_pointer ();
Expand All @@ -86,7 +90,11 @@ public class Gala.HideTracker : Object {
pan_action.gesture_begin.connect (check_valid_gesture);
pan_action.pan.connect (on_pan);

#if HAS_MUTTER48
display.get_compositor ().get_stage ().add_action_full ("panel-swipe-gesture", CAPTURE, pan_action);
#else
display.get_stage ().add_action_full ("panel-swipe-gesture", CAPTURE, pan_action);
#endif

panel.notify["anchor"].connect (setup_barrier);

Expand Down
4 changes: 4 additions & 0 deletions src/Widgets/DwellClickTimer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ namespace Gala {
var scale = display.get_monitor_scale (display.get_current_monitor ());
update_cursor_size (scale);

#if HAS_MUTTER48
unowned var tracker = display.get_compositor ().get_backend ().get_cursor_tracker ();
#else
unowned var tracker = display.get_cursor_tracker ();
#endif
Graphene.Point coords = {};
tracker.get_pointer (out coords, null);

Expand Down
4 changes: 4 additions & 0 deletions src/Widgets/MonitorClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ namespace Gala {
display.window_entered_monitor.connect (window_entered);
display.window_left_monitor.connect (window_left);

#if HAS_MUTTER48
unowned GLib.List<Meta.WindowActor> window_actors = display.get_compositor ().get_window_actors ();
#else
unowned GLib.List<Meta.WindowActor> window_actors = display.get_window_actors ();
#endif
foreach (unowned Meta.WindowActor window_actor in window_actors) {
if (window_actor.is_destroyed ())
continue;
Expand Down
4 changes: 4 additions & 0 deletions src/Widgets/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,11 @@ namespace Gala {
}

private void show_docks (bool with_gesture, bool is_cancel_animation) {
#if HAS_MUTTER48
unowned GLib.List<Meta.WindowActor> window_actors = display.get_compositor ().get_window_actors ();
#else
unowned GLib.List<Meta.WindowActor> window_actors = display.get_window_actors ();
#endif
foreach (unowned Meta.WindowActor actor in window_actors) {
const int MAX_OFFSET = 200;

Expand Down
4 changes: 4 additions & 0 deletions src/Widgets/PointerLocator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ namespace Gala {
stroke_color = new Cairo.Pattern.rgb (rgba.red, rgba.green, rgba.blue);
fill_color = new Cairo.Pattern.rgba (rgba.red, rgba.green, rgba.blue, BACKGROUND_OPACITY);

#if HAS_MUTTER48
unowned var tracker = display.get_compositor ().get_backend ().get_cursor_tracker ();
#else
unowned var tracker = display.get_cursor_tracker ();
#endif
Graphene.Point coords = {};
tracker.get_pointer (out coords, null);

Expand Down
14 changes: 12 additions & 2 deletions src/Widgets/ScreenShield.vala
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,12 @@ namespace Gala {
activation_time = GLib.get_monotonic_time ();
}

wm.get_display ().get_cursor_tracker ().set_pointer_visible (false);
#if HAS_MUTTER48
unowned var tracker = wm.get_display ().get_compositor ().get_backend ().get_cursor_tracker ();
#else
unowned var tracker = wm.get_display ().get_cursor_tracker ();
#endif
tracker.set_pointer_visible (false);
visible = true;
grab_key_focus ();
modal_proxy = wm.push_modal (this);
Expand Down Expand Up @@ -401,7 +406,12 @@ namespace Gala {
modal_proxy = null;
}

wm.get_display ().get_cursor_tracker ().set_pointer_visible (true);
#if HAS_MUTTER48
unowned var tracker = wm.get_display ().get_compositor ().get_backend ().get_cursor_tracker ();
#else
unowned var tracker = wm.get_display ().get_cursor_tracker ();
#endif
tracker.set_pointer_visible (true);
visible = false;

activation_time = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/Widgets/WindowOverview.vala
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ public class Gala.WindowOverview : Clutter.Actor, ActivatableComponent {
((WindowCloneContainer) child).close ();
}


#if HAS_MUTTER48
GLib.Timeout.add (MultitaskingView.ANIMATION_DURATION, () => {
#else
Clutter.Threads.Timeout.add (MultitaskingView.ANIMATION_DURATION, () => {
#endif
cleanup ();

return Source.REMOVE;
Expand Down
Loading
Loading