Skip to content

Commit

Permalink
fix(ui): scaling issue fix + gpu monitor
Browse files Browse the repository at this point in the history
Fix #110
  • Loading branch information
ljuzig committed Apr 19, 2024
1 parent 4ba9eb1 commit ab80ca8
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 37 deletions.
7 changes: 7 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Astra Monitor 21 - April 19 2024

### Bug fixes
- Fixed visual bug for system with `scale-monitor-framebuffer` feature disabled [[#110](https://github.com/AstraExt/astra-monitor/issues/110)]

- Fixed GPU monitoring starting even when the GPU menu is disabled

# Astra Monitor 20 - April 17 2024

### Advanced GPU Monitoring
Expand Down
57 changes: 34 additions & 23 deletions src/bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export default GObject.registerClass(
}
style += params.style;

if(params.mini) params.y_align = Clutter.ActorAlign.FILL;
if(params.mini) {
params.y_align = Clutter.ActorAlign.FILL;
}

super({
style: style,
Expand Down Expand Up @@ -160,8 +162,12 @@ export default GObject.registerClass(

setStyle() {
let styleClass;
if(this.layout === 'vertical') styleClass = 'astra-monitor-bars-vertical';
else styleClass = 'astra-monitor-bars-horizontal';
if(this.layout === 'vertical') {
styleClass = 'astra-monitor-bars-vertical';
}
else {
styleClass = 'astra-monitor-bars-horizontal';
}

if(this.mini) styleClass += '-mini';

Expand All @@ -179,21 +185,23 @@ export default GObject.registerClass(
try {
// eslint-disable-next-line prefer-const
let [width, height] = this.get_size();

if(this.layout === 'vertical' && this.header) {
const parentHeight = this.get_parent()!.height;
if(height > parentHeight - 6) height = parentHeight - 6;
}

width /= this.scaleFactor;
height /= this.scaleFactor;

let size;
if(this.layout === 'vertical')
size = height - (this.mini ? 2 : 4); // Remove 2px padding and 2px border
else size = width - (this.mini ? 2 : 4); // Remove 2px padding and 2px border

if(this.layout === 'vertical') {
size = height - 4 * this.scaleFactor;
}
else {
size = width - 4 * this.scaleFactor;
}

if(!values || values.length === 0) {
for(let i = 0; i < this.bars.length; i++) {
const bar = this.bars[i];
for(let l = 0; l < bar.length; l++) bar[l].visible = false;
for(let l = 0; l < bar.length; l++) {
bar[l].visible = false;
}
}
return;
}
Expand Down Expand Up @@ -225,12 +233,17 @@ export default GObject.registerClass(
const normalizedValue = value[l].value * size;
let fillSize = zero;
if(normalizedValue >= 0.5)
fillSize = Math.ceil(normalizedValue) / this.scaleFactor;
fillSize = Math.ceil(normalizedValue);
if(isNaN(fillSize) || fillSize < zero) fillSize = zero;

if(this.layout === 'vertical')
layer.set_position(0, size - start - fillSize);
else layer.set_position(start, 0);

if(this.layout === 'vertical') {
const position = size - start - fillSize;
layer.set_position(0, position * this.scaleFactor);
}
else {
const position = start;
layer.set_position(position * this.scaleFactor, 0);
}

const color = fillSize === 0 ? 'transparent' : this.colors[value[l].color];
const style =
Expand Down Expand Up @@ -265,10 +278,8 @@ export default GObject.registerClass(
}
}

const scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;

const roundedSize = this.mini ? 3 : 4;
if(totalSize - (start + size) <= roundedSize * scaleFactor) {
const roundedSize = (this.mini ? 3 : 4) * this.scaleFactor;
if(totalSize - (start + size) <= roundedSize) {
if(this.layout === 'vertical') {
bordersHelper.topLeft = border;
bordersHelper.topRight = border;
Expand Down
24 changes: 18 additions & 6 deletions src/gpu/gpuMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ export default class GpuMonitor extends Monitor {
};
Config.connect(this, 'changed::gpu-main', updateGpu.bind(this));
updateGpu();

this.updateMonitorStatus();
}

get updateFrequency() {
Expand All @@ -375,9 +377,18 @@ export default class GpuMonitor extends Monitor {
}

updateMonitorStatus() {
const show = Config.get_boolean('gpu-header-show');
if(show || this.isListeningFor('gpuUpdate')) this.start();
else this.stop();
if(Config.get_boolean('gpu-header-show') || this.isListeningFor('gpuUpdateProcessor')) {
this.start();
}
else {
this.stop();
}
}

restart() {
if(!Config.get_boolean('gpu-header-show') && !this.isListeningFor('gpuUpdateProcessor'))
return;
super.restart();
}

reset() {
Expand All @@ -403,20 +414,22 @@ export default class GpuMonitor extends Monitor {
}

startListeningFor(key: string) {
if(key === 'gpuUpdate') {
if(key === 'gpuUpdateProcessor') {
setTimeout(() => {
this.updateMonitorStatus();
});
}
}

stopListeningFor(key: string) {
if(key === 'gpuUpdate') {
if(key === 'gpuUpdateProcessor') {
this.updateMonitorStatus();
}
}

private startGpuTask() {
Utils.log('startGpuTask!');

const selectedGpu = Utils.getSelectedGPU();
if(!selectedGpu) return;

Expand Down Expand Up @@ -446,7 +459,6 @@ export default class GpuMonitor extends Monitor {

private stopGpuTask() {
if(this.updateAmdGpuTask.isRunning) this.updateAmdGpuTask.stop();

if(this.updateNvidiaGpuTask.isRunning) this.updateNvidiaGpuTask.stop();
}

Expand Down
8 changes: 8 additions & 0 deletions src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ export default GObject.registerClass(
showTooltip() {}

hideTooltip() {}

get scaleFactor() {
const themeContext = St.ThemeContext.get_for_stage(global.get_stage());
if(themeContext.get_scale_factor) {
return themeContext.get_scale_factor();
}
return 1;
}

destroy() {
Config.clear(this);
Expand Down
5 changes: 3 additions & 2 deletions src/network/networkHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,9 @@ export default GObject.registerClass(
const calculateStyle = () => {
if(this.ioLayout === 'horizontal') return 'font-size:1em;';
const superHeight = this.speedContainer.get_parent()?.height ?? 0;
if(superHeight <= 20) return 'font-size:0.65em;';
return `font-size:${Math.round(superHeight / 3)}px;`;
const scaledHeight = superHeight / this.scaleFactor;
if(scaledHeight <= 20) return 'font-size:0.65em;';
return `font-size:${Math.round(scaledHeight / 3)}px;`;
};
const style = calculateStyle();

Expand Down
5 changes: 4 additions & 1 deletion src/processor/processorMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,10 @@ export default class ProcessorMenu extends MenuBase {

const processorGpuShow = Config.get_boolean('processor-gpu');
const gpuHeaderShow = Config.get_boolean('gpu-header-show');
if(processorGpuShow && !gpuHeaderShow)
if(processorGpuShow && !gpuHeaderShow) {
Utils.gpuMonitor.listen(this, 'gpuUpdateProcessor', () => {});
Utils.gpuMonitor.listen(this, 'gpuUpdate', this.update.bind(this, 'gpuUpdate'));
}
}

async onClose() {
Expand All @@ -840,6 +842,7 @@ export default class ProcessorMenu extends MenuBase {
Utils.processorMonitor.unlisten(this, 'loadAverage');

Utils.gpuMonitor.unlisten(this, 'gpuUpdate');
Utils.gpuMonitor.unlisten(this, 'gpuUpdateProcessor');

this.queueTopProcessesUpdate = false;

Expand Down
5 changes: 3 additions & 2 deletions src/sensors/sensorsHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ export default GObject.registerClass(
if(this.sensorsNum === 1 || this.sensorsLayout === 'horizontal')
return 'font-size:1em;';
const superHeight = this.valuesContainer.get_parent()?.height ?? 0;
if(superHeight <= 20) return 'font-size:0.65em;';
return `font-size:${Math.round(superHeight / 3)}px;`;
const scaledHeight = superHeight / this.scaleFactor;
if(scaledHeight <= 20) return 'font-size:0.65em;';
return `font-size:${Math.round(scaledHeight / 3)}px;`;
};
const style = calculateStyle();

Expand Down
2 changes: 1 addition & 1 deletion src/storage/storageBars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default GObject.registerClass(
return;
}

this.updateBars([[{ color: 0, value: usage.usePercentage / 100.0 }]]);
this.updateBars([[{ color: 0, value: 1/*usage.usePercentage / 100.0*/ }]]);
}
}
);
5 changes: 3 additions & 2 deletions src/storage/storageHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,9 @@ export default GObject.registerClass(
const calculateStyle = () => {
if(this.ioLayout === 'horizontal') return 'font-size:1em;';
const superHeight = this.speedContainer.get_parent()?.height ?? 0;
if(superHeight <= 20) return 'font-size:0.65em;';
return `font-size:${Math.round(superHeight / 3)}px;`;
const scaledHeight = superHeight / this.scaleFactor;
if(scaledHeight <= 20) return 'font-size:0.65em;';
return `font-size:${Math.round(scaledHeight / 3)}px;`;
};
const style = calculateStyle();

Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fi
export SHELL_DEBUG=all

export MUTTER_DEBUG_DUMMY_MODE_SPECS=$RESOLUTION
#export MUTTER_DEBUG_DUMMY_MONITOR_SCALES=2
export XDG_SESSION_TYPE=wayland
export XDG_CURRENT_DESKTOP=GNOME-Shell
export XDG_SESSION_DESKTOP=GNOME-Shell
Expand Down

0 comments on commit ab80ca8

Please sign in to comment.