modified: src/color.c
This commit is contained in:
parent
24bd7e705c
commit
5077643bf8
105
src/color.c
105
src/color.c
@ -1,15 +1,27 @@
|
|||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
//TODO: fix your ugly ass vim colors, I don't care if it's part of the code
|
#define PROMPT_BUFSIZE 32
|
||||||
|
|
||||||
|
#define X_ENTER_KEY 36
|
||||||
|
|
||||||
|
#define X_Q_KEY 24
|
||||||
|
#define X_W_KEY 25
|
||||||
|
#define X_E_KEY 26
|
||||||
|
|
||||||
|
#define X_A_KEY 38
|
||||||
|
#define X_S_KEY 39
|
||||||
|
#define X_D_KEY 40
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
char text_prompt_buffer[32] = "testing"; //TODO: everything
|
char text_prompt_buffer[PROMPT_BUFSIZE] = "";
|
||||||
|
|
||||||
Display *display;
|
Display *display;
|
||||||
Window window;
|
Window window;
|
||||||
@ -18,10 +30,22 @@ int main(void) {
|
|||||||
int screen;
|
int screen;
|
||||||
|
|
||||||
XColor background_color;
|
XColor background_color;
|
||||||
|
XColor foreground_color;
|
||||||
XTextItem text_prompt;
|
XTextItem text_prompt;
|
||||||
XGCValues text_prompt_formatting;
|
XGCValues text_prompt_formatting;
|
||||||
GC text_prompt_gc;
|
GC text_prompt_gc;
|
||||||
|
|
||||||
|
int text_buffer_space;
|
||||||
|
|
||||||
|
int is_prompt = 0;
|
||||||
|
|
||||||
|
unsigned int winsize_x;
|
||||||
|
unsigned int winsize_y;
|
||||||
|
|
||||||
|
XFontStruct* font;
|
||||||
|
|
||||||
|
XWindowAttributes win_info;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -32,13 +56,21 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
screen = DefaultScreen(display);
|
screen = DefaultScreen(display);
|
||||||
colormap = DefaultColormap(display, screen);
|
|
||||||
|
|
||||||
background_color.red = 0;
|
//background colormap
|
||||||
background_color.green = 65535;
|
colormap = DefaultColormap(display, screen);
|
||||||
background_color.blue = 0;
|
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;
|
||||||
|
|
||||||
XAllocColor(display, colormap, &background_color);
|
XAllocColor(display, colormap, &background_color);
|
||||||
|
XAllocColor(display, colormap, &foreground_color);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window = XCreateSimpleWindow(display, RootWindow(display, screen),
|
window = XCreateSimpleWindow(display, RootWindow(display, screen),
|
||||||
@ -59,23 +91,72 @@ int main(void) {
|
|||||||
text_prompt.font = None;
|
text_prompt.font = None;
|
||||||
|
|
||||||
//text formatting struct
|
//text formatting struct
|
||||||
text_prompt_formatting.foreground = BlackPixel(display, screen);
|
text_prompt_formatting.foreground = foreground_color.pixel;
|
||||||
text_prompt_gc = XCreateGC(display, window, GCForeground | GCBackground, &text_prompt_formatting);
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
XNextEvent(display, &event);
|
XNextEvent(display, &event);
|
||||||
|
XGetWindowAttributes(display, window, &win_info);
|
||||||
|
winsize_x = win_info.width;
|
||||||
|
winsize_y = win_info.height;
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
printf("Key press\n");
|
printf("%i\n", event.xkey.keycode);
|
||||||
|
if(is_prompt) {
|
||||||
|
XClearWindow(display, window);
|
||||||
|
|
||||||
|
text_buffer_space = PROMPT_BUFSIZE - text_prompt.nchars;
|
||||||
|
|
||||||
|
if(event.xkey.keycode == X_ENTER_KEY) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch(event.xkey.keycode) {
|
||||||
|
case X_ENTER_KEY:
|
||||||
|
break;
|
||||||
|
case X_Q_KEY:
|
||||||
|
printf("%i\n", background_color.red);
|
||||||
|
XFreeColors(display, colormap, &background_color.pixel, 1, NULL);
|
||||||
|
background_color.red += 1000;
|
||||||
|
printf("%i\n", background_color.red);
|
||||||
|
XAllocColor(display, colormap, &background_color);
|
||||||
|
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, 10, winsize_y - 10, &text_prompt, 1);
|
||||||
break;
|
break;
|
||||||
case Expose:
|
case Expose:
|
||||||
XDrawText(display, window, text_prompt_gc, 10, 10, &text_prompt, 1); //TODO learn inverting math, move to bottom right of window
|
XDrawText(display, window, text_prompt_gc, 10, winsize_y - 10, &text_prompt, 1);
|
||||||
|
printf("exposed\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("wot\n");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user