1 // SystemTray.hh 2 // Copyright (c) 2003 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 22 #ifndef SYSTEMTRAY_HH 23 #define SYSTEMTRAY_HH 24 25 26 #include "FbTk/FbWindow.hh" 27 #include "FbTk/EventHandler.hh" 28 #include "FbTk/Signal.hh" 29 30 #include "ToolTheme.hh" 31 #include "ToolbarItem.hh" 32 33 #include <list> 34 #include <memory> 35 36 class BScreen; 37 class ButtonTheme; 38 class TrayWindow; 39 class AtomHandler; 40 41 namespace FbTk { 42 template <class T> class ThemeProxy; 43 } 44 45 class SystemTray: public ToolbarItem, public FbTk::EventHandler, 46 private FbTk::SignalTracker { 47 public: 48 49 explicit SystemTray(const FbTk::FbWindow &parent, 50 FbTk::ThemeProxy<ToolTheme> &theme, BScreen& screen); 51 virtual ~SystemTray(); 52 53 void move(int x, int y); 54 void resize(unsigned int width, unsigned int height); 55 void moveResize(int x, int y, 56 unsigned int width, unsigned int height); 57 void show(); 58 void hide(); 59 active()60 bool active() { return !m_clients.empty(); } 61 62 bool clientMessage(const XClientMessageEvent &event); 63 void exposeEvent(XExposeEvent &event); 64 void handleEvent(XEvent &event); 65 66 void addClient(Window win, bool using_xembed); 67 void removeClient(Window win, bool destroyed); 68 69 unsigned int width() const; 70 unsigned int height() const; 71 unsigned int borderWidth() const; 72 numClients() const73 int numClients() const { return m_clients.size(); } window() const74 const FbTk::FbWindow &window() const { return m_window; } 75 renderTheme(int alpha)76 void renderTheme(int alpha) { 77 m_window.setBorderWidth(m_theme->border().width()); 78 m_window.setBorderColor(m_theme->border().color()); 79 m_window.setAlpha(alpha); 80 update(); 81 } updateSizing()82 void updateSizing() { m_window.setBorderWidth(m_theme->border().width()); } 83 parentMoved()84 void parentMoved() { m_window.parentMoved(); } 85 86 static std::string getNetSystemTrayAtom(int screen_nr); 87 88 static Atom getXEmbedInfoAtom(); 89 90 private: 91 void update(); 92 93 typedef std::list<TrayWindow *> ClientList; 94 ClientList::iterator findClient(Window win); 95 96 void rearrangeClients(); 97 void removeAllClients(); 98 void hideClient(TrayWindow *traywin, bool destroyed = false); 99 void showClient(TrayWindow *traywin); 100 101 FbTk::FbWindow m_window; 102 FbTk::ThemeProxy<ToolTheme> &m_theme; 103 BScreen& m_screen; 104 Pixmap m_pixmap; 105 106 std::auto_ptr<AtomHandler> m_handler; 107 108 ClientList m_clients; 109 size_t m_num_visible_clients; 110 111 // gaim/pidgin seems to barf if the selection is not an independent window. 112 // I suspect it's an interacton with parent relationship and gdk window caching. 113 FbTk::FbWindow m_selection_owner; 114 }; 115 116 #endif // SYSTEMTRAY_HH 117