* daemonization support

* better placement, alhough this can be improved
* resizing support if text is larger than window
This commit is contained in:
Sanel Zukan 2012-05-10 11:09:35 +00:00
parent 9635713236
commit 3cc94e7060
3 changed files with 101 additions and 27 deletions

View File

@ -41,15 +41,13 @@ NotifyWindow::NotifyWindow() : Fl_Window(DEFAULT_W, DEFAULT_H) {
imgbox = new Fl_Box(10, 10, 48, 48); imgbox = new Fl_Box(10, 10, 48, 48);
imgbox->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); imgbox->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
summary = new Fl_Output(65, 10, 185, 25); summary = new Fl_Multiline_Output(65, 10, 185, 25);
/* use flat box so text can be drawn correctly */ /* use flat box so text can be drawn correctly */
summary->box(FL_FLAT_BOX); summary->box(FL_FLAT_BOX);
summary->cursor_color(FL_BACKGROUND2_COLOR);
body = new Fl_Output(65, 31, 185, 25); body = new Fl_Multiline_Output(65, 31, 185, 25);
/* use flat box so text can be drawn correctly */ /* use flat box so text can be drawn correctly */
body->box(FL_FLAT_BOX); body->box(FL_FLAT_BOX);
body->cursor_color(FL_BACKGROUND2_COLOR);
end(); end();
border(0); border(0);
} }
@ -61,22 +59,6 @@ void NotifyWindow::set_icon(const char *img) {
IconLoader::set(imgbox, img, ICON_SIZE_MEDIUM); IconLoader::set(imgbox, img, ICON_SIZE_MEDIUM);
} }
void NotifyWindow::set_summary(const char *s) {
E_ASSERT(s != NULL && "Got NULL string?");
summary->value(s);
int W = 0, H = 0;
fl_measure(summary->value(), W, H);
}
void NotifyWindow::set_body(const char *s) {
E_ASSERT(s != NULL && "Got NULL string?");
body->value(s);
int W = 0, H = 0;
fl_measure(summary->value(), W, H);
}
void NotifyWindow::show(void) { void NotifyWindow::show(void) {
if(exp != 0) { if(exp != 0) {
if(exp == -1) exp = DEFAULT_EXPIRE; if(exp == -1) exp = DEFAULT_EXPIRE;
@ -85,3 +67,66 @@ void NotifyWindow::show(void) {
Fl_Window::show(); Fl_Window::show();
} }
void NotifyWindow::resize(int X, int Y, int W, int H) {
/* resize summary if needed */
if(summary->value()) {
int fw = 0, fh = 0;
fl_font(summary->textfont(), summary->textsize());
fl_measure(summary->value(), fw, fh);
if(fw > summary->w()) {
int d = fw - summary->w();
summary->size(fw, summary->h());
/* move X button */
closeb->position(closeb->x() + d, closeb->y());
/* resize body too */
body->size(body->w() + d, body->h());
W += d;
/* this depends on window position */
X -= d;
}
if(fh > summary->h()) {
int d = fh - summary->h();
summary->size(summary->w(), fh);
/* move body down */
body->position(body->x(), body->y() + d);
H += d;
Y -= d;
}
}
/* resize body if needed */
if(body->value()) {
int fw = 0, fh = 0;
fl_font(body->textfont(), body->textsize());
fl_measure(body->value(), fw, fh);
if(fw > body->w()) {
int d = fw - body->w();
body->size(fw, body->h());
/* move X button again */
closeb->position(closeb->x() + d, closeb->y());
W += d;
X -= d;
}
if(fh > body->h()) {
int d = fh - body->h();
body->size(body->w(), fh);
H += d;
Y -= d;
}
}
Fl_Window::resize(X, Y, W, H);
}

View File

@ -4,19 +4,17 @@
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <FL/Fl_Button.H> #include <FL/Fl_Button.H>
#include <FL/Fl_Box.H> #include <FL/Fl_Box.H>
#include <FL/Fl_Output.H> #include <FL/Fl_Multiline_Output.H>
/* just keep it greater than FL_WINDOW or FL_DOUBLE_WINDOW */ /* just keep it greater than FL_WINDOW or FL_DOUBLE_WINDOW */
#define NOTIFYWINDOW_TYPE 0xF9 #define NOTIFYWINDOW_TYPE 0xF9
class NotifyWindow : public Fl_Window { class NotifyWindow : public Fl_Window {
private: private:
int id; int id, exp;
int exp;
Fl_Button *closeb; Fl_Button *closeb;
Fl_Box *imgbox; Fl_Box *imgbox;
Fl_Output *summary; Fl_Multiline_Output *summary, *body;
Fl_Output *body;
public: public:
NotifyWindow(); NotifyWindow();
@ -25,8 +23,8 @@ public:
int get_id(void) { return id; } int get_id(void) { return id; }
void set_icon(const char *img); void set_icon(const char *img);
void set_summary(const char *s); void set_summary(const char *s) { summary->value(s); }
void set_body(const char *s); void set_body(const char *s) { body->value(s); }
/* /*
* match to spec: if is -1, then we handle it, if is 0, then window will not be closed and * match to spec: if is -1, then we handle it, if is 0, then window will not be closed and
@ -34,6 +32,8 @@ public:
*/ */
void set_expire(int t) { exp = t; } void set_expire(int t) { exp = t; }
void show(void); void show(void);
virtual void resize(int X, int Y, int W, int H);
}; };
#endif #endif

View File

@ -4,6 +4,8 @@
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/Fl_Shared_Image.H> #include <FL/Fl_Shared_Image.H>
#include <edelib/Ede.h>
#include <edelib/Debug.h> #include <edelib/Debug.h>
#include <edelib/EdbusConnection.h> #include <edelib/EdbusConnection.h>
#include <edelib/EdbusMessage.h> #include <edelib/EdbusMessage.h>
@ -12,6 +14,7 @@
#include <edelib/EdbusDict.h> #include <edelib/EdbusDict.h>
#include <edelib/IconLoader.h> #include <edelib/IconLoader.h>
#include <edelib/Netwm.h> #include <edelib/Netwm.h>
#include <edelib/Missing.h>
#include "NotifyWindow.h" #include "NotifyWindow.h"
@ -36,6 +39,7 @@
#define WINDOWS_PADDING 10 #define WINDOWS_PADDING 10
#define IS_MEMBER(m, s1) (strcmp((m->member()), (s1)) == 0) #define IS_MEMBER(m, s1) (strcmp((m->member()), (s1)) == 0)
#define CHECK_ARGV(argv, pshort, plong) ((strcmp(argv, pshort) == 0) || (strcmp(argv, plong) == 0))
EDELIB_NS_USING(EdbusConnection) EDELIB_NS_USING(EdbusConnection)
EDELIB_NS_USING(EdbusMessage) EDELIB_NS_USING(EdbusMessage)
@ -278,7 +282,30 @@ static int notifications_dbus_signal_cb(const EdbusMessage *m, void *d) {
} }
#endif #endif
static void help(void) {
puts("Usage: ede-notify-daemon [OPTIONS]");
puts("Background service responsible for displaying various notifications");
puts("Options:");
puts(" -h, --help this help");
puts(" -n, --no-daemon do not run in background");
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
/* daemon behaves as GUI app, as will use icon theme and etc. */
EDE_APPLICATION("ede-notify-daemon");
bool daemonize = true;
if(argc > 1) {
if(CHECK_ARGV(argv[1], "-h", "--help")) {
help();
return 0;
}
if(CHECK_ARGV(argv[1], "-n", "--no-daemon")) {
daemonize = false;
}
}
server_running = false; server_running = false;
notify_id = 0; notify_id = 0;
EdbusConnection dbus; EdbusConnection dbus;
@ -297,6 +324,8 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
if(daemonize) edelib_daemon(0, 0);
dbus.register_object(NOTIFICATIONS_DBUS_PATH); dbus.register_object(NOTIFICATIONS_DBUS_PATH);
dbus.method_callback(notifications_dbus_method_cb, &dbus); dbus.method_callback(notifications_dbus_method_cb, &dbus);
//dbus.signal_callback(notifications_dbus_signal_cb, &dbus); //dbus.signal_callback(notifications_dbus_signal_cb, &dbus);