Skip to content

Commit

Permalink
change prefs to use xml
Browse files Browse the repository at this point in the history
  • Loading branch information
GrylledCheez committed Oct 25, 2023
1 parent 9671202 commit 37f8af3
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 234 deletions.
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "WinTile",
"description": "WinTile is a hotkey driven window tiling system for GNOME that imitates the standard Win-Arrow keys of Windows 10, allowing you to maximize, maximize to sides, or 1/4 sized to corner across a single or multiple monitors using just Super+Arrow.\n\nAs of v16, WinTile also supports:\n- 2-5 columns and 1-4 rows for standard or ultrawide monitors\n- Top/bottom half support\n- Mouse preview and snapping for placing windows\n- 'Maximize' mode, which adds/removes GNOME animations\n- 'Ultrawide-only' mode, to allow standard screens to have different cols/row than ultrawides\n- Portrait screens will automatically swap columns and rows\n- Add gaps around tiles to avoid the 'crowded elevator' feeling'\n- Ctrl+Super+Arrow to grow a tile in that direction if space is available\n- Ctrl+drag to drop a tile in a specific spot\n- Ctrl+Super+drag to draw a grid for the new tile",
"description": "WinTile is a hotkey driven window tiling system for GNOME that imitates the standard Win-Arrow keys of Windows 10, allowing you to maximize, maximize to sides, or 1/4 sized to corner across a single or multiple monitors using just Super+Arrow.\n\nAs of v16, WinTile also supports:\n- 1-5 columns and 1-5 rows for standard or ultrawide monitors\n- Top/bottom half support\n- Mouse preview and snapping for placing windows\n- 'Maximize' mode, which adds/removes GNOME animations\n- 'Ultrawide-only' mode, to allow standard screens to have different cols/row than ultrawides\n- Portrait screens will automatically swap columns and rows\n- Add gaps around tiles to avoid the 'crowded elevator' feeling'\n- Ctrl+Super+Arrow to grow a tile in that direction if space is available\n- Ctrl+drag to drop a tile in a specific spot\n- Ctrl+Super+drag to draw a grid for the new tile",
"uuid": "wintile@nowsci.com",
"url": "https://github.com/fmstrat/wintile",
"settings-schema":"org.gnome.shell.extensions.wintile",
Expand Down
264 changes: 31 additions & 233 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,253 +2,52 @@

const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Adw = imports.gi.Adw;

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

const Gettext = imports.gettext;
const _ = Gettext.domain('wintile').gettext;

const gsettings = ExtensionUtils.getSettings();

/**
*
*/
function init() {
// empty
}


/**
*
* @param {object} window - Don't worry about this. Gnome handles it for you.
*/
function fillPreferencesWindow(window) {
let gsettings;
gsettings = ExtensionUtils.getSettings();

const gridPage = new Adw.PreferencesPage({
name: 'Dimensions',
title: 'Dimensions',
icon_name: 'preferences-desktop-apps-symbolic',
});
let builder = Gtk.Builder.new();
builder.add_from_file(`${Me.path}/settings.ui`);
let gridPage = builder.get_object('gridPage');
let behaviorPage = builder.get_object('behaviorPage');
window.add(gridPage);

const gridGroup = new Adw.PreferencesGroup({
title: 'Grid size',
description: `Configure the rows and columns of ${Me.metadata.name}`,
});
gridPage.add(gridGroup);

// COLUMNS
const colsRow = new Adw.ActionRow({
title: 'Columns',
});
gridGroup.add(colsRow);

let colsSettingInt = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
'lower': 1,
'step-increment': 1,
'upper': 5,
'value': gsettings.get_int('cols'),
}),
});
colsRow.add_suffix(colsSettingInt);

// ROWS
const rowsRow = new Adw.ActionRow({
title: 'Rows',
});
gridGroup.add(rowsRow);

