diff --git a/ede-panel/applets/system-tray/Jamfile b/ede-panel/applets/system-tray/Jamfile index 2d34238..ece2258 100644 --- a/ede-panel/applets/system-tray/Jamfile +++ b/ede-panel/applets/system-tray/Jamfile @@ -10,4 +10,4 @@ SubDir TOP ede-panel applets system-tray ; -PanelApplet system_tray : Tray.cpp TrayWindow.cpp ; +PanelApplet system_tray : Tray.cpp ; diff --git a/ede-panel/applets/system-tray/Tray.cpp b/ede-panel/applets/system-tray/Tray.cpp index 9a742b7..a9aa161 100644 --- a/ede-panel/applets/system-tray/Tray.cpp +++ b/ede-panel/applets/system-tray/Tray.cpp @@ -1,20 +1,23 @@ #include #define FL_LIBRARY 1 #include +#include #include -#include #include "Applet.h" #include "Panel.h" #include "Tray.h" -#include "TrayWindow.h" #define SYSTEM_TRAY_REQUEST_DOCK 0 #define SYSTEM_TRAY_BEGIN_MESSAGE 1 #define SYSTEM_TRAY_CANCEL_MESSAGE 2 -EDELIB_NS_USING(netwm_window_get_icon) -EDELIB_NS_USING(netwm_window_get_title) +/* dimenstions of tray items */ +#define TRAY_ICON_W 25 +#define TRAY_ICON_H 25 + +/* space between tray icons */ +#define TRAY_ICONS_SPACE 5 /* multiple tray's are not allowed anyways so this can work */ Tray *curr_tray = 0; @@ -45,9 +48,8 @@ static int handle_xevent(int e) { return false; } -Tray::Tray() : Fl_Group(0, 0, 5, 25), opcode(0) { +Tray::Tray() : Fl_Group(0, 0, 1, 25), opcode(0) { box(FL_FLAT_BOX); - color(FL_RED); register_notification_area(); } @@ -60,6 +62,17 @@ Tray::~Tray() { XSetSelectionOwner(fl_display, sel, None, CurrentTime); } +void Tray::distribute_children(void) { + int X, Y; + + X = x(); + Y = y(); + for(int i = 0; i < children(); i++) { + child(i)->position(X, Y); + X += child(i)->w() + TRAY_ICONS_SPACE; + } +} + void Tray::register_notification_area(void) { Atom sel; char sel_name[20]; @@ -97,17 +110,16 @@ void Tray::register_notification_area(void) { } void Tray::embed_window(Window id) { - TrayWindow *win = new TrayWindow(25, 25); + Fl_Window *win = new Fl_Window(TRAY_ICON_W, TRAY_ICON_H); win->end(); - win->set_image(netwm_window_get_icon(id)); - win->set_tooltip(netwm_window_get_title(id)); add_to_tray(win); win->show(); + /* do real magic */ + XResizeWindow(fl_display, id, win->w(), win->h()); XReparentWindow(fl_display, id, fl_xid(win), 0, 0); - /* remove any pixmap from reparented window, so 'TrayWindow' can display own content */ - XSetWindowBackgroundPixmap(fl_display, id, None); + XMapWindow(fl_display, id); /* need to know when child dies */ XSelectInput(fl_display, fl_xid(win), SubstructureNotifyMask); @@ -132,22 +144,23 @@ void Tray::unembed_window(Window id) { } void Tray::add_to_tray(Fl_Widget *win) { - win->position(x(), y()); - insert(*win, 0); - int W = w() + win->w() + 5; - w(W); - + w(w() + win->w() + TRAY_ICONS_SPACE); + + distribute_children(); + redraw(); EDE_PANEL_GET_PANEL_OBJECT(this)->relayout(); } void Tray::remove_from_tray(Fl_Widget *win) { remove(win); + w(w() - win->w() - TRAY_ICONS_SPACE); - int W = w() - win->w() - 5; - w(W); + distribute_children(); + redraw(); EDE_PANEL_GET_PANEL_OBJECT(this)->relayout(); + EDE_PANEL_GET_PANEL_OBJECT(this)->redraw(); } int Tray::handle(int e) { diff --git a/ede-panel/applets/system-tray/Tray.h b/ede-panel/applets/system-tray/Tray.h index 761967f..342f347 100644 --- a/ede-panel/applets/system-tray/Tray.h +++ b/ede-panel/applets/system-tray/Tray.h @@ -19,6 +19,7 @@ class Tray : public Fl_Group { private: Atom opcode, message_data; WinList win_list; + void distribute_children(void); public: Tray(); ~Tray(); diff --git a/ede-panel/applets/system-tray/TrayWindow.cpp b/ede-panel/applets/system-tray/TrayWindow.cpp deleted file mode 100644 index 58ebc25..0000000 --- a/ede-panel/applets/system-tray/TrayWindow.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include "TrayWindow.h" - -/* scale image by keeping aspect ratio */ -static Fl_RGB_Image *aspect_scale(Fl_RGB_Image *orig, int W, int H) { - float aspect, neww, newh; - - neww = (float)orig->w(); - newh = (float)orig->h(); - - if(neww > W) { - aspect = (float)W / (float)neww; - neww *= aspect; - newh *= aspect; - } - - if(newh > H) { - aspect = (float)H / (float)newh; - neww *= aspect; - newh *= aspect; - } - - return (Fl_RGB_Image*)orig->copy((int)neww, (int)newh); -} - -TrayWindow::TrayWindow(int W, int H) : Fl_Window(W, H), img(0) { - box(FL_FLAT_BOX); - color(FL_BLUE); -} - -void TrayWindow::set_image(Fl_RGB_Image *im) { - E_RETURN_IF_FAIL(im != 0); - - /* delete previous one */ - delete img; - - /* do not use full w/h, but leave some room for few pixels around image */ - img = aspect_scale(im, w() - 2, h() - 2); -} - -void TrayWindow::draw(void) { - Fl_Window::draw(); - if(img) { - int X = w()/2 - img->w()/2; - int Y = h()/2 - img->h()/2; - img->draw(X, Y); - } -} - -void TrayWindow::set_tooltip(char *t) { - if(!t) { - ttip.clear(); - tooltip(0); - } else { - ttip = t; - tooltip(ttip.c_str()); - } -} diff --git a/ede-panel/applets/system-tray/TrayWindow.h b/ede-panel/applets/system-tray/TrayWindow.h deleted file mode 100644 index edb65fd..0000000 --- a/ede-panel/applets/system-tray/TrayWindow.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __TRAYWINDOW_H__ -#define __TRAYWINDOW_H__ - -#include -#include -#include - -EDELIB_NS_USING(String) - -/* window dedicated to displaying tray window with icon resized to window size */ -class TrayWindow : public Fl_Window { -private: - Fl_RGB_Image *img; - String ttip; -public: - TrayWindow(int W, int H); - void set_image(Fl_RGB_Image *im); - void draw(void); - void set_tooltip(char *t); -}; - -#endif