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-26 21:41:34 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
|
|
#include "common/swindow.h"
|
|
|
|
#include "common/util.h"
|
|
|
|
#include "common/awesome-version.h"
|
|
|
|
|
2008-01-29 17:24:58 +01:00
|
|
|
#define PROGNAME "awesome-message"
|
|
|
|
|
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-01-29 17:24:58 +01:00
|
|
|
fprintf(outfile, "Usage: %s [-x xcoord] [-y ycoord] [-f fgcolor] [-b bgcolor] <message> <icon>\n",
|
|
|
|
PROGNAME);
|
2008-01-26 21:41:34 +01:00
|
|
|
exit(exit_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
Display *disp;
|
|
|
|
SimpleWindow *sw;
|
|
|
|
DrawCtx *ctx;
|
2008-01-27 18:59:12 +01:00
|
|
|
XColor fg, bg;
|
2008-01-26 21:41:34 +01:00
|
|
|
XEvent ev;
|
2008-01-27 18:55:03 +01:00
|
|
|
Bool running = True;
|
2008-01-26 21:41:34 +01:00
|
|
|
const char *fg_color = "#000000";
|
|
|
|
const char *bg_color = "#ffffff";
|
|
|
|
int opt;
|
2008-01-28 18:30:23 +01:00
|
|
|
Area geometry = { 0, 0, 200, 50, NULL },
|
|
|
|
icon_geometry = { -1, -1, -1, -1, NULL };
|
2008-01-26 21:41:34 +01:00
|
|
|
XftFont *font = NULL;
|
2008-01-27 01:34:37 +01:00
|
|
|
int option_index = 0;
|
|
|
|
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
|
|
|
|
|
|
|
if(!(disp = XOpenDisplay(NULL)))
|
|
|
|
eprint("unable to open display");
|
|
|
|
|
2008-01-27 01:34:37 +01:00
|
|
|
while((opt = getopt_long(argc, argv, "vhf:b:x:y:n:",
|
|
|
|
long_options, &option_index)) != -1)
|
2008-01-26 21:41:34 +01:00
|
|
|
switch(opt)
|
|
|
|
{
|
|
|
|
case 'v':
|
2008-01-29 17:24:58 +01:00
|
|
|
eprint_version(PROGNAME);
|
2008-01-26 21:41:34 +01:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
fg_color = a_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
bg_color = a_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
geometry.x = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
geometry.y = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
exit_help(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
font = XftFontOpenName(disp, DefaultScreen(disp), optarg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(argc - optind < 1)
|
|
|
|
exit_help(EXIT_FAILURE);
|
|
|
|
|
|
|
|
if(!font)
|
|
|
|
font = XftFontOpenName(disp, DefaultScreen(disp), "vera-12");
|
|
|
|
|
|
|
|
geometry.width = draw_textwidth(disp, font, argv[optind]);
|
|
|
|
geometry.height = font->height * 1.5;
|
2008-01-27 01:34:37 +01:00
|
|
|
|
2008-01-26 21:41:34 +01:00
|
|
|
if(argc - optind >= 2)
|
|
|
|
{
|
|
|
|
icon_geometry = draw_get_image_size(argv[optind + 1]);
|
|
|
|
if(icon_geometry.width <= 0 || icon_geometry.height <= 0)
|
|
|
|
eprint("invalid image\n");
|
|
|
|
else
|
|
|
|
geometry.width += icon_geometry.width * ((double) font->height / (double) icon_geometry.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
sw = simplewindow_new(disp, DefaultScreen(disp),
|
|
|
|
geometry.x, geometry.y, geometry.width, geometry.height, 0);
|
|
|
|
|
|
|
|
XStoreName(disp, sw->window, "awmessage");
|
|
|
|
|
2008-01-27 19:02:08 +01:00
|
|
|
ctx = draw_context_new(disp, DefaultScreen(disp),
|
2008-01-26 21:41:34 +01:00
|
|
|
geometry.width, geometry.height, sw->drawable);
|
|
|
|
|
|
|
|
|
2008-01-27 18:59:12 +01:00
|
|
|
bg = draw_color_new(disp, DefaultScreen(disp), bg_color);
|
|
|
|
fg = draw_color_new(disp, DefaultScreen(disp), fg_color);
|
2008-01-26 21:41:34 +01:00
|
|
|
|
|
|
|
geometry.x = geometry.y = 0;
|
|
|
|
draw_text(ctx, geometry, AlignRight,
|
|
|
|
0, font, argv[optind], fg, bg);
|
|
|
|
|
|
|
|
if(icon_geometry.width > 0 && icon_geometry.height > 0)
|
|
|
|
draw_image(ctx, 0, (geometry.height / 2) - (font->height / 2),
|
|
|
|
font->height,
|
|
|
|
argv[optind + 1]);
|
|
|
|
|
|
|
|
p_delete(&ctx);
|
|
|
|
|
|
|
|
simplewindow_refresh_drawable(sw, DefaultScreen(disp));
|
|
|
|
|
|
|
|
XMapRaised(disp, sw->window);
|
|
|
|
XSync(disp, False);
|
|
|
|
|
2008-01-27 18:55:03 +01:00
|
|
|
while (running)
|
2008-01-26 21:41:34 +01:00
|
|
|
{
|
|
|
|
XNextEvent(disp, &ev);
|
|
|
|
switch (ev.type)
|
|
|
|
{
|
|
|
|
case ButtonPress:
|
|
|
|
case KeyPress:
|
2008-01-27 18:55:03 +01:00
|
|
|
running = False;
|
2008-01-26 21:41:34 +01:00
|
|
|
case Expose:
|
|
|
|
simplewindow_refresh_drawable(sw, DefaultScreen(disp));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
simplewindow_delete(sw);
|
|
|
|
XCloseDisplay(disp);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|