Skip to content

Commit ae9f505

Browse files
bennypowersmmstick
authored andcommitted
fix: clamp border radius
1 parent 3c94a37 commit ae9f505

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

schemas/org.gnome.shell.extensions.pop-shell.gschema.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<key type="u" name="active-hint-border-radius">
1111
<default>5</default>
12+
<range min="5" max="30"/>
1213
<summary>Border radius for active window hint, in pixels</summary>
1314
</key>
1415

src/panel_settings.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export class Indicator {
6767

6868
this.border_radius = number_entry(
6969
_("Active Border Radius"),
70-
ext.settings.active_hint_border_radius(),
70+
{
71+
value: ext.settings.active_hint_border_radius(),
72+
min: 5,
73+
max: 30
74+
},
7175
(value) => {
7276
ext.settings.set_active_hint_border_radius(value);
7377
}
@@ -203,15 +207,19 @@ function shortcuts(menu: any): any {
203207
return item;
204208
}
205209

206-
function clamp(input: number): number {
207-
return Math.min(Math.max(0, input), 128);
210+
function clamp(input: number, min = 0, max = 128): number {
211+
return Math.min(Math.max(min, input), max);
208212
}
209213

210214
function number_entry(
211215
label: string,
212-
value: number,
216+
valueOrOptions: number|{value: number, min: number, max: number},
213217
callback: (a: number) => void,
214218
): any {
219+
let value = valueOrOptions, min: number, max: number;
220+
if (typeof valueOrOptions !== 'number')
221+
({ value, min, max } = valueOrOptions);
222+
215223
const entry = new St.Entry({
216224
text: String(value),
217225
input_purpose: Clutter.InputContentPurpose.NUMBER,
@@ -234,9 +242,9 @@ function number_entry(
234242
symbol == 65293 // enter key
235243
? parse_number(text.text)
236244
: symbol == 65361 // left key
237-
? clamp(parse_number(text.text) - 1)
245+
? clamp(parse_number(text.text) - 1, min, max)
238246
: symbol == 65363 // right key
239-
? clamp(parse_number(text.text) + 1)
247+
? clamp(parse_number(text.text) + 1, min, max)
240248
: null;
241249

242250
if (number !== null) {
@@ -250,12 +258,12 @@ function number_entry(
250258

251259
entry.set_primary_icon(create_icon('value-decrease'))
252260
entry.connect('primary-icon-clicked', () => {
253-
text.set_text(String(clamp(parseInt(text.get_text()) - 1)))
261+
text.set_text(String(clamp(parseInt(text.get_text()) - 1, min, max)))
254262
})
255263

256264
entry.set_secondary_icon(create_icon('value-increase'))
257265
entry.connect('secondary-icon-clicked', () => {
258-
text.set_text(String(clamp(parseInt(text.get_text()) + 1)))
266+
text.set_text(String(clamp(parseInt(text.get_text()) + 1, min, max)))
259267
})
260268

261269
text.connect('text-changed', () => {

0 commit comments

Comments
 (0)