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.
33 #include "common/swindow.h"
34 #include "common/util.h"
35 #include "common/version.h"
36 #include "common/configopts.h"
38 #define PROGNAME "awesome-message"
40 static Bool running
= True
;
42 /** Import awesome config file format */
43 extern cfg_opt_t awesome_opts
[];
45 /** awesome-run global configuration structure */
52 /** Foreground color */
54 /** Background color */
56 /** Draw shadow_offset under text */
60 static AwesomeMsgConf globalconf
;
62 static void __attribute__ ((noreturn
))
63 exit_help(int exit_code
)
65 FILE *outfile
= (exit_code
== EXIT_SUCCESS
) ? stdout
: stderr
;
66 fprintf(outfile
, "Usage: %s [-x xcoord] [-y ycoord] [-d delay] <message> <icon>\n",
72 config_parse(const char *confpatharg
)
76 cfg_t
*cfg
, *cfg_screen
, *cfg_general
, *cfg_colors
;
79 confpath
= config_file();
81 confpath
= a_strdup(confpatharg
);
83 cfg
= cfg_init(awesome_opts
, CFGF_NONE
);
85 switch((ret
= cfg_parse(cfg
, confpath
)))
88 perror("awesome-message: parsing configuration file failed");
91 cfg_error(cfg
, "awesome: parsing configuration file %s failed.\n", confpath
);
98 /* get global screen section */
99 cfg_screen
= cfg_getsec(cfg
, "screen");
102 eprint("parsing configuration file failed, no screen section found\n");
104 /* get colors and general section */
105 cfg_general
= cfg_getsec(cfg_screen
, "general");
106 cfg_colors
= cfg_getsec(cfg_screen
, "colors");
109 draw_color_new(globalconf
.display
, DefaultScreen(globalconf
.display
),
110 cfg_getstr(cfg_colors
, "normal_fg"),
112 draw_color_new(globalconf
.display
, DefaultScreen(globalconf
.display
),
113 cfg_getstr(cfg_colors
, "normal_bg"),
116 globalconf
.shadow_offset
= cfg_getint(cfg_general
, "text_shadow_offset");
119 globalconf
.font
= XftFontOpenName(globalconf
.display
, DefaultScreen(globalconf
.display
),
120 cfg_getstr(cfg_general
, "font"));
128 exit_on_signal(int sig
__attribute__ ((unused
)))
134 main(int argc
, char **argv
)
140 Area geometry
= { 0, 0, 200, 50, NULL
},
141 icon_geometry
= { -1, -1, -1, -1, NULL
};
144 char *configfile
= NULL
;
145 static struct option long_options
[] =
147 {"help", 0, NULL
, 'h'},
148 {"version", 0, NULL
, 'v'},
152 if(!(disp
= XOpenDisplay(NULL
)))
153 eprint("unable to open display");
155 globalconf
.display
= disp
;
157 while((opt
= getopt_long(argc
, argv
, "vhf:b:x:y:n:c:d:",
158 long_options
, NULL
)) != -1)
162 delay
= atoi(optarg
);
165 eprint_version(PROGNAME
);
168 geometry
.x
= atoi(optarg
);
171 geometry
.y
= atoi(optarg
);
174 exit_help(EXIT_SUCCESS
);
177 configfile
= a_strdup(optarg
);
181 if(argc
- optind
< 1)
182 exit_help(EXIT_FAILURE
);
184 if((ret
= config_parse(configfile
)))
187 geometry
.width
= draw_textwidth(disp
, globalconf
.font
, argv
[optind
]);
188 geometry
.height
= globalconf
.font
->height
* 1.5;
190 if(argc
- optind
>= 2)
192 icon_geometry
= draw_get_image_size(argv
[optind
+ 1]);
193 if(icon_geometry
.width
<= 0 || icon_geometry
.height
<= 0)
194 eprint("invalid image\n");
196 geometry
.width
+= icon_geometry
.width
197 * ((double) globalconf
.font
->height
/ (double) icon_geometry
.height
);
200 sw
= simplewindow_new(disp
, DefaultScreen(disp
),
201 geometry
.x
, geometry
.y
, geometry
.width
, geometry
.height
, 0);
203 XStoreName(disp
, sw
->window
, PROGNAME
);
205 ctx
= draw_context_new(disp
, DefaultScreen(disp
),
206 geometry
.width
, geometry
.height
, sw
->drawable
);
208 geometry
.x
= geometry
.y
= 0;
209 draw_text(ctx
, geometry
, AlignRight
,
210 0, globalconf
.font
, argv
[optind
],
211 globalconf
.shadow_offset
, globalconf
.fg
, globalconf
.bg
);
213 if(icon_geometry
.width
> 0 && icon_geometry
.height
> 0)
214 draw_image(ctx
, 0, (geometry
.height
/ 2) - (globalconf
.font
->height
/ 2),
215 globalconf
.font
->height
,
220 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
222 XMapRaised(disp
, sw
->window
);
225 signal(SIGALRM
, &exit_on_signal
);
232 XNextEvent(disp
, &ev
);
239 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
248 simplewindow_delete(sw
);
254 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80