Skip to content

Commit

Permalink
Add ratio layout.
Browse files Browse the repository at this point in the history
Also refactor Gio.Settings call
  • Loading branch information
paradoxxxzero committed Jul 9, 2019
1 parent c092c5f commit 51be08c
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 43 deletions.
4 changes: 4 additions & 0 deletions assets/icons/view-quilt-ratio-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gschemas.compiled
Binary file not shown.
10 changes: 10 additions & 0 deletions layouts.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,15 @@
<summary>Vertical Grid layout</summary>
<description>Tile windows vertically</description>
</key>
<key name="ratio-grid" type="b">
<default>false</default>
<summary>Ratio based Grid layout</summary>
<description>Tile windows in both way according to the ratio of the remaining space</description>
</key>
<key name="ratio-grid-ratio" type="d">
<default>0.6180339887498948</default>
<summary>Ratio of the ratio layout</summary>
<description>Determines the ratio of the tiling</description>
</key>
</schema>
</schemalist>
13 changes: 4 additions & 9 deletions module/hotKeysModule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { Meta, Shell, Gio } = imports.gi;
const { Meta, Shell } = imports.gi;
const Main = imports.ui.main;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const { getSettings } = Me.imports.utils.settings;

/* exported HotKeysModule */
var HotKeysModule = class HotKeysModule {
Expand All @@ -9,14 +10,8 @@ var HotKeysModule = class HotKeysModule {
}

enable() {
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['bindings'], true)
});
const settings = getSettings('bindings');

Main.wm.addKeybinding(
'previous-window',
settings,
Expand Down
10 changes: 2 additions & 8 deletions module/requiredSettingsModule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { Gio } = imports.gi;
const Main = imports.ui.main;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const { getSettings } = Me.imports.utils.settings;

/* exported RequiredSettingsModule */
var RequiredSettingsModule = class RequiredSettingsModule {
Expand Down Expand Up @@ -56,14 +57,7 @@ var RequiredSettingsModule = class RequiredSettingsModule {
});
});

const SchemaSource = Gio.SettingsSchemaSource.new_from_directory(
Me.dir.get_path(),
Gio.SettingsSchemaSource.get_default(),
false
);
const bindingSettings = new Gio.Settings({
settings_schema: SchemaSource.lookup(Me.metadata['bindings'], true)
});
const bindingSettings = getSettings('bindings');
this.hotkeysToRemove = bindingSettings.list_keys().map(key => {
return bindingSettings.get_strv(key)[0];
});
Expand Down
47 changes: 30 additions & 17 deletions 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();
const { getSettings } = Me.imports.utils.settings;

function init() {}

Expand Down Expand Up @@ -40,14 +41,7 @@ function buildPrefsWidget() {
}

function accel_tab(notebook) {
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['bindings'], true)
});
const settings = getSettings('bindings');

let ks_grid = new Gtk.Grid({
column_spacing: 10,
Expand Down Expand Up @@ -161,16 +155,11 @@ function layouts_tab(notebook) {
maximize: 'Maximize all windows',
'auto-grid': 'Tile windows according to screen ratio',
'vertical-grid': 'Tile windows vertically',
'horizontal-grid': 'Tile windows horizontally'
'horizontal-grid': 'Tile windows horizontally',
'ratio-grid':
'Tile windows in both way according to the ratio of the remaining space'
};
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)
});
const settings = getSettings('layouts');

