diff options
| author | philw <dscr@duck.com> | 2025-04-15 01:41:05 +0200 |
|---|---|---|
| committer | philw <dscr@duck.com> | 2025-04-15 01:41:05 +0200 |
| commit | 8146021a2ea4130cfb0d2bf846b451ec538b1bb6 (patch) | |
| tree | 3a946ef5ee4769bf4eae89b4e77858cc67b8060b /src/transient/transient.c | |
| parent | 515b7f3b4f048b29325e3e38f0f4a2ef898e8daa (diff) | |
| download | dwm-8146021a2ea4130cfb0d2bf846b451ec538b1bb6.tar.gz dwm-8146021a2ea4130cfb0d2bf846b451ec538b1bb6.zip | |
Refactor the project
Refactored core logic to improve readability and maintainability.
Documented the 'transient.c' file to provide clear explanations of its purpose and functions.
Updated the 'util.c' file with necessary comments and improvements to existing code.
Documented the 'util.h' header file to clarify function prototypes and usage.
This update should improve the overall code quality and make it easier for future development.
Signed-off-by: philw <dscr@duck.com>
Diffstat (limited to 'src/transient/transient.c')
| -rw-r--r-- | src/transient/transient.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/transient/transient.c b/src/transient/transient.c new file mode 100644 index 0000000..ed6539f --- /dev/null +++ b/src/transient/transient.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | #include <X11/Xlib.h> | ||
| 2 | #include <X11/Xutil.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | |||
| 6 | #define FLOATING_WINDOW_WIDTH 400 | ||
| 7 | #define FLOATING_WINDOW_HEIGHT 400 | ||
| 8 | #define FLOATING_WINDOW_X_POS 100 | ||
| 9 | #define FLOATING_WINDOW_Y_POS 100 | ||
| 10 | |||
| 11 | #define TRANSIENT_WINDOW_WIDTH 100 | ||
| 12 | #define TRANSIENT_WINDOW_HEIGHT 100 | ||
| 13 | #define TRANSIENT_WINDOW_X_POS 50 | ||
| 14 | #define TRANSIENT_WINDOW_Y_POS 50 | ||
| 15 | |||
| 16 | #define SLEEP_TIME 5 | ||
| 17 | |||
| 18 | #define WINDOW_BORDER_WIDTH 0 | ||
| 19 | #define WINDOW_BORDER_COLOR 0 | ||
| 20 | #define WINDOW_BACKGROUND_COLOR 0 | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @brief Function that creates and manages floating and transient window. | ||
| 24 | * | ||
| 25 | * This program opens an X display, creates a floating window with specific | ||
| 26 | * size and position, and then creates a transient (child) window after a | ||
| 27 | * specified delay. The transient window is always associated with the | ||
| 28 | * floating window, meaning it will behave as a child of the floating window. | ||
| 29 | * The program uses Xlib to interact with the X server, handle events, and | ||
| 30 | * manage window properties such as size, title, and position. | ||
| 31 | * | ||
| 32 | * The key steps are: | ||
| 33 | * 1. Create the floating window and set its size constraints. | ||
| 34 | * 2. After a delay (5 seconds), create the transient window and associate | ||
| 35 | * it with the floating window. | ||
| 36 | * 3. Display both windows on the screen. | ||
| 37 | * 4. Wait for and process X events in an infinite loop. This allows the | ||
| 38 | * windows to remain open and interact with the X server. | ||
| 39 | * | ||
| 40 | * @return int Exit status (always 0). | ||
| 41 | */ | ||
| 42 | int main(void) { | ||
| 43 | Display *display; | ||
| 44 | Window rootWindow, floatingWindow, transientWindow = None; | ||
| 45 | XSizeHints sizeHints; | ||
| 46 | XEvent event; | ||
| 47 | |||
| 48 | display = XOpenDisplay(NULL); | ||
| 49 | if (!display) | ||
| 50 | exit(1); | ||
| 51 | |||
| 52 | rootWindow = DefaultRootWindow(display); | ||
| 53 | |||
| 54 | floatingWindow = XCreateSimpleWindow( | ||
| 55 | display, rootWindow, FLOATING_WINDOW_X_POS, FLOATING_WINDOW_Y_POS, | ||
| 56 | FLOATING_WINDOW_WIDTH, FLOATING_WINDOW_HEIGHT, WINDOW_BORDER_WIDTH, | ||
| 57 | WINDOW_BORDER_COLOR, WINDOW_BACKGROUND_COLOR); | ||
| 58 | |||
| 59 | sizeHints.min_width = sizeHints.max_width = sizeHints.min_height = | ||
| 60 | sizeHints.max_height = FLOATING_WINDOW_WIDTH; | ||
| 61 | sizeHints.flags = PMinSize | PMaxSize; | ||
| 62 | XSetWMNormalHints(display, floatingWindow, &sizeHints); | ||
| 63 | XStoreName(display, floatingWindow, "floating"); | ||
| 64 | XMapWindow(display, floatingWindow); | ||
| 65 | XSelectInput(display, floatingWindow, ExposureMask); | ||
| 66 | |||
| 67 | while (1) { | ||
| 68 | XNextEvent(display, &event); | ||
| 69 | |||
| 70 | if (transientWindow == None) { | ||
| 71 | sleep(SLEEP_TIME); | ||
| 72 | |||
| 73 | transientWindow = XCreateSimpleWindow( | ||
| 74 | display, rootWindow, TRANSIENT_WINDOW_X_POS, TRANSIENT_WINDOW_Y_POS, | ||
| 75 | TRANSIENT_WINDOW_WIDTH, TRANSIENT_WINDOW_HEIGHT, WINDOW_BORDER_WIDTH, | ||
| 76 | WINDOW_BORDER_COLOR, WINDOW_BACKGROUND_COLOR); | ||
| 77 | |||
| 78 | XSetTransientForHint(display, transientWindow, floatingWindow); | ||
| 79 | XStoreName(display, transientWindow, "transient"); | ||
| 80 | XMapWindow(display, transientWindow); | ||
| 81 | XSelectInput(display, transientWindow, ExposureMask); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | XCloseDisplay(display); | ||
| 86 | exit(0); | ||
| 87 | } | ||
