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"
37 #include "common/xscreen.h"
39 #define PROGNAME "awesome-message"
41 static Bool running
= True
;
43 /** Import awesome config file format */
44 extern cfg_opt_t awesome_opts
[];
46 /** awesome-run global configuration structure */
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] [-d delay] <message> <icon>\n",
67 config_parse(int screen
, const char *confpatharg
)
71 cfg_t
*cfg
, *cfg_screen
;
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 if(!(cfg_screen
= cfg_getnsec(cfg
, "screen", screen
)))
95 if(!(cfg_screen
= cfg_getsec(cfg
, "screen")))
96 eprint("parsing configuration file failed, no screen section found\n");
99 draw_style_init(globalconf
.display
, DefaultScreen(globalconf
.display
),
100 cfg_getsec(cfg_getsec(cfg_screen
, "styles"), "normal"),
101 &globalconf
.style
, NULL
);
103 if(!globalconf
.style
.font
)
104 eprint("no default font available\n");
112 exit_on_signal(int sig
__attribute__ ((unused
)))
118 main(int argc
, char **argv
)
124 Area geometry
= { 0, 0, 200, 50, NULL
, NULL
},
125 icon_geometry
= { -1, -1, -1, -1, NULL
, NULL
};
126 int opt
, i
, x
, y
, ret
, screen
= 0, delay
= 0;
128 char *configfile
= NULL
;
131 static struct option long_options
[] =
133 {"help", 0, NULL
, 'h'},
134 {"version", 0, NULL
, 'v'},
138 if(!(disp
= XOpenDisplay(NULL
)))
139 eprint("unable to open display");
141 globalconf
.display
= disp
;
143 while((opt
= getopt_long(argc
, argv
, "vhf:b:x:y:n:c:d:",
144 long_options
, NULL
)) != -1)
148 delay
= atoi(optarg
);
151 eprint_version(PROGNAME
);
154 geometry
.x
= atoi(optarg
);
157 geometry
.y
= atoi(optarg
);
160 exit_help(EXIT_SUCCESS
);
163 configfile
= a_strdup(optarg
);
167 if(argc
- optind
< 1)
168 exit_help(EXIT_FAILURE
);
170 si
= screensinfo_new(disp
);
171 if(si
->xinerama_is_active
)
173 if(XQueryPointer(disp
, RootWindow(disp
, DefaultScreen(disp
)),
174 &dummy
, &dummy
, &x
, &y
, &i
, &i
, &ui
))
175 screen
= screen_get_bycoord(si
, 0, x
, y
);
178 screen
= DefaultScreen(disp
);
180 if((ret
= config_parse(screen
, configfile
)))
183 geometry
.width
= draw_textwidth(disp
, globalconf
.style
.font
, argv
[optind
]);
184 geometry
.height
= globalconf
.style
.font
->height
* 1.5;
186 if(argc
- optind
>= 2)
188 icon_geometry
= draw_get_image_size(argv
[optind
+ 1]);
189 if(icon_geometry
.width
<= 0 || icon_geometry
.height
<= 0)
190 eprint("invalid image\n");
192 geometry
.width
+= icon_geometry
.width
193 * ((double) globalconf
.style
.font
->height
/ (double) icon_geometry
.height
);
196 sw
= simplewindow_new(disp
, DefaultScreen(disp
),
197 geometry
.x
, geometry
.y
, geometry
.width
, geometry
.height
, 0);
199 XStoreName(disp
, sw
->window
, PROGNAME
);
201 ctx
= draw_context_new(disp
, DefaultScreen(disp
),
202 geometry
.width
, geometry
.height
, sw
->drawable
);
204 geometry
.x
= geometry
.y
= 0;
205 draw_text(ctx
, geometry
, AlignRight
, 0,argv
[optind
], globalconf
.style
);
207 if(icon_geometry
.width
> 0 && icon_geometry
.height
> 0)
208 draw_image(ctx
, 0, (geometry
.height
/ 2) - (globalconf
.style
.font
->height
/ 2),
209 globalconf
.style
.font
->height
, argv
[optind
+ 1]);
213 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
215 XMapRaised(disp
, sw
->window
);
218 signal(SIGALRM
, &exit_on_signal
);
225 XNextEvent(disp
, &ev
);
232 simplewindow_refresh_drawable(sw
, DefaultScreen(disp
));
241 simplewindow_delete(sw
);
247 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80