Skip to content

Commit

Permalink
🎉 Port to GNOME 47
Browse files Browse the repository at this point in the history
  • Loading branch information
Schneegans committed Jul 31, 2024
1 parent a10b724 commit 50755fd
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 21 deletions.
3 changes: 2 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"settings-schema": "org.gnome.shell.extensions.flypie",
"shell-version": [
"45",
"46"
"46",
"47"
],
"url": "https://github.com/Schneegans/Fly-Pie",
"version": 26
Expand Down
33 changes: 33 additions & 0 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import PangoCairo from 'gi://PangoCairo';
// as in the GNOME Shell process. Some modules are only available or required in one of
// these processes.
const St = await importInShellOnly('gi://St');
const Clutter = await importInShellOnly('gi://Clutter');
const Cogl= await importInShellOnly('gi://Cogl');
const Gtk = await importInPrefsOnly('gi://Gtk');

// We import the Config module. This is done differently in the GNOME Shell process and in
Expand Down Expand Up @@ -517,6 +519,37 @@ export function getAverageIconColor(iconSurface, iconSize) {
return [rTotal / total * 255, gTotal / total * 255, bTotal / total * 255];
}

//////////////////////////////////////////////////////////////////////////////////////////
// This methods create a new Clutter.Color or Cogl.Color object, depending on the //
// current shell version. //
//////////////////////////////////////////////////////////////////////////////////////////

export function createColorRGB(r, g, b, a=255) {
if (shellVersionIsAtLeast(47, 'alpha')) {
return new Cogl.Color({red: r, green: g, blue: b, alpha: a});
}
return new Clutter.Color({red: r, green: g, blue: b, alpha: a});
}

export function createColorHSL(h, s, l) {
if (shellVersionIsAtLeast(47, 'alpha')) {
return Cogl.Color.init_from_hsl(h, s, l);
}
return Clutter.Color.from_hsl(h, s, l);
}

//////////////////////////////////////////////////////////////////////////////////////////
// Converts a hex, rgb, or rgba CSS-like color string to either a Clutter.Color or a //
// Cogl.Color object. //
//////////////////////////////////////////////////////////////////////////////////////////

export function parseColor(color) {
if (shellVersionIsAtLeast(47, 'alpha'))
{
return Cogl.Color.from_string(color);
}
return Clutter.Color.from_string(color);
}

