Skip to content

Commit

Permalink
refactor!: port preferences to libadwaita (#15)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: reset-page uses Adw.AlertDialog, which was added in 1.5, but usually gnome-shell 45 ships with 1.4, so gnome-shell 45 support was dropped.
  • Loading branch information
garaevdi committed May 20, 2024
1 parent c99fc9c commit 61c326e
Show file tree
Hide file tree
Showing 24 changed files with 1,597 additions and 2,069 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This is the fork of the [original rounded-window-corners extension][14] by

## Features

- Works with Gnome 45+
- Works with Gnome 46+
- Custom border radius and clip paddings for windows
- Blocklist for applications that draw their own window decorations
- Custom shadow for windows with rounded corners
Expand Down
2 changes: 1 addition & 1 deletion resources/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"gettext-domain": "rounded-window-corners@fxgn",
"settings-schema": "org.gnome.shell.extensions.rounded-window-corners",
"session-modes": ["user", "unlock-dialog"],
"shell-version": ["45", "46"]
"shell-version": ["46"]
}
25 changes: 5 additions & 20 deletions src/preferences/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import type Gtk from 'gi:https://Gtk';
import type Adw from 'gi:https://Adw';

import {gettext as _} from 'resource:https:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import {BlackList} from '../preferences/pages/blacklist.js';
import {Custom} from '../preferences/pages/custom.js';
import {General} from '../preferences/pages/general.js';

type Page = {title: string; icon_name: string; widget: Gtk.Widget};

