CMPS-3600 - Fall 2025 - Semester ProjectPhase-4 - Show passes and collisions in a child window ------------------------------------------------------ Start with your bblab9.c program. Name your program: 3600/f/bbphase4.c You may move all project phases to Odin directory 3600/f $ cd 3600/f $ cp ../4/myxwindow.c . $ cp ../6/bbphase2.c . $ cp ../9/bbphase3.c . $ cp ../9/bblab9.c bbphase4.c Compile like this... gcc bbphase4.c -Wall -lX11 -lXext -pthreadWhat to do... 1. Press 'W' to get a child window. ----------------------------------- The child will show the statistics for each car. Show the passes for each car. Show the total number of collisions. 2. In the parent window, add a feature to pause the action. ----------------------------------------------------------- Now we can easily see the statistics. 3. If the parent window is moved, the child follows. ---------------------------------------------------- See the animation. 4. Inter process communication. ------------------------------- Use a System-V message queue to send the child the data. You may also use a pipe. recommended: Use a message queue to send car data. Use a pipe to send the parent window position when it moves. When a car passes through the intersection, send a message to the child updating that one car. Tips: Your child process should be the bbphase4.c executable, but without... - the cars - the intersection graphics - the car thread You cannot run the car thread inside your child process. Pass these things to the child on the command-line... - message-queue ID - pipe file descriptors Allow multiple child windows. See the code below for child window movement. Please allow for multiple child windows.
Code samples ------------ Update your main() function event loop -------------------------------------- // Add this to your event loop. check_resize(&e); Add this function ----------------- void check_resize(XEvent *e) { //ConfigureNotify is sent when the window is resized or moved. if (e->type != ConfigureNotify) return; XConfigureEvent xce = e->xconfigure; g.xres = xce.width; g.yres = xce.height; //The following line removed courtesy: student Michael Kausch //init(); if (child) { //store the child's position g.child_pos[0] = xce.x; g.child_pos[1] = xce.y; } if (!child) { // Translate the position coordinates. // Translating the window coordinates is documented here: // https://stackoverflow.com/questions/25391791/ // x11-configurenotify-always-returning-x-y-0-0 // Window root = DefaultRootWindow(g.dpy); Window chld; int x, y; XTranslateCoordinates(g.dpy, g.win, root, 0, 0, &x, &y, &chld); g.parent_pos[0] = x; g.parent_pos[1] = y; g.parent_dim[0] = xce.width; g.parent_dim[1] = xce.height; //parent sends its new position to the child. if (g.nchildren > 0) { // Send a message to the child here } } set_window_title(); usleep(4000); } Use this function in your child window -------------------------------------- // When the parent window moves, it will send the child a message. // The child process will call this function. void moveWindow(int x, int y) { XMoveWindow(g.dpy, g.win, x, y); }