#include #include #include #include #define FLOATING_WINDOW_WIDTH 400 #define FLOATING_WINDOW_HEIGHT 400 #define FLOATING_WINDOW_X_POS 100 #define FLOATING_WINDOW_Y_POS 100 #define TRANSIENT_WINDOW_WIDTH 100 #define TRANSIENT_WINDOW_HEIGHT 100 #define TRANSIENT_WINDOW_X_POS 50 #define TRANSIENT_WINDOW_Y_POS 50 #define SLEEP_TIME 5 #define WINDOW_BORDER_WIDTH 0 #define WINDOW_BORDER_COLOR 0 #define WINDOW_BACKGROUND_COLOR 0 /** * @brief Function that creates and manages floating and transient window. * * This program opens an X display, creates a floating window with specific * size and position, and then creates a transient (child) window after a * specified delay. The transient window is always associated with the * floating window, meaning it will behave as a child of the floating window. * The program uses Xlib to interact with the X server, handle events, and * manage window properties such as size, title, and position. * * The key steps are: * 1. Create the floating window and set its size constraints. * 2. After a delay (5 seconds), create the transient window and associate * it with the floating window. * 3. Display both windows on the screen. * 4. Wait for and process X events in an infinite loop. This allows the * windows to remain open and interact with the X server. * * @return int Exit status (always 0). */ int main(void) { Display *display; Window rootWindow, floatingWindow, transientWindow = None; XSizeHints sizeHints; XEvent event; display = XOpenDisplay(NULL); if (!display) exit(1); rootWindow = DefaultRootWindow(display); floatingWindow = XCreateSimpleWindow( display, rootWindow, FLOATING_WINDOW_X_POS, FLOATING_WINDOW_Y_POS, FLOATING_WINDOW_WIDTH, FLOATING_WINDOW_HEIGHT, WINDOW_BORDER_WIDTH, WINDOW_BORDER_COLOR, WINDOW_BACKGROUND_COLOR); sizeHints.min_width = sizeHints.max_width = sizeHints.min_height = sizeHints.max_height = FLOATING_WINDOW_WIDTH; sizeHints.flags = PMinSize | PMaxSize; XSetWMNormalHints(display, floatingWindow, &sizeHints); XStoreName(display, floatingWindow, "floating"); XMapWindow(display, floatingWindow); XSelectInput(display, floatingWindow, ExposureMask); while (1) { XNextEvent(display, &event); if (transientWindow == None) { sleep(SLEEP_TIME); transientWindow = XCreateSimpleWindow( display, rootWindow, TRANSIENT_WINDOW_X_POS, TRANSIENT_WINDOW_Y_POS, TRANSIENT_WINDOW_WIDTH, TRANSIENT_WINDOW_HEIGHT, WINDOW_BORDER_WIDTH, WINDOW_BORDER_COLOR, WINDOW_BACKGROUND_COLOR); XSetTransientForHint(display, transientWindow, floatingWindow); XStoreName(display, transientWindow, "transient"); XMapWindow(display, transientWindow); XSelectInput(display, transientWindow, ExposureMask); } } XCloseDisplay(display); exit(0); }