summaryrefslogtreecommitdiff
path: root/src/color.c
blob: 872114000dccb57c3146de0205848e61acbf0107 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

//TODO: fix your ugly ass vim colors, I don't care if it's part of the code


int main(void) {

  char text_prompt_buffer[32] = "testing"; //TODO: everything

   Display *display;
   Window window;
   XEvent event;
   Colormap colormap;
   int screen;
   
   XColor background_color;
   XTextItem text_prompt;
   XGCValues text_prompt_formatting;
   GC text_prompt_gc; 




 
   if((display = XOpenDisplay(NULL)) == NULL) {
      printf("Couldn't open display due to fatal error: %s\n", strerror(errno));
      exit(errno);
   }
 
   screen = DefaultScreen(display);
   colormap = DefaultColormap(display, screen);
   
   background_color.red = 0;
   background_color.green = 65535;
   background_color.blue = 0;

   XAllocColor(display, colormap, &background_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);


   //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 = BlackPixel(display, screen);
   text_prompt_gc = XCreateGC(display, window, GCForeground | GCBackground, &text_prompt_formatting);


   for(;;) {
     XNextEvent(display, &event);
     switch (event.type) {
       case KeyPress:
         printf("Key press\n");
         break;
       case Expose:
         XDrawText(display, window, text_prompt_gc, 10, 10, &text_prompt, 1); //TODO learn inverting math, move to bottom right of window
         break;
       default:
         printf("wot\n");
         break;
     }
   }
 
 
   return 0;
}