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.
32 #include "common/swindow.h"
33 #include "common/util.h"
34 #include "common/awesome-version.h"
35 #include "common/configopts.h"
37 #define PROGNAME "awesome-message"
39 /** Import awesome config file format */
40 extern cfg_opt_t awesome_opts
[];
42 /** awesome-run global configuration structure */
49 /** Foreground color */
51 /** Background color */
55 static AwesomeMsgConf globalconf
;
57 static void __attribute__ ((noreturn
))
58 exit_help(int exit_code
)
60 FILE *outfile
= (exit_code
== EXIT_SUCCESS
) ? stdout
: stderr
;
61 fprintf(outfile
, "Usage: %s [-x xcoord] [-y ycoord] <message> <icon>\n",
67 config_parse(const char *confpatharg
)
71 cfg_t
*cfg
, *cfg_screen
, *cfg_general
, *cfg_colors
;
74 confpath
= config_file();
76 confpath
= a_strdup(confpatharg
);
78 cfg
= cfg_init(awesome_opts
, CFGF_NONE
);
80 switch((ret
= cfg_parse(cfg
, confpath
)))
83 perror("awesome-message: parsing configuration file failed");
86 cfg_error(cfg
, "awesome: parsing configuration file %s failed.\n", confpath
);
93 /* get global screen section */
94 cfg_screen
= cfg_getsec(cfg
, "screen");
97 eprint("parsing configuration file failed, no screen section found\n");
99 /* get colors and general section */
100 cfg_general
= cfg_getsec(cfg_screen
, "general");
101 cfg_colors
= cfg_getsec(cfg_screen
, "colors");
104 globalconf
.fg
= draw_color_new(globalconf
.display
, DefaultScreen(globalconf
.display
),
105 cfg_getstr(cfg_colors
, "normal_fg"));
106 globalconf
.bg
= draw_color_new(globalconf
.display
, DefaultScreen(globalconf
.display
),
107 cfg_getstr(cfg_colors
, "normal_bg"));
110 globalconf
.font
= XftFontOpenName(globalconf
.display
, DefaultScreen(globalconf
.display
),
111 cfg_getstr(cfg_general
, "font"));
117 main(int argc
, char **argv
)
124 Area geometry
= { 0, 0, 200, 50, NULL
},
125 icon_geometry
= { -1, -1, -1, -1, NULL
};
127 char *configfile
= NULL
;
128 static struct option long_options
[] =
130 {"help", 0, NULL
, 'h'},
131 {"version", 0, NULL
, 'v'},
135 if(!(disp
= XOpenDisplay(NULL
)))
136 eprint("unable to open display");
138 globalconf
.display
= disp
;
140 while((opt
= getopt_long(argc
, argv
, "vhf:b:x:y:n:c:",
141 long_options
, NULL
)) != -1)
145 eprint_version(PROGNAME
);
148 geometry
.x
= atoi(optarg
);
151 geometry
.y
= atoi(optarg
);
154 exit_help(EXIT_SUCCESS
);
157 configfile
= a_strdup(optarg
);
161 if(argc
- optind
< 1)
162 exit_help(EXIT_FAILURE
);
164 config_parse(configfile
);
166 geometry
.width
= draw_textwidth(disp
, globalconf
.font
, argv
[optind
]);
167 geometry
.height
= globalconf
.font
->height
* 1.5;
169 if(argc
- optind
>= 2)
171 icon_geometry
= draw_get_image_size(argv
[optind
+ 1]);
172 if(icon_geometry
.width
<= 0 || icon_geometry
.height
<= 0)
173 eprint("invalid image\n");
175 geometry
.width
+= icon_geometry
.width
176 * ((double) globalconf
.font
->height
/ (double) icon_geometry
.height
);
179 sw
= simplewindow_new(disp
, DefaultScreen(disp
),
180 geometry
.x
, geometry
.y
, geometry
.width
, geometry
.height
, 0);
182 XStoreName(disp
, sw
->window
, "awmessage");
184 ctx
= draw_context_new(disp
, DefaultScreen(disp
),
185 geometry
.width
, geometry
.height
, sw
->drawable
);
187 geometry
.x
= geometry
.y
= 0;
188 draw_text(ctx
, geometry
, AlignRight
,
189 0, globalconf
.font
, argv
[optind
], globalconf
.fg
, globalconf
.bg
);
191 if(icon_geometry
.width
> 0 && icon_geometry
.height
> 0)
192 draw_image(ctx
, 0, (geometry
.height
/ 2) - (globalconf
.font
->height
/ 2),
193 globalconf
.font
->height
,
198 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
200 XMapRaised(disp
, sw
->window
);
205 XNextEvent(disp
, &ev
);
212 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
219 simplewindow_delete(sw
);
225 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80