2 * awmessage.c - message window for awesome
4 * Copyright © 2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "common/swindow.h"
27 #include "common/util.h"
28 #include "common/awesome-version.h"
30 static void __attribute__ ((noreturn
))
31 exit_help(int exit_code
)
33 FILE *outfile
= (exit_code
== EXIT_SUCCESS
) ? stdout
: stderr
;
34 fprintf(outfile
, "Usage: awmessage [-x xcoord] [-y ycoord] [-f fgcolor] [-b bgcolor] <message> <icon>\n");
39 main(int argc
, char **argv
)
47 const char *fg_color
= "#000000";
48 const char *bg_color
= "#ffffff";
50 Area geometry
= { 0, 0, 200, 50 }, icon_geometry
= { -1, -1, -1, -1 };
53 if(!(disp
= XOpenDisplay(NULL
)))
54 eprint("unable to open display");
56 while((opt
= getopt(argc
, argv
, "vhf:b:x:y:n:")) != -1)
60 eprint_version("awmessage");
63 fg_color
= a_strdup(optarg
);
66 bg_color
= a_strdup(optarg
);
69 geometry
.x
= atoi(optarg
);
72 geometry
.y
= atoi(optarg
);
75 exit_help(EXIT_SUCCESS
);
78 font
= XftFontOpenName(disp
, DefaultScreen(disp
), optarg
);
83 exit_help(EXIT_FAILURE
);
86 font
= XftFontOpenName(disp
, DefaultScreen(disp
), "vera-12");
88 geometry
.width
= draw_textwidth(disp
, font
, argv
[optind
]);
89 geometry
.height
= font
->height
* 1.5;
91 if(argc
- optind
>= 2)
93 icon_geometry
= draw_get_image_size(argv
[optind
+ 1]);
94 if(icon_geometry
.width
<= 0 || icon_geometry
.height
<= 0)
95 eprint("invalid image\n");
97 geometry
.width
+= icon_geometry
.width
* ((double) font
->height
/ (double) icon_geometry
.height
);
100 sw
= simplewindow_new(disp
, DefaultScreen(disp
),
101 geometry
.x
, geometry
.y
, geometry
.width
, geometry
.height
, 0);
103 XStoreName(disp
, sw
->window
, "awmessage");
105 ctx
= draw_get_context(disp
, DefaultScreen(disp
),
106 geometry
.width
, geometry
.height
, sw
->drawable
);
108 /* XXX replace by initxcolor() */
109 XAllocNamedColor(disp
, DefaultColormap(disp
, DefaultScreen(disp
)),
112 XAllocNamedColor(disp
, DefaultColormap(disp
, DefaultScreen(disp
)),
115 geometry
.x
= geometry
.y
= 0;
116 draw_text(ctx
, geometry
, AlignRight
,
117 0, font
, argv
[optind
], fg
, bg
);
119 if(icon_geometry
.width
> 0 && icon_geometry
.height
> 0)
120 draw_image(ctx
, 0, (geometry
.height
/ 2) - (font
->height
/ 2),
126 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
128 XMapRaised(disp
, sw
->window
);
133 XNextEvent(disp
, &ev
);
140 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
147 simplewindow_delete(sw
);
153 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80