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.
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",
44 main(int argc
, char **argv
)
52 const char *fg_color
= "#000000";
53 const char *bg_color
= "#ffffff";
55 Area geometry
= { 0, 0, 200, 50, NULL
},
56 icon_geometry
= { -1, -1, -1, -1, NULL
};
59 static struct option long_options
[] = {
60 {"help", 0, NULL
, 'h'},
61 {"version", 0, NULL
, 'v'},
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)
73 eprint_version(PROGNAME
);
76 fg_color
= a_strdup(optarg
);
79 bg_color
= a_strdup(optarg
);
82 geometry
.x
= atoi(optarg
);
85 geometry
.y
= atoi(optarg
);
88 exit_help(EXIT_SUCCESS
);
91 font
= XftFontOpenName(disp
, DefaultScreen(disp
), optarg
);
96 exit_help(EXIT_FAILURE
);
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");
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),
136 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
138 XMapRaised(disp
, sw
->window
);
143 XNextEvent(disp
, &ev
);
150 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
157 simplewindow_delete(sw
);
163 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80