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/version.h"
35 #include "common/configopts.h"
36 #include "common/xscreen.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 */
54 static AwesomeMsgConf globalconf
;
56 static void __attribute__ ((noreturn
))
57 exit_help(int exit_code
)
59 FILE *outfile
= (exit_code
== EXIT_SUCCESS
) ? stdout
: stderr
;
60 fprintf(outfile
, "Usage: %s [-x xcoord] [-y ycoord] [-d delay] <message> <icon>\n",
66 config_parse(int screen
, const char *confpatharg
)
70 cfg_t
*cfg
, *cfg_screen
;
73 confpath
= config_file();
75 confpath
= a_strdup(confpatharg
);
79 switch((ret
= cfg_parse(cfg
, confpath
)))
82 warn("parsing configuration file failed: %s\n", strerror(errno
));
85 cfg_error(cfg
, "awesome: parsing configuration file %s failed.\n", confpath
);
92 /* get global screen section */
93 if(!(cfg_screen
= cfg_getnsec(cfg
, "screen", screen
)))
94 if(!(cfg_screen
= cfg_getsec(cfg
, "screen")))
95 eprint("parsing configuration file failed, no screen section found\n");
98 draw_style_init(globalconf
.display
, DefaultScreen(globalconf
.display
),
99 cfg_getsec(cfg_getsec(cfg_screen
, "styles"), "normal"),
100 &globalconf
.style
, NULL
);
102 if(!globalconf
.style
.font
)
103 eprint("no default font available\n");
111 exit_on_signal(int sig
__attribute__ ((unused
)))
117 main(int argc
, char **argv
)
122 area_t geometry
= { 0, 0, 200, 50, NULL
, NULL
},
123 icon_geometry
= { -1, -1, -1, -1, NULL
, NULL
};
124 int opt
, i
, x
, y
, ret
, screen
= 0, delay
= 0;
126 char *configfile
= NULL
;
129 static struct option long_options
[] =
131 {"help", 0, NULL
, 'h'},
132 {"version", 0, NULL
, 'v'},
136 while((opt
= getopt_long(argc
, argv
, "vhf:b:x:y:n:c:d:",
137 long_options
, NULL
)) != -1)
141 if((delay
= atoi(optarg
)) <= 0)
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 if(!(globalconf
.display
= XOpenDisplay(NULL
)))
165 eprint("unable to open display");
167 si
= screensinfo_new(globalconf
.display
);
168 if(si
->xinerama_is_active
)
170 if(XQueryPointer(globalconf
.display
, RootWindow(globalconf
.display
, DefaultScreen(globalconf
.display
)),
171 &dummy
, &dummy
, &x
, &y
, &i
, &i
, &ui
))
172 screen
= screen_get_bycoord(si
, 0, x
, y
);
175 screen
= DefaultScreen(globalconf
.display
);
177 if((ret
= config_parse(screen
, configfile
)))
180 geometry
.width
= draw_textwidth(globalconf
.display
, globalconf
.style
.font
, argv
[optind
]);
181 geometry
.height
= globalconf
.style
.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
.style
.font
->height
/ (double) icon_geometry
.height
);
193 sw
= simplewindow_new(globalconf
.display
, DefaultScreen(globalconf
.display
),
194 geometry
.x
, geometry
.y
, geometry
.width
, geometry
.height
, 0);
196 XStoreName(globalconf
.display
, sw
->window
, PROGNAME
);
198 ctx
= draw_context_new(globalconf
.display
, DefaultScreen(globalconf
.display
),
199 geometry
.width
, geometry
.height
, sw
->drawable
);
201 geometry
.x
= geometry
.y
= 0;
202 draw_text(ctx
, geometry
, AlignRight
, 0,argv
[optind
], globalconf
.style
);
204 if(icon_geometry
.width
> 0 && icon_geometry
.height
> 0)
205 draw_image(ctx
, 0, (geometry
.height
/ 2) - (globalconf
.style
.font
->height
/ 2),
206 globalconf
.style
.font
->height
, argv
[optind
+ 1]);
210 simplewindow_refresh_drawable(sw
, DefaultScreen(globalconf
.display
));
212 XMapRaised(globalconf
.display
, sw
->window
);
213 XSync(globalconf
.display
, False
);
215 signal(SIGALRM
, &exit_on_signal
);
220 if(XPending(globalconf
.display
))
222 XNextEvent(globalconf
.display
, &ev
);
229 simplewindow_refresh_drawable(sw
, DefaultScreen(globalconf
.display
));
238 simplewindow_delete(&sw
);
239 XCloseDisplay(globalconf
.display
);
244 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80