Add settings UI with workspace controls and gap and margin spinners

`Settings.ui` is built with and can be inpsected with Glade.
This commit is contained in:
Tor Hedin Brønner
2018-07-11 18:47:56 +02:00
parent e21433333c
commit 55c6b60803
4 changed files with 998 additions and 14 deletions
+722
View File
@@ -0,0 +1,722 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="horizontal_margin">
<property name="upper">100</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="vertical_margin">
<property name="upper">100</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="window_gap">
<property name="upper">99</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkNotebook" id="paperwm_settings">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkBox" id="general">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">24</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame" id="dock_display2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<child>
<object class="GtkListBoxRow" id="general_row">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="workspace_grid2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel" id="workspace_label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Gap between windows</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="window_gap_spin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width_chars">2</property>
<property name="max_width_chars">2</property>
<property name="progress_pulse_step">1</property>
<property name="input_purpose">number</property>
<property name="adjustment">window_gap</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="update_policy">if-valid</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="general_row1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="workspace_grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Horizontal margin</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="hmargin_spinner">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width_chars">2</property>
<property name="max_width_chars">2</property>
<property name="text" translatable="yes">0</property>
<property name="progress_pulse_step">1</property>
<property name="input_purpose">number</property>
<property name="adjustment">horizontal_margin</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="update_policy">if-valid</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="general_row2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="workspace_grid5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel" id="horizontal_margin1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Vertical margin</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="vmargin_spinner">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width_chars">2</property>
<property name="max_width_chars">2</property>
<property name="text" translatable="yes">0</property>
<property name="progress_pulse_step">1</property>
<property name="input_purpose">number</property>
<property name="adjustment">vertical_margin</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="update_policy">if-valid</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="general_tab">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_General</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkBox" id="workspaces">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">24</property>
<property name="margin_bottom">24</property>
<property name="orientation">vertical</property>
<property name="spacing">24</property>
<child>
<object class="GtkFrame" id="dock_display">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<child>
<object class="GtkListBoxRow" id="workspace_list_row">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="workspace_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel" id="workspace_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Configure workspace</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="worskpace_combo_text">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkStack" id="workspace_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="workspaces_tab">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Workspaces</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkBox" id="keybindings">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">24</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame" id="dock_display3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<child>
<object class="GtkListBoxRow" id="general_row3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="workspace_grid6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel" id="workspace_label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Switch next</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">+</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_entry">True</property>
<child internal-child="entry">
<object class="GtkEntry">
<property name="can_focus">False</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">-</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="general_row4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="workspace_grid7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel" id="workspace_label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Switch previous</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">+</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_entry">True</property>
<child internal-child="entry">
<object class="GtkEntry">
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">-</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="general_row5">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="workspace_grid8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel" id="workspace_label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Switch left</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">+</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_entry">True</property>
<child internal-child="entry">
<object class="GtkEntry">
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">-</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="general_row6">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="workspace_grid9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel" id="workspace_label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Switch right</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">+</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_entry">True</property>
<child internal-child="entry">
<object class="GtkEntry">
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">-</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="keybindings_tab">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Keybindings</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkBox" id="about">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="about_tab">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_About</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="position">3</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
</interface>
+233
View File
@@ -0,0 +1,233 @@
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const WORKSPACE_KEY = 'org.gnome.Shell.Extensions.PaperWM.Workspace';
const WORKSPACE_LIST_KEY = 'org.gnome.Shell.Extensions.PaperWM.WorkspaceList';
const wmSettings = new Gio.Settings({ schema_id:
'org.gnome.desktop.wm.preferences'});
const schemaSource = Gio.SettingsSchemaSource.new_from_directory(
GLib.build_filenamev([Me.path, "schemas"]),
Gio.SettingsSchemaSource.get_default(),
false
);
const workspaceList = new Gio.Settings({
settings_schema: schemaSource.lookup(WORKSPACE_LIST_KEY, true)
});
function getWorkspaceSettingsByUUID(uuid) {
return new Gio.Settings({
settings_schema: schemaSource.lookup(WORKSPACE_KEY, true),
path: `/org/gnome/shell/extensions/paperwm/workspaces/${uuid}/`});
}
function getWorkspaceSettings(index) {
let list = workspaceList.get_strv('list');
for (let uuid of list) {
let settings = getWorkspaceSettingsByUUID(uuid);
if (settings.get_int('index') === index) {
return [uuid, settings];
}
}
return getNewWorkspaceSettings(index);
}
function getNewWorkspaceSettings(index) {
let uuid = GLib.uuid_string_random();
let settings = getWorkspaceSettingsByUUID(uuid);
let id = settings.connect('changed', () => {
settings.disconnect(id);
if (settings.get_int('index') === -1) {
settings.set_int('index', index);
}
let list = workspaceList.get_strv('list');
list.push(uuid);
workspaceList.set_strv('list', list);
});
return [uuid, settings];
}
class SettingsWidget {
constructor() {
this._settings = Convenience.getSettings();
this._workspaceList = workspaceList;
this.builder = new Gtk.Builder();
this.builder.add_from_file(Me.path + '/Settings.ui');
this.widget = new Gtk.ScrolledWindow({ hscrollbar_policy: Gtk.PolicyType.NEVER });
this._notebook = this.builder.get_object('paperwm_settings');
this.widget.add(this._notebook);
// General
let windowGap = this.builder.get_object('window_gap_spin');
let gap = this._settings.get_int('window-gap');
windowGap.set_value(gap);
windowGap.connect('value-changed', () => {
this._settings.set_int('window-gap', windowGap.get_value());
});
let hMargin = this.builder.get_object('hmargin_spinner');
hMargin.set_value(this._settings.get_int('horizontal-margin'));
hMargin.connect('value-changed', () => {
this._settings.set_int('horizontal-margin', hMargin.get_value());
});
let vMargin = this.builder.get_object('vmargin_spinner');
vMargin.set_value(this._settings.get_int('vertical-margin'));
vMargin.connect('value-changed', () => {
this._settings.set_int('vertical-margin', vMargin.get_value());
});
// Workspaces
const workspaceCombo = this.builder.get_object('worskpace_combo_text');
const workspaceStack = this.builder.get_object('workspace_stack');
const nWorkspaces = wmSettings.get_int('num-workspaces');
this.workspaceNames = wmSettings.get_strv('workspace-names');
for (let i=0; i < nWorkspaces; i++) {
let [uuid, settings] = getWorkspaceSettings(i);
let view = this.createWorkspacePage(settings, i);
workspaceStack.add_named(view, i.toString());
let name = this.getWorkspaceName(settings, i);
workspaceCombo.append_text(name);
}
workspaceCombo.connect('changed', () => {
if (this._updatingName)
return;
let active = workspaceCombo.get_active();
log(`active ${active}`);
let page = workspaceStack.get_child_by_name(active.toString());
workspaceStack.set_visible_child(page);
});
workspaceCombo.set_active(0);
createRow('foo', new Gtk.ColorButton());
}
createWorkspacePage(settings, index) {
let view = new Gtk.Frame();
let list = new Gtk.ListBox();
view.add(list);
let nameEntry = new Gtk.Entry();
let colorButton = new Gtk.ColorButton();
let background = new Gtk.FileChooserButton();
list.add(createRow('Name', nameEntry));
list.add(createRow('Color', colorButton));
list.add(createRow('Background', background));
let rgba = new Gdk.RGBA();
let color = settings.get_string('color');
let palette = this._settings.get_strv('workspace-colors');
if (color === '')
color = palette[index % palette.length];
rgba.parse(color);
colorButton.set_rgba(rgba);
let filename = settings.get_string('background');
if (filename === '')
background.unselect_all();
else
background.set_filename(filename);
nameEntry.set_text(this.getWorkspaceName(settings, index));
let workspace_combo = this.builder.get_object('worskpace_combo_text');
nameEntry.connect('changed', () => {
let active = workspace_combo.get_active();
let name = nameEntry.get_text();
this._updatingName = true;
workspace_combo.remove(active);
workspace_combo.insert_text(active, name);
workspace_combo.set_active(active);
this._updatingName = false;
settings.set_string('name', name);
});
colorButton.connect('color-set', () => {
let color = colorButton.get_rgba().to_string();
settings.set_string('color', color);
settings.set_string('background', '');
background.unselect_all();
});
background.connect('file-set', () => {
let filename = background.get_filename();
settings.set_string('background', filename);
});
return view;
}
getWorkspaceName(settings, index) {
let name = settings.get_string('name');
if (name === '')
name = this.workspaceNames[index];
if (name === undefined)
name = `Workspace ${index}`;
return name;
}
}
function createRow(text, widget, signal, handler) {
let margin = 12;
let row = new Gtk.ListBoxRow({selectable: false});
let box = new Gtk.Box({
margin_start: margin, margin_end: margin,
orientation: Gtk.Orientation.HORIZONTAL
});
let label = new Gtk.Label({
label: text, hexpand: true, xalign: 0
});
box.add(label);
box.add(widget);
row.add(box);
return row;
}
function init() {
}
function buildPrefsWidget() {
let settings = new SettingsWidget();
let widget = settings.widget;
widget.show_all();
return widget;
}
+22 -1
View File
@@ -1,10 +1,13 @@
var Extension = imports.misc.extensionUtils.extensions['paperwm@hedning:matrix.org'];
var Gio = imports.gi.Gio;
var GLib = imports.gi.GLib;
var settings = Extension.imports.convenience.getSettings();
var Tiling = Extension.imports.tiling;
var utils = Extension.imports.utils;
var Tiling = Extension.imports.tiling;
var debug = utils.debug;
var screen = global.screen;
var WORKSPACE_KEY = 'org.gnome.Shell.Extensions.PaperWM.Workspace';
var WORKSPACE_LIST_KEY = 'org.gnome.Shell.Extensions.PaperWM.WorkspaceList';
@@ -44,6 +47,7 @@ function init() {
settings.connect('changed::workspace-colors', setState);
}
var id;
function enable() {
schemaSource = Gio.SettingsSchemaSource.new_from_directory(
GLib.build_filenamev([Extension.path, "schemas"]),
@@ -54,6 +58,23 @@ function enable() {
workspaceList = new Gio.Settings({
settings_schema: schemaSource.lookup(WORKSPACE_LIST_KEY, true)
});
// Update workspace settings if it's changed from the preference UI
id = workspaceList.connect('changed::list', () => {
for (let uuid of workspaceList.get_strv('list')) {
let settings = getWorkspaceSettingsByUUID(uuid);
let index = settings.get_int('index');
let workspace = screen.get_workspace_by_index(index);
if (!workspace)
continue;
let space = Tiling.spaces.spaceOf(workspace);
space.setSettings([uuid, settings]);
}
});
}
function disable() {
workspaceList.disconnect(id);
}
function getWorkspaceSettings(space) {
+21 -13
View File
@@ -145,19 +145,7 @@ class Space extends Array {
}
this.setMonitor(monitor, false);
[this.uuid, this.settings] =
Settings.getWorkspaceSettings(this);
this.updateColor();
this.updateBackground();
this.updateName();
this.signals.connect(this.settings, 'changed::name',
this.updateName.bind(this));
this.signals.connect(this.settings, 'changed::color',
this.updateColor.bind(this));
this.signals.connect(this.settings, 'changed::background',
this.updateBackground.bind(this));
this.setSettings(Settings.getWorkspaceSettings(this));
actor.set_pivot_point(0.5, 0);
@@ -478,6 +466,22 @@ class Space extends Array {
});
}
setSettings([uuid, settings]) {
this.signals.disconnect(this.settings);
this.settings = settings;
this.uuid = uuid;
this.updateColor();
this.updateBackground();
this.updateName();
this.signals.connect(this.settings, 'changed::name',
this.updateName.bind(this));
this.signals.connect(this.settings, 'changed::color',
this.updateColor.bind(this));
this.signals.connect(this.settings, 'changed::background',
this.updateBackground.bind(this));
}
updateColor() {
let color = this.settings.get_string('color');
if (color === '') {
@@ -506,6 +510,10 @@ class Space extends Array {
Meta.prefs_change_workspace_name(this.workspace.index(), name);
this.label.text = name;
this.name = name;
if (this.workspace === screen.get_active_workspace()) {
TopBar.setWorkspaceName(this.name);
}
}
setMonitor(monitor, animate) {