Commit 6074e8ec authored by Florian Müllner's avatar Florian Müllner

wip: Port to GTK4

parent ebbb2cd6
Pipeline #200751 passed with stages
in 55 seconds
...@@ -29,9 +29,9 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow { ...@@ -29,9 +29,9 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
margin_start: 36, margin_start: 36,
margin_end: 36, margin_end: 36,
}); });
this.add(box); this.set_child(box);
box.add(new Gtk.Label({ box.append(new Gtk.Label({
label: '<b>%s</b>'.format(_('Workspace Rules')), label: '<b>%s</b>'.format(_('Workspace Rules')),
use_markup: true, use_markup: true,
halign: Gtk.Align.START, halign: Gtk.Align.START,
...@@ -40,9 +40,9 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow { ...@@ -40,9 +40,9 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
this._list = new Gtk.ListBox({ this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE, selection_mode: Gtk.SelectionMode.NONE,
valign: Gtk.Align.START, valign: Gtk.Align.START,
show_separators: true,
}); });
this._list.set_header_func(this._updateHeader.bind(this)); box.append(this._list);
box.add(this._list);
const context = this._list.get_style_context(); const context = this._list.get_style_context();
const cssProvider = new Gtk.CssProvider(); const cssProvider = new Gtk.CssProvider();
...@@ -53,7 +53,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow { ...@@ -53,7 +53,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
context.add_class('frame'); context.add_class('frame');
this._list.add(new NewRuleRow()); this._list.insert(new NewRuleRow(), -1);
this._actionGroup = new Gio.SimpleActionGroup(); this._actionGroup = new Gio.SimpleActionGroup();
this._list.insert_action_group('rules', this._actionGroup); this._list.insert_action_group('rules', this._actionGroup);
...@@ -84,12 +84,10 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow { ...@@ -84,12 +84,10 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
this._sync(); this._sync();
this.connect('destroy', () => this._settings.run_dispose()); this.connect('destroy', () => this._settings.run_dispose());
this.show_all();
} }
_onAddActivated() { _onAddActivated() {
const dialog = new NewRuleDialog(this.get_toplevel()); const dialog = new NewRuleDialog(this.get_root());
dialog.connect('response', (dlg, id) => { dialog.connect('response', (dlg, id) => {
const appInfo = id === Gtk.ResponseType.OK const appInfo = id === Gtk.ResponseType.OK
? dialog.get_widget().get_app_info() : null; ? dialog.get_widget().get_app_info() : null;
...@@ -101,6 +99,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow { ...@@ -101,6 +99,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
} }
dialog.destroy(); dialog.destroy();
}); });
dialog.show();
} }
_onRemoveActivated(action, param) { _onRemoveActivated(action, param) {
...@@ -113,7 +112,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow { ...@@ -113,7 +112,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
} }
_getRuleRows() { _getRuleRows() {
return this._list.get_children().filter(row => !!row.id); return [...this._list].filter(row => !!row.id);
} }
_sync() { _sync() {
...@@ -139,17 +138,11 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow { ...@@ -139,17 +138,11 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
const removed = oldRules.filter( const removed = oldRules.filter(
({ id }) => !newRules.find(r => r.id === id)); ({ id }) => !newRules.find(r => r.id === id));
removed.forEach(r => r.destroy()); removed.forEach(r => this._list.remove(r));
this._settings.unblock_signal_handler(this._changedId); this._settings.unblock_signal_handler(this._changedId);
this._updateAction.enabled = true; this._updateAction.enabled = true;
} }
_updateHeader(row, before) {
if (!before || row.get_header())
return;
row.set_header(new Gtk.Separator());
}
}); });
const RuleRow = GObject.registerClass({ const RuleRow = GObject.registerClass({
...@@ -165,12 +158,6 @@ const RuleRow = GObject.registerClass({ ...@@ -165,12 +158,6 @@ const RuleRow = GObject.registerClass({
}, },
}, class RuleRow extends Gtk.ListBoxRow { }, class RuleRow extends Gtk.ListBoxRow {
_init(appInfo, value) { _init(appInfo, value) {
super._init({
activatable: false,
value,
});
this._appInfo = appInfo;
const box = new Gtk.Box({ const box = new Gtk.Box({
spacing: 6, spacing: 6,
margin_top: 6, margin_top: 6,
...@@ -179,12 +166,19 @@ const RuleRow = GObject.registerClass({ ...@@ -179,12 +166,19 @@ const RuleRow = GObject.registerClass({
margin_end: 6, margin_end: 6,
}); });
super._init({
activatable: false,
value,
child: box,
});
this._appInfo = appInfo;
const icon = new Gtk.Image({ const icon = new Gtk.Image({
gicon: appInfo.get_icon(), gicon: appInfo.get_icon(),
pixel_size: 32, pixel_size: 32,
}); });
icon.get_style_context().add_class('icon-dropshadow'); icon.get_style_context().add_class('icon-dropshadow');
box.add(icon); box.append(icon);
const label = new Gtk.Label({ const label = new Gtk.Label({
label: appInfo.get_display_name(), label: appInfo.get_display_name(),
...@@ -193,7 +187,7 @@ const RuleRow = GObject.registerClass({ ...@@ -193,7 +187,7 @@ const RuleRow = GObject.registerClass({
max_width_chars: 20, max_width_chars: 20,
ellipsize: Pango.EllipsizeMode.END, ellipsize: Pango.EllipsizeMode.END,
}); });
box.add(label); box.append(label);
const spinButton = new Gtk.SpinButton({ const spinButton = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({ adjustment: new Gtk.Adjustment({
...@@ -207,26 +201,17 @@ const RuleRow = GObject.registerClass({ ...@@ -207,26 +201,17 @@ const RuleRow = GObject.registerClass({
this.bind_property('value', this.bind_property('value',
spinButton, 'value', spinButton, 'value',
GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.BIDIRECTIONAL); GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.BIDIRECTIONAL);
box.add(spinButton); box.append(spinButton);
const button = new Gtk.Button({ const button = new Gtk.Button({
action_name: 'rules.remove', action_name: 'rules.remove',
action_target: new GLib.Variant('s', this.id), action_target: new GLib.Variant('s', this.id),
image: new Gtk.Image({ icon_name: 'edit-delete-symbolic',
icon_name: 'edit-delete-symbolic',
pixel_size: 16,
}),
});
box.add(button);
this.add(box);
this.connect('notify::value', () => {
const actionGroup = this.get_action_group('rules');
actionGroup.activate_action('update', null);
}); });
box.append(button);
this.show_all(); this.connect('notify::value',
() => this.activate_action('rules.update', null));
} }
get id() { get id() {
...@@ -239,19 +224,17 @@ class NewRuleRow extends Gtk.ListBoxRow { ...@@ -239,19 +224,17 @@ class NewRuleRow extends Gtk.ListBoxRow {
_init() { _init() {
super._init({ super._init({
action_name: 'rules.add', action_name: 'rules.add',
child: new Gtk.Image({
icon_name: 'list-add-symbolic',
pixel_size: 16,
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
}),
}); });
this.get_accessible().set_name(_('Add Rule')); this.update_property_value(
Gtk.AccessibleProperty.LABEL, _('Add Rule'));
this.add(new Gtk.Image({
icon_name: 'list-add-symbolic',
pixel_size: 16,
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
}));
this.show_all();
} }
}); });
...@@ -273,8 +256,6 @@ class NewRuleDialog extends Gtk.AppChooserDialog { ...@@ -273,8 +256,6 @@ class NewRuleDialog extends Gtk.AppChooserDialog {
this.get_widget().connect('application-selected', this.get_widget().connect('application-selected',
this._updateSensitivity.bind(this)); this._updateSensitivity.bind(this));
this._updateSensitivity(); this._updateSensitivity();
this.show();
} }
_updateSensitivity() { _updateSensitivity() {
......
...@@ -26,18 +26,21 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow { ...@@ -26,18 +26,21 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
}); });
const box = new Gtk.Box(); const box = new Gtk.Box();
this.add(box); this.set_child(box);
this._list = new Gtk.ListBox({ this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE, selection_mode: Gtk.SelectionMode.NONE,
show_separators: true,
halign: Gtk.Align.CENTER, halign: Gtk.Align.CENTER,
valign: Gtk.Align.START, valign: Gtk.Align.START,
hexpand: true, hexpand: true,
margin: 60, margin_top: 60,
margin_bottom: 60,
margin_start: 60,
margin_end: 60,
}); });
this._list.get_style_context().add_class('frame'); this._list.get_style_context().add_class('frame');
this._list.set_header_func(this._updateHeader.bind(this)); box.append(this._list);
box.add(this._list);
this._actionGroup = new Gio.SimpleActionGroup(); this._actionGroup = new Gio.SimpleActionGroup();
this._list.insert_action_group('theme', this._actionGroup); this._list.insert_action_group('theme', this._actionGroup);
...@@ -90,11 +93,10 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow { ...@@ -90,11 +93,10 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
} }
_addTheme(name) { _addTheme(name) {
const row = new ThemeRow(name); const row = new ThemeRow(name, this._settings);
this._rows.set(name, row); this._rows.set(name, row);
this._list.add(row); this._list.insert(row, -1);
row.show_all();
} }
async _enumerateDir(dir) { async _enumerateDir(dir) {
...@@ -121,31 +123,29 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow { ...@@ -121,31 +123,29 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
return fileInfos.map(info => info.get_name()); return fileInfos.map(info => info.get_name());
} }
_updateHeader(row, before) {
if (!before || row.get_header())
return;
row.set_header(new Gtk.Separator());
}
}); });
const ThemeRow = GObject.registerClass( const ThemeRow = GObject.registerClass(
class ThemeRow extends Gtk.ListBoxRow { class ThemeRow extends Gtk.ListBoxRow {
_init(name) { _init(name, settings) {
this._name = new GLib.Variant('s', name); this._name = name;
this._settings = settings;
super._init({
action_name: 'theme.name',
action_target: this._name,
});
const box = new Gtk.Box({ const box = new Gtk.Box({
spacing: 12, spacing: 12,
margin: 12, margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
});
const target = new GLib.Variant('s', name);
super._init({
action_name: 'theme.name',
action_target: target,
child: box,
}); });
this.add(box);
box.add(new Gtk.Label({ box.append(new Gtk.Label({
label: name || 'Default', label: name || 'Default',
hexpand: true, hexpand: true,
xalign: 0, xalign: 0,
...@@ -157,24 +157,21 @@ class ThemeRow extends Gtk.ListBoxRow { ...@@ -157,24 +157,21 @@ class ThemeRow extends Gtk.ListBoxRow {
icon_name: 'emblem-ok-symbolic', icon_name: 'emblem-ok-symbolic',
pixel_size: 16, pixel_size: 16,
}); });
box.add(this._checkmark); box.append(this._checkmark);
box.show_all(); const id = this._settings.connect('changed::name',
this._syncCheckmark.bind(this));
this._syncCheckmark();
const id = this.connect('parent-set', () => { this.connect('destroy', () => {
this.disconnect(id); this._settings.disconnect(id);
this._settings = null;
const actionGroup = this.get_action_group('theme');
actionGroup.connect('action-state-changed::name',
this._syncCheckmark.bind(this));
this._syncCheckmark();
}); });
} }
_syncCheckmark() { _syncCheckmark() {
const actionGroup = this.get_action_group('theme'); const visible = this._name === this._settings.get_string('name');
const state = actionGroup.get_action_state('name'); this._checkmark.opacity = visible ? 1. : 0.;
this._checkmark.opacity = this._name.equal(state);
} }
}); });
...@@ -182,8 +179,5 @@ function init() { ...@@ -182,8 +179,5 @@ function init() {
} }
function buildPrefsWidget() { function buildPrefsWidget() {
let widget = new UserThemePrefsWidget(); return new UserThemePrefsWidget();
widget.show_all();
return widget;
} }
...@@ -27,7 +27,7 @@ class WindowListPrefsWidget extends Gtk.Box { ...@@ -27,7 +27,7 @@ class WindowListPrefsWidget extends Gtk.Box {
}); });
let groupingLabel = '<b>%s</b>'.format(_('Window Grouping')); let groupingLabel = '<b>%s</b>'.format(_('Window Grouping'));
this.add(new Gtk.Label({ this.append(new Gtk.Label({
label: groupingLabel, use_markup: true, label: groupingLabel, use_markup: true,
halign: Gtk.Align.START, halign: Gtk.Align.START,
})); }));
...@@ -37,7 +37,7 @@ class WindowListPrefsWidget extends Gtk.Box { ...@@ -37,7 +37,7 @@ class WindowListPrefsWidget extends Gtk.Box {
spacing: 12, spacing: 12,
margin_bottom: 12, margin_bottom: 12,
}); });
this.add(box); this.append(box);
const context = box.get_style_context(); const context = box.get_style_context();
const cssProvider = new Gtk.CssProvider(); const cssProvider = new Gtk.CssProvider();
...@@ -76,7 +76,7 @@ class WindowListPrefsWidget extends Gtk.Box { ...@@ -76,7 +76,7 @@ class WindowListPrefsWidget extends Gtk.Box {
group: radio, group: radio,
margin_end: 12, margin_end: 12,
}); });
box.add(radio); box.append(radio);
if (currentMode === mode) if (currentMode === mode)
currentRadio = radio; currentRadio = radio;
...@@ -94,15 +94,13 @@ class WindowListPrefsWidget extends Gtk.Box { ...@@ -94,15 +94,13 @@ class WindowListPrefsWidget extends Gtk.Box {
label: _('Show on all monitors'), label: _('Show on all monitors'),
}); });
this._settings.bind('show-on-all-monitors', check, 'active', Gio.SettingsBindFlags.DEFAULT); this._settings.bind('show-on-all-monitors', check, 'active', Gio.SettingsBindFlags.DEFAULT);
this.add(check); this.append(check);
check = new Gtk.CheckButton({ check = new Gtk.CheckButton({
label: _('Show windows from all workspaces'), label: _('Show windows from all workspaces'),
}); });
this._settings.bind('display-all-workspaces', check, 'active', Gio.SettingsBindFlags.DEFAULT); this._settings.bind('display-all-workspaces', check, 'active', Gio.SettingsBindFlags.DEFAULT);
this.add(check); this.append(check);
this.show_all();
} }
}); });
......
// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- // -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
/* exported init buildPrefsWidget */ /* exported init buildPrefsWidget */
const { Gdk, Gio, GLib, GObject, Gtk, Pango } = imports.gi; const { Gio, GLib, GObject, Gtk, Pango } = imports.gi;
const Gettext = imports.gettext.domain('gnome-shell-extensions'); const Gettext = imports.gettext.domain('gnome-shell-extensions');
const _ = Gettext.gettext; const _ = Gettext.gettext;
...@@ -28,9 +28,9 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow { ...@@ -28,9 +28,9 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
margin_start: 36, margin_start: 36,
margin_end: 36, margin_end: 36,
}); });
this.add(box); this.set_child(box);
box.add(new Gtk.Label({ box.append(new Gtk.Label({
label: '<b>%s</b>'.format(_('Workspace Names')), label: '<b>%s</b>'.format(_('Workspace Names')),
use_markup: true, use_markup: true,
halign: Gtk.Align.START, halign: Gtk.Align.START,
...@@ -39,10 +39,10 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow { ...@@ -39,10 +39,10 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
this._list = new Gtk.ListBox({ this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE, selection_mode: Gtk.SelectionMode.NONE,
valign: Gtk.Align.START, valign: Gtk.Align.START,
show_separators: true,
}); });
this._list.set_header_func(this._updateHeader.bind(this));
this._list.connect('row-activated', (l, row) => row.edit()); this._list.connect('row-activated', (l, row) => row.edit());
box.add(this._list); box.append(this._list);
const context = this._list.get_style_context(); const context = this._list.get_style_context();
const cssProvider = new Gtk.CssProvider(); const cssProvider = new Gtk.CssProvider();
...@@ -53,7 +53,7 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow { ...@@ -53,7 +53,7 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
context.add_class('frame'); context.add_class('frame');
this._list.add(new NewWorkspaceRow()); this._list.insert(new NewWorkspaceRow(), -1);
this._actionGroup = new Gio.SimpleActionGroup(); this._actionGroup = new Gio.SimpleActionGroup();
this._list.insert_action_group('workspaces', this._actionGroup); this._list.insert_action_group('workspaces', this._actionGroup);
...@@ -94,12 +94,10 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow { ...@@ -94,12 +94,10 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
this._settings.connect(`changed::${WORKSPACE_KEY}`, this._settings.connect(`changed::${WORKSPACE_KEY}`,
this._sync.bind(this)); this._sync.bind(this));
this._sync(); this._sync();
this.show_all();
} }
_getWorkspaceRows() { _getWorkspaceRows() {
return this._list.get_children().filter(row => row.name); return [...this._list].filter(row => row.name);
} }
_sync() { _sync() {
...@@ -111,17 +109,11 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow { ...@@ -111,17 +109,11 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
const removed = oldNames.filter(n => !newNames.includes(n)); const removed = oldNames.filter(n => !newNames.includes(n));
const added = newNames.filter(n => !oldNames.includes(n)); const added = newNames.filter(n => !oldNames.includes(n));
removed.forEach(n => rows.find(r => r.name === n).destroy()); removed.forEach(n => this._list.remove(rows.find(r => r.name === n)));
added.forEach(n => { added.forEach(n => {
this._list.insert(new WorkspaceRow(n), newNames.indexOf(n)); this._list.insert(new WorkspaceRow(n), newNames.indexOf(n));
}); });
} }
_updateHeader(row, before) {
if (!before || row.get_header())
return;
row.set_header(new Gtk.Separator());
}
}); });
const WorkspaceRow = GObject.registerClass( const WorkspaceRow = GObject.registerClass(
...@@ -129,6 +121,13 @@ class WorkspaceRow extends Gtk.ListBoxRow { ...@@ -129,6 +121,13 @@ class WorkspaceRow extends Gtk.ListBoxRow {
_init(name) { _init(name) {
super._init({ name }); super._init({ name });
const controller = new Gtk.ShortcutController();
controller.add_shortcut(new Gtk.Shortcut({
trigger: Gtk.ShortcutTrigger.parse_string('Escape'),
action: Gtk.CallbackAction.new(this._stopEdit.bind(this)),
}));