systemtray-tool has now a propper background. its styleable via the

toolbar.systray.* ressource, same way as the clock.
This commit is contained in:
mathias 2005-01-14 09:58:16 +00:00
parent a07d61e63d
commit 69e86c6c25
4 changed files with 91 additions and 30 deletions

View file

@ -1,5 +1,5 @@
// SystemTray.cc
// Copyright (c) 2003-2004 Henrik Kinnunen (fluxgen at users.sourceforge.net)
// Copyright (c) 2003-2005 Henrik Kinnunen (fluxgen at users.sourceforge.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@ -24,6 +24,7 @@
#include "SystemTray.hh"
#include "FbTk/EventManager.hh"
#include "FbTk/ImageControl.hh"
#include "AtomHandler.hh"
#include "fluxbox.hh"
@ -100,15 +101,19 @@ private:
SystemTray &m_tray;
};
SystemTray::SystemTray(const FbTk::FbWindow &parent):
SystemTray::SystemTray(const FbTk::FbWindow& parent, ButtonTheme& theme, BScreen& screen):
ToolbarItem(ToolbarItem::FIXED),
m_window(parent, 0, 0, 1, 1, ExposureMask | ButtonPressMask | ButtonReleaseMask |
SubstructureNotifyMask | SubstructureRedirectMask) {
SubstructureNotifyMask | SubstructureRedirectMask),
m_theme(theme),
m_screen(screen),
m_pixmap(0) {
FbTk::EventManager::instance()->add(*this, m_window);
m_theme.reconfigSig().attach(this);
// just try to blend in... (better than defaulting to white)
m_window.setBackgroundPixmap(ParentRelative);
Fluxbox* fluxbox = Fluxbox::instance();
Display *disp = fluxbox->display();
// setup atom name to _NET_SYSTEM_TRAY_S<screen number>
char intbuff[16];
@ -116,8 +121,6 @@ SystemTray::SystemTray(const FbTk::FbWindow &parent):
std::string atom_name("_NET_SYSTEM_TRAY_S");
atom_name += intbuff; // append number
Display *disp = FbTk::App::instance()->display();
// get selection owner and see if it's free
Atom tray_atom = XInternAtom(disp, atom_name.c_str(), False);
Window owner = XGetSelectionOwner(disp, tray_atom);
@ -134,11 +137,14 @@ SystemTray::SystemTray(const FbTk::FbWindow &parent):
#endif // DEBUG
// set owner
XSetSelectionOwner(disp, tray_atom, m_window.window(), CurrentTime);
m_handler.reset(new SystemTrayHandler(*this));
Fluxbox::instance()->addAtomHandler(m_handler.get(), atom_name);
Window root_window = RootWindow(disp, m_window.screenNumber());
fluxbox->addAtomHandler(m_handler.get(), atom_name);
// send selection owner msg
Window root_window = m_screen.rootWindow().window();
XEvent ce;
ce.xclient.type = ClientMessage;
ce.xclient.message_type = XInternAtom(disp, "MANAGER", False);
@ -153,12 +159,17 @@ SystemTray::SystemTray(const FbTk::FbWindow &parent):
XSendEvent(disp, root_window, false, StructureNotifyMask, &ce);
update(0);
}
SystemTray::~SystemTray() {
// remove us, else fluxbox might delete the memory too
Fluxbox::instance()->removeAtomHandler(m_handler.get());
removeAllClients();
if (m_pixmap)
m_screen.imageControl().removeImage(m_pixmap);
// ~FbWindow cleans EventManager
}
@ -196,11 +207,13 @@ void SystemTray::hide() {
}
void SystemTray::show() {
update(0);
m_window.show();
}
unsigned int SystemTray::width() const {
return m_clients.size()*height();
return m_clients.size()* (height() - 2 * m_theme.border().width());
}
unsigned int SystemTray::height() const {
@ -313,6 +326,7 @@ void SystemTray::removeClient(Window win) {
void SystemTray::exposeEvent(XExposeEvent &event) {
m_window.clear();
update(0);
}
void SystemTray::handleEvent(XEvent &event) {
@ -349,11 +363,15 @@ void SystemTray::rearrangeClients() {
ClientList::iterator client_it = m_clients.begin();
ClientList::iterator client_it_end = m_clients.end();
int next_x = 0;
for (; client_it != client_it_end; ++client_it, next_x += height()) {
(*client_it)->moveResize(next_x, 0, height(), height());
const unsigned int h = height();
const unsigned int b = m_theme.border().width();
for (; client_it != client_it_end;
++client_it, next_x += h - 2 * b) {
(*client_it)->moveResize(next_x, b, h - b, h - b);
}
resize(next_x, height());
update(0);
}
void SystemTray::removeAllClients() {
@ -366,3 +384,34 @@ void SystemTray::removeAllClients() {
m_clients.pop_back();
}
}
void SystemTray::update(FbTk::Subject* subject) {
if (!m_theme.texture().usePixmap()) {
m_window.setBackgroundColor(m_theme.texture().color());
}
else {
if(m_pixmap)
m_screen.imageControl().removeImage(m_pixmap);
m_pixmap = m_screen.imageControl().renderImage(width(), height(),
m_theme.texture());
m_window.setBackgroundPixmap(m_pixmap);
}
// "themereconfigure"
if (subject) {
ClientList::iterator client_it = m_clients.begin();
ClientList::iterator client_it_end = m_clients.end();
int next_x = 0;
const unsigned int h = height();
const unsigned int b = m_theme.border().width();
for (; client_it != client_it_end;
++client_it, next_x += h - 2 * b) {
// maybe not the best solution (yet), force a refresh of the
// background of the client
(*client_it)->hide();
(*client_it)->show();
}
}
}

View file

@ -1,5 +1,5 @@
// SystemTray.hh
// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
// Copyright (c) 2003-2005 Henrik Kinnunen (fluxgen at users.sourceforge.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@ -27,8 +27,11 @@
#include "FbTk/FbWindow.hh"
#include "FbTk/EventHandler.hh"
#include "FbTk/Observer.hh"
#include "ToolbarItem.hh"
#include "ButtonTheme.hh"
#include "Screen.hh"
#include <X11/Xlib.h>
@ -36,10 +39,10 @@
class AtomHandler;
class SystemTray: public ToolbarItem, public FbTk::EventHandler {
class SystemTray: public ToolbarItem, public FbTk::EventHandler, public FbTk::Observer {
public:
explicit SystemTray(const FbTk::FbWindow &parent);
explicit SystemTray(const FbTk::FbWindow &parent, ButtonTheme &theme, BScreen& screen);
virtual ~SystemTray();
void move(int x, int y);
@ -69,6 +72,9 @@ public:
inline void updateSizing() {}
private:
void update(FbTk::Subject *subj);
typedef std::list<FbTk::FbWindow *> ClientList;
ClientList::iterator findClient(Window win);
@ -76,6 +82,9 @@ private:
void removeAllClients();
FbTk::FbWindow m_window;
ButtonTheme& m_theme;
BScreen& m_screen;
Pixmap m_pixmap;
std::auto_ptr<AtomHandler> m_handler;

View file

@ -1,5 +1,5 @@
// ToolFactory.cc for Fluxbox
// Copyright (c) 2003-2004 Henrik Kinnunen (fluxgen at users.sourceforge.net)
// Copyright (c) 2003-2005 Henrik Kinnunen (fluxgen at users.sourceforge.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@ -77,6 +77,8 @@ ToolFactory::ToolFactory(BScreen &screen):m_screen(screen),
m_clock_theme(screen.screenNumber(), "toolbar.clock", "Toolbar.Clock"),
m_button_theme(new ButtonTheme(screen.screenNumber(), "toolbar.button", "Toolbar.Button",
"toolbar.clock", "Toolbar.Clock")),
m_systray_theme(new ButtonTheme(screen.screenNumber(), "toolbar.systray", "Toolbar.Systray",
"toolbar.clock", "Toolbar.Systray")),
m_workspace_theme(new WorkspaceNameTheme(screen.screenNumber(), "toolbar.workspace", "Toolbar.Workspace")),
m_iconbar_theme(screen.screenNumber(), "toolbar.iconbar", "Toolbar.Iconbar") {
@ -97,10 +99,9 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &
witem->button().setOnClick(showmenu);
item = witem;
} else if (name == "iconbar") {
item = new IconbarTool(parent, m_iconbar_theme,
screen(), tbar.menu());
item = new IconbarTool(parent, m_iconbar_theme, screen(), tbar.menu());
} else if (name == "systemtray") {
item = new SystemTray(parent);
item = new SystemTray(parent, dynamic_cast<ButtonTheme &>(*m_systray_theme), screen());
} else if (name == "clock") {
item = new ClockTool(parent, m_clock_theme, screen(), tbar.menu());
} else if (name == "nextworkspace" ||

View file

@ -52,7 +52,9 @@ public:
private:
BScreen &m_screen;
ToolTheme m_clock_theme;
std::auto_ptr<ToolTheme> m_button_theme, m_workspace_theme;
std::auto_ptr<ToolTheme> m_button_theme;
std::auto_ptr<ToolTheme> m_workspace_theme;
std::auto_ptr<ToolTheme> m_systray_theme;
IconbarTheme m_iconbar_theme;
};