@@ -52,6 +52,8 @@ function buildPrefsWidget(): Gtk.Widget {
5252}
5353
5454export default class TilingShellExtensionPreferences extends ExtensionPreferences {
55+ private GNOME_VERSION_MAJOR = Number ( Config . PACKAGE_VERSION . split ( '.' ) [ 0 ] ) ;
56+
5557 /**
5658 * This function is called when the preferences window is first created to fill
5759 * the `Adw.PreferencesWindow`.
@@ -130,41 +132,54 @@ export default class TilingShellExtensionPreferences extends ExtensionPreference
130132 ) ,
131133 ) ;
132134
133- const windowBorderRow = new Adw . ExpanderRow ( {
135+ const windowBorderExpanderRow = new Adw . ExpanderRow ( {
134136 title : _ ( 'Window border' ) ,
135137 subtitle : _ ( 'Show a border around focused window' ) ,
136138 } ) ;
137- appearenceGroup . add ( windowBorderRow ) ;
138- windowBorderRow . add_row (
139+ appearenceGroup . add ( windowBorderExpanderRow ) ;
140+ windowBorderExpanderRow . add_row (
139141 this . _buildSwitchRow (
140142 Settings . KEY_ENABLE_WINDOW_BORDER ,
141143 _ ( 'Enable' ) ,
142144 _ ( 'Show a border around focused window' ) ,
143145 ) ,
144146 ) ;
145- windowBorderRow . add_row (
147+ windowBorderExpanderRow . add_row (
146148 this . _buildSwitchRow (
147149 Settings . KEY_ENABLE_SMART_WINDOW_BORDER_RADIUS ,
148150 _ ( 'Smart border radius' ) ,
149151 _ ( 'Dynamically adapt to the window’s actual border radius' ) ,
150152 ) ,
151153 ) ;
152- windowBorderRow . add_row (
154+ windowBorderExpanderRow . add_row (
153155 this . _buildSpinButtonRow (
154156 Settings . KEY_WINDOW_BORDER_WIDTH ,
155157 _ ( 'Width' ) ,
156158 _ ( 'The size of the border' ) ,
157159 1 ,
158160 ) ,
159161 ) ;
160- windowBorderRow . add_row (
161- this . _buildColorRow (
162- _ ( 'Border color' ) ,
163- _ ( 'Choose the color of the border' ) ,
164- this . _getRGBAFromString ( Settings . WINDOW_BORDER_COLOR ) ,
165- ( val : string ) => ( Settings . WINDOW_BORDER_COLOR = val ) ,
166- ) ,
162+ const colorButton = this . _buildColorButton (
163+ this . _getRGBAFromString ( Settings . WINDOW_BORDER_COLOR ) ,
164+ ( val : string ) => ( Settings . WINDOW_BORDER_COLOR = val ) ,
167165 ) ;
166+ const windowBorderColorRow = new Adw . ActionRow ( {
167+ title : _ ( 'Border color' ) ,
168+ subtitle : _ ( 'Choose the color of the border' ) ,
169+ } ) ;
170+ windowBorderColorRow . add_suffix ( colorButton ) ;
171+ colorButton . set_visible ( Settings . WINDOW_USE_CUSTOM_BORDER_COLOR ) ;
172+ if ( this . GNOME_VERSION_MAJOR >= 47 ) {
173+ const customColorDropDown = this . _buildCustomColorDropDown (
174+ Settings . WINDOW_USE_CUSTOM_BORDER_COLOR ,
175+ ( use_custom_color : boolean ) => {
176+ colorButton . set_visible ( use_custom_color ) ;
177+ Settings . WINDOW_USE_CUSTOM_BORDER_COLOR = use_custom_color ;
178+ } ,
179+ ) ;
180+ windowBorderColorRow . add_suffix ( customColorDropDown ) ;
181+ }
182+ windowBorderExpanderRow . add_row ( windowBorderColorRow ) ;
168183
169184 const animationsRow = new Adw . ExpanderRow ( {
170185 title : _ ( 'Animations' ) ,
@@ -1199,12 +1214,10 @@ export default class TilingShellExtensionPreferences extends ExtensionPreference
11991214 return rgba ;
12001215 }
12011216
1202- _buildColorRow (
1203- title : string ,
1204- subtitle : string ,
1217+ _buildColorButton (
12051218 rgba : Gdk . RGBA ,
12061219 onChange : ( s : string ) => void ,
1207- ) : Adw . ActionRow {
1220+ ) : Gtk . ColorButton {
12081221 const colorButton = new Gtk . ColorButton ( {
12091222 rgba,
12101223 use_alpha : true ,
@@ -1213,13 +1226,30 @@ export default class TilingShellExtensionPreferences extends ExtensionPreference
12131226 colorButton . connect ( 'color-set' , ( ) => {
12141227 onChange ( colorButton . get_rgba ( ) . to_string ( ) ) ;
12151228 } ) ;
1216- const adwRow = new Adw . ActionRow ( {
1217- title,
1218- subtitle,
1219- activatableWidget : colorButton ,
1229+ return colorButton ;
1230+ }
1231+
1232+ _buildCustomColorDropDown (
1233+ initialValue : boolean ,
1234+ onChange : ( _ : boolean ) => void ,
1235+ styleClass ?: string ,
1236+ ) {
1237+ const options = new Gtk . StringList ( ) ;
1238+ options . append ( _ ( 'Choose custom color' ) ) ; // true
1239+ options . append ( _ ( 'Use system accent color' ) ) ; // false
1240+ const dropdown = new Gtk . DropDown ( {
1241+ model : options ,
1242+ selected : initialValue ? 0 : 1 ,
12201243 } ) ;
1221- adwRow . add_suffix ( colorButton ) ;
1222- return adwRow ;
1244+ dropdown . connect ( 'notify::selected-item' , ( dd : Gtk . DropDown ) => {
1245+ const index = dd . get_selected ( ) ;
1246+ const selected = index === 0 ; // 0 is true, which means to use custom color
1247+ onChange ( selected ) ;
1248+ } ) ;
1249+ if ( styleClass ) dropdown . add_css_class ( styleClass ) ;
1250+ dropdown . set_vexpand ( false ) ;
1251+ dropdown . set_valign ( Gtk . Align . CENTER ) ;
1252+ return dropdown ;
12231253 }
12241254
12251255 _buildFileChooserDialog (
@@ -1245,12 +1275,9 @@ export default class TilingShellExtensionPreferences extends ExtensionPreference
12451275 window . connect ( 'map' , ( ) => {
12461276 fc . set_transient_for ( window ) ;
12471277 } ) ;
1248- const [ major ] = Config . PACKAGE_VERSION . split ( '.' ) . map ( ( s : string ) =>
1249- Number ( s ) ,
1250- ) ;
12511278 // due to a bug, file chooser doesn't open on GNOME 42 when a filter is set
12521279 // filter is then enabled for GNOME 43+
1253- if ( major >= 43 ) fc . set_filter ( filter ) ;
1280+ if ( this . GNOME_VERSION_MAJOR >= 43 ) fc . set_filter ( filter ) ;
12541281 fc . set_current_folder ( Gio . File . new_for_path ( GLib . get_home_dir ( ) ) ) ;
12551282 fc . connect ( 'response' , onResponse ) ;
12561283
@@ -1484,7 +1511,7 @@ const ShortcutSettingButton = class extends Gtk.Button {
14841511 // Because the cairo module isn't real, we have to use these to ignore `any`.
14851512 // We keep them to the minimum possible scope to catch real errors.
14861513 /* eslint-disable @typescript-eslint/no-unsafe-call */
1487- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
1514+
14881515/* ctx.setLineCap(Cairo.LineCap.SQUARE);
14891516 //@ts -ignore
14901517 ctx.setAntialias(Cairo.Antialias.NONE);
0 commit comments