Created
September 12, 2016 03:15
-
-
Save youxkei/e69c9724d5e43aae3d4ac0d13187e79e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <X11/Xlib.h> | |
#include <X11/Xft/Xft.h> | |
#include <string> | |
#include <iostream> | |
int main() { | |
if (setlocale(LC_CTYPE, "") == 0) { | |
std::cerr << "Can't set locale" << std::endl; | |
exit(1); | |
} | |
Display *display = XOpenDisplay(nullptr); | |
if (!display) { | |
exit(2); | |
} | |
uint32_t screen = DefaultScreen(display); | |
Window root = RootWindow(display, screen); | |
Window window = XCreateSimpleWindow(display, root, 0, 0, 200, 100, 0, 0, 0x00'00'00); | |
GC gc = XCreateGC(display, window, GCForeground, (XGCValues[]){ 0xFF'FF'FF }); | |
XSetForeground(display, gc, 0xFFFFFF); | |
XftFont *font = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "NasuM", XFT_SIZE, XftTypeDouble, 64.0, nullptr); | |
XftDraw *draw = XftDrawCreate(display, window, DefaultVisual(display, screen), DefaultColormap(display, screen)); | |
XftColor color = { 0, { 0xC000, 0xFF00, 0xEE00 } }; | |
std::string hello = u8"こんにちは,世界!"; | |
XGlyphInfo glyph_info; | |
XftTextExtentsUtf8(display, font, (const FcChar8*)hello.c_str(), hello.size(), &glyph_info); | |
XMapWindow(display, window); | |
XFlush(display); | |
XSelectInput(display, window, ExposureMask | ButtonPressMask); | |
while(true) { | |
XEvent event; | |
XNextEvent(display, &event); | |
switch (event.type) { | |
case Expose: { | |
XftDrawStringUtf8(draw, &color, font, 10, 10 + glyph_info.height, (const FcChar8*)hello.c_str(), hello.size()); | |
} | |
} | |
} | |
XCloseDisplay(display); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment