diff --git a/Makefile b/Makefile index 9c404d4..c7eeb92 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ -##@ Test -lint: ## Run linters only. - @echo -e "\033[2m→ Run linters...\033[0m" - -test: ## Run go tests for files with tests. - @echo -e "\033[2m→ Run tests for all files...\033[0m" - -check: lint test ## Run full check: lint and test. - ##@ Deploy -zip: ## Make zip file for deploy to https://extensions.gnome.org/upload/. +zip: compile-schemas ## Make zip file for deploy to https://extensions.gnome.org/upload/. @echo -e "\033[2m→ Making zip file...\033[0m" - zip horizontal-workspace-indicatortty2.io.zip metadata.json extension.js stylesheet.css LICENSE + zip horizontal-workspace-indicatortty2.io.zip metadata.json extension.js stylesheet.css prefs.js \ + LICENSE \ + schemas/gschemas.compiled \ + schemas/org.gnome.shell.extensions.nothing-to-say.gschema.xml + +compile-schemas: ## Compile all in schemas folder + glib-compile-schemas --strict schemas/ + +install: compile-schemas ## Copy to extensions directory for debug. + cp -r * ~/.local/share/gnome-shell/extensions/horizontal-workspace-indicator@tty2.io ##@ Other #------------------------------------------------------------------------------ @@ -19,4 +19,4 @@ help: ## Display help #------------- -------------- .DEFAULT_GOAL := help -.PHONY: help lint test check build install run \ No newline at end of file +.PHONY: help zip compile-schemas install diff --git a/extension.js b/extension.js index 249065a..f1d4e28 100644 --- a/extension.js +++ b/extension.js @@ -2,6 +2,8 @@ const { Clutter, St, GObject } = imports.gi; const Main = imports.ui.main; const PanelMenu = imports.ui.panelMenu; +const ExtensionUtils = imports.misc.extensionUtils; + const bullet = "●"; const circle = "○"; const leftButton = 1; @@ -39,10 +41,10 @@ let WorkspaceIndicator = GObject.registerClass( this.connect('button-press-event', this._onButtonPress); } - _onDestroy() { + destroy() { for (let i = 0; i < this._workspaceManagerSignals.length; i++) global.workspace_manager.disconnect(this._workspaceManagerSignals[i]) - super._onDestroy(); + super.destroy(); } _updateView() { @@ -71,12 +73,15 @@ let WorkspaceIndicator = GObject.registerClass( class Extension { constructor(uuid) { + this._indicator = null; this._uuid = uuid; + this.settings = ExtensionUtils.getSettings(); } enable() { this._indicator = new WorkspaceIndicator(); - Main.panel.addToStatusArea(this._uuid, this._indicator); + let widgetPosition = this.settings.get_value("widget-position").unpack(); + Main.panel.addToStatusArea(this._uuid, this._indicator, getWidgetIndex(widgetPosition), widgetPosition); } disable() { @@ -85,6 +90,14 @@ class Extension { } } +function getWidgetIndex(position) { + if (position === "right") { + return 0 + } + + return 1 +} + function getWidgetText() { let txt = ""; let numberWorkspaces = global.workspace_manager.get_n_workspaces(); diff --git a/metadata.json b/metadata.json index 96a94b7..f48baa5 100644 --- a/metadata.json +++ b/metadata.json @@ -1,8 +1,9 @@ { "description": "Workspace indicator shows the amount of opened workspaces and the current one", "name": "Workspace indicator", - "shell-version": ["3.38","40", "41"], + "settings-schema": "org.gnome.shell.extensions.horizontal-workspace-indicator", + "shell-version": ["40", "41"], "url": "https://github.com/tty2/horizontal-workspace-indicator", "uuid": "horizontal-workspace-indicator@tty2.io", - "version": "0.0.9" + "version": "0.1.0" } diff --git a/prefs.js b/prefs.js new file mode 100644 index 0000000..aa89efe --- /dev/null +++ b/prefs.js @@ -0,0 +1,61 @@ +"use strict"; + +const Gio = imports.gi.Gio; +const Gtk = imports.gi.Gtk; + +const ExtensionUtils = imports.misc.extensionUtils; +const Extension = ExtensionUtils.getCurrentExtension(); + +function init() {} + +function buildPrefsWidget() { + this.settings = ExtensionUtils.getSettings(); + + const prefsWidget = new Gtk.Grid({ + margin_top: 20, + margin_bottom: 20, + margin_start: 20, + margin_end: 20, + column_spacing: 12, + row_spacing: 12, + visible: true, + halign: Gtk.Align.CENTER, + }); + + let title = new Gtk.Label({ + label: `Preferences`, + halign: Gtk.Align.CENTER, + use_markup: true, + visible: true + }); + prefsWidget.attach(title, 0, 0, 2, 1); + + let note = new Gtk.Label({ + label: `After any changes turn the extension off and on again.`, + halign: Gtk.Align.CENTER, + use_markup: true, + visible: true + }); + prefsWidget.attach(note, 0, 1, 2, 1); + + const widgetPositionLabel = new Gtk.Label({ + label: "Widget position", + halign: Gtk.Align.START, + visible: true, + }); + prefsWidget.attach(widgetPositionLabel, 0, 2, 1, 1); + + const widgetPositionComboBox = new Gtk.ComboBoxText(); + widgetPositionComboBox.append("right", "Right corner | Status area"); + widgetPositionComboBox.append("center", "Center | Date time area"); + widgetPositionComboBox.append("left", "Left corner | Activities area"); + this.settings.bind( + "widget-position", + widgetPositionComboBox, + "active-id", + Gio.SettingsBindFlags.DEFAULT + ); + prefsWidget.attach(widgetPositionComboBox, 1, 2, 1, 1); + + return prefsWidget; +} diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled new file mode 100644 index 0000000..08082a1 Binary files /dev/null and b/schemas/gschemas.compiled differ diff --git a/schemas/org.gnome.shell.extensions.horizontal-workspace-indicator.gschema.xml b/schemas/org.gnome.shell.extensions.horizontal-workspace-indicator.gschema.xml new file mode 100644 index 0000000..cfcfbec --- /dev/null +++ b/schemas/org.gnome.shell.extensions.horizontal-workspace-indicator.gschema.xml @@ -0,0 +1,15 @@ + + + + + + + + + + 'right' + Widget position + This specifies the position of widget on the left, center or right of top panel. + + +