In the curses library (as used in Unix-like systems, often via Python's curses module), when two or more windows overlap—especially when they are placed at the same location—what determines which content is displayed on the screen is the order of refresh calls and how the underlying ncurses layer handles overlapping windows.
Key Concepts:
1. Overlapping Windows
When two windows occupy the same screen space (i.e., same coordinates), their contents can overwrite each other depending on drawing order and refresh logic.
2. Which One Is Displayed?
The last window that was refreshed to that area will generally be the one whose contents appear on the screen. This is because:
The refresh() method copies the contents of a window to the virtual screen (also called curscr).
After all updates, curses.doupdate() (called internally by refresh) physically updates the terminal display.
So if two windows overlap and both call refresh(), the second one overwrites what the first one drew in the overlapping region.
Example (Python):
python
import curses
def main(stdscr):
# Create two windows at the same location
win1 = curses.newwin(10, 20, 0, 0)
win2 = curses.newwin(10, 20, 0, 0)
win1.addstr(0, 0, "Window 1")
win2.addstr(1, 0, "Window 2")
# Which one appears depends on refresh order
win1.refresh()
win2.refresh() # This overwrites win1 in overlapping areas
stdscr.getch()
curses.wrapper(main)
In this case, only "Window 2" will be visible because it was refreshed last.
Important Notes:
overlay() / overwrite(): If you want finer control over how windows interact, you can use win.overlay() or win.overwrite() to copy one window onto another without immediately affecting the screen. Then you can refresh() the target window afterward.
Panels Module: For more advanced management of overlapping windows with z-ordering, consider using the panel module (available in C as libpanel, and accessible in Python via third-party modules or extensions).
Summary:
The window whose refresh() is called last will determine what is displayed in overlapping regions, assuming they share the same physical screen coordinates.
Let me know if you'd like an example using panels or overlays!