Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from tpikonen/vertical
Browse files Browse the repository at this point in the history
Use a vertical label on a vertical panel
  • Loading branch information
tty2 authored Oct 5, 2022
2 parents adce92d + 067971a commit 6525b13
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
44 changes: 26 additions & 18 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Clutter, St, GObject } = imports.gi;
const { Clutter, St, GObject, Pango } = imports.gi;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;

Expand All @@ -25,10 +25,14 @@ let WorkspaceIndicator = GObject.registerClass(

this._statusLabel = new St.Label({
style_class: "panel-button-text",
text: getWidgetText(),
text: this.getWidgetText(),
x_expand: true,
y_expand: true,
y_align: Clutter.ActorAlign.CENTER,
});
this._statusLabel.clutter_text.line_wrap = true;
this._statusLabel.clutter_text.line_wrap_mode = Pango.WrapMode.CHAR;
this._statusLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
this._container.add_actor(this._statusLabel);

let workspaceManager = global.workspace_manager;
Expand All @@ -49,7 +53,7 @@ let WorkspaceIndicator = GObject.registerClass(
}

_updateView() {
this._statusLabel.text = getWidgetText();
this._statusLabel.text = this.getWidgetText();
}

_onButtonPress(actor, event) {
Expand All @@ -75,6 +79,24 @@ let WorkspaceIndicator = GObject.registerClass(
}
}
}

isHorizontal() {
let settings = ExtensionUtils.getSettings();
let orientation = settings.get_string("widget-orientation");
return orientation != 'vertical';
}

getWidgetText() {
let items = [];
let numberWorkspaces = global.workspace_manager.get_n_workspaces();
let currentWorkspaceIndex = global.workspace_manager.get_active_workspace_index();
let separator = this.isHorizontal() ? "" : "\n";

for (let i = 0; i < numberWorkspaces; i++) {
items.push(i == currentWorkspaceIndex ? bullet : circle);
}
return items.join(separator)
}
}
);

Expand Down Expand Up @@ -105,20 +127,6 @@ function getWidgetIndex(position) {
return 1
}

function getWidgetText() {
let txt = "";
let numberWorkspaces = global.workspace_manager.get_n_workspaces();
let currentWorkspaceIndex = global.workspace_manager.get_active_workspace_index();
for (let i = 0; i < numberWorkspaces; i++) {
if (i == currentWorkspaceIndex) {
txt += bullet;
} else {
txt += circle;
}
}
return txt
}

function init(meta) {
return new Extension(meta.uuid);
}
}
18 changes: 18 additions & 0 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,23 @@ function buildPrefsWidget() {
);
prefsWidget.attach(widgetPositionComboBox, 1, 2, 1, 1);

const widgetOrientationLabel = new Gtk.Label({
label: "Widget orientation",
halign: Gtk.Align.START,
visible: true,
});
prefsWidget.attach(widgetOrientationLabel, 0, 3, 1, 1);

const widgetOrientationComboBox = new Gtk.ComboBoxText();
widgetOrientationComboBox.append("horizontal", "Horizontal");
widgetOrientationComboBox.append("vertical", "Vertical");
this.settings.bind(
"widget-orientation",
widgetOrientationComboBox,
"active-id",
Gio.SettingsBindFlags.DEFAULT
);
prefsWidget.attach(widgetOrientationComboBox, 1, 3, 1, 1);

return prefsWidget;
}
Binary file modified schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,14 @@
<summary>Widget position</summary>
<description>This specifies the position of widget on the left, center or right of top panel.</description>
</key>
<key name="widget-orientation" type="s">
<choices>
<choice value="horizontal"/>
<choice value="vertical"/>
</choices>
<default>'horizontal'</default>
<summary>Widget orientation</summary>
<description>This specifies the orientation of the dots in the widget, horizontal or vertical (for vertical panels).</description>
</key>
</schema>
</schemalist>

0 comments on commit 6525b13

Please sign in to comment.