2 #include <X11/Xft/Xft.h>
16 event
.type
= ButtonPress
;
17 XSendEvent(display
, window
, 0, 0, &event
);
21 int main(int argc
, char *argv
[])
25 fprintf(stderr
, "Usage: herbe message\n");
31 signal(SIGALRM
, expire
);
34 display
= XOpenDisplay(NULL
);
38 fprintf(stderr
, "Cannot open display\n");
42 int screen
= DefaultScreen(display
);
43 Visual
*visual
= DefaultVisual(display
, screen
);
44 Colormap colormap
= DefaultColormap(display
, screen
);
46 int screen_width
= DisplayWidth(display
, screen
);
47 int screen_height
= DisplayHeight(display
, screen
);
51 XSetWindowAttributes attributes
;
52 attributes
.override_redirect
= True
;
53 XftColorAllocName(display
, visual
, colormap
, background_color
, &color
);
54 attributes
.background_pixel
= color
.pixel
;
55 XftColorAllocName(display
, visual
, colormap
, border_color
, &color
);
56 attributes
.border_pixel
= color
.pixel
;
58 XftFont
*font
= XftFontOpenName(display
, screen
, font_pattern
);
60 int max_text_width
= width
- 2 * padding
;
62 int *eols
= malloc(eols_size
* sizeof(int));
64 int remainder
= strlen(body
);
71 int eol
= max_text_width
/ font
->max_advance_width
;
72 while (info
.width
< max_text_width
)
75 XftTextExtentsUtf8(display
, font
, body
+ eols
[num_of_lines
- 1], eol
, &info
);
82 if (eols_size
< num_of_lines
+ 1)
85 eols
= realloc(eols
, eols_size
* sizeof(int));
87 eols
[num_of_lines
] = eols
[num_of_lines
- 1] + remainder
;
92 while (body
[eols
[num_of_lines
- 1] + eol
] != ' ')
98 if (eols_size
< num_of_lines
+ 1)
101 eols
= realloc(eols
, eols_size
* sizeof(int));
103 eols
[num_of_lines
] = eols
[num_of_lines
- 1] + eol
;
107 unsigned int x
= pos_x
;
108 unsigned int y
= pos_y
;
109 unsigned int text_height
= font
->ascent
- font
->descent
;
110 unsigned int height
= (num_of_lines
- 2) * line_spacing
+ (num_of_lines
- 1) * text_height
+ 2 * padding
;
115 y
= screen_height
- height
- border_size
* 2 - pos_y
;
117 x
= screen_width
- width
- border_size
* 2 - pos_x
;
120 y
= screen_height
- height
- border_size
* 2 - pos_y
;
123 window
= XCreateWindow(display
, RootWindow(display
, screen
), x
, y
, width
, height
, border_size
, DefaultDepth(display
, screen
), CopyFromParent
, visual
,
124 CWOverrideRedirect
| CWBackPixel
| CWBorderPixel
, &attributes
);
126 XftDraw
*draw
= XftDrawCreate(display
, window
, visual
, colormap
);
127 XftColorAllocName(display
, visual
, colormap
, font_color
, &color
);
129 XSelectInput(display
, window
, ExposureMask
| ButtonPress
);
131 XMapWindow(display
, window
);
137 XNextEvent(display
, &event
);
139 if (event
.type
== Expose
)
141 XClearWindow(display
, window
);
142 for (int i
= 1; i
< num_of_lines
; i
++)
143 XftDrawStringUtf8(draw
, &color
, font
, padding
, line_spacing
* (i
- 1) + text_height
* i
+ padding
, body
+ eols
[i
- 1], eols
[i
] - eols
[i
- 1]);
145 if (event
.type
== ButtonPress
)
150 XftDrawDestroy(draw
);
151 XftColorFree(display
, visual
, colormap
, &color
);
152 XftFontClose(display
, font
);
154 XCloseDisplay(display
);