ltkx

GUI toolkit for X11 (WIP)
git clone git://lumidify.org/ltkx.git
Log | Files | Refs | README | LICENSE

tmp.c (2346B)


      1 #include <math.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <stdint.h>
      5 #include <X11/Xlib.h>
      6 #include <X11/Xutil.h>
      7 #include <X11/Xos.h>
      8 #include <pango/pangoxft.h>
      9 
     10 int main(int argc, const char * argv[])
     11 {
     12 
     13     Display *display;
     14     int screen;
     15     Window window;
     16     GC gc;
     17 
     18     unsigned long black, white;
     19     Colormap colormap;
     20     display = XOpenDisplay((char *)0);
     21     screen = DefaultScreen(display);
     22     colormap = DefaultColormap(display, screen);
     23     black = BlackPixel(display, screen);
     24     white = WhitePixel(display, screen);
     25     window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, 1366, 512, 0, black, white);
     26     XSetStandardProperties(display, window, "Random Window", NULL, None, NULL, 0, NULL);
     27     XSelectInput(display, window, ExposureMask|ButtonPressMask|KeyPressMask);
     28     gc = XCreateGC(display, window, 0, 0);
     29     XSetBackground(display, gc, black);
     30     XSetForeground(display, gc, black);
     31     XClearWindow(display, window);
     32     XMapRaised(display, window);
     33 
     34   PangoFontMap *fontmap = pango_xft_get_font_map(display, screen);
     35   PangoContext *context = pango_font_map_create_context(fontmap);
     36   PangoLayout *layout = pango_layout_new(context);
     37   pango_layout_set_text (layout, "jhkashdfkashfaksjfla", -1);
     38   /*PangoFontDescription *desc = pango_font_description_from_string ("Sans Bold 27");
     39   pango_layout_set_font_description (layout, desc);
     40   pango_font_description_free (desc);*/
     41 
     42   XftDraw *draw = XftDrawCreate(display, window, DefaultVisual(display, screen), DefaultColormap(display, screen));
     43   XftColor xftcolor;
     44   XftColorAllocName(display, DefaultVisual(display, screen), colormap, "red", &xftcolor);
     45   pango_xft_render_layout(draw, &xftcolor, layout, 0, 0);
     46 
     47     XEvent event;
     48     KeySym key;
     49     char text[255];
     50 
     51     while(1)
     52     {
     53         XNextEvent(display, &event);
     54         if (event.type == KeyPress && XLookupString(&event.xkey, text, 255, &key, 0) == 1)
     55         {
     56 	  pango_xft_render_layout(draw, &xftcolor, layout, 0, 0);
     57             if (text[0] == 'q')
     58             {
     59                 XFreeGC(display, gc);
     60                 XFreeColormap(display, colormap);
     61                 XDestroyWindow(display, window);
     62                 XCloseDisplay(display);
     63                 exit(0);
     64             }
     65         }
     66     }
     67 
     68   /* free the layout object */
     69   g_object_unref (layout);
     70 
     71     return 0;
     72 }