Skip to content

Commit

Permalink
added gaps around tiles (#133)
Browse files Browse the repository at this point in the history
default gap is zero, but can can be increased to 50 in 2px increments
  • Loading branch information
GrylledCheez committed Jun 15, 2023
1 parent 7c718c6 commit a7604cc
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 31 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ WinTile also supports:
- Mouse preview and snapping for placing tiles
- "Maximize" mode, which adds/removes GNOME animations
- Ultrawide-only mode limits 16:9 screens to a 2x2 grid
- Adding gaps around tiles

<img src='demo.gif'>

Expand Down
39 changes: 24 additions & 15 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ let config = {
ultrawideOnly: false,
useMaximize: true,
useMinimize: true,
debug: true,
preview: {
enabled: true,
doubleWidth: true,
distance: 75,
delay: 500,
},
gap: 0,
debug: true,
};

/**
Expand All @@ -53,6 +54,7 @@ function updateSettings() {
config.preview.enabled = gsettings.get_value('preview').deep_unpack();
config.preview.distance = gsettings.get_value('distance').deep_unpack();
config.preview.delay = gsettings.get_value('delay').deep_unpack();
config.gap = gsettings.get_value('gap').deep_unpack();
config.debug = gsettings.get_value('debug').deep_unpack();
_log(JSON.stringify(config));
}
Expand Down Expand Up @@ -102,7 +104,14 @@ function requestMinimize(app) {
* @param {number} h - desired height
*/
function moveAppCoordinates(app, x, y, w, h) {
_log(`Moving window to (${x},${y}), size (${w},${h})`);
if (config.gap) {
const halfGap = Math.floor(config.gap / 2);
w -= config.gap;
h -= config.gap;
x += halfGap;
y += halfGap;
}
_log(`moveAppCoordinates) Moving window to (${x},${y}), size (${w},${h}) with ${config.gap}px gaps`);
app.move_frame(true, x, y);
app.move_resize_frame(true, x, y, w, h);
}
Expand Down Expand Up @@ -151,11 +160,11 @@ function moveApp(app, loc) {
// Maximize
_log('maximize');
app.maximize(Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL);
} else if (loc.height === 2) {
} else if (loc.height === config.rows && !config.gap) {
// Maximize vertically
_log('maximize - v');
app.maximize(Meta.MaximizeFlags.VERTICAL);
} else if (loc.width === config.cols) {
} else if (loc.width === config.cols && !config.gap) {
// Maximize horizontally
_log('maximize - h');
app.maximize(Meta.MaximizeFlags.HORIZONTAL);
Expand All @@ -167,8 +176,8 @@ function moveApp(app, loc) {
app.wintile.width = loc.width;
app.wintile.height = loc.height;
let window = app.get_frame_rect();
let leftShift = window.width - w;
let upShift = window.height - h;
let leftShift = window.width - w + config.gap;
let upShift = window.height - h + config.gap;
if (leftShift && loc.col === colCount - 1) {
_log(`moveApp) window wider than anticipated. Shift left by ${leftShift} px`);
x -= leftShift;
Expand Down Expand Up @@ -833,12 +842,12 @@ function isClose(a, b, distance = config.preview.distance) {
/**
*
* @param {object} loc = { col, row, width, height }
* @param {number} _x - The x-coordinate of the preview.
* @param {number} _y - The y-coordinate of the preview.
* @param {number} _w - The width of the preview.
* @param {number} _h - The height of the preview.
* @param {number} spaceX - starting x of the screen
* @param {number} spaceY - starting y of the screen
* @param {number} colWidth - single col width
* @param {number} rowHeight - single row height
*/
function showPreview(loc, _x, _y, _w, _h) {
function showPreview(loc, spaceX, spaceY, colWidth, rowHeight) {
if (preview.loc && JSON.stringify(preview.loc) === JSON.stringify(loc))
return;

Expand All @@ -852,10 +861,10 @@ function showPreview(loc, _x, _y, _w, _h) {
opacity: 255,
visible: true,
transition: Clutter.AnimationMode.EASE_OUT_QUAD,
x: _x,
y: _y,
width: _w,
height: _h,
x: spaceX + (colWidth * loc.col) + Math.floor(config.gap / 2),
y: spaceY + (rowHeight * loc.row) + Math.floor(config.gap / 2),
width: colWidth * loc.width - config.gap,
height: rowHeight * loc.height - config.gap,
});
}

Expand Down
68 changes: 52 additions & 16 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,36 @@ function buildPrefsWidget() {
layout.attach(previewDelayLabel, 0, row, 1, 1);
layout.attach(previewDelayInput, 1, row++, 1, 1);

// Gap setting
let gapLabel = new Gtk.Label({
label: _('Gap width around tiles'),
visible: true,
hexpand: true,
halign: Gtk.Align.START,
});
let gapInput = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
visible: true,
});
let gapAdjustment = new Gtk.Adjustment({
lower: 0,
upper: 50,
step_increment: 2,
});
let gapSettingInt = new Gtk.SpinButton({
adjustment: gapAdjustment,
snap_to_ticks: true,
visible: true,
});
gapSettingInt.set_value(gsettings.get_int('gap'));
if (SHELL_VERSION >= 40)
gapInput.append(gapSettingInt);
else
gapInput.add(gapSettingInt);

layout.attach(gapLabel, 0, row, 1, 1);
layout.attach(gapInput, 1, row++, 1, 1);

// Debug setting
let debugLabel = new Gtk.Label({
label: _('Turn on debugging'),
Expand All @@ -224,23 +254,29 @@ function buildPrefsWidget() {
layout.attach(debugLabel, 0, row, 1, 1);
layout.attach(debugInput, 1, row++, 1, 1);

gsettings.bind('cols', colsInput, 'active', Gio.SettingsBindFlags.DEFAULT);
gsettings.bind('ultrawide-only', ultrawideOnlyInput, 'active', Gio.SettingsBindFlags.DEFAULT);
gsettings.bind('use-maximize', maximizeInput, 'active', Gio.SettingsBindFlags.DEFAULT);
gsettings.bind('use-minimize', minimizeInput, 'active', Gio.SettingsBindFlags.DEFAULT);
gsettings.bind('preview', previewInput, 'active', Gio.SettingsBindFlags.DEFAULT);
gsettings.bind('double-width', doubleWidthInput, 'active', Gio.SettingsBindFlags.DEFAULT);
colsSettingInt.connect('value-changed', function (entry) {
gsettings.set_int('cols', entry.value);
});
previewDistanceSettingInt.connect('value-changed', function (entry) {
gsettings.set_int('distance', entry.value);
});
previewDelaySettingInt.connect('value-changed', function (entry) {
gsettings.set_int('delay', entry.value);
});
gsettings.bind('debug', debugInput, 'active', Gio.SettingsBindFlags.DEFAULT);
const bindSettings = (key, input) => {
gsettings.bind(key, input, 'active', Gio.SettingsBindFlags.DEFAULT);
};

const connectAndSetInt = (setting, key) => {
setting.connect('value-changed', entry => {
gsettings.set_int(key, entry.value);
});
};

// settings that aren't toggles need a connect
connectAndSetInt(colsSettingInt, 'cols');
connectAndSetInt(previewDistanceSettingInt, 'distance');
connectAndSetInt(previewDelaySettingInt, 'delay');
connectAndSetInt(gapSettingInt, 'gap');

// all other settings need a bind
bindSettings('ultrawide-only', ultrawideOnlyInput);
bindSettings('use-maximize', maximizeInput);
bindSettings('use-minimize', minimizeInput);
bindSettings('preview', previewInput);
bindSettings('double-width', doubleWidthInput);
bindSettings('debug', debugInput);

// Return our widget which will be added to the window
return layout;
Expand Down
Binary file modified schemas/gschemas.compiled
Binary file not shown.
6 changes: 6 additions & 0 deletions schemas/org.gnome.shell.extensions.wintile.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<description></description>
<range min="25" max="1000"/>
</key>
<key name="gap" type="i">
<default>0</default>
<summary>Gap width around tiles</summary>
<description></description>
<range min="0" max="50"/>
</key>
<key name="debug" type="b">
<default>false</default>
<summary>Turn on/off debug output</summary>
Expand Down

0 comments on commit a7604cc

Please sign in to comment.