Uses 911K of libraries. Click here for Pure Java version (7967L/41K).
!7 cmodule CombinedCPUTrayIcon > DynBigNumber { transient BufferedImage trayImage; transient TrayIcon trayIcon; switchable S processColor = "ADFF2F"; // green yellow switchable S restColor = "6666FF"; switchable S backgroundColor = "000000"; switchable int size = goodSystemTrayIconSize().x; switchable double interval = 1; switchable bool postToServer; transient double systemLoad; transient int systemPercent; // these are for the process transient double loadRelativeToAllCores, recentLoad; transient RollingAverage avg = new(5); // =10 seconds start { setDescription("STEFAN'S OS/SYSTEM CPU %"); setToolTip("Percentage is per core (total: " + numberOfCores()*100 + "%)"); doEvery(interval, r actualUpdate); ownResource(tempTrayIcon(trayIcon = installTrayIcon( trayImage = newBufferedImage(size, size, colorFromHex(backgroundColor)), "Stefan's OS + System CPU (" + nCores(numberOfCores()) + ")", rThread dm_activateOSAndModule))); dm_registerAs_direct combinedCPUTrayIcon(); } void grabSystemLoad { systemLoad = systemCPULoad(); systemPercent = toIntPercent_ceil(systemLoad*numberOfCores()); if (postToServer) dm_postCPULoadToServer(systemPercent); } void actualUpdate { grabSystemLoad(); recentLoad = processCPULoad(); avg.add(recentLoad); loadRelativeToAllCores = avg!; setValue( toIntPercent_ceil(loadRelativeToAllCores*numberOfCores()) + " / " + systemPercent + " %"); int w = trayImage.getWidth(), h = trayImage.getHeight(); copyImagePart(trayImage, 1, 0, trayImage, 0, 0, w-1, h); int y1 = iround(h*(1 - loadRelativeToAllCores)); int y2 = min(y1, iround(h*(1 - systemLoad))); fillRect(trayImage, w-1, 0, 1, y2, colorFromHex(backgroundColor)); fillRect(trayImage, w-1, y2, 1, y1-y2, colorFromHex(restColor)); fillRect(trayImage, w-1, y1, 1, h-y1, colorFromHex(processColor)); setTrayIconImage(trayIcon, trayImage); vmBus_send newCombinedCPUTrayImage(module(), trayImage); } // API BufferedImage getImage() { ret trayImage; } }
Began life as a copy of #1020927
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xkfnxevppnqj, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1026796 |
Snippet name: | Combined Process+System CPU % Host Tray Icon |
Eternal ID of this version: | #1026796/13 |
Text MD5: | 4e8b140d742cd958f1b9d3cce1ad8ed7 |
Transpilation MD5: | c913c7a1451ecc37b1d92aeae833695d |
Author: | stefan |
Category: | javax / modules |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-28 01:48:57 |
Source code size: | 2194 bytes / 63 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 227 / 257919 |
Version history: | 12 change(s) |
Referenced in: | [show references] |