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/awesome-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 */
58 static AwesomeMsgConf globalconf
;
60 static void __attribute__ ((noreturn
))
61 exit_help(int exit_code
)
63 FILE *outfile
= (exit_code
== EXIT_SUCCESS
) ? stdout
: stderr
;
64 fprintf(outfile
, "Usage: %s [-x xcoord] [-y ycoord] [-d delay] <message> <icon>\n",
70 config_parse(const char *confpatharg
)
74 cfg_t
*cfg
, *cfg_screen
, *cfg_general
, *cfg_colors
;
77 confpath
= config_file();
79 confpath
= a_strdup(confpatharg
);
81 cfg
= cfg_init(awesome_opts
, CFGF_NONE
);
83 switch((ret
= cfg_parse(cfg
, confpath
)))
86 perror("awesome-message: parsing configuration file failed");
89 cfg_error(cfg
, "awesome: parsing configuration file %s failed.\n", confpath
);
96 /* get global screen section */
97 cfg_screen
= cfg_getsec(cfg
, "screen");
100 eprint("parsing configuration file failed, no screen section found\n");
102 /* get colors and general section */
103 cfg_general
= cfg_getsec(cfg_screen
, "general");
104 cfg_colors
= cfg_getsec(cfg_screen
, "colors");
107 draw_color_new(globalconf
.display
, DefaultScreen(globalconf
.display
),
108 cfg_getstr(cfg_colors
, "normal_fg"),
110 draw_color_new(globalconf
.display
, DefaultScreen(globalconf
.display
),
111 cfg_getstr(cfg_colors
, "normal_bg"),
115 globalconf
.font
= XftFontOpenName(globalconf
.display
, DefaultScreen(globalconf
.display
),
116 cfg_getstr(cfg_general
, "font"));
122 exit_on_signal(int sig
__attribute__ ((unused
)))
128 main(int argc
, char **argv
)
134 Area geometry
= { 0, 0, 200, 50, NULL
},
135 icon_geometry
= { -1, -1, -1, -1, NULL
};
138 char *configfile
= NULL
;
139 static struct option long_options
[] =
141 {"help", 0, NULL
, 'h'},
142 {"version", 0, NULL
, 'v'},
146 if(!(disp
= XOpenDisplay(NULL
)))
147 eprint("unable to open display");
149 globalconf
.display
= disp
;
151 while((opt
= getopt_long(argc
, argv
, "vhf:b:x:y:n:c:d:",
152 long_options
, NULL
)) != -1)
156 delay
= atoi(optarg
);
159 eprint_version(PROGNAME
);
162 geometry
.x
= atoi(optarg
);
165 geometry
.y
= atoi(optarg
);
168 exit_help(EXIT_SUCCESS
);
171 configfile
= a_strdup(optarg
);
175 if(argc
- optind
< 1)
176 exit_help(EXIT_FAILURE
);
178 config_parse(configfile
);
180 geometry
.width
= draw_textwidth(disp
, globalconf
.font
, argv
[optind
]);
181 geometry
.height
= globalconf
.font
->height
* 1.5;
183 if(argc
- optind
>= 2)
185 icon_geometry
= draw_get_image_size(argv
[optind
+ 1]);
186 if(icon_geometry
.width
<= 0 || icon_geometry
.height
<= 0)
187 eprint("invalid image\n");
189 geometry
.width
+= icon_geometry
.width
190 * ((double) globalconf
.font
->height
/ (double) icon_geometry
.height
);
193 sw
= simplewindow_new(disp
, DefaultScreen(disp
),
194 geometry
.x
, geometry
.y
, geometry
.width
, geometry
.height
, 0);
196 XStoreName(disp
, sw
->window
, PROGNAME
);
198 ctx
= draw_context_new(disp
, DefaultScreen(disp
),
199 geometry
.width
, geometry
.height
, sw
->drawable
);
201 geometry
.x
= geometry
.y
= 0;
202 draw_text(ctx
, geometry
, AlignRight
,
203 0, globalconf
.font
, argv
[optind
], globalconf
.fg
, globalconf
.bg
);
205 if(icon_geometry
.width
> 0 && icon_geometry
.height
> 0)
206 draw_image(ctx
, 0, (geometry
.height
/ 2) - (globalconf
.font
->height
/ 2),
207 globalconf
.font
->height
,
212 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
214 XMapRaised(disp
, sw
->window
);
217 signal(SIGALRM
, &exit_on_signal
);
224 XNextEvent(disp
, &ev
);
231 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
240 simplewindow_delete(sw
);
246 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80