I have this code in C:
#include <X11/X.h>
#include <X11/Xlib.h>
#include <mpv/client.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Handle MPV errors
void checkMPV(int status) {
if (status < 0) {
printf("MPV error: %s\n", mpv_error_string(status));
exit(1);
}
}
int main(void) {
Display *display = XOpenDisplay(NULL);
if (display == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
// Create X11 window
int screen = DefaultScreen(display);
Window window = XCreateSimpleWindow(
display, RootWindow(display, screen), 10, 10, 100, 100, 1,
BlackPixel(display, screen), WhitePixel(display, screen));
XSelectInput(display, window, ExposureMask);
XMapWindow(display, window);
// Create MPV context
mpv_handle *ctx = mpv_create();
if (!ctx) {
printf("failed to create context\n");
return 1;
}
// bind MPV to master window
char wid[64];
sprintf(wid, "0x%lx", window);
checkMPV(mpv_set_option_string(ctx, "wid", wid));
// configure MPV
checkMPV(mpv_set_option_string(ctx, "keepaspect", "no"));
checkMPV(mpv_set_option_string(ctx, "x11-bypass-compositor", "no"));
checkMPV(mpv_set_option_string(ctx, "gapless-audio", "yes"));
checkMPV(mpv_set_option_string(ctx, "aid", "no"));
checkMPV(mpv_set_option_string(ctx, "vo", "xv"));
checkMPV(mpv_set_option_string(ctx, "hwdec", "auto"));
checkMPV(mpv_set_option_string(ctx, "input-default-bindings", "no"));
checkMPV(mpv_set_option_string(ctx, "input-vo-keyboard", "no"));
int flag = 0;
checkMPV(mpv_set_option(ctx, "osc", MPV_FORMAT_FLAG, &flag));
// Initialize MPV
checkMPV(mpv_initialize(ctx));
// Play video
const char *cmd[] = {"loadfile", "video.mp4", NULL};
checkMPV(mpv_command(ctx, cmd));
// Draw rectangle in loop
XEvent event;
while (1) {
XNextEvent(display, &event);
XClearWindow(display, window);
XFillRectangle(display, window, DefaultGC(display, screen), 10, 10, 300,
300);
}
// Cleanup
mpv_terminate_destroy(ctx);
XCloseDisplay(display);
return 0;
}
It attaches MPV window to X11 window. It looks like this (just a video frame):
The question is, can I make MPV window semi-transparent (for example, by 70%), so rectangle drawed by XFillRectangle(display, window, DefaultGC(display, screen), 10, 10, 300, 300); will be kinda visible? It would look like this:
Is it possible without using things like opengl?