let rowsSettingInt = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
'lower': 1,
'step-increment': 1,
'upper': 5,
'value': gsettings.get_int('rows'),
}),
});
rowsRow.add_suffix(rowsSettingInt);

// ULTRAWIDE
const ultrawideOnlyRow = new Adw.ActionRow({
title: 'Use different rows and columns for non-ultrawide monitors',
});
gridGroup.add(ultrawideOnlyRow);

const ultrawideOnlyInput = new Gtk.CheckButton();
ultrawideOnlyRow.add_suffix(ultrawideOnlyInput);
ultrawideOnlyRow.set_activatable_widget(ultrawideOnlyInput);
ultrawideOnlyInput.active = gsettings.get_boolean('ultrawide-only');

// preference group
const nonUltrawideGroup = new Adw.PreferencesGroup({
title: 'Number of columns for non-ultrawide',
description: 'Configure the separate rows and columns of non-ultrawides',
});
gridPage.add(nonUltrawideGroup);

// NON-ULTRAWIDE COLUMNS
const nonUltraColsRow = new Adw.ActionRow({
title: 'Columns',
});
nonUltrawideGroup.add(nonUltraColsRow);

let nonUltraColsSettingInt = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
'lower': 1,
'step-increment': 1,
'upper': 5,
'value': gsettings.get_int('non-ultra-cols'),
}),
});
nonUltraColsRow.add_suffix(nonUltraColsSettingInt);

// NON-ULTRAWIDE ROWS
const nonUltraRowsRow = new Adw.ActionRow({
title: 'Rows',
});
nonUltrawideGroup.add(nonUltraRowsRow);

let nonUltraRowsSettingInt = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
'lower': 1,
'step-increment': 1,
'upper': 5,
'value': gsettings.get_int('non-ultra-rows'),
}),
});
nonUltraRowsRow.add_suffix(nonUltraRowsSettingInt);

const behaviorPage = new Adw.PreferencesPage({
name: 'Behavior',
title: 'Behavior',
icon_name: 'applications-system-symbolic',
});
window.add(behaviorPage);

const behaviorGroup = new Adw.PreferencesGroup({
title: 'Behavior',
});
behaviorPage.add(behaviorGroup);

// Maximize setting
const maximizeRow = new Adw.ActionRow({
title: 'Use true maximizing of windows',
});
behaviorGroup.add(maximizeRow);

const maximizeInput = new Gtk.CheckButton();
maximizeRow.add_suffix(maximizeInput);
maximizeRow.set_activatable_widget(maximizeInput);
maximizeInput.active = gsettings.get_boolean('use-maximize');

// Minimize setting
const minimizeRow = new Adw.ActionRow({
title: 'Use true miniming of windows',
});
behaviorGroup.add(minimizeRow);

const minimizeInput = new Gtk.CheckButton();
minimizeRow.add_suffix(minimizeInput);
minimizeRow.set_activatable_widget(minimizeInput);
minimizeInput.active = gsettings.get_boolean('use-minimize');

// Preview settings
const previewRow = new Adw.ActionRow({
title: 'Enable preview and snapping when dragging windows',
});
behaviorGroup.add(previewRow);

const previewInput = new Gtk.CheckButton();
previewRow.add_suffix(previewInput);
previewRow.set_activatable_widget(previewInput);
previewInput.active = gsettings.get_boolean('preview');

// Preview distance
const previewDistanceRow = new Adw.ActionRow({
title: 'Pixels from edge to start preview',
});
behaviorGroup.add(previewDistanceRow);

let previewDistanceSettingInt = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
'lower': 0,
'step-increment': 1,
'upper': 150,
'value': gsettings.get_int('distance'),
}),
});
previewDistanceRow.add_suffix(previewDistanceSettingInt);


// Delay
const previewDelayRow = new Adw.ActionRow({
title: 'Delay in ms before preview displays',
});
behaviorGroup.add(previewDelayRow);