//////////////////////////////////////////////////////////////////////////////////////////
// This rounds the given number to the nearest multiple of base. This works for integer //
Expand Down
4 changes: 2 additions & 2 deletions src/extension/Background.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class Background extends Clutter.Actor {

// Set the background color according to the settings.
this.backgroundColor =
Clutter.Color.from_string(this._settings.get_string('background-color'))[1];
utils.parseColor(this._settings.get_string('background-color'))[1];

// And update it in case of changes.
this._settingsConnections.push(
this._settings.connect('changed::background-color', () => {
this.backgroundColor =
Clutter.Color.from_string(this._settings.get_string('background-color'))[1];
utils.parseColor(this._settings.get_string('background-color'))[1];
}));

// Switch monitor side when the preview-on-right-side settings key changes.
Expand Down
29 changes: 17 additions & 12 deletions src/extension/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class MenuItem extends Clutter.Actor {

// This is recursively updated using setParentColor(). It is used for the background
// coloring when the color mode is set to 'parent'.
this._parentColor = new Clutter.Color({red: 255, green: 255, blue: 255});
this._parentColor = utils.createColorRGB( 255, 255, 255);

// This callback will be executed when the item is selected. Only items without any
// children but with such a callback can be activated.
Expand Down Expand Up @@ -347,11 +347,11 @@ class MenuItem extends Clutter.Actor {
globalScale: globalScale,
easingDuration: settings.get_double('easing-duration') * 1000,
easingMode: settings.get_enum('easing-mode'),
textColor: Clutter.Color.from_string(settings.get_string('text-color'))[1],
textColor: utils.parseColor(settings.get_string('text-color'))[1],
font: settings.get_string('font'),
labelFont: settings.get_string('label-font'),
traceThickness: settings.get_double('trace-thickness') * globalScale,
traceColor: Clutter.Color.from_string(settings.get_string('trace-color'))[1],
traceColor: utils.parseColor(settings.get_string('trace-color'))[1],
state: new Map ([
[MenuItemState.INVISIBLE, {
colorMode: '',
Expand All @@ -361,7 +361,7 @@ class MenuItem extends Clutter.Actor {
}],
[MenuItemState.CENTER, {
colorMode: settings.get_string('center-color-mode'),
fixedColor: Clutter.Color.from_string(settings.get_string('center-fixed-color'))[1],
fixedColor: utils.parseColor(settings.get_string('center-fixed-color'))[1],
size: settings.get_double('center-size') * globalScale,
offset: 0,
iconScale: settings.get_double('center-icon-scale'),
Expand All @@ -376,7 +376,7 @@ class MenuItem extends Clutter.Actor {
}],
[MenuItemState.CENTER_HOVERED, {
colorMode: settings.get_string('center-color-mode-hover'),
fixedColor: Clutter.Color.from_string(settings.get_string('center-fixed-color-hover'))[1],
fixedColor: utils.parseColor(settings.get_string('center-fixed-color-hover'))[1],
size: settings.get_double('center-size-hover') * globalScale,
offset: 0,
iconScale: settings.get_double('center-icon-scale-hover'),
Expand All @@ -391,7 +391,7 @@ class MenuItem extends Clutter.Actor {
}],
[MenuItemState.CHILD, {
colorMode: settings.get_string('child-color-mode'),
fixedColor: Clutter.Color.from_string(settings.get_string('child-fixed-color'))[1],
fixedColor: utils.parseColor(settings.get_string('child-fixed-color'))[1],
size: settings.get_double('child-size') * globalScale,
offset: settings.get_double('child-offset') * globalScale,
iconScale: settings.get_double('child-icon-scale'),
Expand All @@ -406,7 +406,7 @@ class MenuItem extends Clutter.Actor {
}],
[MenuItemState.CHILD_HOVERED, {
colorMode: settings.get_string('child-color-mode-hover'),
fixedColor: Clutter.Color.from_string(settings.get_string('child-fixed-color-hover'))[1],
fixedColor: utils.parseColor(settings.get_string('child-fixed-color-hover'))[1],
size: settings.get_double('child-size-hover') * globalScale,
offset: settings.get_double('child-offset-hover') * globalScale,
iconScale: settings.get_double('child-icon-scale-hover'),
Expand All @@ -421,7 +421,7 @@ class MenuItem extends Clutter.Actor {
}],
[MenuItemState.GRANDCHILD, {
colorMode: settings.get_string('grandchild-color-mode'),
fixedColor: Clutter.Color.from_string(settings.get_string('grandchild-fixed-color'))[1],
fixedColor: utils.parseColor(settings.get_string('grandchild-fixed-color'))[1],
size: settings.get_double('grandchild-size') * globalScale,
offset: settings.get_double('grandchild-offset') * globalScale,
iconOpacity: 0,
Expand All @@ -431,7 +431,7 @@ class MenuItem extends Clutter.Actor {
}],
[MenuItemState.GRANDCHILD_HOVERED, {
colorMode: settings.get_string('grandchild-color-mode-hover'),
fixedColor: Clutter.Color.from_string(settings.get_string('grandchild-fixed-color-hover'))[1],
fixedColor: utils.parseColor(settings.get_string('grandchild-fixed-color-hover'))[1],
size: settings.get_double('grandchild-size-hover') * globalScale,
offset: settings.get_double('grandchild-offset-hover') * globalScale,
iconOpacity: 0,
Expand Down Expand Up @@ -539,7 +539,7 @@ class MenuItem extends Clutter.Actor {
blue: MenuItemSettings.textColor.blue / 255
});
const [r, g, b] = utils.getAverageIconColor(surface, 24);
this._averageIconColor = new Clutter.Color({red: r, green: g, blue: b});
this._averageIconColor = utils.createColorRGB(r, g, b);
}

// Now we modify this color based on the configured luminance and saturation values.
Expand Down Expand Up @@ -771,7 +771,12 @@ class MenuItem extends Clutter.Actor {
// but the luminance and saturation values are based on the given input values.
static getAutoColor(averageColor, luminance, saturation, opacity) {

let [h, l, s] = averageColor.to_hls();
let h, l, s;
if (utils.shellVersionIsAtLeast(47, 'alpha')) {
[h,s,l] = averageColor.to_hsl();
} else {
[h, l, s] = averageColor.to_hls();
}

// First we increase the base luminance to 0.5 so that we do not create pitch black
// colors.
Expand All @@ -788,7 +793,7 @@ class MenuItem extends Clutter.Actor {
s = sFac > 0 ? s * (1 - sFac) + 1 * sFac : s * (sFac + 1);
}

const result = Clutter.Color.from_hls(h, l, s);
const result = utils.createColorHSL(h, l, s);
result.alpha = opacity;

return result;
Expand Down
6 changes: 3 additions & 3 deletions src/extension/SelectionWedges.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ class SelectionWedges extends Clutter.Actor {
this._settings = {
wedgeWidth: settings.get_double('wedge-width') * globalScale,
wedgeInnerRadius: settings.get_double('wedge-inner-radius') * globalScale,
wedgeColor: Clutter.Color.from_string(settings.get_string('wedge-color'))[1],
wedgeColorHover: Clutter.Color.from_string(settings.get_string('wedge-color-hover'))[1],
wedgeSeparatorColor: Clutter.Color.from_string(settings.get_string('wedge-separator-color'))[1],
wedgeColor: utils.parseColor(settings.get_string('wedge-color'))[1],
wedgeColorHover: utils.parseColor(settings.get_string('wedge-color-hover'))[1],
wedgeSeparatorColor: utils.parseColor(settings.get_string('wedge-separator-color'))[1],
wedgeSeparatorWidth: settings.get_double('wedge-separator-width') * globalScale,
gestureSelectionTimeout: settings.get_double('gesture-selection-timeout'),
gestureJitterThreshold: settings.get_double('gesture-jitter-threshold') * globalScale,
Expand Down
6 changes: 3 additions & 3 deletions src/extension/TouchButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default class TouchButtons {
// clang-format off
this._cachedSettings = {
easingDuration: this._settings.get_double('easing-duration') * 1000,
textColor: Clutter.Color.from_string(this._settings.get_string('text-color'))[1],
textColor: utils.parseColor(this._settings.get_string('text-color'))[1],
font: this._settings.get_string('font'),
opacity: this._settings.get_double('touch-buttons-opacity') * 255,
showInOverview: this._settings.get_boolean('touch-buttons-show-in-overview-mode'),
Expand Down Expand Up @@ -209,7 +209,7 @@ export default class TouchButtons {
// clang-format on

const [r, g, b] = utils.getAverageIconColor(surface, 24);
const averageIconColor = new Clutter.Color({red: r, green: g, blue: b});
const averageIconColor = utils.createColorRGB(r, g, b);

// Now we modify this color based on the configured luminance and saturation values.
const saturation = this._settings.get_double('center-auto-color-saturation-hover');
Expand All @@ -222,7 +222,7 @@ export default class TouchButtons {
}
// Else we simply use the configured fixed color.
else {
this._cachedSettings.backgroundColor = Clutter.Color.from_string(
this._cachedSettings.backgroundColor = utils.parseColor(
this._settings.get_string('center-fixed-color-hover'))[1];
}

Expand Down

0 comments on commit 50755fd

Please sign in to comment.