1*388550b0Srillig /* $NetBSD: panel_impl.h,v 1.3 2022/04/19 20:32:17 rillig Exp $ */ 25858a2dbSuwe 35858a2dbSuwe /* 45858a2dbSuwe * Copyright (c) 2015 Valery Ushakov 55858a2dbSuwe * All rights reserved. 65858a2dbSuwe * 75858a2dbSuwe * Redistribution and use in source and binary forms, with or without 85858a2dbSuwe * modification, are permitted provided that the following conditions 95858a2dbSuwe * are met: 105858a2dbSuwe * 1. Redistributions of source code must retain the above copyright 115858a2dbSuwe * notice, this list of conditions and the following disclaimer. 125858a2dbSuwe * 2. Redistributions in binary form must reproduce the above copyright 135858a2dbSuwe * notice, this list of conditions and the following disclaimer in the 145858a2dbSuwe * documentation and/or other materials provided with the distribution. 155858a2dbSuwe * 165858a2dbSuwe * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 175858a2dbSuwe * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 185858a2dbSuwe * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 195858a2dbSuwe * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 205858a2dbSuwe * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 215858a2dbSuwe * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 225858a2dbSuwe * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 235858a2dbSuwe * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 245858a2dbSuwe * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 255858a2dbSuwe * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265858a2dbSuwe */ 275858a2dbSuwe 285858a2dbSuwe #ifndef _PANEL_IMPL_H_ 295858a2dbSuwe #define _PANEL_IMPL_H_ 305858a2dbSuwe 315858a2dbSuwe #include "panel.h" 325858a2dbSuwe 335858a2dbSuwe #include <sys/queue.h> 345858a2dbSuwe 355858a2dbSuwe #define DECK_HEAD(head) TAILQ_HEAD(head, __panel) 365858a2dbSuwe #define DECK_ENTRY TAILQ_ENTRY(__panel) 375858a2dbSuwe 385858a2dbSuwe 395858a2dbSuwe /* 405858a2dbSuwe * Panels are just curses windows with Z-order added. 415858a2dbSuwe * See update_panels() for details. 425858a2dbSuwe */ 435858a2dbSuwe struct __panel { 445858a2dbSuwe WINDOW *win; 45f7b066afSkamil char *user; 465858a2dbSuwe DECK_ENTRY zorder; 475858a2dbSuwe }; 485858a2dbSuwe 495858a2dbSuwe 505858a2dbSuwe /* Deck of panels in Z-order from bottom to top. */ 515858a2dbSuwe DECK_HEAD(deck); 525858a2dbSuwe extern struct deck _deck __dso_hidden; 535858a2dbSuwe 545858a2dbSuwe /* Fake stdscr panel at the bottom, not user visible */ 555858a2dbSuwe extern PANEL _stdscr_panel __dso_hidden; 565858a2dbSuwe 575858a2dbSuwe 585858a2dbSuwe /* 595858a2dbSuwe * Hidden panels are not in the deck. <sys/queue.h> macros don't have 605858a2dbSuwe * a concept of an entry not on the list, so provide a kludge that 615858a2dbSuwe * digs into internals. 625858a2dbSuwe */ 635858a2dbSuwe #define TAILQ_REMOVE_NP(head, elm, field) do { \ 645858a2dbSuwe TAILQ_REMOVE((head), (elm), field); \ 655858a2dbSuwe (elm)->field.tqe_next = NULL; \ 665858a2dbSuwe (elm)->field.tqe_prev = NULL; \ 67*388550b0Srillig } while (0) 685858a2dbSuwe 695858a2dbSuwe #define TAILQ_LINKED_NP(elm, field) \ 705858a2dbSuwe (((elm)->field.tqe_prev) != NULL) 715858a2dbSuwe 725858a2dbSuwe 735858a2dbSuwe #define DECK_INSERT_TOP(p) do { \ 745858a2dbSuwe TAILQ_INSERT_TAIL(&_deck, (p), zorder); \ 75*388550b0Srillig } while (0) 765858a2dbSuwe 775858a2dbSuwe #define DECK_INSERT_BOTTOM(p) do { \ 785858a2dbSuwe TAILQ_INSERT_AFTER(&_deck, &_stdscr_panel, (p), zorder); \ 79*388550b0Srillig } while (0) 805858a2dbSuwe 815858a2dbSuwe #define DECK_REMOVE(p) do { \ 825858a2dbSuwe TAILQ_REMOVE_NP(&_deck, (p), zorder); \ 83*388550b0Srillig } while (0) 845858a2dbSuwe 855858a2dbSuwe 865858a2dbSuwe #define PANEL_ABOVE(p) (TAILQ_NEXT((p), zorder)) 875858a2dbSuwe #define PANEL_BELOW(p) (TAILQ_PREV((p), deck, zorder)) 885858a2dbSuwe #define PANEL_HIDDEN(p) (!TAILQ_LINKED_NP((p), zorder)) 895858a2dbSuwe 905858a2dbSuwe #define FOREACH_PANEL(var) TAILQ_FOREACH(var, &_deck, zorder) 915858a2dbSuwe 925858a2dbSuwe #endif /* _PANEL_IMPL_H_ */ 93