summaryrefslogtreecommitdiff
path: root/src/user/include
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-03-11 22:00:22 -0500
committerBenji Dial <benji6283@gmail.com>2021-03-11 22:00:22 -0500
commit5fcf57739e68a8b5053e03778aaee0eed445babd (patch)
treee7a8bab18668d112e58b1b48190195035c71fa8a /src/user/include
parent0f2398d1f622cce37925f52d978d92e6cce1c7a9 (diff)
downloadportland-os-5fcf57739e68a8b5053e03778aaee0eed445babd.tar.gz
settings editor, and lots of changes in service of that
Diffstat (limited to 'src/user/include')
-rw-r--r--src/user/include/cxx/raleigh/d/dialog.h37
-rw-r--r--src/user/include/cxx/raleigh/d/saving_window.h20
-rw-r--r--src/user/include/cxx/raleigh/runtime.h1
-rw-r--r--src/user/include/cxx/raleigh/w/button.h9
-rw-r--r--src/user/include/cxx/raleigh/w/colorpicker.h1
-rw-r--r--src/user/include/cxx/raleigh/w/entry.h7
-rw-r--r--src/user/include/cxx/raleigh/w/multicontainer.h3
-rw-r--r--src/user/include/cxx/raleigh/w/vbox.h2
-rw-r--r--src/user/include/cxx/raleigh/window.h23
-rw-r--r--src/user/include/cxx/structs/alist.h41
-rw-r--r--src/user/include/cxx/structs/dllist.h38
-rw-r--r--src/user/include/cxx/structs/map.h39
-rw-r--r--src/user/include/knob/file.h9
-rw-r--r--src/user/include/pland/pcrt.h4
-rw-r--r--src/user/include/popups/info.h22
-rw-r--r--src/user/include/popups/popup.h22
16 files changed, 217 insertions, 61 deletions
diff --git a/src/user/include/cxx/raleigh/d/dialog.h b/src/user/include/cxx/raleigh/d/dialog.h
new file mode 100644
index 0000000..f207033
--- /dev/null
+++ b/src/user/include/cxx/raleigh/d/dialog.h
@@ -0,0 +1,37 @@
+#ifndef RALEIGH_D_DIALOG_H
+#define RALEIGH_D_DIALOG_H
+
+#include <raleigh/w/vbox.h>
+#include <raleigh/window.h>
+#include <structs/alist.h>
+#include <structs/duple.h>
+#include <stdint.h>
+
+namespace raleigh {
+ typedef uint32_t diag_result_t;
+ enum : diag_result_t {
+ NONE = 0,
+ YES,
+ NO,
+ CANCEL,
+ RETRY
+ };
+ extern alist<duple<const char *, diag_result_t>> &yes_no_cancel;
+ extern alist<duple<const char *, diag_result_t>> &yes_no_retry;
+ class dialog : public window {
+ public:
+ //button names are copied
+ //alist isn't needed past constructor
+ dialog(widget &top_part, alist<duple<const char *, diag_result_t>> buttons);
+
+ //zero means not set yet
+ diag_result_t result;
+
+ void show_modal();
+
+ private:
+ vbox *main_box;
+ };
+}
+
+#endif \ No newline at end of file
diff --git a/src/user/include/cxx/raleigh/d/saving_window.h b/src/user/include/cxx/raleigh/d/saving_window.h
new file mode 100644
index 0000000..84b6f69
--- /dev/null
+++ b/src/user/include/cxx/raleigh/d/saving_window.h
@@ -0,0 +1,20 @@
+#ifndef RALEIGH_D_SAVING_WINDOW_H
+#define RALEIGH_D_SAVING_WINDOW_H
+
+#include <raleigh/w/vbox.h>
+#include <raleigh/window.h>
+
+namespace raleigh {
+ typedef void *save_tag_t;
+ class saving_window : public window {
+ public:
+ //save_func returns true if saving was successful
+ saving_window(bool (*save_func)(save_tag_t), save_tag_t save_tag, widget &root, _pixel_t bg_color=RGB(bf, bf, bf));
+ bool is_saved;
+
+ bool (*save_func)(save_tag_t);
+ save_tag_t save_tag;
+ };
+};
+
+#endif \ No newline at end of file
diff --git a/src/user/include/cxx/raleigh/runtime.h b/src/user/include/cxx/raleigh/runtime.h
index 92bd230..4342beb 100644
--- a/src/user/include/cxx/raleigh/runtime.h
+++ b/src/user/include/cxx/raleigh/runtime.h
@@ -7,6 +7,7 @@
namespace raleigh {
void start_runtime() __attribute__ ((noreturn));
extern dllist<window &> open_windows;
+ extern dllist<window &> to_be_deleted;
}
#endif \ No newline at end of file
diff --git a/src/user/include/cxx/raleigh/w/button.h b/src/user/include/cxx/raleigh/w/button.h
index 71ccae2..c56a6e3 100644
--- a/src/user/include/cxx/raleigh/w/button.h
+++ b/src/user/include/cxx/raleigh/w/button.h
@@ -4,10 +4,12 @@
#include <raleigh/widget.h>
namespace raleigh {
+ typedef void *button_tag_t;
class button : public widget {
public:
- button(widget &inner, void (*on_click)(button &), _pixel_t border_color=RGB(00, 00, 00),
- _pixel_t bg_color=RGB(bf, bf, bf), _pixel_t pressed_color=RGB(9f, 9f, 9f));
+ button(widget &inner, void (*on_click)(button_tag_t), button_tag_t tag=0,
+ _pixel_t border_color=RGB(00, 00, 00), _pixel_t bg_color=RGB(bf, bf, bf),
+ _pixel_t pressed_color=RGB(9f, 9f, 9f));
void notify_window_change() override;
void paint(_pixel_t *pixbuf, uint32_t pitch) override;
@@ -16,7 +18,8 @@ namespace raleigh {
void notify_has_opaque_parent(widget *parent) override;
private:
widget &inner;
- void (*on_click)(button &);
+ void (*on_click)(button_tag_t);
+ button_tag_t tag;
_pixel_t border_color;
_pixel_t bg_color;
_pixel_t pressed_color;
diff --git a/src/user/include/cxx/raleigh/w/colorpicker.h b/src/user/include/cxx/raleigh/w/colorpicker.h
index 471787d..f791b2a 100644
--- a/src/user/include/cxx/raleigh/w/colorpicker.h
+++ b/src/user/include/cxx/raleigh/w/colorpicker.h
@@ -8,6 +8,7 @@ namespace raleigh {
public:
colorpicker(_pixel_t default_color=RGB(20, 70, 30), uint8_t resolution=4);
_pixel_t get_picked_color() __attribute__ ((pure));
+ void set_picked_color(_pixel_t c);
void paint(_pixel_t *pixbuf, uint32_t pitch) override;
void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override;
diff --git a/src/user/include/cxx/raleigh/w/entry.h b/src/user/include/cxx/raleigh/w/entry.h
index 001cae2..c86b281 100644
--- a/src/user/include/cxx/raleigh/w/entry.h
+++ b/src/user/include/cxx/raleigh/w/entry.h
@@ -8,10 +8,15 @@ namespace raleigh {
class entry : public widget {
public:
//default_text's data is copied, so it's okay if it changes or if the memory is freed
- entry(uint32_t rows, uint32_t cols, const char *default_text="",
+ entry(uint32_t rows=25, uint32_t cols=25, const char *default_text="",
const char *font="fixed-10", _pixel_t bg=RGB(ff, ff, ff),
_pixel_t fg=RGB(00, 00, 00), _pixel_t border_color=RGB(00, 00, 00));
+ //not a copy
+ const char *get_contents();
+ //s's data is copied
+ void set_contents(const char *s);
+
void notify_window_change() override;
void paint(_pixel_t *pixbuf, uint32_t pitch) override;
void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override;
diff --git a/src/user/include/cxx/raleigh/w/multicontainer.h b/src/user/include/cxx/raleigh/w/multicontainer.h
index 8a3497f..729f6a1 100644
--- a/src/user/include/cxx/raleigh/w/multicontainer.h
+++ b/src/user/include/cxx/raleigh/w/multicontainer.h
@@ -7,6 +7,9 @@
namespace raleigh {
class multicontainer : public widget {
public:
+ void add_end(widget &w);
+ void add_start(widget &w);
+
void notify_window_change() override;
void paint(_pixel_t *pixbuf, uint32_t pitch) override;
void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override;
diff --git a/src/user/include/cxx/raleigh/w/vbox.h b/src/user/include/cxx/raleigh/w/vbox.h
index d51e61d..6bace59 100644
--- a/src/user/include/cxx/raleigh/w/vbox.h
+++ b/src/user/include/cxx/raleigh/w/vbox.h
@@ -7,7 +7,7 @@ namespace raleigh {
class vbox : public multicontainer {
public:
//do not modify this list afterward
- vbox(dllist<widget &> widgets);
+ vbox(dllist<widget &> widgets=dllist<widget &>());
private:
coord determine_size() override;
diff --git a/src/user/include/cxx/raleigh/window.h b/src/user/include/cxx/raleigh/window.h
index 2b759d5..3448536 100644
--- a/src/user/include/cxx/raleigh/window.h
+++ b/src/user/include/cxx/raleigh/window.h
@@ -1,45 +1,50 @@
#ifndef RALEIGH_WINDOW_H
#define RALEIGH_WINDOW_H
+#include <stdint.h>
+
namespace raleigh {
class window;
}
#include <raleigh/runtime.h>
#include <raleigh/widget.h>
-#include <structs/dllist.h>
-#include <structs/duple.h>
#include <pland/syscall.h>
#include <raleigh/util.h>
+#include <structs/map.h>
+#include <knob/key.h>
namespace raleigh {
+ typedef void *window_tag_t;
class window {
friend void start_runtime();
public:
//pass on_close to specify a close handler. if on_close returns false, the window will not be closed.
- window(widget &root, _pixel_t bg_color=RGB(bf, bf, bf), bool (*on_close)(window &)=0);
- void add_keybind(struct key_packet kp, void (*handler)(window &));
+ window(widget &root, _pixel_t bg_color=RGB(bf, bf, bf), bool (*on_close)(window_tag_t)=0, window_tag_t tag=0);
+ void add_keybind(struct key_packet kp, void (*handler)(window_tag_t));
void notify_needs_paint(widget &from);
void notify_widget_size_change(widget &from, coord old_size);
void notify_wants_movements(widget &from, enum mouse_packet::mouse_button while_down);
- enum try_actions_return_t {NONE, GOOD, DELETE};
- try_actions_return_t try_actions();
+ void consume_actions();
void show();
void focus(widget &w);
+
+ protected:
+ widget &root;
private:
_window_handle_t handle;
_pixel_t *pixbuf;
coord size;
- widget &root;
widget *focussed;
widget *drag_reciever;
enum mouse_packet::mouse_button drag_until;
_pixel_t bg_color;
bool needs_repaint;
void paint_full();
- bool (*on_close)(window &);
- dllist<duple<struct key_packet, void (*)(window &)>> keybinds;
+ bool (*on_close)(window_tag_t);
+ window_tag_t tag;
+ map<struct key_packet, void (*)(window_tag_t), &match_side_agnostic> keybinds;
};
}
diff --git a/src/user/include/cxx/structs/alist.h b/src/user/include/cxx/structs/alist.h
new file mode 100644
index 0000000..050f775
--- /dev/null
+++ b/src/user/include/cxx/structs/alist.h
@@ -0,0 +1,41 @@
+#ifndef STRUCTS_ALIST_H
+#define STRUCTS_ALIST_H
+
+#include <knob/format.h>
+#include <knob/block.h>
+#include <knob/panic.h>
+#include <knob/heap.h>
+#include <stdint.h>
+
+template<class data>
+class alist {
+public:
+ uint32_t n_entries;
+ uint32_t buf_size;
+ uint32_t expand_by;
+ data *buf;
+
+ alist(uint32_t default_size=10, uint32_t expand_by=10)
+ : n_entries(0), buf_size(default_size), expand_by(expand_by),
+ buf((data *)get_block(default_size * sizeof(data))) {}
+
+ void add_back(data d) {
+ if (n_entries == buf_size) {
+ data *const new_buf = (data *)get_block((buf_size += expand_by) * sizeof(data));
+ blockcpy(new_buf, buf, n_entries * sizeof(data));
+ free_block(buf);
+ buf = new_buf;
+ }
+ buf[n_entries++] = d;
+ }
+
+ //returns -1 if not found
+ uint32_t index_of(data d) {
+ for (uint32_t i = 0; i < n_entries; ++i)
+ if (buf[i] == d)
+ return i;
+ return -1;
+ }
+};
+
+#endif \ No newline at end of file
diff --git a/src/user/include/cxx/structs/dllist.h b/src/user/include/cxx/structs/dllist.h
index 5783364..91b0369 100644
--- a/src/user/include/cxx/structs/dllist.h
+++ b/src/user/include/cxx/structs/dllist.h
@@ -1,6 +1,8 @@
#ifndef STRUCTS_DLLIST_H
#define STRUCTS_DLLIST_H
+#include <stdint.h>
+
template<class data>
class dllist {
public:
@@ -13,20 +15,34 @@ public:
: next(next), prev(prev), d(d) {}
};
node *first;
+ node *last;
- dllist() : first(0) {}
+ dllist() : first(0), last(0) {}
void add_front(data d) {
node *const n = new node(first, 0, d);
if (first)
first->prev = n;
first = n;
+ if (!last)
+ last = n;
+ }
+
+ void add_back(data d) {
+ node *const n = new node(0, last, d);
+ if (last)
+ last->next = n;
+ last = n;
+ if (!first)
+ first = n;
}
//return previous, or zero if this is the first
node *remove_in_place(node *n) {
if (n == first)
first = n->next;
+ if (n == last)
+ last = n->prev;
if (n->next)
n->next->prev = n->prev;
if (n->prev)
@@ -34,6 +50,26 @@ public:
delete n;
return n->prev;
}
+
+ bool try_remove_by_ref(data d) {
+ for (node *n = first; n; n = n->next)
+ if (&n->d == &d) {
+ remove_in_place(n);
+ return true;
+ }
+ return false;
+ }
+
+ //returns -1 if it isn't found
+ uint32_t index_of(data d) {
+ uint32_t i = 0;
+ for (const node *n = first; n; n = n->next)
+ if (d == n->d)
+ return i;
+ else
+ ++i;
+ return -1;
+ }
};
#endif \ No newline at end of file
diff --git a/src/user/include/cxx/structs/map.h b/src/user/include/cxx/structs/map.h
new file mode 100644
index 0000000..f9c477f
--- /dev/null
+++ b/src/user/include/cxx/structs/map.h
@@ -0,0 +1,39 @@
+#ifndef STRUCTS_MAP_H
+#define STRUCTS_MAP_H
+
+#include <structs/alist.h>
+
+template<class type>
+bool default_equals(type a, type b) {
+ return a == b;
+}
+
+template<class key, class value, bool (*equals)(key, key) = &default_equals<key>>
+class map {
+public:
+ alist<key> keys;
+ alist<value> values;
+
+ map(uint32_t default_size=10, uint32_t expand_by=10)
+ : keys(default_size, expand_by), values(default_size, expand_by) {}
+
+ void add_pair(key k, value v) {
+ for (key *i = keys.buf; i < keys.buf + keys.n_entries; ++i)
+ if (equals(k, *i)) {
+ values.buf[i - keys.buf] = v;
+ return;
+ }
+ keys.add_back(k);
+ values.add_back(v);
+ }
+
+ __attribute__ ((pure))
+ value transform(key k, value fallback=value()) {
+ for (key *i = keys.buf; i < keys.buf + keys.n_entries; ++i)
+ if (equals(k, *i))
+ return values.buf[i - keys.buf];
+ return fallback;
+ }
+};
+
+#endif \ No newline at end of file
diff --git a/src/user/include/knob/file.h b/src/user/include/knob/file.h
index d283288..04fc201 100644
--- a/src/user/include/knob/file.h
+++ b/src/user/include/knob/file.h
@@ -1,6 +1,10 @@
#ifndef KNOB_FILE_H
#define KNOB_FILE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdint.h>
#include <pland/syscall.h>
@@ -18,10 +22,15 @@ uint32_t read_line_from_file(struct file *f, char *sz, uint32_t max_length);
uint32_t seek_file_to(struct file *f, uint32_t to);
int32_t seek_file_by(struct file *f, int32_t by);
+uint32_t get_file_pos(struct file *f) __attribute__ ((pure));
uint32_t file_size(struct file *f) __attribute__ ((pure));
void trunc_file(struct file *f);
//return value must be manually freed, unless it is a null pointer
_dir_info_entry_t *get_directory_info(const char *path, uint32_t *count_out);
+#ifdef __cplusplus
+}
+#endif
+
#endif \ No newline at end of file
diff --git a/src/user/include/pland/pcrt.h b/src/user/include/pland/pcrt.h
index 6581cbe..4888494 100644
--- a/src/user/include/pland/pcrt.h
+++ b/src/user/include/pland/pcrt.h
@@ -9,12 +9,12 @@ extern "C" {
#define BEFORE_MAIN(f) \
__attribute__ ((section (".__pcrt_before_main"))) \
- __attribute__ ((unused)) \
+ __attribute__ ((used)) \
void (*const __pcrt_bm_##f)() = &f;
#define BEFORE_QUIT(f) \
__attribute__ ((section (".__pcrt_before_quit"))) \
- __attribute__ ((unused)) \
+ __attribute__ ((used)) \
void (*const __pcrt_bq_##f)() = &f;
void __pcrt_quit() __attribute__ ((noreturn));
diff --git a/src/user/include/popups/info.h b/src/user/include/popups/info.h
deleted file mode 100644
index de6be57..0000000
--- a/src/user/include/popups/info.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef POPUPS_INFO_H
-#define POPUPS_INFO_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <popups/popup.h>
-
-#include <pland/syscall.h>
-
-#include <stdarg.h>
-
-void info_popup(struct popup *into, const char *text, _pixel_t fg, _pixel_t bg);
-void info_popupf(struct popup *into, const char *text, _pixel_t fg, _pixel_t bg, ...);
-void info_popupf_v(struct popup *into, const char *text, _pixel_t fg, _pixel_t bg, va_list args);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif \ No newline at end of file
diff --git a/src/user/include/popups/popup.h b/src/user/include/popups/popup.h
deleted file mode 100644
index cf4315b..0000000
--- a/src/user/include/popups/popup.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef POPUPS_POPUP_H
-#define POPUPS_POPUP_H
-
-#include <pland/syscall.h>
-
-struct popup {
- _window_handle_t handle;
- _pixel_t *pixbuf;
-
- bool has_quit;
- struct key_packet quit_as;
-
- //terminated by one with .key_id == 0
- const struct key_packet *quit_binds;
-};
-
-void handle_actions(struct popup *p);
-//deletes popup before returning
-void make_modal(struct popup *p);
-void delete_popup(struct popup *p);
-
-#endif \ No newline at end of file