#include #include #include #include #include #include #include #include "color.h" int add_color(color_info color) { } int main(void) { char text_prompt_buffer[PROMPT_BUFSIZE] = ""; Display *display; Window window; XEvent event; Colormap colormap; int screen; XColor background_color; XColor foreground_color; XTextItem text_prompt; XGCValues text_prompt_formatting; GC text_prompt_gc; int text_buffer_space; unsigned int color_step; int is_prompt = 0; unsigned int textpos_y; XFontStruct* font; XWindowAttributes win_info; if((display = XOpenDisplay(NULL)) == NULL) { printf("Couldn't open display due to fatal error: %s\n", strerror(errno)); exit(errno); } screen = DefaultScreen(display); //background colormap colormap = DefaultColormap(display, screen); background_color.red = 1000; background_color.green = 0; background_color.blue = 60000; //text colormap foreground_color.red = 0xffff - background_color.red; foreground_color.green = 0xffff - background_color.green; foreground_color.blue = 0xffff - background_color.blue; unsigned long live_pixels[2] = {foreground_color.pixel, foreground_color.pixel}; XAllocColor(display, colormap, &background_color); XAllocColor(display, colormap, &foreground_color); window = XCreateSimpleWindow(display, RootWindow(display, screen), 10, 10, 100, 100, 0, background_color.pixel, background_color.pixel); //last arg is color XMapWindow(display, window); XSelectInput(display, window, KeyPressMask | ExposureMask); XGetWindowAttributes(display, window, &win_info); color_step = 0xffff / pow(2, (win_info.depth / 3)) ; //text struct text_prompt.chars = text_prompt_buffer; text_prompt.nchars = strlen(text_prompt_buffer); text_prompt.delta = 0; //what? text_prompt.font = None; //text formatting struct text_prompt_formatting.foreground = foreground_color.pixel; text_prompt_gc = XCreateGC(display, window, GCForeground | GCLineWidth, &text_prompt_formatting); font = XLoadQueryFont(display, "-*-helvetica-medium-r-normal-*-20-*"); XSetFont(display, text_prompt_gc, font->fid); XGetWindowAttributes(display, window, &win_info); textpos_y = win_info.height - TEXT_CORNER_OFFSET; update_info display_summary = { .window = window, .display = display, .colormap = colormap, .background = background_color, .foreground = foreground_color, .channel_step = color_step }; for(;;) { XNextEvent(display, &event); switch (event.type) { case KeyPress: if(is_prompt) { XClearWindow(display, window); text_buffer_space = PROMPT_BUFSIZE - text_prompt.nchars; if(event.xkey.keycode == X_BACKSPACE) { if(text_buffer_space < PROMPT_BUFSIZE) { text_prompt.nchars--; } } else if(text_buffer_space > 0) { text_prompt.nchars += XLookupString(&event.xkey, text_prompt_buffer + text_prompt.nchars, text_buffer_space, NULL, NULL); } XDrawText(display, window, text_prompt_gc, TEXT_CORNER_OFFSET, textpos_y, &text_prompt, 1); } else { switch(event.xkey.keycode) { case X_ENTER_KEY: break; case X_Q_KEY: printf("%i\n", channel_step); XFreeColors(display, colormap, &background_color.pixel, 1, 0); XFreeColors(display, colormap, &foreground_color.pixel, 1, 0); background_color.red += channel_step; foreground_color.red = 0xffff - background_color.red; //we could just sub channel_step, but eh. i donno. printf("----%i\n", background_color.red); XAllocColor(display, colormap, &foreground_color); XAllocColor(display, colormap, &background_color); XClearWindow(display, window); XSetWindowBackground(display, window, background_color.pixel); break; case X_W_KEY: break; case X_E_KEY: break; case X_A_KEY: break; case X_S_KEY: break; case X_D_KEY: break; default: break; } } XDrawText(display, window, text_prompt_gc, TEXT_CORNER_OFFSET, textpos_y, &text_prompt, 1); break; case Expose: XGetWindowAttributes(display, window, &win_info); textpos_y = win_info.height - TEXT_CORNER_OFFSET; XDrawText(display, window, text_prompt_gc, TEXT_CORNER_OFFSET, textpos_y, &text_prompt, 1); break; default: break; } } return 0; }