Skip to content

Commit

Permalink
Add a compatibility helper function for Clutter.cairo_set_source_colo…
Browse files Browse the repository at this point in the history
…r().
  • Loading branch information
glerroo authored and mgalgs committed Mar 25, 2024
1 parent f2e6992 commit 694f159
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ function interesting_mountpoint(mount) {
return ((mount[0].indexOf('/dev/') === 0 || mount[2].toLowerCase() === 'nfs') && mount[2].toLowerCase() !== 'udf');
}

// Gnome 45 Clutter.cairo_set_source_color compatibility
function sm_cairo_set_source_color(cr, bg_color) {
if (Clutter.cairo_set_source_color)
Clutter.cairo_set_source_color(cr, bg_color);
else
cr.setSourceColor(bg_color);
}

const smStyleManager = class SystemMonitor_smStyleManager {
constructor(extension) {
Expand Down Expand Up @@ -346,12 +353,7 @@ const Chart = class SystemMonitor_Chart {
max = Math.max.apply(this, this.data[this.data.length - 1]);
max = Math.max(1, Math.pow(2, Math.ceil(Math.log(max) / Math.log(2))));
}
// GNOME 46 removed Clutter.cairo_set_source_color
if (Clutter.cairo_set_source_color)
Clutter.cairo_set_source_color(cr, this.extension._Background);
else
cr.setSourceColor(this.extension._Background);

sm_cairo_set_source_color(cr, this.extension._Background);
cr.rectangle(0, 0, width, height);
cr.fill();
for (let i = this.parentC.colors.length - 1; i >= 0; i--) {
Expand All @@ -372,11 +374,7 @@ const Chart = class SystemMonitor_Chart {
cr.lineTo(x, (1 - this.data[i][0] / max) * height);
cr.lineTo(x, height);
cr.closePath();
if (Clutter.cairo_set_source_color)
Clutter.cairo_set_source_color(cr, this.parentC.colors[i]);
else
cr.setSourceColor(this.parentC.colors[i]);

sm_cairo_set_source_color(cr, this.parentC.colors[i]);
cr.fill();
}
}
Expand Down Expand Up @@ -612,11 +610,7 @@ const Bar = class SystemMonitor_Bar extends Graph {
for (let mount in this.mounts) {
GTop.glibtop_get_fsusage(this.gtop, this.mounts[mount]);
let perc_full = (this.gtop.blocks - this.gtop.bfree) / this.gtop.blocks;
// GNOME 46 removed Clutter.cairo_set_source_color
if (Clutter.cairo_set_source_color)
Clutter.cairo_set_source_color(cr, this.colors[mount % this.colors.length]);
else
cr.setSourceColor(this.colors[mount % this.colors.length]);
sm_cairo_set_source_color(cr, this.colors[mount % this.colors.length]);

let text = this.mounts[mount];
if (text.length > 10) {
Expand Down Expand Up @@ -682,12 +676,7 @@ const Pie = class SystemMonitor_Pie extends Graph {
let r = (height - ring_width) / 2;
for (let mount in this.mounts) {
GTop.glibtop_get_fsusage(this.gtop, this.mounts[mount]);
// GNOME 46 removed Clutter.cairo_set_source_color
if (Clutter.cairo_set_source_color)
Clutter.cairo_set_source_color(cr, this.colors[mount % this.colors.length]);
else
cr.setSourceColor(this.colors[mount % this.colors.length]);

sm_cairo_set_source_color(cr, this.colors[mount % this.colors.length]);
arc(r, this.gtop.blocks - this.gtop.bfree, this.gtop.blocks, -pi / 2);
cr.stroke();
r -= ring_width;
Expand Down

0 comments on commit 694f159

Please sign in to comment.