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

Remove Clutter.get_default_backend usage #2218

Merged
merged 2 commits into from
Jan 13, 2025
Merged
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
19 changes: 16 additions & 3 deletions lib/Drawing/Canvas.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,33 @@ public class Gala.Drawing.Canvas : GLib.Object, Clutter.Content {
private int height = -1;
private float scale_factor = 1.0f;

private Cogl.Context? cogl_context;

private Cogl.Texture? texture = null;
private Cogl.Bitmap? bitmap = null;

private bool dirty = false;

public signal void draw (Cairo.Context cr, int width, int height);

private void emit_draw () requires (width > 0 && height > 0) {
public override void attached (Clutter.Actor actor) {
#if HAS_MUTTER47
cogl_context = actor.context.get_backend ().get_cogl_context ();
#else
cogl_context = Clutter.get_default_backend ().get_cogl_context ();
#endif
}

public override void detached (Clutter.Actor actor) {
cogl_context = null;
}

private void emit_draw () requires (width > 0 && height > 0 && cogl_context != null) {
dirty = true;
int real_width = (int) Math.ceilf (width * scale_factor);
int real_height = (int) Math.ceilf (height * scale_factor);
if (bitmap == null) {
unowned Cogl.Context ctx = Clutter.get_default_backend ().get_cogl_context ();
bitmap = new Cogl.Bitmap.with_size (ctx, real_width, real_height, Cogl.PixelFormat.CAIRO_ARGB32_COMPAT);
bitmap = new Cogl.Bitmap.with_size (cogl_context, real_width, real_height, Cogl.PixelFormat.CAIRO_ARGB32_COMPAT);
}

unowned Cogl.Buffer? buffer = bitmap.get_buffer ();
Expand Down
20 changes: 15 additions & 5 deletions lib/ShadowEffect.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,33 @@ public class Gala.ShadowEffect : Clutter.Effect {
public int border_radius { get; set; default = 9;}

private int shadow_size;
private Cogl.Pipeline pipeline;
private Cogl.Pipeline? pipeline;
private string? current_key = null;

public ShadowEffect (string css_class = "") {
Object (css_class: css_class);
}

construct {
pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());
}

~ShadowEffect () {
if (current_key != null) {
decrement_shadow_users (current_key);
}
}

public override void set_actor (Clutter.Actor? actor) {
base.set_actor (actor);

if (actor != null) {
#if HAS_MUTTER47
pipeline = new Cogl.Pipeline (actor.context.get_backend ().get_cogl_context ());
#else
pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());
#endif
} else {
pipeline = null;
}
}

private Cogl.Texture? get_shadow (Cogl.Context context, int width, int height, int shadow_size) {
var old_key = current_key;
current_key = "%ix%i:%i".printf (width, height, shadow_size);
Expand Down
12 changes: 12 additions & 0 deletions src/Background/BlurEffect.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public class Gala.BlurEffect : Clutter.Effect {
}

construct {
#if HAS_MUTTER47
unowned var ctx = actor.context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif

actor_pipeline = new Cogl.Pipeline (ctx);
actor_pipeline.set_layer_null_texture (0);
Expand Down Expand Up @@ -98,7 +102,11 @@ public class Gala.BlurEffect : Clutter.Effect {
return true;
}

#if HAS_MUTTER47
unowned var ctx = actor.context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif

framebuffer = null;
texture = null;
Expand Down Expand Up @@ -136,7 +144,11 @@ public class Gala.BlurEffect : Clutter.Effect {

actor_painted = false;

#if HAS_MUTTER47
unowned var ctx = actor.context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif

actor_framebuffer = null;
actor_texture = null;
Expand Down
8 changes: 8 additions & 0 deletions src/InternalUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -380,5 +380,13 @@ namespace Gala {
new_parent.add_child (actor);
actor.unref ();
}

public static void bell_notify (Meta.Display display) {
#if HAS_MUTTER47
display.get_stage ().context.get_backend ().get_default_seat ().bell_notify ();
#else
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
#endif
}
}
}
10 changes: 8 additions & 2 deletions src/Widgets/DwellClickTimer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ namespace Gala {
visible = false;
reactive = false;

pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());
#if HAS_MUTTER47
unowned var backend = context.get_backend ();
#else
unowned var backend = Clutter.get_default_backend ();
#endif

pipeline = new Cogl.Pipeline (backend.get_cogl_context ());

transition = new Clutter.PropertyTransition ("angle");
transition.set_progress_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
Expand All @@ -65,7 +71,7 @@ namespace Gala {

interface_settings = new GLib.Settings ("org.gnome.desktop.interface");

var seat = Clutter.get_default_backend ().get_default_seat ();
var seat = backend.get_default_seat ();
seat.set_pointer_a11y_dwell_click_type (Clutter.PointerA11yDwellClickType.PRIMARY);

seat.ptr_a11y_timeout_started.connect ((device, type, timeout) => {
Expand Down
8 changes: 7 additions & 1 deletion src/Widgets/PointerLocator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ namespace Gala {
reactive = false;

settings = new GLib.Settings ("org.gnome.desktop.interface");
pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());

#if HAS_MUTTER47
unowned var ctx = context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif
pipeline = new Cogl.Pipeline (ctx);

var pivot = Graphene.Point ();
pivot.init (0.5f, 0.5f);
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/WindowCloneContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ namespace Gala {

if (closest == null) {
if (current_window != null) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
InternalUtils.bell_notify (display);
current_window.active = true;
}
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Widgets/WindowSwitcher/WindowSwitcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public class Gala.WindowSwitcher : CanvasActor {

private void open_switcher () {
if (container.get_n_children () == 0) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
InternalUtils.bell_notify (wm.get_display ());
return;
}

Expand Down Expand Up @@ -473,7 +473,7 @@ public class Gala.WindowSwitcher : CanvasActor {
Clutter.Actor actor;

if (container.get_n_children () == 1 && current_icon != null) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
InternalUtils.bell_notify (wm.get_display ());
return;
}

Expand Down
7 changes: 6 additions & 1 deletion src/Widgets/WorkspaceClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ namespace Gala {
}

construct {
pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());
#if HAS_MUTTER47
unowned var ctx = context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif
pipeline = new Cogl.Pipeline (ctx);
var primary = display.get_primary_monitor ();
var monitor_geom = display.get_monitor_geometry (primary);

Expand Down
6 changes: 3 additions & 3 deletions src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ namespace Gala {
if (active_workspace_index != index) {
manager.get_workspace_by_index (index).activate (event.get_time ());
} else {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
InternalUtils.bell_notify (display);
}
}

Expand Down Expand Up @@ -787,13 +787,13 @@ namespace Gala {

// don't allow empty workspaces to be created by moving, if we have dynamic workspaces
if (Meta.Prefs.get_dynamic_workspaces () && Utils.get_n_windows (active) == 1 && workspace.index () == manager.n_workspaces - 1) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
InternalUtils.bell_notify (display);
return;
}

// don't allow moving into non-existing workspaces
if (active == workspace) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
InternalUtils.bell_notify (display);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Zoom.vala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class Gala.Zoom : Object {
// Nothing to do if zooming out of our bounds is requested
if ((current_zoom <= MIN_ZOOM && delta < 0) || (current_zoom >= MAX_ZOOM && delta >= 0)) {
if (play_sound) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
InternalUtils.bell_notify (wm.get_display ());
}
return;
}
Expand Down
Loading