export const pages = (): Page[] => [
{
title: _('General'),
icon_name: 'emblem-system-symbolic',
widget: new General(),
},
{
title: _('Blacklist'),
icon_name: 'action-unavailable-symbolic',
widget: new BlackList(),
},
{
title: _('Custom'),
icon_name: 'document-edit-symbolic',
widget: new Custom(),
},
export const pages = (): Adw.PreferencesPage[] => [
new General(),
new BlackList(),
new Custom(),
];
126 changes: 44 additions & 82 deletions src/preferences/pages/blacklist.ts
Original file line number Diff line number Diff line change
@@ -1,111 +1,73 @@
// imports.gi
import Adw from 'gi:https://Adw';
import GObject from 'gi:https://GObject';
import type Gtk from 'gi:https://Gtk';

// Local Modules
import {AppRow} from '../../preferences/widgets/app_row.js';
import {connections} from '../../utils/connections.js';
import {TIPS_EMPTY, show_err_msg} from '../../utils/prefs.js';
import {settings} from '../../utils/settings.js';
import type {AppRowCallbacks, AppRowClass} from '../widgets/app_row.js';
import {BlacklistRow} from '../widgets/blacklist_row.js';

// types
import type {AppRowHandler} from '../widgets/app_row.js';

import Gtk from 'gi:https://Gtk';
import {gettext as _} from 'resource:https:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import {uri} from '../../utils/io.js';

// --------------------------------------------------------------- [end imports]

/** Black list Preferences Page */
export const BlackList = GObject.registerClass(
{
Template: uri(import.meta.url, 'blacklist.ui'),
GTypeName: 'RoundedWindowCornersPrefsBlacklist',
InternalChildren: ['black_list_group', 'add_row_btn'],
GTypeName: 'PrefsBlacklist',
InternalChildren: ['blacklist_group'],
},
class extends Gtk.Box {
private declare _black_list_group: Gtk.ListBox;
private declare _add_row_btn: Gtk.Button;
class extends Adw.PreferencesPage {
private declare _blacklist_group: Adw.PreferencesGroup;

/** Store value of settings */
private declare black_list: string[];
private declare blacklist: string[];

_init() {
super._init();
this.black_list = settings().black_list;
constructor() {
super();
this.blacklist = settings().black_list;

// Read blacklist from settings, and add it to this._black_list
for (const name of this.black_list) {
this.on_add_row(name);
for (const title of this.blacklist) {
this.add_window(undefined, title);
}

connections.get().connect(this._add_row_btn, 'clicked', () => {
if (this.black_list.includes('')) {
return;
}

this.on_add_row();
this.black_list.push('');
settings().black_list = this.black_list;
});

connections
.get()
.connect(
this._black_list_group,
'row-activated',
(_me: Gtk.ListBox, row: Gtk.ListBoxRow) => {
if (row instanceof AppRow) {
row.on_expanded_changed();
}
},
);
}

private show_err_msg(item: string) {
const title = `${item}: ${_(
"Can't add to list, because it has exists",
)}`;
show_err_msg(title);
}

// --------------------------------------------------- [signal handlers]

private on_delete_row(row: Gtk.ListBoxRow, title: string) {
this.black_list.splice(this.black_list.indexOf(title), 1);
settings().black_list = this.black_list;
this._black_list_group.remove(row);
}

/** Add a row to black list */
private on_add_row(title = '') {
const handlers: AppRowHandler = {
on_delete: (row, title) => this.on_delete_row(row, title),
on_title_changed: (old_title, new_title) =>
this.on_title_changed(old_title, new_title),
private add_window(_?: Gtk.Button, title?: string) {
const callbacks: AppRowCallbacks = {
on_delete: row => this.delete_row(row),
on_title_changed: (_, old_title, new_title) =>
this.change_title(old_title, new_title),
};

const row = new AppRow(handlers);
row.title = title;

if (!title) {
row.description = TIPS_EMPTY();
}
const row = new BlacklistRow(callbacks);
row.set_subtitle(title ?? '');
this._blacklist_group.add(row);
}

this._black_list_group.append(row);
private delete_row(row: AppRowClass) {
this.blacklist.splice(this.blacklist.indexOf(row.title), 1);
settings().black_list = this.blacklist;
this._blacklist_group.remove(row);
}

/** Called when title of item need to changed */
on_title_changed(old_title: string, new_title: string): boolean {
if (this.black_list.includes(new_title)) {
this.show_err_msg(new_title);
private change_title(old_title: string, new_title: string): boolean {
if (this.blacklist.includes(new_title)) {
const win = this.root as unknown as Adw.PreferencesDialog;
win.add_toast(
new Adw.Toast({
title: _(
`Can't add ${new_title} to the list, because it already there`,
),
}),
);
return false;
}

const old_idx = this.black_list.indexOf(old_title);
this.black_list.splice(old_idx, 1, new_title);
if (old_title === '') {
this.blacklist.push(new_title);
} else {
const old_id = this.blacklist.indexOf(old_title);
this.blacklist.splice(old_id, 1, new_title);
}

settings().black_list = this.black_list;
settings().black_list = this.blacklist;

return true;
}
Expand Down
60 changes: 16 additions & 44 deletions src/preferences/pages/blacklist.ui
Original file line number Diff line number Diff line change
@@ -1,56 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0" />
<template class="RoundedWindowCornersPrefsBlacklist" parent="GtkBox">
<property name="spacing">12</property>
<property name="orientation">vertical</property>
<requires lib="adw" version="1.0" />
<template class="PrefsBlacklist" parent="AdwPreferencesPage">
<property name="title" translatable="yes">Blacklist</property>
<property name="icon-name">action-unavailable-symbolic</property>
<child>
<object class="GtkLabel">
<property name="halign">fill</property>
<property name="wrap">true</property>
<property name="xalign">0</property>
<property name="wrap-mode">word-char</property>
<property name="max-width-chars">25</property>
<property name="label" translatable="yes">Not all application can works well with rounded corners effects, add them to this list to disable effects.

The item of list is instance part of WM_CLASS property with window. You can pick a window to add it into this list.</property>
<style>
<class name="caption" />
</style>
</object>
</child>
<child>
<object class="GtkButton" id="add_row_btn">
<property name="halign">start</property>
<property name="valign">center</property>
<child>
<object class="GtkBox">
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<object class="AdwPreferencesGroup" id="blacklist_group">
<property name="title" translatable="yes">Blacklist</property>
<property name="description" translatable="yes">Not all application can works well with rounded corners effects, add them to this list to disable effects.</property>
<property name="header-suffix">
<object class="GtkButton">
<property name="valign">start</property>
<property name="margin-start">4px</property>
<property name="margin-end">4px</property>
<child>
<object class="GtkImage">
<property name="margin-end">6</property>
<object class="AdwButtonContent">
<property name="label" translatable="yes">Add window</property>
<property name="icon-name">list-add-symbolic</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property translatable="yes" name="label">Add Window</property>
</object>
</child>
<signal name="clicked" handler="add_window"/>
</object>
</child>
<style>
<class name="circular" />
</style>
</object>
</child>
<child>
<object class="GtkListBox" id="black_list_group">
<property name="selection-mode">none</property>
<style>
<class name="rich-list"></class>
</style>
</property>
</object>
</child>
</template>
Expand Down
Loading

0 comments on commit 61c326e

Please sign in to comment.