rename to awesome-message to be respect awesome naming scheme
[awesome.git] / awesome-message.c
blobd9cbedab94aa4c3246e84c7ef5c317adf8fa2390
1 /*
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.
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <X11/Xlib.h>
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");
35 exit(exit_code);
38 int
39 main(int argc, char **argv)
41 Display *disp;
42 SimpleWindow *sw;
43 DrawCtx *ctx;
44 XColor fg, bg, c;
45 XEvent ev;
46 const char *fg_color = "#000000";
47 const char *bg_color = "#ffffff";
48 int opt;
49 Area geometry = { 0, 0, 200, 50 }, icon_geometry = { -1, -1, -1, -1 };
50 XftFont *font = NULL;
52 if(!(disp = XOpenDisplay(NULL)))
53 eprint("unable to open display");
55 while((opt = getopt(argc, argv, "vhf:b:x:y:n:")) != -1)
56 switch(opt)
58 case 'v':
59 eprint_version("awmessage");
60 break;
61 case 'f':
62 fg_color = a_strdup(optarg);
63 break;
64 case 'b':
65 bg_color = a_strdup(optarg);
66 break;
67 case 'x':
68 geometry.x = atoi(optarg);
69 break;
70 case 'y':
71 geometry.y = atoi(optarg);
72 break;
73 case 'h':
74 exit_help(EXIT_SUCCESS);
75 break;
76 case 'n':
77 font = XftFontOpenName(disp, DefaultScreen(disp), optarg);
78 break;
81 if(argc - optind < 1)
82 exit_help(EXIT_FAILURE);
84 if(!font)
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");
95 else
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)),
109 bg_color, &bg, &c);
111 XAllocNamedColor(disp, DefaultColormap(disp, DefaultScreen(disp)),
112 fg_color, &fg, &c);
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),
120 font->height,
121 argv[optind + 1]);
123 p_delete(&ctx);
125 simplewindow_refresh_drawable(sw, DefaultScreen(disp));
127 XMapRaised(disp, sw->window);
128 XSync(disp, False);
130 while (1)
132 XNextEvent(disp, &ev);
133 switch (ev.type)
135 case ButtonPress:
136 case KeyPress:
137 return EXIT_SUCCESS;
138 case Expose:
139 simplewindow_refresh_drawable(sw, DefaultScreen(disp));
140 break;
141 default:
142 break;
146 simplewindow_delete(sw);
147 XCloseDisplay(disp);
149 return EXIT_SUCCESS;
152 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80