3600 - Operating Systems Semester Project
Phase 3

Start with your phase2.c program.

Copy 3600/4/phase2.c to 3600/c/phase3.c

Move to the 3600/c directory for phase 3.

Our goal is two-way communication between parent and child windows. 





Please make these updates for lab-12
=====================================

0. Change message queue to pipe communication.

1. When the child is clicked for the first time, colored boxes will show.

2. When child clicks a box, parent's background will change to that color.

3. Child will send messages to parent through a pipe.

4. The parent window will listen for messages from inside a thread.





other requirements...

1. When child window is created, it will be located just under parent window.

2. When the parent window is moved,
   the child window will move to stay located under the parent window.

3. Some communication must be done with pipes.
   You may do all comunication with pipes.
   Shared memory will not be used for communication at this point.


To locate the child window under the parent window
==================================================

1. You first need to know the location and dimensions of the parent window.

Add these variables to your global struct:
------------------------------------------
    int parent_x;
    int parent_y;
    int parent_w;
    int parent_h;

Add this function to your program:
----------------------------------
    void configure_notify(XEvent *e)
    {
        //ConfigureNotify event is sent by the server if the window
        //is resized, moved, etc.
        if (e->type != ConfigureNotify)
            return;
        XConfigureEvent xce = e->xconfigure;
        //Update the values of your window dimensions.
        g.xres = xce.width;
        g.yres = xce.height;
        //Translate the position coordinates.
        //  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);
        if (this_is_the_parent) {
            g.parent_x = x;
            g.parent_y = y;
            g.parent_w = xce.width;
            g.parent_h = xce.height;
        }
    }

Add this call in your main() event loop:
----------------------------------------
    configure_notify(&e);


2. The child needs to move under the parent.

Add this at the bottom of your x11_init_xwindows() function:
------------------------------------------------------------
    if (this_is_the_child) {
        XMoveWindow(g.dpy, g.win, g.parent_x, g.parent_y + g.parent_h + 3);
    }

3. You must pass the information about the parent's location and size
   to the child.

   Pass it on the command-line.

   Pass it through the pipe.

   Code this part yourself.


Note:
Your variable names may differ from the code sample above.