Fixing way how tray icon window is drawn. This required changing a bit of code here

This commit is contained in:
Sanel Zukan 2011-10-27 12:02:07 +00:00
parent a23957a49e
commit 513ffe504a
5 changed files with 33 additions and 100 deletions

View File

@ -10,4 +10,4 @@
SubDir TOP ede-panel applets system-tray ;
PanelApplet system_tray : Tray.cpp TrayWindow.cpp ;
PanelApplet system_tray : Tray.cpp ;

View File

@ -1,20 +1,23 @@
#include <stdio.h>
#define FL_LIBRARY 1
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <edelib/Debug.h>
#include <edelib/Netwm.h>
#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) {

View File

@ -19,6 +19,7 @@ class Tray : public Fl_Group {
private:
Atom opcode, message_data;
WinList win_list;
void distribute_children(void);
public:
Tray();
~Tray();

View File

@ -1,59 +0,0 @@
#include <FL/fl_draw.H>
#include <edelib/Debug.h>
#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());
}
}

View File

@ -1,22 +0,0 @@
#ifndef __TRAYWINDOW_H__
#define __TRAYWINDOW_H__
#include <FL/Fl_Window.H>
#include <FL/Fl_Image.H>
#include <edelib/String.h>
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