Skip to content

Commit

Permalink
Add configurable gaps.
Browse files Browse the repository at this point in the history
Also add animation time setting.
  • Loading branch information
paradoxxxzero committed Jul 15, 2019
1 parent 0f724d5 commit 94062fe
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 13 deletions.
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 @@ -55,5 +55,15 @@
<summary>Simple vertical layout</summary>
<description>Split screen vertically</description>
</key>
<key name="gap" type="i">
<default>0</default>
<summary>Gap size around tiled windows</summary>
<description>Determines the gap size between windows</description>
</key>
<key name="tween-time" type="d">
<default>0.25</default>
<summary>Animation duration</summary>
<description>Ajust duration of window move/resize animation</description>
</key>
</schema>
</schemalist>
88 changes: 85 additions & 3 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function buildPrefsWidget() {
let notebook = new Gtk.Notebook();
accel_tab(notebook);
layouts_tab(notebook);
layouts_settings_tab(notebook);
/* basics_tab(notebook);
presets_tab(notebook);
Expand Down Expand Up @@ -167,10 +168,14 @@ function layouts_tab(notebook) {

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);
const w_box = new Gtk.VBox({
border_width: 10
});

w_box.add(ks_lbox);
ks_window.add(w_box);
let ks_label = new Gtk.Label({
label: 'Layouts',
halign: Gtk.Align.START,
Expand All @@ -182,7 +187,11 @@ function layouts_tab(notebook) {
let item = new Gtk.Switch({ valign: Gtk.Align.CENTER });

const name = new Gtk.Label({ xalign: 0 });
name.set_markup(`<span size="medium">${layout}</span>`);
name.set_markup(
`<span size="medium">${layout
.replace('-', ' ')
.replace(/^\w/g, c => c.toUpperCase())}</span>`
);
const desc = new Gtk.Label({ xalign: 0 });
desc.set_markup(`<span size="small">${description}</span>`);

Expand Down Expand Up @@ -223,6 +232,79 @@ function layouts_tab(notebook) {
notebook.append_page(ks_window, ks_label);
}

function layouts_settings_tab(notebook) {
const settings = getSettings('layouts');

let ks_window = new Gtk.ScrolledWindow({ vexpand: true });
const parent_vbox = new Gtk.VBox({
valign: Gtk.Align.START,
border_width: 10
});
ks_window.add(parent_vbox);
let ks_label = new Gtk.Label({
label: 'Tiling settings',
halign: Gtk.Align.START,
use_markup: false
});

const gaphbox = new Gtk.HBox();
const gap = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 0, 50, 1);
settings.bind(
'gap',
gap.get_adjustment(),
'value',
Gio.SettingsBindFlags.DEFAULT
);

const gapname = new Gtk.Label({ xalign: 0 });
gapname.set_markup(`<span size="medium">Gap size</span>`);
const gapdesc = new Gtk.Label({ xalign: 0 });
gapdesc.set_markup(
`<span size="small">Determines the gap size in pixel between windows</span>`
);

const gapvbox = new Gtk.VBox();
gapvbox.pack_start(gapname, false, false, 0);
gapvbox.pack_start(gapdesc, false, false, 0);
gaphbox.pack_start(gapvbox, true, true, 10);
gaphbox.pack_end(gap, true, true, 0);

parent_vbox.add(gaphbox);

const tweentimehbox = new Gtk.HBox();
const tweentime = Gtk.Scale.new_with_range(
Gtk.Orientation.HORIZONTAL,
0,
1,
0.01
);
settings.bind(
'tween-time',
tweentime.get_adjustment(),
'value',
Gio.SettingsBindFlags.DEFAULT
);
tweentime.add_mark(0.1, Gtk.PositionType.BOTTOM, 'Fast');
tweentime.add_mark(0.25, Gtk.PositionType.BOTTOM, 'Smooth');
tweentime.add_mark(0.75, Gtk.PositionType.BOTTOM, 'Mesmerizing');

const tweentimename = new Gtk.Label({ xalign: 0 });
tweentimename.set_markup(`<span size="medium">Animation duration</span>`);
const tweentimedesc = new Gtk.Label({ xalign: 0 });
tweentimedesc.set_markup(
`<span size="small">Ajust duration (in seconds) of window move/resize animation</span>`
);

const tweentimevbox = new Gtk.VBox();
tweentimevbox.pack_start(tweentimename, false, false, 0);
tweentimevbox.pack_start(tweentimedesc, false, false, 0);
tweentimehbox.pack_start(tweentimevbox, true, true, 10);
tweentimehbox.pack_start(tweentime, true, true, 0);

parent_vbox.add(tweentimehbox);
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
27 changes: 23 additions & 4 deletions tilingManager/tilingLayouts/baseTiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const { Backdrop } = Me.imports.widget.backdrop;

const TILE_TWEEN_TIME = 0.25;
const { getSettings } = Me.imports.utils.settings;

/* exported BaseTilingLayout */
var BaseTilingLayout = class BaseTilingLayout {
Expand All @@ -31,6 +30,18 @@ var BaseTilingLayout = class BaseTilingLayout {
this.onTile();
}
);
this.settings = getSettings('layouts');
this.settingsSignals = [
this.settings.connect('changed::gap', (schema, key) => {
this.gap = schema.get_int('gap');
this.onTile();
}),
this.settings.connect('changed::tween-time', (schema, key) => {
this.tweenTime = schema.get_double('tween-time');
})
];
this.gap = this.settings.get_int('gap');
this.tweenTime = this.settings.get_double('tween-time');
this.windows = superWorkspace.windows;
}

