loqy/bak.c

160 lines
3.4 KiB
C
Raw Normal View History

2022-02-27 12:59:54 +01:00
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xatom.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/Xutil.h>
#include <X11/Xft/Xft.h>
#define PASS_LEN 20
#define FONT_SIZE 12
typedef struct { unsigned long flags;
unsigned long functions;
unsigned long decorations;
long inputMode;
unsigned long status;
} Hints;
char *message = "Password";
void catch_fire(char *string, int error){
fprintf(stderr, string);
exit(error);
}
void draw_gui(Display*, Window, Visual*, Colormap, int, int, int);
int main(void) {
Display *d = XOpenDisplay(NULL);
if ( d == NULL )
catch_fire("Cannot open display\n", 1);
int s = DefaultScreen(d);
Window w;
XEvent e;
Visual *visual = DefaultVisual(d, s);
Colormap cmap = DefaultColormap(d, s);
int depth = DefaultDepth(d, s);
int width = DisplayWidth(d, s);
int height = DisplayHeight(d, s);
int mode_count;
// VIDEO MODES
XF86VidModeModeInfo **modes, *video_mode;
XF86VidModeGetAllModeLines(d, s, &mode_count, &modes);
video_mode = modes[0];
// ATTRIBUTES
XSetWindowAttributes attributes;
attributes.override_redirect = True;
attributes.background_pixel = BlackPixel(d, s);
// COCKS FOR FULLSCREEN QOQS
Hints hints;
hints.flags = 2;
hints.decorations = 0;
Atom roperty = XInternAtom(d, "_MOTIF_WM_HINTS", True);
w = XCreateWindow(d, XRootWindow(d, s), 0, 0, width, height, 0, depth, InputOutput, visual, CWBackPixel|CWOverrideRedirect, &attributes);
draw_gui(d, w, visual, cmap, width, height, s);
XSelectInput(d, w, ExposureMask | KeyPressMask);
XMapWindow(d, w);
// SETTING FULLSCREEN
XF86VidModeSwitchToMode(d, s, video_mode);
XF86VidModeSetViewPort(d, s, 0, 0);
XMoveResizeWindow(d, w, 0, 0, width, height);
XMapRaised(d, w);
XGrabPointer(d, w, True, 0, GrabModeAsync, GrabModeAsync, w, 0L, CurrentTime);
XGrabKeyboard(d, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
while (1) {
XNextEvent(d, &e);
if (e.type == KeyPress)
break;
}
XCloseDisplay(d);
return 0;
}
void draw_gui(Display *d, Window w, Visual *visual, Colormap cmap, int width, int height, int s){
// FONT
char font_name[strlen("monospace-") +2];
sprintf(font_name, "monospace-%d", FONT_SIZE);
XftFont *font = XftFontOpenName(d, s, font_name);
// FONT COLORS
XftColor xft_black;
XftColorAllocName (d, visual, cmap, "black", &xft_black);
XftColor xft_white;
XftColorAllocName (d, visual, cmap, "white", &xft_white);
XftDraw *xftdraw = XftDrawCreate(d, w, visual, cmap);
// WHITE RECTANGLE
XftDrawRect(xftdraw, &xft_white, width/2 - ((strlen(message) + PASS_LEN) / 2)*FONT_SIZE, height/2 - 2*FONT_SIZE,
(strlen(message) + PASS_LEN)*FONT_SIZE, 4*FONT_SIZE);
// BLACK RECTANGLE
XftDrawRect(xftdraw, &xft_black, width/2 - ((PASS_LEN - strlen(message)) / 2)*FONT_SIZE, height/2 - 2*FONT_SIZE + FONT_SIZE/2,
(PASS_LEN * FONT_SIZE) - FONT_SIZE/2, 3*FONT_SIZE);
// MESSAGE STRING
XftDrawString8(xftdraw, &xft_black, font, width/2 - ((strlen(message) + PASS_LEN) / 2)*FONT_SIZE + FONT_SIZE/2,
height/2 + FONT_SIZE/2, message, strlen(message));
}