diff options
Diffstat (limited to 'src/user/raleigh/window.cpp')
-rw-r--r-- | src/user/raleigh/window.cpp | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/user/raleigh/window.cpp b/src/user/raleigh/window.cpp index b99346d..5fa82c3 100644 --- a/src/user/raleigh/window.cpp +++ b/src/user/raleigh/window.cpp @@ -5,25 +5,26 @@ #include <knob/format.h> namespace raleigh { - window::window(widget &root, _pixel_t bg_color, bool (*on_close)(window &)) - : handle(0), size(root.size), root(root), focussed(&root), - drag_reciever(0), bg_color(bg_color), on_close(on_close) { + window::window(widget &root, _pixel_t bg_color, bool (*on_close)(window_tag_t), window_tag_t tag) + : root(root), handle(0), pixbuf(0), size(root.size), focussed(&root), + drag_reciever(0), bg_color(bg_color), on_close(on_close), tag(tag) { root.w = this; root.window_offset = coord(0, 0); root.notify_window_change(); - pixbuf = new _pixel_t[size.x * size.y]; - if (!pixbuf) - show_error_and_quitf("Failed to create %d byte pixel buffer\nfor requested %dx%d pixel window.", size.x * size.y * sizeof(_pixel_t), size.x, size.y); + if (size.x && size.y) { + pixbuf = new _pixel_t[size.x * size.y]; + if (!pixbuf) + show_error_and_quitf("Failed to create %d byte pixel buffer\nfor requested %dx%d pixel window.", size.x * size.y * sizeof(_pixel_t), size.x, size.y); + } paint_full(); root.on_focus(); needs_repaint = false; } - window::try_actions_return_t window::try_actions() { + void window::consume_actions() { struct window_action wa; - window::try_actions_return_t got = NONE; while (1) { _get_win_action(handle, &wa); if (!wa.action_type) { @@ -31,15 +32,17 @@ namespace raleigh { needs_repaint = false; _paint_window(handle); } - return got; + return; } if ((wa.action_type == wa.KEY_DOWN) && (wa.as_key.modifiers & wa.as_key.ALTS) && - (wa.as_key.key_id == wa.as_key.KEY_F4)) - if (!on_close || on_close(*this)) - return DELETE; - got = GOOD; - if (wa.action_type == wa.MOUSE_DOWN) + (wa.as_key.key_id == wa.as_key.KEY_F4)) { + if (!on_close || on_close(tag)) { + to_be_deleted.add_back(*this); + return; + } + } + else if (wa.action_type == wa.MOUSE_DOWN) root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, false); else if (wa.action_type == wa.MOUSE_UP) { if (drag_reciever && (wa.as_mouse.which == drag_until)) @@ -47,14 +50,11 @@ namespace raleigh { root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, true); } else if (wa.action_type == wa.KEY_DOWN) { - for (dllist<duple<struct key_packet, void (*)(window &)>>::node *n = keybinds.first; n; n = n->next) - if (match_side_agnostic(wa.as_key, n->d.a)) { - n->d.b(*this); - goto next_loop; - } - focussed->handle_key(wa.as_key); - next_loop: - ; + void (*const f)(window_tag_t) = keybinds.transform(wa.as_key); + if (f) + f(tag); + else + focussed->handle_key(wa.as_key); } else if (wa.action_type == wa.FOCUS_ENTER) focussed->on_focus(); @@ -103,7 +103,8 @@ namespace raleigh { from.parent->notify_child_size_change(from, old_size); else { size = root.size; - delete[] pixbuf; + if (pixbuf) + delete[] pixbuf; pixbuf = new _pixel_t[size.x * size.y]; if (!pixbuf) show_error_and_quitf("Failed to allocate %u byte buffer while\nresizing window to %ux%u pixels.", size.x * size.y, size.x, size.y); @@ -112,8 +113,8 @@ namespace raleigh { } } - void window::add_keybind(struct key_packet kp, void (*handler)(window &)) { - keybinds.add_front(duple<struct key_packet, void (*)(window &)>(kp, handler)); + void window::add_keybind(struct key_packet kp, void (*handler)(window_tag_t)) { + keybinds.add_pair(kp, handler); } void window::notify_wants_movements(widget &from, enum mouse_packet::mouse_button while_down) { |