2008-01-26 21:41:34 +01:00
|
|
|
/*
|
2008-01-27 19:10:43 +01:00
|
|
|
* awesome-message.c - message window for awesome
|
2008-01-26 21:41:34 +01:00
|
|
|
*
|
|
|
|
* Copyright © 2008 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-01-27 01:34:37 +01:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <getopt.h>
|
2008-01-31 18:34:59 +01:00
|
|
|
|
2008-02-08 11:51:12 +01:00
|
|
|
#include <signal.h>
|
2008-01-26 21:41:34 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2008-03-19 13:11:13 +01:00
|
|
|
#include <errno.h>
|
2008-01-31 17:32:05 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
#include <xcb/xcb_atom.h>
|
2008-01-26 21:41:34 +01:00
|
|
|
|
|
|
|
#include "common/swindow.h"
|
|
|
|
#include "common/util.h"
|
2008-02-27 09:04:17 +01:00
|
|
|
#include "common/version.h"
|
2008-01-31 17:32:05 +01:00
|
|
|
#include "common/configopts.h"
|
2008-03-14 09:12:03 +01:00
|
|
|
#include "common/xscreen.h"
|
2008-01-26 21:41:34 +01:00
|
|
|
|
2008-01-29 17:24:58 +01:00
|
|
|
#define PROGNAME "awesome-message"
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
static bool running = true;
|
2008-02-08 11:51:12 +01:00
|
|
|
|
2008-01-31 17:32:05 +01:00
|
|
|
/** Import awesome config file format */
|
|
|
|
extern cfg_opt_t awesome_opts[];
|
|
|
|
|
|
|
|
/** awesome-run global configuration structure */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/** Display ref */
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_connection_t *connection;
|
|
|
|
/** Default screen number */
|
|
|
|
int default_screen;
|
2008-03-14 08:35:06 +01:00
|
|
|
/** Style */
|
|
|
|
style_t style;
|
2008-01-31 17:32:05 +01:00
|
|
|
} AwesomeMsgConf;
|
|
|
|
|
|
|
|
static AwesomeMsgConf globalconf;
|
|
|
|
|
2008-01-26 21:41:34 +01:00
|
|
|
static void __attribute__ ((noreturn))
|
|
|
|
exit_help(int exit_code)
|
|
|
|
{
|
|
|
|
FILE *outfile = (exit_code == EXIT_SUCCESS) ? stdout : stderr;
|
2008-02-08 11:51:12 +01:00
|
|
|
fprintf(outfile, "Usage: %s [-x xcoord] [-y ycoord] [-d delay] <message> <icon>\n",
|
2008-01-29 17:24:58 +01:00
|
|
|
PROGNAME);
|
2008-01-26 21:41:34 +01:00
|
|
|
exit(exit_code);
|
|
|
|
}
|
|
|
|
|
2008-03-04 20:40:37 +01:00
|
|
|
static int
|
2008-03-14 09:12:03 +01:00
|
|
|
config_parse(int screen, const char *confpatharg)
|
2008-01-31 17:32:05 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *confpath;
|
2008-03-14 08:35:06 +01:00
|
|
|
cfg_t *cfg, *cfg_screen;
|
2008-01-31 17:32:05 +01:00
|
|
|
|
|
|
|
if(!confpatharg)
|
|
|
|
confpath = config_file();
|
|
|
|
else
|
|
|
|
confpath = a_strdup(confpatharg);
|
|
|
|
|
2008-03-18 13:00:10 +01:00
|
|
|
cfg = cfg_new();
|
2008-01-31 17:32:05 +01:00
|
|
|
|
|
|
|
switch((ret = cfg_parse(cfg, confpath)))
|
|
|
|
{
|
|
|
|
case CFG_FILE_ERROR:
|
2008-03-19 13:11:13 +01:00
|
|
|
warn("parsing configuration file failed: %s\n", strerror(errno));
|
2008-01-31 17:32:05 +01:00
|
|
|
break;
|
|
|
|
case CFG_PARSE_ERROR:
|
|
|
|
cfg_error(cfg, "awesome: parsing configuration file %s failed.\n", confpath);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret)
|
2008-03-04 20:40:37 +01:00
|
|
|
return ret;
|
2008-01-31 17:32:05 +01:00
|
|
|
|
|
|
|
/* get global screen section */
|
2008-03-14 09:12:03 +01:00
|
|
|
if(!(cfg_screen = cfg_getnsec(cfg, "screen", screen)))
|
|
|
|
if(!(cfg_screen = cfg_getsec(cfg, "screen")))
|
|
|
|
eprint("parsing configuration file failed, no screen section found\n");
|
2008-01-31 17:32:05 +01:00
|
|
|
|
2008-03-14 08:35:06 +01:00
|
|
|
/* style */
|
2008-03-21 16:50:17 +01:00
|
|
|
draw_style_init(globalconf.connection, globalconf.default_screen,
|
2008-03-14 08:35:06 +01:00
|
|
|
cfg_getsec(cfg_getsec(cfg_screen, "styles"), "normal"),
|
|
|
|
&globalconf.style, NULL);
|
2008-01-31 17:32:05 +01:00
|
|
|
|
2008-03-14 08:35:06 +01:00
|
|
|
if(!globalconf.style.font)
|
|
|
|
eprint("no default font available\n");
|
2008-01-31 17:32:05 +01:00
|
|
|
|
|
|
|
p_delete(&confpath);
|
2008-03-04 20:40:37 +01:00
|
|
|
|
|
|
|
return ret;
|
2008-01-31 17:32:05 +01:00
|
|
|
}
|
|
|
|
|
2008-02-08 11:51:12 +01:00
|
|
|
static void
|
|
|
|
exit_on_signal(int sig __attribute__ ((unused)))
|
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
running = false;
|
2008-02-08 11:51:12 +01:00
|
|
|
}
|
|
|
|
|
2008-01-26 21:41:34 +01:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2008-04-09 19:41:28 +02:00
|
|
|
simple_window_t *sw;
|
2008-04-28 15:32:30 +02:00
|
|
|
draw_context_t *ctx;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_generic_event_t *ev;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t geometry = { 0, 0, 200, 50, NULL, NULL },
|
2008-03-10 10:37:23 +01:00
|
|
|
icon_geometry = { -1, -1, -1, -1, NULL, NULL };
|
2008-03-21 16:50:17 +01:00
|
|
|
int opt, ret, screen = 0, delay = 0;
|
|
|
|
xcb_query_pointer_reply_t *xqp = NULL;
|
2008-01-31 17:32:05 +01:00
|
|
|
char *configfile = NULL;
|
2008-03-14 09:12:03 +01:00
|
|
|
ScreensInfo *si;
|
2008-01-31 17:32:05 +01:00
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
2008-01-29 17:20:32 +01:00
|
|
|
{"help", 0, NULL, 'h'},
|
|
|
|
{"version", 0, NULL, 'v'},
|
|
|
|
{NULL, 0, NULL, 0}
|
2008-01-27 01:34:37 +01:00
|
|
|
};
|
2008-01-26 21:41:34 +01:00
|
|
|
|
2008-02-08 11:51:12 +01:00
|
|
|
while((opt = getopt_long(argc, argv, "vhf:b:x:y:n:c:d:",
|
2008-01-31 18:34:59 +01:00
|
|
|
long_options, NULL)) != -1)
|
2008-01-26 21:41:34 +01:00
|
|
|
switch(opt)
|
|
|
|
{
|
2008-02-08 11:51:12 +01:00
|
|
|
case 'd':
|
2008-03-23 20:25:21 +01:00
|
|
|
if((delay = atoi(optarg)) <= 0)
|
|
|
|
delay = 1;
|
2008-02-08 11:51:12 +01:00
|
|
|
break;
|
2008-01-26 21:41:34 +01:00
|
|
|
case 'v':
|
2008-01-29 17:24:58 +01:00
|
|
|
eprint_version(PROGNAME);
|
2008-01-26 21:41:34 +01:00
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
geometry.x = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
geometry.y = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
exit_help(EXIT_SUCCESS);
|
|
|
|
break;
|
2008-01-31 17:32:05 +01:00
|
|
|
case 'c':
|
|
|
|
configfile = a_strdup(optarg);
|
2008-01-26 21:41:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(argc - optind < 1)
|
|
|
|
exit_help(EXIT_FAILURE);
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
globalconf.connection = xcb_connect(NULL, &globalconf.default_screen);
|
|
|
|
if(xcb_connection_has_error(globalconf.connection))
|
2008-03-25 16:56:47 +01:00
|
|
|
eprint("unable to open display");
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
si = screensinfo_new(globalconf.connection);
|
2008-03-14 09:12:03 +01:00
|
|
|
if(si->xinerama_is_active)
|
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
if((xqp = xcb_query_pointer_reply(globalconf.connection,
|
|
|
|
xcb_query_pointer(globalconf.connection,
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_aux_get_screen(globalconf.connection,
|
|
|
|
globalconf.default_screen)->root),
|
2008-03-21 16:50:17 +01:00
|
|
|
NULL)) != NULL)
|
|
|
|
{
|
|
|
|
screen = screen_get_bycoord(si, 0, xqp->root_x, xqp->root_y);
|
|
|
|
p_delete(&xqp);
|
|
|
|
}
|
2008-03-14 09:12:03 +01:00
|
|
|
}
|
|
|
|
else
|
2008-03-21 16:50:17 +01:00
|
|
|
screen = globalconf.default_screen;
|
2008-03-14 09:12:03 +01:00
|
|
|
|
|
|
|
if((ret = config_parse(screen, configfile)))
|
2008-03-04 20:40:37 +01:00
|
|
|
return ret;
|
2008-01-26 21:41:34 +01:00
|
|
|
|
2008-04-23 17:44:09 +02:00
|
|
|
geometry.width = draw_text_extents(globalconf.connection, globalconf.default_screen,
|
|
|
|
globalconf.style.font, argv[optind]).width;
|
2008-03-14 08:35:06 +01:00
|
|
|
geometry.height = globalconf.style.font->height * 1.5;
|
2008-01-27 01:34:37 +01:00
|
|
|
|
2008-01-26 21:41:34 +01:00
|
|
|
if(argc - optind >= 2)
|
|
|
|
{
|
2008-03-19 17:51:12 +01:00
|
|
|
icon_geometry = draw_get_image_size(argv[optind + 1]);
|
2008-01-26 21:41:34 +01:00
|
|
|
if(icon_geometry.width <= 0 || icon_geometry.height <= 0)
|
|
|
|
eprint("invalid image\n");
|
|
|
|
else
|
2008-01-31 17:32:05 +01:00
|
|
|
geometry.width += icon_geometry.width
|
2008-03-14 08:35:06 +01:00
|
|
|
* ((double) globalconf.style.font->height / (double) icon_geometry.height);
|
2008-01-26 21:41:34 +01:00
|
|
|
}
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
sw = simplewindow_new(globalconf.connection, globalconf.default_screen,
|
2008-01-26 21:41:34 +01:00
|
|
|
geometry.x, geometry.y, geometry.width, geometry.height, 0);
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, sw->window,
|
|
|
|
WM_NAME, STRING, 8, strlen(PROGNAME), PROGNAME);
|
2008-01-26 21:41:34 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
ctx = draw_context_new(globalconf.connection, globalconf.default_screen,
|
2008-01-26 21:41:34 +01:00
|
|
|
geometry.width, geometry.height, sw->drawable);
|
|
|
|
|
|
|
|
geometry.x = geometry.y = 0;
|
2008-04-28 14:53:32 +02:00
|
|
|
draw_text(ctx, geometry, argv[optind], globalconf.style);
|
2008-01-26 21:41:34 +01:00
|
|
|
|
|
|
|
if(icon_geometry.width > 0 && icon_geometry.height > 0)
|
2008-03-14 08:35:06 +01:00
|
|
|
draw_image(ctx, 0, (geometry.height / 2) - (globalconf.style.font->height / 2),
|
|
|
|
globalconf.style.font->height, argv[optind + 1]);
|
2008-01-26 21:41:34 +01:00
|
|
|
|
|
|
|
p_delete(&ctx);
|
|
|
|
|
2008-04-09 14:17:08 +02:00
|
|
|
xcb_map_window(globalconf.connection, sw->window);
|
2008-04-09 19:40:32 +02:00
|
|
|
simplewindow_refresh_drawable(sw);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_aux_sync(globalconf.connection);
|
2008-01-26 21:41:34 +01:00
|
|
|
|
2008-02-08 11:51:12 +01:00
|
|
|
signal(SIGALRM, &exit_on_signal);
|
|
|
|
alarm(delay);
|
|
|
|
|
|
|
|
while(running)
|
2008-01-26 21:41:34 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
while((ev = xcb_poll_for_event(globalconf.connection)))
|
2008-01-26 21:41:34 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
/* Skip errors */
|
|
|
|
if(ev->response_type == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch(ev->response_type & 0x7f)
|
2008-02-08 11:51:12 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
case XCB_BUTTON_PRESS:
|
|
|
|
case XCB_KEY_PRESS:
|
|
|
|
running = false;
|
|
|
|
case XCB_EXPOSE:
|
2008-04-09 19:40:32 +02:00
|
|
|
simplewindow_refresh_drawable(sw);
|
2008-02-08 11:51:12 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
p_delete(&ev);
|
2008-01-26 21:41:34 +01:00
|
|
|
}
|
2008-03-20 18:30:28 +01:00
|
|
|
usleep(100000);
|
2008-01-26 21:41:34 +01:00
|
|
|
}
|
|
|
|
|
2008-03-21 11:26:56 +01:00
|
|
|
simplewindow_delete(&sw);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_disconnect(globalconf.connection);
|
2008-01-26 21:41:34 +01:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|