Skip to content

Instantly share code, notes, and snippets.

@bFraley
Last active November 1, 2015 01:41
Show Gist options
  • Save bFraley/11f60f20c42211bbdf70 to your computer and use it in GitHub Desktop.
Save bFraley/11f60f20c42211bbdf70 to your computer and use it in GitHub Desktop.

Revisions

  1. bFraley revised this gist Aug 11, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion X11_testAPI.c
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ int main()
    redraw();
    }

    XSetForeground(display, gc, 100); // 100 is a color
    XSetForeground(display, gc, 100); // 100 is a color
    XFillRectangle(display, win, gc, 30, 30, 200, 200);
    }
    } /* END MAIN */
  2. bFraley revised this gist Aug 11, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions X11_testAPI.c
    Original file line number Diff line number Diff line change
    @@ -44,8 +44,8 @@ int main()
    /* The window was exposed, redraw it */
    redraw();
    }

    XSetForeground(display, gc, 100); // 100 is a color
    XSetForeground(display, gc, 100); // 100 is a color
    XFillRectangle(display, win, gc, 30, 30, 200, 200);
    }
    } /* END MAIN */
  3. bFraley revised this gist Aug 11, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions X11_testAPI.c
    Original file line number Diff line number Diff line change
    @@ -30,10 +30,10 @@ int main()
    window_init();

    // Basic setup for events and keypress keys
    XEvent event; /* XEvent declaration. */
    XEvent event; /* XEvent declaration. */
    KeySym key; /* KeyPress event key */
    char text[255]; /* Buffer for KeyPress events */
    _Bool run = 1;
    _Bool run = 1;

    while(run)
    {
    @@ -74,7 +74,7 @@ void window_init()

    // NOTE: At minimum, we have to select the ExposureMask in order for draw
    // functions to produce output (draw) to the window.
    XSelectInput(display, win, ExposureMask|ButtonPressMask|KeyPressMask);
    XSelectInput(display, win, ExposureMask|ButtonPressMask|KeyPressMask);

    gc=XCreateGC(display, win, 0, 0);

  4. bFraley revised this gist Aug 11, 2015. 1 changed file with 15 additions and 16 deletions.
    31 changes: 15 additions & 16 deletions X11_testAPI.c
    Original file line number Diff line number Diff line change
    @@ -27,26 +27,26 @@ Main
    */
    int main()
    {
    window_init();
    window_init();

    // Basic setup for events and keypress keys
    XEvent event; /* XEvent declaration. */
    KeySym key; /* KeyPress event key */
    char text[255]; /* Buffer for KeyPress events */
    _Bool run = 1;
    _Bool run = 1;

    while(run)
    while(run)
    {
    XNextEvent(display, &event);

    if (event.type==Expose && event.xexpose.count==0)
    {
    /* The window was exposed, redraw it */
    redraw();
    }
    }

    XSetForeground(display, gc, 100); // 100 is a color
    XFillRectangle(display, win, gc, 30, 30, 200, 200);
    XSetForeground(display, gc, 100); // 100 is a color
    XFillRectangle(display, win, gc, 30, 30, 200, 200);
    }
    } /* END MAIN */

    @@ -57,34 +57,34 @@ Function definitions.
    /* window_init creates and manages a window and it's structures.*/
    void window_init()
    {
    unsigned long black, white;
    unsigned long black, white;

    display=XOpenDisplay((char *)0);

    screen=DefaultScreen(display);

    black=BlackPixel(display, screen),
    black=BlackPixel(display, screen),

    white=WhitePixel(display, screen);
    white=WhitePixel(display, screen);

    win=XCreateSimpleWindow(display,DefaultRootWindow(display),
    50, 50, 500, 500, 5, black, white);
    50, 50, 500, 500, 5, black, white);

    XSetStandardProperties(display, win, "zeta","zeta", None, NULL, 0, NULL);
    XSetStandardProperties(display, win, "zeta","zeta", None, NULL, 0, NULL);

    // NOTE: At minimum, we have to select the ExposureMask in order for draw
    // functions to produce output (draw) to the window.
    XSelectInput(display, win, ExposureMask|ButtonPressMask|KeyPressMask);

    gc=XCreateGC(display, win, 0, 0);

    XSetBackground(display, gc, white);
    XSetBackground(display, gc, white);

    XSetForeground(display, gc, black);
    XSetForeground(display, gc, black);

    XClearWindow(display, win);
    XClearWindow(display, win);

    XMapRaised(display, win);
    XMapRaised(display, win);
    };

    void close_window()
    @@ -94,7 +94,6 @@ void close_window()
    XDestroyWindow(display, win);

    XCloseDisplay(display);

    };

    void redraw()
  5. bFraley created this gist Aug 11, 2015.
    103 changes: 103 additions & 0 deletions X11_testAPI.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,103 @@
    /*
    This should compile using:
    gcc X11_testAPI.c-o X11_test -I /usr/include/X11 -L /usr/X11/lib -lX11
    */

    // X11 header files.
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    #include <X11/Xos.h>

    // Declare X11 globals
    Display *display; /* X11 display type */
    int screen; /* X11 - client screen */
    Window win; /* X11 Window type */
    GC gc; /* X11 GC (graphic context) type */

    /**
    Function declarations.
    */
    void window_init();
    void close_window();
    void redraw();

    /**
    Main
    */
    int main()
    {
    window_init();

    // Basic setup for events and keypress keys
    XEvent event; /* XEvent declaration. */
    KeySym key; /* KeyPress event key */
    char text[255]; /* Buffer for KeyPress events */
    _Bool run = 1;

    while(run)
    {
    XNextEvent(display, &event);

    if (event.type==Expose && event.xexpose.count==0)
    {
    /* The window was exposed, redraw it */
    redraw();
    }

    XSetForeground(display, gc, 100); // 100 is a color
    XFillRectangle(display, win, gc, 30, 30, 200, 200);
    }
    } /* END MAIN */

    /**
    Function definitions.
    */

    /* window_init creates and manages a window and it's structures.*/
    void window_init()
    {
    unsigned long black, white;

    display=XOpenDisplay((char *)0);

    screen=DefaultScreen(display);

    black=BlackPixel(display, screen),

    white=WhitePixel(display, screen);

    win=XCreateSimpleWindow(display,DefaultRootWindow(display),
    50, 50, 500, 500, 5, black, white);

    XSetStandardProperties(display, win, "zeta","zeta", None, NULL, 0, NULL);

    // NOTE: At minimum, we have to select the ExposureMask in order for draw
    // functions to produce output (draw) to the window.
    XSelectInput(display, win, ExposureMask|ButtonPressMask|KeyPressMask);

    gc=XCreateGC(display, win, 0, 0);

    XSetBackground(display, gc, white);

    XSetForeground(display, gc, black);

    XClearWindow(display, win);

    XMapRaised(display, win);
    };

    void close_window()
    {
    XFreeGC(display, gc);

    XDestroyWindow(display, win);

    XCloseDisplay(display);

    };

    void redraw()
    {
    XClearWindow(display, win);
    };