Skip to content

Commit 62f1999

Browse files
committed
(#3) Linux highlight implementation
1 parent c0a9e5c commit 62f1999

File tree

1 file changed

+27
-49
lines changed

1 file changed

+27
-49
lines changed

src/highlightwindow_linux.c

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,39 @@
11
#include <X11/Xlib.h>
22
#include <X11/Xutil.h>
3-
#include <stdio.h>
43
#include "highlightwindow.h"
54

6-
void showHighlightWindow(int x, int y, int width, int height, int duration, float opacity) {
7-
// Display *dpy;
8-
// XVisualInfo vinfo;
9-
// int depth;
10-
// XVisualInfo *visual_list;
11-
// XVisualInfo visual_template;
12-
// int nxvisuals;
13-
// int i;
14-
// XSetWindowAttributes attrs;
15-
// Window parent;
16-
// Visual *visual;
5+
void showHighlightWindow(int x, int y, int width, int height, int duration, float opacity)
6+
{
7+
Display *d = XOpenDisplay(NULL);
8+
Window root = DefaultRootWindow(d);
9+
int default_screen = XDefaultScreen(d);
1710

18-
// dpy = XOpenDisplay(NULL);
11+
XSetWindowAttributes attrs;
12+
attrs.override_redirect = True;
1913

20-
// nxvisuals = 0;
21-
// visual_template.screen = DefaultScreen(dpy);
22-
// visual_list = XGetVisualInfo (dpy, VisualScreenMask, &visual_template, &nxvisuals);
14+
XVisualInfo vinfo;
15+
if (!XMatchVisualInfo(d, DefaultScreen(d), 32, TrueColor, &vinfo)) {
16+
return;
17+
}
18+
attrs.colormap = XCreateColormap(d, root, vinfo.visual, AllocNone);
19+
int colorValue = 255 * opacity;
20+
attrs.background_pixel = (colorValue << 24 | colorValue << 16);
21+
attrs.border_pixel = 0;
2322

24-
// for (i = 0; i < nxvisuals; ++i)
25-
// {
26-
// printf(" %3d: visual 0x%lx class %d (%s) depth %d\n",
27-
// i,
28-
// visual_list[i].visualid,
29-
// visual_list[i].depth);
30-
// }
23+
Window overlay = XCreateWindow(
24+
d, root,
25+
x, y, width, height, 0,
26+
vinfo.depth, InputOutput,
27+
vinfo.visual,
28+
CWOverrideRedirect | CWColormap | CWBackPixel | CWBorderPixel, &attrs
29+
);
3130

32-
// if (!XMatchVisualInfo(dpy, XDefaultScreen(dpy), 32, TrueColor, &vinfo))
33-
// {
34-
// fprintf(stderr, "no such visual\n");
35-
// return;
36-
// }
31+
XMapWindow(d, overlay);
3732

38-
// printf("Matched visual 0x%lx class %d (%s) depth %d\n",
39-
// vinfo.visualid,
40-
// vinfo.depth);
33+
XFlush(d);
4134

42-
// parent = XDefaultRootWindow(dpy);
35+
sleep(duration);
4336

44-
// XSync(dpy, True);
45-
46-
// printf("creating RGBA child\n");
47-
48-
// visual = vinfo.visual;
49-
// depth = vinfo.depth;
50-
51-
// attrs.colormap = XCreateColormap(dpy, XDefaultRootWindow(dpy), visual, AllocNone);
52-
// attrs.background_pixel = 0;
53-
// attrs.border_pixel = 0;
54-
55-
// XCreateWindow(dpy, parent, 10, 10, 150, 100, 0, depth, InputOutput,
56-
// visual, CWBackPixel | CWColormap | CWBorderPixel, &attrs);
57-
58-
// XSync(dpy, True);
59-
60-
// printf("No error\n");
37+
XUnmapWindow(d, overlay);
38+
XCloseDisplay(d);
6139
}

0 commit comments

Comments
 (0)