Skip to content

Commit

Permalink
Add a layout settings tab to select available layouts.
Browse files Browse the repository at this point in the history
Also handle active removed layout.
  • Loading branch information
paradoxxxzero committed Jul 8, 2019
1 parent f3581b8 commit b5fe5f4
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 31 deletions.
2 changes: 2 additions & 0 deletions extension.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
<file>assets/icons/play-circle-outline-symbolic.svg</file>
<file>assets/icons/plus-symbolic.svg</file>
<file>assets/icons/web-symbolic.svg</file>
<file>assets/icons/view-quilt-symbolic.svg</file>
<file>assets/icons/view-quilt-vertical-symbolic.svg</file>
</gresource>
</gresources>
4 changes: 2 additions & 2 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ function init() {
modules = [
new RequiredSettingsModule(),
new LeftPanelModule(),
new TilingModule(),
new SuperWorkspaceModule(),
new NoTitleBarModule(),
new HotKeysModule(),
new TilingModule()
new HotKeysModule()
];
}

Expand Down
Binary file modified gschemas.compiled
Binary file not shown.
19 changes: 19 additions & 0 deletions layouts.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<schemalist>
<schema id="org.gnome.shell.extensions.materialshell.layouts" path="/org/gnome/shell/extensions/materialshell/layouts/">
<key name="maximize" type="b">
<default>true</default>
<summary>Maximize layout</summary>
<description>Maximize all windows</description>
</key>
<key name="grid" type="b">
<default>true</default>
<summary>Grid layout</summary>
<description>Tile windows horizontaly</description>
</key>
<key name="vertical-grid" type="b">
<default>false</default>
<summary>Vertical Grid layout</summary>
<description>Tile windows vertically</description>
</key>
</schema>
</schemalist>
9 changes: 4 additions & 5 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "Material Shell",
"description": "Change the workflow of the Gnome-shell to Mouse-driven Tileable workflow",
"uuid": "material-shell@papyelgringo",
"shell-version": [
"3.32"
],
"bindings": "org.gnome.shell.extensions.materialshell.bindings"
}
"shell-version": ["3.32"],
"bindings": "org.gnome.shell.extensions.materialshell.bindings",
"layouts": "org.gnome.shell.extensions.materialshell.layouts"
}
53 changes: 52 additions & 1 deletion prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Lang = imports.lang;

// Extension imports
const Me = imports.misc.extensionUtils.getCurrentExtension();

function init() {}

