summaryrefslogtreecommitdiff
path: root/src/user/meminfo
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/meminfo')
-rw-r--r--src/user/meminfo/meminfo.c31
-rw-r--r--src/user/meminfo/meminfo.cpp51
2 files changed, 51 insertions, 31 deletions
diff --git a/src/user/meminfo/meminfo.c b/src/user/meminfo/meminfo.c
deleted file mode 100644
index 3c3c45b..0000000
--- a/src/user/meminfo/meminfo.c
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <popups/info.h>
-
-#include <pland/syscall.h>
-
-static const struct key_packet meminfo_quits[] = {
- { .key_id = KEY_ESCAPE, .modifiers = NO_MODS },
- { .key_id = KEY_F5, .modifiers = NO_MODS },
- { .key_id = 0 }
-};
-
-void main() {
- struct popup p;
-redo:
- info_popupf(&p,
- "kernel memory free: %uk\n"
- "userspace memory free: %uk / %uk\n"
- "Escape to quit, F5 to refresh.",
- (_pixel_t){.r = 0, .g = 0, .b = 0},
- (_pixel_t){.r = 0xbf, .g = 0xbf, .b = 0xbf},
- _kernel_dynamic_area_left() * 4,
- _total_userspace_left() * 4,
- _total_userspace_size() * 4
- );
- //hacky, i should really make info_popup take an arg
- p.quit_binds = meminfo_quits;
- make_modal(&p);
- if (p.quit_as.key_id == KEY_F5)
- //i should make popups have changable text
- //(make a new pixbuf but reuse the window)
- goto redo;
-} \ No newline at end of file
diff --git a/src/user/meminfo/meminfo.cpp b/src/user/meminfo/meminfo.cpp
new file mode 100644
index 0000000..2b035a4
--- /dev/null
+++ b/src/user/meminfo/meminfo.cpp
@@ -0,0 +1,51 @@
+#include <raleigh/w/padding.h>
+#include <raleigh/w/vbox.h>
+#include <raleigh/w/label.h>
+
+#include <raleigh/runtime.h>
+#include <raleigh/window.h>
+
+#include <pland/syscall.h>
+#include <knob/format.h>
+#include <pland/pcrt.h>
+
+using namespace raleigh;
+
+label *kmem;
+label *umem;
+
+void refresh(window &w) {
+ char *const kstr = format("kernel memory free: %uk", _kernel_dynamic_area_left() * 4);
+ char *const ustr = format("userspace memory free: %uk / %uk", _total_userspace_left() * 4, _total_userspace_size() * 4);
+
+ kmem->change_value(kstr);
+ umem->change_value(ustr);
+
+ free_block(kstr);
+ free_block(ustr);
+}
+
+void main() {
+ kmem = new label("");
+ umem = new label("");
+ label msg("press Alt+F4 to quit, or F5 to refresh");
+
+ padding pkmem(*kmem, 1);
+ padding pumem(*umem, 1);
+ padding pmsg(msg, 1);
+
+ dllist<widget &> ll;
+ ll.add_front(pmsg);
+ ll.add_front(pumem);
+ ll.add_front(pkmem);
+ vbox box(ll);
+
+ padding pbox(box, 3);
+ window w(pbox, RGB(bf, bf, bf), (bool (*)(window &))&__pcrt_quit);
+ w.add_keybind((struct key_packet){.key_id = key_packet::KEY_F5, .modifiers = key_packet::NO_MODS}, &refresh);
+
+ refresh(w);
+
+ w.show();
+ start_runtime();
+} \ No newline at end of file