Skip to content

Commit

Permalink
Add gridgrid layout. We might need to do something about the tiling n…
Browse files Browse the repository at this point in the history
…aming.
  • Loading branch information
paradoxxxzero committed Jul 10, 2019
1 parent 51be08c commit 3546119
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
4 changes: 4 additions & 0 deletions assets/icons/view-quilt-grid-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.
5 changes: 5 additions & 0 deletions layouts.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
<summary>Ratio of the ratio layout</summary>
<description>Determines the ratio of the tiling</description>
</key>
<key name="grid-grid" type="b">
<default>false</default>
<summary>Regular Grid layout</summary>
<description>Tile windows according to a regular grid</description>
</key>
</schema>
</schemalist>
18 changes: 9 additions & 9 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ const pretty_names = {
'next-workspace': 'Focus the next workspace',
'kill-focused-window': 'kill the current window'
};

const layouts = {
maximize: 'Maximize all windows',
'auto-grid': 'Tile windows according to screen ratio',
'vertical-grid': 'Tile windows vertically',
'horizontal-grid': 'Tile windows horizontally',
'ratio-grid':
'Tile windows in both way according to the ratio of the remaining space',
'grid-grid': 'Tile windows according to a regular grid'
};
function buildPrefsWidget() {
let notebook = new Gtk.Notebook();
accel_tab(notebook);
Expand Down Expand Up @@ -151,14 +159,6 @@ function accel_tab(notebook) {
}

function layouts_tab(notebook) {
const layouts = {
maximize: 'Maximize all windows',
'auto-grid': 'Tile windows according to screen ratio',
'vertical-grid': 'Tile windows vertically',
'horizontal-grid': 'Tile windows horizontally',
'ratio-grid':
'Tile windows in both way according to the ratio of the remaining space'
};
const settings = getSettings('layouts');

let ks_window = new Gtk.ScrolledWindow({ vexpand: true });
Expand Down
55 changes: 55 additions & 0 deletions tilingManager/tilingLayouts/gridGrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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 range = to =>
Array(to)
.fill(0)
.map((_, i) => i);

/* exported GridGridLayout */
var GridGridLayout = class GridGridLayout extends AutoGridLayout {
constructor(superWorkspace) {
super(superWorkspace);
this.key = 'grid-grid';
this.icon = Gio.icon_new_for_string(
`${Me.path}/assets/icons/view-quilt-grid-symbolic.svg`
);
}

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

const workArea = Main.layoutManager.getWorkAreaForMonitor(
this.monitor.index
);
const columns = Math.ceil(Math.sqrt(windows.length));
const rows = Math.ceil(windows.length / columns);
const width = workArea.width / columns;
const height = workArea.height / rows;
range(columns).forEach(i => {
range(rows).forEach(j => {
const index = j + i * rows;
const window = windows[index];
if (!window || window.grabbed) return;

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

this.moveAndResizeMetaWindow(
window,
workArea.x + i * width,
workArea.y + j * height,
width,
index == windows.length - 1
? // If last window fill remaining space
height * (columns * rows - index)
: height
);
});
});
}
};
4 changes: 3 additions & 1 deletion tilingManager/tilingLayouts/layoutByKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ const {
HorizontalGridLayout
} = Me.imports.tilingManager.tilingLayouts.horizontalGrid;
const { RatioGridLayout } = Me.imports.tilingManager.tilingLayouts.ratioGrid;
const { GridGridLayout } = Me.imports.tilingManager.tilingLayouts.gridGrid;

/* exported TilingLayoutByKey */
var TilingLayoutByKey = {
'auto-grid': AutoGridLayout,
'vertical-grid': VerticalGridLayout,
'horizontal-grid': HorizontalGridLayout,
maximize: MaximizeLayout,
'ratio-grid': RatioGridLayout
'ratio-grid': RatioGridLayout,
'grid-grid': GridGridLayout
};

0 comments on commit 3546119

Please sign in to comment.