2020-07-24 13:51:07 +02:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xft/Xft.h>
|
2020-07-20 15:41:19 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-07-24 13:51:07 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
2020-07-20 15:41:19 +02:00
|
|
|
{
|
2020-07-24 13:51:07 +02:00
|
|
|
Display *display = XOpenDisplay(NULL);
|
|
|
|
XEvent event;
|
|
|
|
|
|
|
|
if (display == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot open display\n");
|
2020-07-20 15:41:19 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:51:07 +02:00
|
|
|
int screen = DefaultScreen(display);
|
2020-07-20 15:41:19 +02:00
|
|
|
|
2020-07-24 13:51:07 +02:00
|
|
|
int window_width = DisplayWidth(display, screen);
|
2020-07-29 15:09:34 +02:00
|
|
|
int window_height = DisplayHeight(display, screen);
|
|
|
|
|
|
|
|
XftColor color;
|
2020-07-20 15:41:19 +02:00
|
|
|
|
2020-07-24 13:51:07 +02:00
|
|
|
Window root = RootWindow(display, screen);
|
|
|
|
XSetWindowAttributes attributes;
|
|
|
|
attributes.override_redirect = True;
|
2020-07-29 15:09:34 +02:00
|
|
|
XftColorAllocName(display, DefaultVisual(display, screen), DefaultColormap(display, screen), background_color, &color);
|
|
|
|
attributes.background_pixel = color.pixel;
|
|
|
|
XftColorAllocName(display, DefaultVisual(display, screen), DefaultColormap(display, screen), border_color, &color);
|
|
|
|
attributes.border_pixel = color.pixel;
|
2020-07-20 15:41:19 +02:00
|
|
|
|
2020-07-24 13:51:07 +02:00
|
|
|
XftFont *font = XftFontOpenName(display, screen, font_style);
|
2020-07-20 15:41:19 +02:00
|
|
|
|
2020-07-29 15:09:34 +02:00
|
|
|
unsigned short x = pos_x;
|
|
|
|
unsigned short y = pos_y;
|
2020-07-29 19:39:15 +02:00
|
|
|
int height = font->ascent - font->descent + text_padding * 2;
|
2020-07-29 15:09:34 +02:00
|
|
|
switch (corner) {
|
|
|
|
case down_right:
|
2020-07-29 19:39:15 +02:00
|
|
|
y = window_height - height - border_size * 2 - pos_y;
|
2020-07-29 15:09:34 +02:00
|
|
|
case top_right:
|
|
|
|
x = window_width - width - border_size * 2 - pos_x;
|
|
|
|
break;
|
|
|
|
case down_left:
|
2020-07-29 19:39:15 +02:00
|
|
|
y = window_height - height - border_size * 2 - pos_y;
|
2020-07-29 15:09:34 +02:00
|
|
|
}
|
|
|
|
|
2020-07-24 13:51:07 +02:00
|
|
|
Window window = XCreateWindow(
|
2020-07-29 15:09:34 +02:00
|
|
|
display, root, x,
|
2020-07-29 19:39:15 +02:00
|
|
|
y, width, height, border_size,
|
2020-07-24 13:51:07 +02:00
|
|
|
DefaultDepth(display, screen), CopyFromParent,
|
|
|
|
DefaultVisual(display, screen),
|
|
|
|
CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
|
2020-07-20 15:41:19 +02:00
|
|
|
|
2020-07-24 13:51:07 +02:00
|
|
|
XftDraw *draw = XftDrawCreate(display, window, DefaultVisual(display, screen), DefaultColormap(display, screen));
|
2020-07-29 15:09:34 +02:00
|
|
|
XftColorAllocName(display, DefaultVisual(display, screen), DefaultColormap(display, screen), font_color, &color);
|
2020-07-20 15:41:19 +02:00
|
|
|
|
2020-07-30 11:21:27 +02:00
|
|
|
XSelectInput(display, window, ExposureMask | ButtonPress);
|
2020-07-20 15:41:19 +02:00
|
|
|
|
2020-07-30 11:21:27 +02:00
|
|
|
XMapWindow(display, window);
|
2020-07-29 19:39:15 +02:00
|
|
|
|
|
|
|
// TODO free xftcolor
|
2020-07-20 15:41:19 +02:00
|
|
|
|
2020-07-30 11:21:27 +02:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
XNextEvent(display, &event);
|
2020-07-20 15:41:19 +02:00
|
|
|
|
2020-07-30 11:21:27 +02:00
|
|
|
if (event.type == Expose)
|
|
|
|
{
|
2020-07-30 12:41:37 +02:00
|
|
|
XClearWindow(display, window);
|
2020-07-30 11:21:27 +02:00
|
|
|
XftDrawString8(draw, &color, font, text_padding, height - text_padding, (XftChar8 *)argv[1], strlen(argv[1]));
|
|
|
|
}
|
|
|
|
if (event.type == ButtonPress)
|
|
|
|
break;
|
|
|
|
}
|
2020-07-29 15:09:34 +02:00
|
|
|
|
|
|
|
XCloseDisplay(display);
|
|
|
|
return 0;
|
2020-07-20 15:41:19 +02:00
|
|
|
}
|