Skip to content

Commit

Permalink
zhrexl#47 gnome 45 support added
Browse files Browse the repository at this point in the history
  • Loading branch information
André Abramé committed Nov 30, 2023
1 parent b8567d1 commit 5dad0ea
Show file tree
Hide file tree
Showing 15 changed files with 1,334 additions and 1,318 deletions.
752 changes: 385 additions & 367 deletions area.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
/* jslint esversion: 6 */
/* exported Shape, TextAlignment, Transformation, getAllFontFamilies, DrawingElement */

const Cairo = imports.cairo;
const Clutter = imports.gi.Clutter;
const GObject = imports.gi.GObject;
import Cairo from 'cairo';

const Pango = imports.gi.Pango;
const PangoCairo = imports.gi.PangoCairo;
import Clutter from 'gi://Clutter';
import GObject from 'gi://GObject';
import Pango from 'gi://Pango';
import PangoCairo from 'gi://PangoCairo';

const Me = imports.misc.extensionUtils.getCurrentExtension();
const UUID = Me.uuid.replace(/@/gi, '_at_').replace(/[^a-z0-9+_-]/gi, '_');
import { CURATED_UUID as UUID } from './utils.js';

var Shape = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6, IMAGE: 7 };
var TextAlignment = { LEFT: 0, CENTER: 1, RIGHT: 2 };
var Transformation = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5, SMOOTH: 100 };

var getAllFontFamilies = function() {
export const Shape = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6, IMAGE: 7 };
export const TextAlignment = { LEFT: 0, CENTER: 1, RIGHT: 2 };
export const Transformation = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5, SMOOTH: 100 };

export const getAllFontFamilies = function() {
return PangoCairo.font_map_get_default().list_families().map(fontFamily => fontFamily.get_name()).sort((a,b) => a.localeCompare(b));
};

Expand Down Expand Up @@ -67,7 +67,7 @@ const MIN_DRAWING_SIZE = 3; // px
const MIN_INTERMEDIATE_POINT_DISTANCE = 1; // px, the higher it is, the fewer points there will be
const MARK_COLOR = Clutter.Color.get_static(Clutter.StaticColor.BLUE);