Expand Down Expand Up @@ -90,6 +101,13 @@ var BaseTilingLayout = class BaseTilingLayout {
}

moveAndResizeMetaWindow(metaWindow, x, y, width, height) {
if (this.gap) {
x = x + this.gap;
y = y + this.gap;
width = width - 2 * this.gap;
height = height - 2 * this.gap;
}

const rect = metaWindow.get_frame_rect();
const buf = metaWindow.get_buffer_rect();
x = Math.floor(x);
Expand Down Expand Up @@ -118,7 +136,7 @@ var BaseTilingLayout = class BaseTilingLayout {
Tweener.addTween(actor, {
scale_x: width / oldRect.width,
scale_y: height / oldRect.height,
time: TILE_TWEEN_TIME,
time: this.tweenTime,
transition: 'easeOutQuad'
});
return;
Expand All @@ -136,7 +154,7 @@ var BaseTilingLayout = class BaseTilingLayout {
scale_y: 1.0,
translation_x: 0,
translation_y: 0,
time: TILE_TWEEN_TIME,
time: this.tweenTime,
transition: 'easeOutQuad'
});
});
Expand Down Expand Up @@ -177,6 +195,7 @@ var BaseTilingLayout = class BaseTilingLayout {
}

onDestroy() {
this.settings.disconnect(this.settingsSignal);
this.superWorkspace.disconnect(this.windowChangedId);
this.superWorkspace.disconnect(this.windowFocusedChangedId);
global.display.disconnect(this.workAreaChangedId);
Expand Down
10 changes: 4 additions & 6 deletions tilingManager/tilingLayouts/custom/ratio.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ var RatioLayout = class RatioLayout extends BaseGrabbableLayout {
this.settingsSignal = this.settings.connect(
'changed::ratio-value',
(schema, key) => {
log('changed');
this.ratio = schema.get_double('ratio-value');
this.onTile();
}
);
this.ratio = this.settings.get_double('ratio-value');
}

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

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

const workArea = Main.layoutManager.getWorkAreaForMonitor(
this.monitor.index
);
Expand All @@ -51,13 +49,13 @@ var RatioLayout = class RatioLayout extends BaseGrabbableLayout {
windowArea = freeArea;
} else {
if (freeArea.width > freeArea.height) {
windowArea.width = freeArea.width * ratio;
windowArea.width = freeArea.width * this.ratio;
windowArea.height = freeArea.height;
freeArea.x += windowArea.width;
freeArea.width -= windowArea.width;
} else {
windowArea.width = freeArea.width;
windowArea.height = freeArea.height * ratio;
windowArea.height = freeArea.height * this.ratio;
freeArea.y += windowArea.height;
freeArea.height -= windowArea.height;
}
Expand Down

0 comments on commit 94062fe

Please sign in to comment.