diff --git a/Makefile b/Makefile index 0491dbb..66e89e5 100644 --- a/Makefile +++ b/Makefile @@ -113,6 +113,7 @@ dist: $(PACKAGE)-$(VERSION)/src/applets/tasks.atoms \ $(PACKAGE)-$(VERSION)/src/applets/project.conf \ $(PACKAGE)-$(VERSION)/tools/embed.c \ + $(PACKAGE)-$(VERSION)/tools/message.c \ $(PACKAGE)-$(VERSION)/tools/notify.c \ $(PACKAGE)-$(VERSION)/tools/test.c \ $(PACKAGE)-$(VERSION)/tools/Makefile \ diff --git a/tools/.cvsignore b/tools/.cvsignore index 2750338..d9e17da 100644 --- a/tools/.cvsignore +++ b/tools/.cvsignore @@ -1,3 +1,4 @@ panel-embed +panel-message panel-notify panel-test diff --git a/tools/Makefile b/tools/Makefile index 0ac34a9..a363894 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,4 +1,4 @@ -TARGETS = panel-embed panel-notify panel-test +TARGETS = panel-embed panel-message panel-notify panel-test PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -23,6 +23,13 @@ panel-embed_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) panel-embed: $(panel-embed_OBJS) $(CC) -o panel-embed $(panel-embed_OBJS) $(panel-embed_LDFLAGS) +panel-message_OBJS = message.o +panel-message_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +panel-message_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +panel-message: $(panel-message_OBJS) + $(CC) -o panel-message $(panel-message_OBJS) $(panel-message_LDFLAGS) + panel-notify_OBJS = notify.o panel-notify_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) -D PREFIX=\"$(PREFIX)\" $(CFLAGSF) $(CFLAGS) panel-notify_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) @@ -40,6 +47,9 @@ panel-test: $(panel-test_OBJS) embed.o: embed.c ../include/Panel.h ../config.h $(CC) $(panel-embed_CFLAGS) -c embed.c +message.o: message.c ../include/Panel.h + $(CC) $(panel-message_CFLAGS) -c message.c + notify.o: notify.c helper.c ../src/panel.h ../config.h $(CC) $(panel-notify_CFLAGS) -c notify.c @@ -47,7 +57,7 @@ test.o: test.c helper.c ../src/panel.h ../config.h $(CC) $(panel-test_CFLAGS) -c test.c clean: - $(RM) -- $(panel-embed_OBJS) $(panel-notify_OBJS) $(panel-test_OBJS) + $(RM) -- $(panel-embed_OBJS) $(panel-message_OBJS) $(panel-notify_OBJS) $(panel-test_OBJS) distclean: clean $(RM) -- $(TARGETS) @@ -56,10 +66,13 @@ install: $(TARGETS) $(MKDIR) $(DESTDIR)$(BINDIR) $(INSTALL) -m 0755 -- panel-embed $(DESTDIR)$(BINDIR)/panel-embed $(MKDIR) $(DESTDIR)$(BINDIR) + $(INSTALL) -m 0755 -- panel-message $(DESTDIR)$(BINDIR)/panel-message + $(MKDIR) $(DESTDIR)$(BINDIR) $(INSTALL) -m 0755 -- panel-notify $(DESTDIR)$(BINDIR)/panel-notify uninstall: $(RM) -- $(DESTDIR)$(BINDIR)/panel-embed + $(RM) -- $(DESTDIR)$(BINDIR)/panel-message $(RM) -- $(DESTDIR)$(BINDIR)/panel-notify .PHONY: all clean distclean install uninstall diff --git a/tools/message.c b/tools/message.c new file mode 100644 index 0000000..93bd513 --- /dev/null +++ b/tools/message.c @@ -0,0 +1,113 @@ +/* $Id$ */ +/* Copyright (c) 2012 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Panel */ +/* 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, version 3 of the License. + * + * 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, see . */ + + + +#include +#include +#include +#include +#include "../include/Panel.h" + + +/* private */ +/* prototypes */ +static int _message(unsigned int timeout, GtkMessageType type, + char const * message); + +/* callbacks */ +static gboolean _message_on_timeout(gpointer data); + +static int _error(char const * message, int ret); +static int _usage(void); + + +/* functions */ +/* message */ +static int _message(unsigned int timeout, GtkMessageType type, + char const * message) +{ + GtkWidget * widget; + GtkWidget * label; + uint32_t xid; + + widget = gtk_plug_new(0); + gtk_container_set_border_width(GTK_CONTAINER(widget), 4); + label = gtk_label_new(message); + gtk_container_add(GTK_CONTAINER(widget), label); + gtk_widget_show_all(widget); + xid = gtk_plug_get_id(GTK_PLUG(widget)); + desktop_message_send(PANEL_CLIENT_MESSAGE, PANEL_MESSAGE_EMBED, xid, 0); + if(timeout > 0) + g_timeout_add(timeout * 1000, _message_on_timeout, NULL); + gtk_main(); + return 0; +} + + +/* callbacks */ +/* message_on_timeout */ +static gboolean _message_on_timeout(gpointer data) +{ + gtk_main_quit(); + return FALSE; +} + + +/* error */ +static int _error(char const * message, int ret) +{ + fprintf(stderr, "%s%s\n", "panel-message: ", message); + return ret; +} + + +/* usage */ +static int _usage(void) +{ + fputs("Usage: panel-message [-T type][-t timeout] message\n", stderr); + return 1; +} + + +/* public */ +/* functions */ +/* main */ +int main(int argc, char * argv[]) +{ + GtkMessageType type = GTK_MESSAGE_INFO; + unsigned int timeout = 3; + int o; + char * p; + + gtk_init(&argc, &argv); + while((o = getopt(argc, argv, "t:T:")) != -1) + switch(o) + { + case 'T': + /* FIXME implement */ + break; + case 't': + timeout = strtoul(optarg, &p, 10); + if(optarg[0] == '\0' || *p != '\0') + return _usage(); + break; + default: + return _usage(); + } + if(argc - optind != 1) + return _usage(); + return (_message(timeout, type, argv[optind]) == 0) ? 0 : 2; +} diff --git a/tools/project.conf b/tools/project.conf index c25f4ff..a19eba4 100644 --- a/tools/project.conf +++ b/tools/project.conf @@ -1,4 +1,4 @@ -targets=panel-embed,panel-notify,panel-test +targets=panel-embed,panel-message,panel-notify,panel-test cflags_force=-W `pkg-config --cflags libSystem libDesktop` cflags=-Wall -g -O2 ldflags_force=`pkg-config --libs libSystem libDesktop` @@ -15,6 +15,11 @@ cppflags=-D PREFIX=\"$(PREFIX)\" sources=notify.c install=$(BINDIR) +[panel-message] +type=binary +sources=message.c +install=$(BINDIR) + [panel-test] type=binary cppflags=-D PREFIX=\"$(PREFIX)\" @@ -23,6 +28,9 @@ sources=test.c [embed.c] depends=../include/Panel.h,../config.h +[message.c] +depends=../include/Panel.h + [notify.c] depends=helper.c,../src/panel.h,../config.h