|
1 | 1 | #include <X11/Xlib.h>
|
2 | 2 | #include <X11/Xutil.h>
|
3 |
| -#include <stdio.h> |
4 | 3 | #include "highlightwindow.h"
|
5 | 4 |
|
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); |
17 | 10 |
|
18 |
| -// dpy = XOpenDisplay(NULL); |
| 11 | + XSetWindowAttributes attrs; |
| 12 | + attrs.override_redirect = True; |
19 | 13 |
|
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; |
23 | 22 |
|
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 | + ); |
31 | 30 |
|
32 |
| -// if (!XMatchVisualInfo(dpy, XDefaultScreen(dpy), 32, TrueColor, &vinfo)) |
33 |
| -// { |
34 |
| -// fprintf(stderr, "no such visual\n"); |
35 |
| -// return; |
36 |
| -// } |
| 31 | + XMapWindow(d, overlay); |
37 | 32 |
|
38 |
| -// printf("Matched visual 0x%lx class %d (%s) depth %d\n", |
39 |
| -// vinfo.visualid, |
40 |
| -// vinfo.depth); |
| 33 | + XFlush(d); |
41 | 34 |
|
42 |
| -// parent = XDefaultRootWindow(dpy); |
| 35 | + sleep(duration); |
43 | 36 |
|
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); |
61 | 39 | }
|
0 commit comments