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
)
46 const char *fg_color
= "#000000";
47 const char *bg_color
= "#ffffff";
49 Area geometry
= { 0, 0, 200, 50 }, icon_geometry
= { -1, -1, -1, -1 };
52 if(!(disp
= XOpenDisplay(NULL
)))
53 eprint("unable to open display");
55 while((opt
= getopt(argc
, argv
, "vhf:b:x:y:n:")) != -1)
59 eprint_version("awmessage");
62 fg_color
= a_strdup(optarg
);
65 bg_color
= a_strdup(optarg
);
68 geometry
.x
= atoi(optarg
);
71 geometry
.y
= atoi(optarg
);
74 exit_help(EXIT_SUCCESS
);
77 font
= XftFontOpenName(disp
, DefaultScreen(disp
), optarg
);
82 exit_help(EXIT_FAILURE
);
85 font
= XftFontOpenName(disp
, DefaultScreen(disp
), "vera-12");
87 geometry
.width
= draw_textwidth(disp
, font
, argv
[optind
]);
88 geometry
.height
= font
->height
* 1.5;
90 if(argc
- optind
>= 2)
92 icon_geometry
= draw_get_image_size(argv
[optind
+ 1]);
93 if(icon_geometry
.width
<= 0 || icon_geometry
.height
<= 0)
94 eprint("invalid image\n");
96 geometry
.width
+= icon_geometry
.width
* ((double) font
->height
/ (double) icon_geometry
.height
);
99 sw
= simplewindow_new(disp
, DefaultScreen(disp
),
100 geometry
.x
, geometry
.y
, geometry
.width
, geometry
.height
, 0);
102 XStoreName(disp
, sw
->window
, "awmessage");
104 ctx
= draw_get_context(disp
, DefaultScreen(disp
),
105 geometry
.width
, geometry
.height
, sw
->drawable
);
107 /* XXX replace by initxcolor() */
108 XAllocNamedColor(disp
, DefaultColormap(disp
, DefaultScreen(disp
)),
111 XAllocNamedColor(disp
, DefaultColormap(disp
, DefaultScreen(disp
)),
114 geometry
.x
= geometry
.y
= 0;
115 draw_text(ctx
, geometry
, AlignRight
,
116 0, font
, argv
[optind
], fg
, bg
);
118 if(icon_geometry
.width
> 0 && icon_geometry
.height
> 0)
119 draw_image(ctx
, 0, (geometry
.height
/ 2) - (font
->height
/ 2),
125 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
127 XMapRaised(disp
, sw
->window
);
132 XNextEvent(disp
, &ev
);
139 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
146 simplewindow_delete(sw
);
152 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80