const pretty_names = {
Expand All @@ -18,8 +19,9 @@ const pretty_names = {
function buildPrefsWidget() {
let notebook = new Gtk.Notebook();
accel_tab(notebook);
layouts_tab(notebook);
/* basics_tab(notebook);
presets_tab(notebook);
margins_tab(notebook);
help_tab(notebook); */
Expand Down Expand Up @@ -154,6 +156,55 @@ function accel_tab(notebook) {
notebook.append_page(ks_window, ks_label);
}

function layouts_tab(notebook) {
const layouts = {
maximize: 'Maximize all windows',
grid: 'Tile windows horizontaly',
'vertical-grid': 'Tile windows vertically'
};
const SchemaSource = Gio.SettingsSchemaSource.new_from_directory(
Me.dir.get_path(),
Gio.SettingsSchemaSource.get_default(),
false
);
const settings = new Gio.Settings({
settings_schema: SchemaSource.lookup(Me.metadata['layouts'], true)
});

let ks_window = new Gtk.ScrolledWindow({ vexpand: true });
const ks_lbox = new Gtk.ListBox({
vexpand: false,
valign: Gtk.Align.START
});
ks_window.add(ks_lbox);
let ks_label = new Gtk.Label({
label: 'Layouts',
halign: Gtk.Align.START,
use_markup: false
});
Object.entries(layouts).forEach(([layout, description]) => {
const row = new Gtk.ListBoxRow();
const hbox = new Gtk.HBox();
let item = new Gtk.Switch({ valign: Gtk.Align.CENTER });

const name = new Gtk.Label({ xalign: 0 });
name.set_markup(`<span size="medium">${layout}</span>`);
const desc = new Gtk.Label({ xalign: 0 });
desc.set_markup(`<span size="small">${description}</span>`);

const vbox = new Gtk.VBox();
vbox.pack_start(name, false, false, 0);
vbox.pack_start(desc, false, false, 0);
hbox.pack_start(vbox, true, true, 10);
hbox.pack_start(item, false, false, 0);
row.add(hbox);

ks_lbox.add(row);
settings.bind(layout, item, 'active', Gio.SettingsBindFlags.DEFAULT);
});
notebook.append_page(ks_window, ks_label);
}

function append_hotkey(model, settings, name, pretty_name) {
let [key, mods] = Gtk.accelerator_parse(settings.get_strv(name)[0]);

Expand Down
17 changes: 6 additions & 11 deletions superWorkspace/superWorkspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
const Background = imports.ui.background;

const TopPanel = Me.imports.widget.topPanelWidget.TopPanel;
const {
TilingLayoutByKey
} = Me.imports.tilingManager.tilingLayouts.layoutByKey;

const CategorizedAppCard =
Me.imports.widget.categorizedAppCard.CategorizedAppCard;
Expand All @@ -30,7 +27,8 @@ var SuperWorkspace = class SuperWorkspace {
Me.stateManager.getState(
`${this.categoryKey}_${this.monitor.index}`
) || 'grid';
this.tilingLayout = new TilingLayoutByKey[previousLayout](this);
const Layout = global.tilingManager.getLayoutByKey(previousLayout);
this.tilingLayout = new Layout(this);
this.frontendContainer = new St.Widget({
visible: visible
});
Expand Down Expand Up @@ -187,17 +185,14 @@ var SuperWorkspace = class SuperWorkspace {

nextTiling() {
this.tilingLayout.onDestroy();
const layouts = Object.keys(TilingLayoutByKey);
const newLayoutKey =
layouts[
(layouts.indexOf(this.tilingLayout.key) + 1) % layouts.length
];
const Layout = global.tilingManager.getNextLayout(this.tilingLayout);
this.tilingLayout = new Layout(this);
Me.stateManager.setState(
`${this.categoryKey}_${this.monitor.index}`,
newLayoutKey
this.tilingLayout.key
);
this.tilingLayout = new TilingLayoutByKey[newLayoutKey](this);
log(`${this.categoryKey} ask for tiling after layout changed`);
this.panel.tilingIcon.gicon = this.tilingLayout.icon;
this.tilingLayout.onTile();
}

Expand Down
4 changes: 1 addition & 3 deletions tilingManager/tilingLayouts/baseTilingLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ var BaseTilingLayout = class BaseTilingLayout {
onWindowsChanged() {
this.windows = this.superWorkspace.windows;
log(
`${
this.superWorkspace.categoryKey
} tilingLayout tile itself from onWindowsChanged event`
`${this.superWorkspace.categoryKey} tilingLayout tile itself from onWindowsChanged event`
);
this.onTile();
}
Expand Down
2 changes: 1 addition & 1 deletion tilingManager/tilingLayouts/layoutByKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ const {
/* exported TilingLayoutByKey */
var TilingLayoutByKey = {
grid: GridLayout,
verticalGrid: VerticalGridLayout,
'vertical-grid': VerticalGridLayout,
maximize: MaximizeLayout
};
4 changes: 1 addition & 3 deletions tilingManager/tilingLayouts/maximize.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ var MaximizeLayout = class MaximizeLayout extends BaseTilingLayout {
});
global.window_group.remove_child(this.overContainer);
log(
`${
this.superWorkspace.categoryKey
} tilingLayout tile itself after the transition`
`${this.superWorkspace.categoryKey} tilingLayout tile itself after the transition`
);
this.onTile();
}
Expand Down
2 changes: 1 addition & 1 deletion tilingManager/tilingLayouts/verticalGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { GridLayout } = Me.imports.tilingManager.tilingLayouts.grid;
var VerticalGridLayout = class VerticalGridLayout extends GridLayout {
constructor(superWorkspace) {
super(superWorkspace);
this.key = 'verticalGrid';
this.key = 'vertical-grid';
this.icon = Gio.icon_new_for_string(
`${Me.path}/assets/icons/view-quilt-vertical-symbolic.svg`
);
Expand Down
78 changes: 75 additions & 3 deletions tilingManager/tilingManager.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,87 @@
const { Gio } = imports.gi;
const Main = imports.ui.main;
const GLib = imports.gi.GLib;

const Me = imports.misc.extensionUtils.getCurrentExtension();
const {
TilingLayoutByKey
} = Me.imports.tilingManager.tilingLayouts.layoutByKey;

/* exported TilingManager */
var TilingManager = class TilingManager {
constructor() {
this.workspaceManager = global.workspace_manager;
this.grabInProgress = false;
this.signals = [];
this.windows = [];
const SchemaSource = Gio.SettingsSchemaSource.new_from_directory(
Me.dir.get_path(),
Gio.SettingsSchemaSource.get_default(),
false
);
this.layoutsSettings = new Gio.Settings({
settings_schema: SchemaSource.lookup(Me.metadata['layouts'], true)
});

this.allLayouts = Object.keys(TilingLayoutByKey);
// On layout settings change
this.allLayouts.forEach(key => {
this.layoutsSettings.connect(`changed::${key}`, (schema, key) => {
// Compute new available layouts
this.refreshAvailableLayouts();
log('New available', this.availableLayouts);
if (!schema.get_boolean(key)) {
// If a layout has been removed,
// change tiling of all workspaces using that layout.

GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
global.superWorkspaceManager.superWorkspaces.forEach(
superWorkspace => {
log(key, superWorkspace.tilingLayout);
if (key == superWorkspace.tilingLayout.key) {
superWorkspace.nextTiling();
}
}
);
});
}
});
});

// Compute available layouts
this.refreshAvailableLayouts();
}

refreshAvailableLayouts() {
this.availableLayouts = this.allLayouts.filter(key =>
this.layoutsSettings.get_boolean(key)
);
if (!this.availableLayouts.length) {
// Use grid by default if all layouts are disabled
this.availableLayouts = ['grid'];
}
}

getLayoutByKey(key) {
// If the layout is not in the available layouts return the first available
if (!this.availableLayouts.includes(key)) {
key = this.availableLayouts[0];
}
return TilingLayoutByKey[key];
}

getNextLayout(currentLayout) {
let { key } = currentLayout;
if (!this.availableLayouts.includes(key)) {
key = this.availableLayouts[0];
}
// Get the next layout available
const newKey = this.availableLayouts[
(this.availableLayouts.indexOf(key) + 1) %
this.availableLayouts.length
];
// And returns it
return TilingLayoutByKey[newKey];
}

getFilteredWindows(windows) {
Expand Down Expand Up @@ -38,9 +112,7 @@ var TilingManager = class TilingManager {
regularWindows
] = this.getDialogAndRegularWindows(superWorkspace.windows); */
log(
`${
superWorkspace.categoryKey
} ask for tiling from tiling Manager`
`${superWorkspace.categoryKey} ask for tiling from tiling Manager`
);
layout.onTile();
//this.dialogLayout.onTile(dialogWindows, monitor);
Expand Down
1 change: 0 additions & 1 deletion widget/topPanelWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ var TopPanel = GObject.registerClass(

button.connect('button-press-event', () => {
superWorkspace.nextTiling();
this.tilingIcon.gicon = superWorkspace.tilingLayout.icon;
});

this.tilingButton = new RippleContainer(button);
Expand Down

0 comments on commit b5fe5f4

Please sign in to comment.