From 870ec2cd9ebf6e7bba1eb668704726ed134c4bd7 Mon Sep 17 00:00:00 2001 From: Ba2hann Date: Sun, 24 May 2026 13:35:29 +0300 Subject: [PATCH] Add fixed network speed unit option (Closes #532) Add a new 'network-speed-unit' setting that allows users to fix the network speed display unit instead of auto-scaling between Kbps/Mbps. Options: - Auto (default): current auto-scaling behavior - Kbps/KiB/s: always display in kilo units - Mbps/MiB/s: always display in mega units Changes: - New GSetting key 'network-speed-unit' in schema - Modified values.js _legible() to respect fixed unit for 'speed' class - Added combo box in prefs.ui under Network preferences - Connected setting in prefs.js and extension.js Co-Authored-By: Claude Opus 4.7 --- extension.js | 2 +- prefs.js | 2 +- prefs.ui | 34 ++++++++++++++++++ schemas/gschemas.compiled | Bin 2084 -> 2148 bytes ....gnome.shell.extensions.vitals.gschema.xml | 5 +++ values.js | 18 ++++++++-- 6 files changed, 56 insertions(+), 5 deletions(-) diff --git a/extension.js b/extension.js index 0306a11..20a553e 100644 --- a/extension.js +++ b/extension.js @@ -334,7 +334,7 @@ var VitalsMenuButton = GObject.registerClass({ let settings = [ 'use-higher-precision', 'alphabetize', 'hide-zeros', 'fixed-widths', 'hide-icons', 'unit', 'memory-measurement', 'include-public-ip', 'network-public-ip-interval', - 'network-public-ip-show-flag', 'network-speed-format', 'storage-measurement', + 'network-public-ip-show-flag', 'network-speed-format', 'network-speed-unit', 'storage-measurement', 'include-static-info', 'include-static-gpu-info' ]; for (let setting of Object.values(settings)) diff --git a/prefs.js b/prefs.js index bdeb9a8..f0e1ee4 100644 --- a/prefs.js +++ b/prefs.js @@ -62,7 +62,7 @@ const Settings = new GObject.Class({ } // process individual drop down sensor preferences - sensors = [ 'position-in-panel', 'unit', 'network-speed-format', 'memory-measurement', 'storage-measurement', 'battery-slot', 'icon-style' ]; + sensors = [ 'position-in-panel', 'unit', 'network-speed-format', 'network-speed-unit', 'memory-measurement', 'storage-measurement', 'battery-slot', 'icon-style' ]; for (let key in sensors) { let sensor = sensors[key]; diff --git a/prefs.ui b/prefs.ui index 156799b..987b1a2 100644 --- a/prefs.ui +++ b/prefs.ui @@ -147,6 +147,40 @@ + + + 100 + 0 + + + 0 + 6 + 6 + 6 + 6 + + + 1 + 0 + start + Speed Unit + + + + + 0 + 0 + + Auto + Kbps / KiB/s + Mbps / MiB/s + + + + + + + diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index b84716f2279c87ea5ad1ad1bc993508bb54a2564..995491e10904a1587ebb4dcacd9aa3cf3a2ea2c8 100644 GIT binary patch literal 2148 zcmZ8iOK2Tc7(Ug;#>6yf8v8VwSSt4_b8kX5rl<=o#VlL|tWw-e=H7d9=hS&Qk0du% z3D_(YL7^K#OWgQEv~eMZh~h@fM#w^nyH*4VB56fx&8mLiIWxJXA>aMJ`R1SV_|M~i z_C+UFPLPWH?*RC;(WN_bZwL5N<+m|1-wlfiah7_g5FPglaT9-2oiN06g4_VYxLIii zp)V_mD?P6w=TaFYDh!g!j7l9ZVYm>bBZl=a`y~!1)`0PSU5|4gWpx1>j`%(=2`Jd*CmFzXq~%@4rBwn*JL2XW;ihenFpl z0R9H}8nChY%?I?U8815U4{SbvE|VmT5hFy~p9#IxX-e(p{;w z>M}r6vZ325=9{#VRQkFmS7^bu+0~?7dj1l)Q4dg$%yA{-m^^@TO%L0|yjk!6iw?ZMX8H3p<>)jsf@0FDvPyQwd@l6CE2ynz|3ZctD7KKz8yYyKmGSXB>PG*fsa$GRL8& ze*`=MJl)t=rccfFdf*tiIX8NZJ~iV{fZqkaeC}?IJ~h`n3qAvke{svFPfhmvMeq{v=gfY4Uetr|S%`hW*iX+M zV?6av_$BaOVC3XePtd2{0Dl~O5LmqU^~dz7?LL4ffaYj@nm#r2e--Qj-))~ePM>-; z{21H;2A78_^r@NuDex@t`hn$P`qabl&x7ZI^KW~1=u>ZnzW}}pEWNnwFoJQCb_O3f-+N3IUiVvuGQ}O(!a%NPb ziyJS>^@{QIloP5@C)2C=?l*Mgm~=W&m<3PS&qG==%D+dAAj2?mRuBA!8_Q zay-B7slXGcn;F?wu5j~A-9XExI~u}pBb83+q;}_ZG!{y`0 z+W0BX0(m;Ij1=;;|0Ourx=fM!v||Fj@}I-}We|I^u2O#{uYun9`AOM#TT3h!Cc(NX z>cXTlWnDxqZGD5P#6Do|?lJ{dfnp3*lsOH>-BZmXV~q3v4YoVi3S_&N2MRk@iA=ME z8TR~QvVX5Xi<>f4PU?q>^}+RJxGF`6eeb3iDrqnx63aicwiut6D=x`@KV#nf`#no< m$62v_?u*U7*lEVwr|ToM``%r*i4~5wrIS$hl0*>lVCX+*E3Ik( diff --git a/schemas/org.gnome.shell.extensions.vitals.gschema.xml b/schemas/org.gnome.shell.extensions.vitals.gschema.xml index fef102d..baf5e27 100644 --- a/schemas/org.gnome.shell.extensions.vitals.gschema.xml +++ b/schemas/org.gnome.shell.extensions.vitals.gschema.xml @@ -94,6 +94,11 @@ Network speed format Should speed display in bits or bytes? + + 0 + Fixed network speed unit + Fix the network speed unit instead of auto-scaling. 0=Auto, 1=Kbps/KiB/s, 2=Mbps/MiB/s + "/" Storage path diff --git a/values.js b/values.js index 110d0fd..19d6678 100644 --- a/values.js +++ b/values.js @@ -141,11 +141,23 @@ export const Values = GObject.registerClass({ break; case 'speed': + let fixed_unit = this._settings.get_int('network-speed-unit'); + if (value > 0) { if (use_bps) value *= 8; - exp = Math.floor(Math.log(value) / Math.log(unit)); - if (value >= Math.pow(unit, exp) * (unit - 0.05)) exp++; - value = parseFloat((value / Math.pow(unit, exp))); + + if (fixed_unit > 0) { + // fixed unit: force to K (exp=1) or M (exp=2) + exp = fixed_unit; + value = parseFloat((value / Math.pow(unit, exp))); + } else { + // auto: current behavior + exp = Math.floor(Math.log(value) / Math.log(unit)); + if (value >= Math.pow(unit, exp) * (unit - 0.05)) exp++; + value = parseFloat((value / Math.pow(unit, exp))); + } + } else { + exp = 0; } format = (use_higher_precision)?'%.1f %s':'%.0f %s';