Skip to content

Commit

Permalink
Refactor tiling layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Jul 10, 2019
1 parent 3546119 commit ca1b2f3
Show file tree
Hide file tree
Showing 28 changed files with 238 additions and 193 deletions.
4 changes: 4 additions & 0 deletions assets/icons/tiling/float-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
7 changes: 7 additions & 0 deletions assets/icons/tiling/half-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
1 change: 0 additions & 1 deletion assets/icons/view-quilt-symbolic.svg

This file was deleted.

1 change: 0 additions & 1 deletion assets/icons/view-split-vertical-symbolic.svg

This file was deleted.

Binary file modified gschemas.compiled
Binary file not shown.
23 changes: 14 additions & 9 deletions layouts.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,40 @@
<summary>Maximize layout</summary>
<description>Maximize all windows</description>
</key>
<key name="auto-grid" type="b">
<key name="half" type="b">
<default>true</default>
<summary>Grid layout</summary>
<summary>Half layout</summary>
<description>Tile windows according to screen ratio</description>
</key>
<key name="horizontal-grid" type="b">
<key name="half-horizontal" type="b">
<default>false</default>
<summary>Horizontal Grid layout</summary>
<summary>Half Horizontal layout</summary>
<description>Tile windows horizontaly</description>
</key>
<key name="vertical-grid" type="b">
<key name="half-vertical" type="b">
<default>false</default>
<summary>Vertical Grid layout</summary>
<summary>Half Vertical layout</summary>
<description>Tile windows vertically</description>
</key>
<key name="ratio-grid" type="b">
<key name="ratio" 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">
<key name="ratio-value" type="d">
<default>0.6180339887498948</default>
<summary>Ratio of the ratio layout</summary>
<description>Determines the ratio of the tiling</description>
</key>
<key name="grid-grid" type="b">
<key name="grid" type="b">
<default>false</default>
<summary>Regular Grid layout</summary>
<description>Tile windows according to a regular grid</description>
</key>
<key name="float" type="b">
<default>false</default>
<summary>Float layout</summary>
<description>No tiling is done, windows are floating freely</description>
</key>
</schema>
</schemalist>
15 changes: 8 additions & 7 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ const pretty_names = {
};
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':
float: 'Windows are not tiled',
half: 'Tile windows according to screen ratio',
'half-horizontal': 'Tile windows horizontaly',
'half-vertical': 'Tile windows vertically',
ratio:
'Tile windows in both way according to the ratio of the remaining space',
'grid-grid': 'Tile windows according to a regular grid'
grid: 'Tile windows according to a regular grid'
};
function buildPrefsWidget() {
let notebook = new Gtk.Notebook();
Expand Down Expand Up @@ -193,7 +194,7 @@ function layouts_tab(notebook) {
ks_lbox.add(row);

settings.bind(layout, item, 'active', Gio.SettingsBindFlags.DEFAULT);
if (layout === 'ratio-grid') {
if (layout === 'ratio') {
const row = new Gtk.ListBoxRow();
const ratio = Gtk.Scale.new_with_range(
Gtk.Orientation.HORIZONTAL,
Expand All @@ -207,7 +208,7 @@ function layouts_tab(notebook) {
'Golden Ratio'
);
settings.bind(
'ratio-grid-ratio',
'ratio-value',
ratio.get_adjustment(),
'value',
Gio.SettingsBindFlags.DEFAULT
Expand Down
2 changes: 1 addition & 1 deletion superWorkspace/superWorkspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ var SuperWorkspace = class SuperWorkspace {
this.tilingLayout = new Layout(this);
Me.stateManager.setState(
`${this.categoryKey}_${this.monitor.index}`,
this.tilingLayout.key
this.tilingLayout.constructor.key
);
log(`${this.categoryKey} ask for tiling after layout changed`);
this.panel.tilingIcon.gicon = this.tilingLayout.icon;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const { Meta, GLib } = imports.gi;
const { Meta, Gio, GLib } = imports.gi;
const Main = imports.ui.main;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const { Backdrop } = Me.imports.widget.backdrop;

/* exported BaseTilingLayout */
var BaseTilingLayout = class BaseTilingLayout {
constructor(superWorkspace) {
this.icon = '';
this.key = 'base';
this.icon = Gio.icon_new_for_string(
`${Me.path}/assets/icons/tiling/${this.constructor.key}-symbolic.svg`
);
this.superWorkspace = superWorkspace;
this.monitor = superWorkspace.monitor;
this.windowFocused = this.superWorkspace.windowFocused;
Expand All @@ -34,14 +35,12 @@ 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();
}

onFocusChanged(windowFocused, oldWindowFocused) {
onFocusChanged(windowFocused) {
this.windowFocused = windowFocused;
}

Expand All @@ -52,6 +51,7 @@ var BaseTilingLayout = class BaseTilingLayout {
this.onTileDialogs(dialogWindows);
}

// eslint-disable-next-line no-unused-vars
onTileRegulars(windows) {
// Define windows sizes and positions
}
Expand Down
59 changes: 59 additions & 0 deletions tilingManager/tilingLayouts/custom/baseGrabbable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { Meta } = imports.gi;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const { BaseTilingLayout } = Me.imports.tilingManager.tilingLayouts.baseTiling;

/* exported BaseGrabbableLayout */
var BaseGrabbableLayout = class BaseGrabbableLayout extends BaseTilingLayout {
constructor(superWorkspace) {
super(superWorkspace);
this.grabStartSignal = global.display.connect(
'grab-op-begin',
(display1, display2, window, op) => {
if (op !== Meta.GrabOp.MOVING) return;
this.grabInProgress = true;
this.grabWindow = window;
this.grabSignal = window.connect('position-changed', () => {
let windowRect = window.get_frame_rect();
let x = windowRect.x + windowRect.width / 2;
let y = windowRect.y + windowRect.height / 2;
const windowHovered = this.windows.find(windowToCheck => {
if (windowToCheck === this.grabWindow) return false;
let rect = windowToCheck.get_frame_rect();
return (
x >= rect.x &&
x <= rect.x + rect.width &&
y >= rect.y &&
y <= rect.y + rect.height
);
});
if (
windowHovered &&
this.windows.indexOf(windowHovered) > -1 &&
this.windows.indexOf(this.grabWindow) > -1
) {
this.superWorkspace.swapWindows(
this.grabWindow,
windowHovered
);
}
});
}
);

this.grabEndSignal = global.display.connect('grab-op-end', () => {
if (this.grabInProgress) {
this.grabInProgress = false;
this.grabWindow.disconnect(this.grabSignal);
delete this.grabWindow;
delete this.grabSignal;
}
});
}

onDestroy() {
super.onDestroy();
global.display.disconnect(this.grabStartSignal);
}
};
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
const Main = imports.ui.main;
const { Meta, Gio } = imports.gi;
const { Meta } = imports.gi;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const { AutoGridLayout } = Me.imports.tilingManager.tilingLayouts.autoGrid;
const {
BaseGrabbableLayout
} = Me.imports.tilingManager.tilingLayouts.custom.baseGrabbable;

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`
);
}

/* exported GridLayout */
var GridLayout = class GridLayout extends BaseGrabbableLayout {
onTileRegulars(windows) {
if (!windows.length) return;

Expand Down Expand Up @@ -53,3 +47,5 @@ var GridGridLayout = class GridGridLayout extends AutoGridLayout {
});
}
};

GridLayout.key = 'grid';
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,11 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();

const {
BaseTilingLayout
} = Me.imports.tilingManager.tilingLayouts.baseTilingLayout;

/* exported AutoGridLayout */
var AutoGridLayout = class AutoGridLayout extends BaseTilingLayout {
constructor(superWorkspace) {
super(superWorkspace);
this.key = 'auto-grid';
this.icon = Gio.icon_new_for_string(
`${Me.path}/assets/icons/view-quilt-symbolic.svg`
);
this.grabStartSignal = global.display.connect(
'grab-op-begin',
(display1, display2, window, op) => {
if (op !== Meta.GrabOp.MOVING) return;
this.grabInProgress = true;
this.grabWindow = window;
this.grabSignal = window.connect('position-changed', () => {
let windowRect = window.get_frame_rect();
let x = windowRect.x + windowRect.width / 2;
let y = windowRect.y + windowRect.height / 2;
const windowHovered = this.windows.find(windowToCheck => {
if (windowToCheck === this.grabWindow) return false;
let rect = windowToCheck.get_frame_rect();
return (
x >= rect.x &&
x <= rect.x + rect.width &&
y >= rect.y &&
y <= rect.y + rect.height
);
});
if (
windowHovered &&
this.windows.indexOf(windowHovered) > -1 &&
this.windows.indexOf(this.grabWindow) > -1
) {
this.superWorkspace.swapWindows(
this.grabWindow,
windowHovered
);
}
});
}
);

this.grabEndSignal = global.display.connect('grab-op-end', () => {
if (this.grabInProgress) {
this.grabInProgress = false;
this.grabWindow.disconnect(this.grabSignal);
delete this.grabWindow;
delete this.grabSignal;
}
});
}
onWindowsChanged(windows) {
super.onWindowsChanged(windows);
}

onFocusChanged() {}
BaseGrabbableLayout
} = Me.imports.tilingManager.tilingLayouts.custom.baseGrabbable;

/* exported HalfLayout */
var HalfLayout = class HalfLayout extends BaseGrabbableLayout {
onTileRegulars(windows) {
if (!windows.length) return;

Expand Down Expand Up @@ -152,9 +97,6 @@ var AutoGridLayout = class AutoGridLayout extends BaseTilingLayout {
}
});
}

onDestroy() {
super.onDestroy();
global.display.disconnect(this.grabStartSignal);
}
};

HalfLayout.key = 'half';
16 changes: 16 additions & 0 deletions tilingManager/tilingLayouts/custom/halfHorizontal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const Main = imports.ui.main;
const { Meta, Gio } = imports.gi;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();

const { HalfLayout } = Me.imports.tilingManager.tilingLayouts.custom.half;

/* exported HalfHorizontalLayout */
var HalfHorizontalLayout = class HalfHorizontalLayout extends HalfLayout {
onTileRegulars(windows) {
super.onTileHorizontal(windows);
}
};

HalfHorizontalLayout.key = 'half-horizontal';
15 changes: 15 additions & 0 deletions tilingManager/tilingLayouts/custom/halfVertical.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { Gio } = imports.gi;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();

const { HalfLayout } = Me.imports.tilingManager.tilingLayouts.custom.half;

/* exported HalfVerticalLayout */
var HalfVerticalLayout = class HalfVerticalLayout extends HalfLayout {
onTileRegulars(windows) {
super.onTileVertical(windows);
}
};

HalfVerticalLayout.key = 'half-vertical';
Loading

0 comments on commit ca1b2f3

Please sign in to comment.