rename some screens function
[awesome.git] / awesome-message.c
blob66bc0c0023ed4ecdced83cc0fd765207431aa02c
1 /*
2 * awesome-message.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 #define _GNU_SOURCE
23 #include <getopt.h>
24 #include <unistd.h>
25 #include <stdlib.h>
26 #include <X11/Xlib.h>
28 #include "common/swindow.h"
29 #include "common/util.h"
30 #include "common/awesome-version.h"
32 #define PROGNAME "awesome-message"
34 static void __attribute__ ((noreturn))
35 exit_help(int exit_code)
37 FILE *outfile = (exit_code == EXIT_SUCCESS) ? stdout : stderr;
38 fprintf(outfile, "Usage: %s [-x xcoord] [-y ycoord] [-f fgcolor] [-b bgcolor] <message> <icon>\n",
39 PROGNAME);
40 exit(exit_code);
43 int
44 main(int argc, char **argv)
46 Display *disp;
47 SimpleWindow *sw;
48 DrawCtx *ctx;
49 XColor fg, bg;
50 XEvent ev;
51 Bool running = True;
52 const char *fg_color = "#000000";
53 const char *bg_color = "#ffffff";
54 int opt;
55 Area geometry = { 0, 0, 200, 50, NULL },
56 icon_geometry = { -1, -1, -1, -1, NULL };
57 XftFont *font = NULL;
58 int option_index = 0;
59 static struct option long_options[] = {
60 {"help", 0, NULL, 'h'},
61 {"version", 0, NULL, 'v'},
62 {NULL, 0, NULL, 0}
65 if(!(disp = XOpenDisplay(NULL)))
66 eprint("unable to open display");
68 while((opt = getopt_long(argc, argv, "vhf:b:x:y:n:",
69 long_options, &option_index)) != -1)
70 switch(opt)
72 case 'v':
73 eprint_version(PROGNAME);
74 break;
75 case 'f':
76 fg_color = a_strdup(optarg);
77 break;
78 case 'b':
79 bg_color = a_strdup(optarg);
80 break;
81 case 'x':
82 geometry.x = atoi(optarg);
83 break;
84 case 'y':
85 geometry.y = atoi(optarg);
86 break;
87 case 'h':
88 exit_help(EXIT_SUCCESS);
89 break;
90 case 'n':
91 font = XftFontOpenName(disp, DefaultScreen(disp), optarg);
92 break;
95 if(argc - optind < 1)
96 exit_help(EXIT_FAILURE);
98 if(!font)
99 font = XftFontOpenName(disp, DefaultScreen(disp), "vera-12");
101 geometry.width = draw_textwidth(disp, font, argv[optind]);
102 geometry.height = font->height * 1.5;
104 if(argc - optind >= 2)
106 icon_geometry = draw_get_image_size(argv[optind + 1]);
107 if(icon_geometry.width <= 0 || icon_geometry.height <= 0)
108 eprint("invalid image\n");
109 else
110 geometry.width += icon_geometry.width * ((double) font->height / (double) icon_geometry.height);
113 sw = simplewindow_new(disp, DefaultScreen(disp),
114 geometry.x, geometry.y, geometry.width, geometry.height, 0);
116 XStoreName(disp, sw->window, "awmessage");
118 ctx = draw_context_new(disp, DefaultScreen(disp),
119 geometry.width, geometry.height, sw->drawable);
122 bg = draw_color_new(disp, DefaultScreen(disp), bg_color);
123 fg = draw_color_new(disp, DefaultScreen(disp), fg_color);
125 geometry.x = geometry.y = 0;
126 draw_text(ctx, geometry, AlignRight,
127 0, font, argv[optind], fg, bg);
129 if(icon_geometry.width > 0 && icon_geometry.height > 0)
130 draw_image(ctx, 0, (geometry.height / 2) - (font->height / 2),
131 font->height,
132 argv[optind + 1]);
134 p_delete(&ctx);
136 simplewindow_refresh_drawable(sw, DefaultScreen(disp));
138 XMapRaised(disp, sw->window);
139 XSync(disp, False);
141 while (running)
143 XNextEvent(disp, &ev);
144 switch (ev.type)
146 case ButtonPress:
147 case KeyPress:
148 running = False;
149 case Expose:
150 simplewindow_refresh_drawable(sw, DefaultScreen(disp));
151 break;
152 default:
153 break;
157 simplewindow_delete(sw);
158 XCloseDisplay(disp);
160 return EXIT_SUCCESS;
163 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80