!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; } }