1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* ghosd -- OSD with fake transparency, cairo, and pango.
* Copyright (C) 2006 Evan Martin <martine@danga.com>
*/
#include <glib.h>
#include <stdlib.h>
#include <ghosd/ghosd.h>
#include "example-shared.h"
ExampleOptions opts = {
TRUE,
50, -50
};
gboolean
example_options_parse(int *argc, char ***argv, ...) {
GOptionEntry options[] = {
{ "opaque", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
(gpointer)&opts.transparent, "turn off transparent background" },
{ "x", 'x', 0, G_OPTION_ARG_INT, (gpointer)&opts.x,
"x coordinate for window" },
{ "y", 'y', 0, G_OPTION_ARG_INT, (gpointer)&opts.y,
"y coordinate for window" },
{ NULL }
};
GOptionContext *ctx;
GOptionGroup *group;
gboolean ret;
va_list ap;
va_start(ap, argv);
ctx = g_option_context_new("");
g_option_context_add_main_entries(ctx, options, "bar");
while ((group = va_arg(ap, GOptionGroup*)) != NULL) {
g_option_context_add_group(ctx, group);
}
va_end(ap);
g_option_context_set_ignore_unknown_options(ctx, FALSE);
ret = g_option_context_parse(ctx, argc, argv, NULL);
g_option_context_free(ctx);
if (opts.x == 0) opts.x = GHOSD_COORD_CENTER;
if (opts.y == 0) opts.y = GHOSD_COORD_CENTER;
return ret;
}
void
example_round_rect(cairo_t *cr, int x, int y, int w, int h, int r) {
cairo_move_to(cr, x+r, y);
cairo_line_to(cr, x+w-r, y); /* top edge */
cairo_curve_to(cr, x+w, y, x+w, y, x+w, y+r);
cairo_line_to(cr, x+w, y+h-r); /* right edge */
cairo_curve_to(cr, x+w, y+h, x+w, y+h, x+w-r, y+h);
cairo_line_to(cr, x+r, y+h); /* bottom edge */
cairo_curve_to(cr, x, y+h, x, y+h, x, y+h-r);
cairo_line_to(cr, x, y+r); /* left edge */
cairo_curve_to(cr, x, y, x, y, x+r, y);
cairo_close_path(cr);
}
/* vim: set ts=2 sw=2 et cino=(0 : */
|