var DrawingElement = function(params) {
export const DrawingElement = function(params) {
return params.shape == Shape.TEXT ? new TextElement(params) :
params.shape == Shape.IMAGE ? new ImageElement(params) :
new _DrawingElement(params);
Expand Down Expand Up @@ -103,7 +103,7 @@ const _DrawingElement = GObject.registerClass({
});
}

if (params.transform && params.transform.center) {
if (params.transform?.center) {
let angle = (params.transform.angle || 0) + (params.transform.startAngle || 0);
if (angle)
this.transformations.push({ type: Transformation.ROTATION, angle: angle });
Expand Down Expand Up @@ -150,7 +150,7 @@ const _DrawingElement = GObject.registerClass({
if (this.fillRule)
cr.setFillRule(this.fillRule);

if (this.dash && this.dash.active && this.dash.array && this.dash.array[0] && this.dash.array[1])
if (this.dash?.active && this.dash.array && this.dash.array[0] && this.dash.array[1])
cr.setDash(this.dash.array, this.dash.offset);

if (this.eraser)
Expand Down
116 changes: 52 additions & 64 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

/* jslint esversion: 6 */
/* exported init */

const {Gio, GObject} = imports.gi;
const {QuickToggle, SystemIndicator} = imports.ui.quickSettings;
const QuickSettingsMenu = imports.ui.main.panel.statusArea.quickSettings;
const Panel = imports.ui.main.panel;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const AreaManager = Me.imports.ui.areamanager;
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
const UUID = Me.uuid.replace(/@/gi, '_at_').replace(/[^a-z0-9+_-]/gi, '_');

const Config = imports.misc.config;

import GObject from 'gi://GObject';

import { QuickToggle, SystemIndicator, QuickSettingsMenu } from 'resource:///org/gnome/shell/ui/quickSettings.js';
import * as Panel from 'resource:///org/gnome/shell/ui/panel.js';

import * as Config from 'resource:///org/gnome/shell/misc/config.js';

import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';

import { Files } from './files.js';
import * as AreaManager from './ui/areamanager.js';



const GS_VERSION = Config.PACKAGE_VERSION;

function init() {
return new Extension();
}


const FeatureToggle = GObject.registerClass(
class FeatureToggle extends QuickToggle {
Expand All @@ -47,39 +46,26 @@ class FeatureToggle extends QuickToggle {
iconName: 'applications-graphics-symbolic',
toggleMode: true,
});


// NOTE: In GNOME 44, the `label` property must be set after
// construction. The newer `title` property can be set at construction.
// this.label = 'Feature Name';

// Binding the toggle to a GSettings key
//this._settings = new Gio.Settings({
// schema_id: 'org.gnome.shell.extensions.example',
//});

//this._settings.bind('feature-enabled',
// this, 'checked',
// Gio.SettingsBindFlags.DEFAULT);
}
});
var Indicator = GObject.registerClass(


const Indicator = GObject.registerClass(
class Indicator extends SystemIndicator {
_init() {
super._init();

this.toggle = new FeatureToggle();
this.quickSettingsItems.push(this.toggle);
QuickSettingsMenu._indicators.add_child(this);
QuickSettingsMenu._addItems(this.quickSettingsItems);
this._addIndicator();

//Place the toggles above the background apps entry
if (GS_VERSION >= 44) {
this.quickSettingsItems.forEach((item) => {
QuickSettingsMenu.menu._grid.set_child_below_sibling(item,
QuickSettingsMenu._backgroundApps.quickSettingsItems[0]);
});
}
// if (GS_VERSION >= 44) {
// this.quickSettingsItems.forEach((item) => {
// QuickSettingsMenu.menu._grid.set_child_below_sibling(item,
// QuickSettingsMenu._backgroundApps.quickSettingsItems[0]);
// });
// }

this.connect('destroy', () => {
this.quickSettingsItems.forEach(item => item.destroy());
Expand All @@ -91,60 +77,62 @@ class Indicator extends SystemIndicator {
}
});

const Extension = GObject.registerClass({
GTypeName: `${UUID}-Extension`,
}, class Extension extends GObject.Object{
_init() {
ExtensionUtils.initTranslations();

export default class DrawOnYourScreenExtension extends Extension {

constructor(metadata) {
super(metadata);
this.initTranslations();
this.FILES = new Files(this);
}

create_toggle() {
if (GS_VERSION >= '44.0') {
if (!Me.settings.get_boolean("quicktoggle-disabled") && !this.toggle) {
if (!this.getSettings().get_boolean("quicktoggle-disabled") && !this.toggle) {
this.toggle = new Indicator();
this.drawingtoggle = this.toggle.get_toggle();
this.drawingtoggle.connect('clicked',this.toggle_drawing.bind(this));
} else if (Me.settings.get_boolean("quicktoggle-disabled") && this.toggle) {
} else if (this.getSettings().get_boolean("quicktoggle-disabled") && this.toggle) {
this.toggle.destroy();
this.toggle = null;
}
}
}

enable() {
if (ExtensionUtils.isOutOfDate(Me))
log(`${Me.metadata.uuid}: GNOME Shell ${Number.parseFloat(GS_VERSION)} is not supported.`);

Me.settings = ExtensionUtils.getSettings();
Me.internalShortcutSettings = ExtensionUtils.getSettings(Me.metadata['settings-schema'] + '.internal-shortcuts');
Me.drawingSettings = ExtensionUtils.getSettings(Me.metadata['settings-schema'] + '.drawing');
this.areaManager = new AreaManager.AreaManager();
this.settings = this.getSettings();
this.internalShortcutSettings = this.getSettings(this.metadata['settings-schema'] + '.internal-shortcuts');
this.drawingSettings = this.getSettings(this.metadata['settings-schema'] + '.drawing');
this.areaManager = new AreaManager.AreaManager(this);
this.areaManager.enable();

this.toggle = null;
this.create_toggle();

Me.settings.connect('changed', this._onSettingsChanged.bind(this));
}
toggle_drawing()
{
Panel.closeQuickSettings();
this.drawingtoggle.set_checked(false);
this.areaManager.toggleDrawing();
this.getSettings().connect('changed', this._onSettingsChanged.bind(this));
}

disable() {
if (this.toggle)
this.toggle.destroy();

this.areaManager.disable();
delete this.areaManager;
delete Me.settings;
delete Me.internalShortcutSettings;
delete this.settings;
delete this.internalShortcutSettings;
}

toggle_drawing()
{
Panel.closeQuickSettings();
this.drawingtoggle.set_checked(false);
this.areaManager.toggleDrawing();
}

_onSettingsChanged() {
this.create_toggle()
}
});
}



Loading

0 comments on commit 5dad0ea

Please sign in to comment.