let ks_window = new Gtk.ScrolledWindow({ vexpand: true });
const ks_lbox = new Gtk.ListBox({
Expand Down Expand Up @@ -198,10 +187,34 @@ function layouts_tab(notebook) {
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);
if (layout === 'ratio-grid') {
const row = new Gtk.ListBoxRow();
const ratio = Gtk.Scale.new_with_range(
Gtk.Orientation.HORIZONTAL,
0,
1,
0.01
);
ratio.add_mark(
0.6180339887498948,
Gtk.PositionType.BOTTOM,
'Golden Ratio'
);
settings.bind(
'ratio-grid-ratio',
ratio.get_adjustment(),
'value',
Gio.SettingsBindFlags.DEFAULT
);
row.add(ratio);
ks_lbox.add(row);
}
});
notebook.append_page(ks_window, ks_label);
}
Expand Down
5 changes: 4 additions & 1 deletion tilingManager/tilingLayouts/layoutByKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ const {
const {
HorizontalGridLayout
} = Me.imports.tilingManager.tilingLayouts.horizontalGrid;
const { RatioGridLayout } = Me.imports.tilingManager.tilingLayouts.ratioGrid;

/* exported TilingLayoutByKey */
var TilingLayoutByKey = {
'auto-grid': AutoGridLayout,
'vertical-grid': VerticalGridLayout,
'horizontal-grid': HorizontalGridLayout,
maximize: MaximizeLayout
maximize: MaximizeLayout,
'ratio-grid': RatioGridLayout
};
76 changes: 76 additions & 0 deletions tilingManager/tilingLayouts/ratioGrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const Main = imports.ui.main;
const { Meta, Gio } = imports.gi;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const { AutoGridLayout } = Me.imports.tilingManager.tilingLayouts.autoGrid;
const { getSettings } = Me.imports.utils.settings;

/* exported RatioGridLayout */
var RatioGridLayout = class RatioGridLayout extends AutoGridLayout {
constructor(superWorkspace) {
super(superWorkspace);
this.key = 'ratio-grid';
this.icon = Gio.icon_new_for_string(
`${Me.path}/assets/icons/view-quilt-ratio-symbolic.svg`
);
this.settings = getSettings('layouts');
this.settings.connect('changed::ratio-grid-ratio', (schema, key) => {
log('changed');
this.onTile();
});
}

onTileRegulars(windows) {
if (!windows.length) return;

const ratio = this.settings.get_double('ratio-grid-ratio');
log('tile', ratio);

const workArea = Main.layoutManager.getWorkAreaForMonitor(
this.monitor.index
);
const freeArea = {
x: workArea.x,
y: workArea.y,
width: workArea.width,
height: workArea.height
};

windows.forEach((window, index) => {
if (window.grabbed) return;

if (window.get_maximized())
window.unmaximize(Meta.MaximizeFlags.BOTH);

let windowArea = {
x: freeArea.x,
y: freeArea.y
};

if (index === windows.length - 1) {
windowArea = freeArea;
} else {
if (freeArea.width > freeArea.height) {
windowArea.width = freeArea.width * ratio;
windowArea.height = freeArea.height;
freeArea.x += windowArea.width;
freeArea.width -= windowArea.width;
} else {
windowArea.width = freeArea.width;
windowArea.height = freeArea.height * ratio;
freeArea.y += windowArea.height;
freeArea.height -= windowArea.height;
}
}

this.moveAndResizeMetaWindow(
window,
windowArea.x,
windowArea.y,
windowArea.width,
windowArea.height
);
});
}
};
11 changes: 3 additions & 8 deletions tilingManager/tilingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const Main = imports.ui.main;
const GLib = imports.gi.GLib;

const Me = imports.misc.extensionUtils.getCurrentExtension();
const { getSettings } = Me.imports.utils.settings;

const {
TilingLayoutByKey
} = Me.imports.tilingManager.tilingLayouts.layoutByKey;
Expand All @@ -14,14 +16,7 @@ var TilingManager = class TilingManager {
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.layoutsSettings = getSettings('layouts');

this.allLayouts = Object.keys(TilingLayoutByKey);
// On layout settings change
Expand Down
12 changes: 12 additions & 0 deletions utils/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Me = imports.misc.extensionUtils.getCurrentExtension();
const { Gio } = imports.gi;

/* exported getSettings */
var getSettings = key =>
new Gio.Settings({
settings_schema: Gio.SettingsSchemaSource.new_from_directory(
Me.dir.get_path(),
Gio.SettingsSchemaSource.get_default(),
false
).lookup(Me.metadata[key], true)
});

0 comments on commit 51be08c

Please sign in to comment.