let previewDelaySettingInt = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
'lower': 25,
'step-increment': 1,
'upper': 1000,
'value': gsettings.get_int('delay'),
}),
});
previewDelayRow.add_suffix(previewDelaySettingInt);


// Double width previews
const doubleWidthRow = new Adw.ActionRow({
title: 'Use double width previews on sides in 4 and 5 column mode',
});
behaviorGroup.add(doubleWidthRow);

const doubleWidthInput = new Gtk.CheckButton();
doubleWidthRow.add_suffix(doubleWidthInput);
doubleWidthRow.set_activatable_widget(doubleWidthInput);
doubleWidthInput.active = gsettings.get_boolean('double-width');

// Gap setting
const gapRow = new Adw.ActionRow({
title: 'Gap width around tiles',
});
behaviorGroup.add(gapRow);

let gapSettingInt = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
'lower': 0,
'step-increment': 2,
'upper': 50,
'value': gsettings.get_int('gap'),
}),
});
gapRow.add_suffix(gapSettingInt);

// Debug setting
const debugRow = new Adw.ActionRow({
title: 'Turn on debugging',
});
behaviorGroup.add(debugRow);

const debugInput = new Gtk.CheckButton();
debugRow.add_suffix(debugInput);
debugRow.set_activatable_widget(debugInput);
debugInput.active = gsettings.get_boolean('debug');



// let gsettings;
// gsettings = ExtensionUtils.getSettings();
const bindSettings = (key, input) => {
gsettings.bind(key, input, 'active', Gio.SettingsBindFlags.DEFAULT);
key.value = gsettings.get_value(input).deep_unpack();
gsettings.bind(input, key, 'active', Gio.SettingsBindFlags.DEFAULT);
};

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

let ultrawideOnlyInput = builder.get_object('ultrawideOnlyInput');
let nonUltrawideGroup = builder.get_object('nonUltrawideGroup');

const toggleUltrawide = () => {
if (ultrawideOnlyInput.active) {
// Show rows and columns options
Expand All @@ -259,23 +58,22 @@ function fillPreferencesWindow(window) {
}
};


// settings that aren't toggles need a connect
connectAndSetInt(colsSettingInt, 'cols');
connectAndSetInt(rowsSettingInt, 'rows');
connectAndSetInt(nonUltraColsSettingInt, 'non-ultra-cols');
connectAndSetInt(nonUltraRowsSettingInt, 'non-ultra-rows');
connectAndSetInt(previewDistanceSettingInt, 'distance');
connectAndSetInt(previewDelaySettingInt, 'delay');
connectAndSetInt(gapSettingInt, 'gap');
connectAndSetInt(builder.get_object('colsSettingInt'), 'cols');
connectAndSetInt(builder.get_object('rowsSettingInt'), 'rows');
connectAndSetInt(builder.get_object('nonUltraColsSettingInt'), 'non-ultra-cols');
connectAndSetInt(builder.get_object('nonUltraRowsSettingInt'), 'non-ultra-rows');
connectAndSetInt(builder.get_object('previewDistanceSettingInt'), 'distance');
connectAndSetInt(builder.get_object('previewDelaySettingInt'), 'delay');
connectAndSetInt(builder.get_object('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);
bindSettings(builder.get_object('ultrawideOnlyInput'), 'ultrawide-only');
bindSettings(builder.get_object('maximizeInput'), 'use-maximize');
bindSettings(builder.get_object('minimizeInput'), 'use-minimize');
bindSettings(builder.get_object('previewInput'), 'preview');
bindSettings(builder.get_object('doubleWidthInput'), 'double-width');
bindSettings(builder.get_object('debugInput'), 'debug');
ultrawideOnlyInput.connect('notify::active', toggleUltrawide);

// make sure that the non-ultrawide menu is hidden unless it's enabled
Expand Down
Loading

0 comments on commit 37f8af3

Please sign in to comment.