From 92473d69cc773f7c164733d7c8d1584c4e7b567f Mon Sep 17 00:00:00 2001 From: markt Date: Sun, 1 Apr 2007 07:16:17 +0000 Subject: just converting some old code to make future changes easier --- src/AttentionNoticeHandler.cc | 8 +- src/AttentionNoticeHandler.hh | 3 +- src/Focusable.hh | 24 +++--- src/IconbarTool.cc | 126 ++++++++++++------------------- src/IconbarTool.hh | 12 ++- src/WinClient.cc | 1 - src/WinClient.hh | 8 -- src/Window.cc | 2 - src/Window.hh | 4 - src/fluxbox.cc | 168 ++++++++++++++++++++---------------------- 10 files changed, 152 insertions(+), 204 deletions(-) diff --git a/src/AttentionNoticeHandler.cc b/src/AttentionNoticeHandler.cc index a80934a..02fa95c 100644 --- a/src/AttentionNoticeHandler.cc +++ b/src/AttentionNoticeHandler.cc @@ -101,9 +101,9 @@ void AttentionNoticeHandler::update(FbTk::Subject *subj) { // all signals results in destruction of the notice - WinClient::WinClientSubj *winsubj = - static_cast(subj); - delete m_attentions[&winsubj->winClient()]; - m_attentions.erase(&winsubj->winClient()); + Focusable::FocusSubject *winsubj = + static_cast(subj); + delete m_attentions[&winsubj->win()]; + m_attentions.erase(&winsubj->win()); } diff --git a/src/AttentionNoticeHandler.hh b/src/AttentionNoticeHandler.hh index 836a023..368c568 100644 --- a/src/AttentionNoticeHandler.hh +++ b/src/AttentionNoticeHandler.hh @@ -27,6 +27,7 @@ #include +class Focusable; class WinClient; namespace FbTk { @@ -41,7 +42,7 @@ class AttentionNoticeHandler: public FbTk::Observer { public: ~AttentionNoticeHandler(); - typedef std::map NoticeMap; + typedef std::map NoticeMap; /// Adds a client that requires attention, /// will fail if the client is already active void addAttention(WinClient &client); diff --git a/src/Focusable.hh b/src/Focusable.hh index cf14de0..8982f29 100644 --- a/src/Focusable.hh +++ b/src/Focusable.hh @@ -41,8 +41,8 @@ class Focusable: public FbTk::ITypeAheadable { public: Focusable(BScreen &scr, FluxboxWindow *fbwin = 0): m_screen(scr), m_fbwin(fbwin), - m_instance_name("fluxbox"), m_class_name("fluxbox"), - m_focused(false), m_titlesig(*this) { } + m_instance_name("fluxbox"), m_class_name("fluxbox"), m_focused(false), + m_titlesig(*this), m_focussig(*this), m_diesig(*this) { } virtual ~Focusable() { } /** * Take focus. @@ -99,15 +99,18 @@ public: }; /** - * Used for both title and icon changes. - * @return title signal subject - */ + @name signals + @{ + */ + // Used for both title and icon changes. FbTk::Subject &titleSig() { return m_titlesig; } - /** - * Used for both title and icon changes. - * @return title signal subject - */ + // Used for both title and icon changes. const FbTk::Subject &titleSig() const { return m_titlesig; } + FbTk::Subject &focusSig() { return m_focussig; } + const FbTk::Subject &focusSig() const { return m_focussig; } + FbTk::Subject &dieSig() { return m_diesig; } + const FbTk::Subject &dieSig() const { return m_diesig; } + /** @} */ // end group signals protected: BScreen &m_screen; //< the screen in which it works @@ -117,7 +120,8 @@ protected: bool m_focused; //< whether or not it has focus FbTk::PixmapWithMask m_icon; //< icon pixmap with mask - FocusSubject m_titlesig; //< for signaling title and icon changes + // state and hint signals + FocusSubject m_titlesig, m_focussig, m_diesig; }; #endif // FOCUSABLE_HH diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 25b0cf8..2b4edd1 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -287,51 +287,23 @@ void setupModeMenu(FbTk::Menu &menu, IconbarTool &handler) { } inline bool checkAddWindow(IconbarTool::Mode mode, const FluxboxWindow &win) { - bool ret_val = false; - // just add the icons that are on the this workspace - switch (mode) { - case IconbarTool::NONE: - break; - case IconbarTool::ICONS: - if (win.isIconic()) - ret_val = true; - break; - case IconbarTool::NOICONS: - if (!win.isIconic()) - ret_val = true; - break; - case IconbarTool::WORKSPACEICONS: - if(win.workspaceNumber() == win.screen().currentWorkspaceID() && - win.isIconic()) - ret_val = true; - break; - case IconbarTool::WORKSPACENOICONS: - if (win.isIconic()) - break; - case IconbarTool::WORKSPACE: - if (win.workspaceNumber() == win.screen().currentWorkspaceID()) - ret_val = true; - break; - case IconbarTool::ALLWINDOWS: - ret_val = true; - break; - } + if (win.isIconHidden() || mode == IconbarTool::NONE) + return false; - if (win.isIconHidden()) - ret_val = false; + if ((mode == IconbarTool::ICONS || mode == IconbarTool::WORKSPACEICONS) && + !win.isIconic()) + return false; - return ret_val; -} + if ((mode == IconbarTool::NOICONS || mode == IconbarTool::WORKSPACENOICONS) + && win.isIconic()) + return false; -void removeDuplicate(const IconbarTool::IconList &iconlist, list &windowlist) { - IconbarTool::IconList::const_iterator icon_it = iconlist.begin(); - IconbarTool::IconList::const_iterator icon_it_end = iconlist.end(); - list::iterator remove_it = windowlist.end(); - for (; icon_it != icon_it_end; ++icon_it) - remove_it = remove(windowlist.begin(), remove_it, &(*icon_it)->win()); + if ((mode == IconbarTool::WORKSPACE || mode == IconbarTool::WORKSPACEICONS + || mode == IconbarTool::WORKSPACENOICONS) && + win.workspaceNumber() != win.screen().currentWorkspaceID()) + return false; - // remove already existing windows - windowlist.erase(remove_it, windowlist.end()); + return true; } typedef FbTk::RefCount RefCmd; @@ -396,7 +368,8 @@ private: // if desktopwheeling is enabled class WheelWorkspaceCmd : public FbTk::Command { public: - explicit WheelWorkspaceCmd(const IconbarTool& tool, FluxboxWindow &win, const char* cmd) : + explicit WheelWorkspaceCmd(const IconbarTool& tool, Focusable &win, + const char* cmd) : m_win(win), m_cmd(CommandParser::instance().parseLine(cmd)), m_tool(tool) { } void execute() { @@ -415,7 +388,7 @@ public: } private: - FluxboxWindow &m_win; + Focusable &m_win; RefCmd m_cmd; const IconbarTool& m_tool; }; @@ -589,12 +562,7 @@ void IconbarTool::update(FbTk::Subject *subj) { if (subj != 0 && typeid(*subj) == typeid(FluxboxWindow::WinSubject)) { // we handle everything except die signal here FluxboxWindow::WinSubject *winsubj = static_cast(subj); - if (subj == &(winsubj->win().focusSig())) { - // start focus timer, so we can update without flicker - m_focus_timer.start(); - - return; - } else if (subj == &(winsubj->win().workspaceSig())) { + if (subj == &(winsubj->win().workspaceSig())) { // we can ignore this signal if we're in ALLWINDOWS mode // unless the window was focused and has nothing to revert to if (mode() == ALLWINDOWS || mode() == ICONS || mode() == NOICONS) { @@ -608,16 +576,11 @@ void IconbarTool::update(FbTk::Subject *subj) { renderTheme(); } return; - } else if (subj == &(winsubj->win().dieSig())) { // die sig - removeWindow(winsubj->win()); - renderTheme(); - return; // we don't need to update the entire list } else if (subj == &(winsubj->win().stateSig())) { if (!checkAddWindow(mode(), winsubj->win())) { removeWindow(winsubj->win()); renderTheme(); } - return; } else if (subj == &(winsubj->win().attentionSig())) { @@ -632,6 +595,17 @@ void IconbarTool::update(FbTk::Subject *subj) { // signal not handled return; } + } else if (subj != 0 && typeid(*subj) == typeid(Focusable::FocusSubject)) { + Focusable::FocusSubject *winsubj = static_cast(subj); + if (subj == &(winsubj->win().focusSig())) { + // start focus timer, so we can update without flicker + m_focus_timer.start(); + return; + } else if (subj == &(winsubj->win().dieSig())) { // die sig + removeWindow(winsubj->win()); + renderTheme(); + return; // we don't need to update the entire list + } } bool remove_all = false; // if we should readd all windows @@ -670,7 +644,7 @@ void IconbarTool::update(FbTk::Subject *subj) { renderTheme(); } -IconButton *IconbarTool::findButton(FluxboxWindow &win) { +IconButton *IconbarTool::findButton(Focusable &win) { IconList::iterator icon_it = m_icon_list.begin(); IconList::iterator icon_it_end = m_icon_list.end(); @@ -681,14 +655,7 @@ IconButton *IconbarTool::findButton(FluxboxWindow &win) { return 0; } -/* -void IconbarTool::renderWindow(FluxboxWindow &win) { - IconButton *button = findButton(win); - if (button == 0) - return; - renderButton(*button); -} -*/ + void IconbarTool::updateSizing() { m_icon_container.setBorderWidth(m_theme.border().width()); @@ -847,7 +814,7 @@ void IconbarTool::deleteIcons() { } } -void IconbarTool::removeWindow(FluxboxWindow &win) { +void IconbarTool::removeWindow(Focusable &win) { // got window die signal, lets find and remove the window IconList::iterator it = m_icon_list.begin(); IconList::iterator it_end = m_icon_list.end(); @@ -865,9 +832,11 @@ void IconbarTool::removeWindow(FluxboxWindow &win) { // detach from all signals win.focusSig().detach(this); win.dieSig().detach(this); - win.workspaceSig().detach(this); - win.stateSig().detach(this); - win.attentionSig().detach(this); + if (win.fbwindow()) { + win.fbwindow()->workspaceSig().detach(this); + win.fbwindow()->stateSig().detach(this); + win.fbwindow()->attentionSig().detach(this); + } // remove from list and render theme again IconButton *button = *it; @@ -879,9 +848,10 @@ void IconbarTool::removeWindow(FluxboxWindow &win) { } -void IconbarTool::addWindow(FluxboxWindow &win) { - // we just want windows that has clients - if (win.clientList().empty() || win.isIconHidden() ) +void IconbarTool::addWindow(Focusable &win) { + // we just want windows that have clients + FluxboxWindow *fbwin = win.fbwindow(); + if (!fbwin || fbwin->clientList().empty() || fbwin->isIconHidden()) return; #ifdef DEBUG cerr<<"IconbarTool::addWindow(0x"<<&win<<" title = "<setOnClick(focus_cmd, 1); button->setOnClick(menu_cmd, 3); if(win.screen().isReverseWheeling()) { @@ -913,9 +883,9 @@ void IconbarTool::addWindow(FluxboxWindow &win) { // dont forget to detach signal in removeWindow win.focusSig().attach(this); win.dieSig().attach(this); - win.workspaceSig().attach(this); - win.stateSig().attach(this); - win.attentionSig().attach(this); + fbwin->workspaceSig().attach(this); + fbwin->stateSig().attach(this); + fbwin->attentionSig().attach(this); } void IconbarTool::updateList() { @@ -925,14 +895,14 @@ void IconbarTool::updateList() { list::iterator it_end = ordered_list.end(); for (; it != it_end; ++it) { if ((*it)->fbwindow() && checkAddWindow(mode(), *(*it)->fbwindow()) && - !checkDuplicate(*(*it)->fbwindow())) - addWindow(*(*it)->fbwindow()); + !checkDuplicate(**it)) + addWindow(**it); } renderTheme(); } -bool IconbarTool::checkDuplicate(FluxboxWindow &win) { +bool IconbarTool::checkDuplicate(Focusable &win) { IconList::iterator it = m_icon_list.begin(); IconList::iterator it_end = m_icon_list.end(); for (; it != it_end; ++it) { diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh index 3512f78..7662e72 100644 --- a/src/IconbarTool.hh +++ b/src/IconbarTool.hh @@ -41,7 +41,7 @@ class IconbarTheme; class BScreen; class IconButton; -class FluxboxWindow; +class Focusable; class IconbarTool: public ToolbarItem, public FbTk::Observer { public: @@ -93,12 +93,10 @@ public: private: /// @return button associated with window - IconButton *findButton(FluxboxWindow &win); + IconButton *findButton(Focusable &win); void updateSizing(); - /// render single button that holds win - // void renderWindow(FluxboxWindow &win); /// render single button, and probably apply changes (clear) /// @param button the button to render /// @param clear if the window should be cleared first @@ -111,13 +109,13 @@ private: /// destroy all icons void deleteIcons(); /// remove a single window - void removeWindow(FluxboxWindow &win); + void removeWindow(Focusable &win); /// add a single window - void addWindow(FluxboxWindow &win); + void addWindow(Focusable &win); /// add icons to the list void updateList(); /// check if window is already in the list - bool checkDuplicate(FluxboxWindow &win); + bool checkDuplicate(Focusable &win); /// so we can update current window without flicker void timedRender(); diff --git a/src/WinClient.cc b/src/WinClient.cc index 948a363..de6c213 100644 --- a/src/WinClient.cc +++ b/src/WinClient.cc @@ -80,7 +80,6 @@ WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin): m_blackbox_hint(0), m_mwm_hint(0), m_focus_mode(F_PASSIVE), - m_diesig(*this), m_focussig(*this), m_strut(0) { updateWMProtocols(); updateBlackboxHints(); diff --git a/src/WinClient.hh b/src/WinClient.hh index 82f7153..1824ee2 100644 --- a/src/WinClient.hh +++ b/src/WinClient.hh @@ -113,11 +113,6 @@ public: bool getWMIconName(XTextProperty &textprop) const; std::string getWMRole() const; - /// notifies when this client dies - FbTk::Subject &dieSig() { return m_diesig; } - /// notifies when this client becomes focused - FbTk::Subject &focusSig() { return m_focussig; } - inline WinClient *transientFor() { return transient_for; } inline const WinClient *transientFor() const { return transient_for; } inline TransientList &transientList() { return transients; } @@ -190,9 +185,6 @@ private: int m_focus_mode; - WinClientSubj m_diesig; - WinClientSubj m_focussig; - Strut *m_strut; // map transient_for X window to winclient transient // (used if transient_for FbWindow was created after transient) diff --git a/src/Window.cc b/src/Window.cc index 53222a7..fcea7e6 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -245,8 +245,6 @@ FluxboxWindow::FluxboxWindow(WinClient &client, FbWinFrameTheme &tm, m_statesig(*this), m_layersig(*this), m_workspacesig(*this), - m_diesig(*this), - m_focussig(*this), m_attentionsig(*this), m_themelistener(*this), moving(false), resizing(false), shaded(false), iconic(false), diff --git a/src/Window.hh b/src/Window.hh index 91bd4a5..a7acabf 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -420,9 +420,6 @@ public: const FbTk::Subject &hintSig() const { return m_hintsig; } FbTk::Subject &workspaceSig() { return m_workspacesig; } const FbTk::Subject &workspaceSig() const { return m_workspacesig; } - FbTk::Subject &dieSig() { return m_diesig; } - const FbTk::Subject &dieSig() const { return m_diesig; } - FbTk::Subject &focusSig() { return m_focussig; } FbTk::Subject &attentionSig() { return m_attentionsig; } /** @} */ // end group signals @@ -492,7 +489,6 @@ private: m_statesig, m_layersig, m_workspacesig, - m_diesig, m_focussig, m_attentionsig; class ThemeListener: public FbTk::Observer { diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 4441a7d..af9482d 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -1121,73 +1121,94 @@ void Fluxbox::handleSignal(int signum) { void Fluxbox::update(FbTk::Subject *changedsub) { //TODO: fix signaling, this does not look good + FluxboxWindow *fbwin = 0; + WinClient *client = 0; + if (typeid(*changedsub) == typeid(FluxboxWindow::WinSubject)) { FluxboxWindow::WinSubject *winsub = dynamic_cast(changedsub); - FluxboxWindow &win = winsub->win(); - if ((&(win.hintSig())) == changedsub) { // hint signal - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ( (*it).first->update()) - (*it).first->updateHints(win); - } - } else if ((&(win.stateSig())) == changedsub) { // state signal - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it).first->update()) - (*it).first->updateState(win); - } - // if window changed to iconic state - // add to icon list - if (win.isIconic()) { - win.screen().addIcon(&win); - Workspace *space = win.screen().getWorkspace(win.workspaceNumber()); - if (space != 0) - space->removeWindow(&win, true); - } + fbwin = &winsub->win(); + } else if (typeid(*changedsub) == typeid(Focusable::FocusSubject)) { + Focusable::FocusSubject *winsub = dynamic_cast(changedsub); + fbwin = winsub->win().fbwindow(); + if (typeid(winsub->win()) == typeid(WinClient)) + client = dynamic_cast(&winsub->win()); + } - if (win.isStuck()) { - // if we're sticky then reassociate window - // to all workspaces - BScreen &scr = win.screen(); - if (scr.currentWorkspaceID() != win.workspaceNumber()) { - scr.reassociateWindow(&win, - scr.currentWorkspaceID(), - true); - } - } - } else if ((&(win.layerSig())) == changedsub) { // layer signal + if (fbwin && &fbwin->stateSig() == changedsub) { // state signal + for (AtomHandlerContainerIt it= m_atomhandler.begin(); + it != m_atomhandler.end(); ++it) { + if ((*it).first->update()) + (*it).first->updateState(*fbwin); + } + // if window changed to iconic state + // add to icon list + if (fbwin->isIconic()) { + fbwin->screen().addIcon(fbwin); + Workspace *space = fbwin->screen().getWorkspace(fbwin->workspaceNumber()); + if (space != 0) + space->removeWindow(fbwin, true); + } - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it).first->update()) - (*it).first->updateLayer(win); + if (fbwin->isStuck()) { + // if we're sticky then reassociate window + // to all workspaces + BScreen &scr = fbwin->screen(); + if (scr.currentWorkspaceID() != fbwin->workspaceNumber()) { + scr.reassociateWindow(fbwin, + scr.currentWorkspaceID(), + true); } - } else if ((&(win.dieSig())) == changedsub) { // window death signal + } + } else if (fbwin && &fbwin->layerSig() == changedsub) { // layer signal + AtomHandlerContainerIt it= m_atomhandler.begin(); + for (; it != m_atomhandler.end(); ++it) { + if ((*it).first->update()) + (*it).first->updateLayer(*fbwin); + } + } else if (fbwin && &fbwin->dieSig() == changedsub) { // window death signal + AtomHandlerContainerIt it= m_atomhandler.begin(); + for (; it != m_atomhandler.end(); ++it) { + if ((*it).first->update()) + (*it).first->updateFrameClose(*fbwin); + } - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it).first->update()) - (*it).first->updateFrameClose(win); - } + // make sure each workspace get this + BScreen &scr = fbwin->screen(); + scr.removeWindow(fbwin); + if (FocusControl::focusedFbWindow() == fbwin) + FocusControl::setFocusedFbWindow(0); + } else if (fbwin && &fbwin->workspaceSig() == changedsub) { // workspace signal + for (AtomHandlerContainerIt it= m_atomhandler.begin(); + it != m_atomhandler.end(); ++it) { + if ((*it).first->update()) + (*it).first->updateWorkspace(*fbwin); + } + } else if (client && &client->dieSig() == changedsub) { // client death + for (AtomHandlerContainerIt it= m_atomhandler.begin(); + it != m_atomhandler.end(); ++it) { + if ((*it).first->update()) + (*it).first->updateClientClose(*client); + } - // make sure each workspace get this - BScreen &scr = win.screen(); - scr.removeWindow(&win); - if (FocusControl::focusedFbWindow() == &win) - FocusControl::setFocusedFbWindow(0); + BScreen &screen = client->screen(); - } else if ((&(win.workspaceSig())) == changedsub) { // workspace signal - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it).first->update()) - (*it).first->updateWorkspace(win); - } - } else { -#ifdef DEBUG - cerr<<__FILE__<<"("<<__LINE__<<"): WINDOW uncought signal from "<<&win<window()); + + // At this point, we trust that this client is no longer in the + // client list of its frame (but it still has reference to the frame) + // We also assume that any remaining active one is the last focused one + // This is where we revert focus on window close + // NOWHERE ELSE!!! + if (FocusControl::focusedWindow() == client) { + FocusControl::unfocusWindow(*client); + // make sure nothing else uses this window before focus reverts + FocusControl::setFocusedWindow(0); + m_revert_screen = &screen; + m_revert_timer.start(); + } } else if (typeid(*changedsub) == typeid(BScreen::ScreenSubject)) { BScreen::ScreenSubject *subj = dynamic_cast(changedsub); BScreen &screen = subj->screen(); @@ -1222,37 +1243,6 @@ void Fluxbox::update(FbTk::Subject *changedsub) { (*it).first->updateClientList(screen); } } - } else if (typeid(*changedsub) == typeid(WinClient::WinClientSubj)) { - - WinClient::WinClientSubj *subj = dynamic_cast(changedsub); - WinClient &client = subj->winClient(); - - // TODO: don't assume it is diesig (need to fix as soon as another signal appears) - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it).first->update()) - (*it).first->updateClientClose(client); - } - - BScreen &screen = client.screen(); - - screen.removeClient(client); - // finaly send notify signal - screen.updateNetizenWindowDel(client.window()); - - // At this point, we trust that this client is no longer in the - // client list of its frame (but it still has reference to the frame) - // We also assume that any remaining active one is the last focused one - - // This is where we revert focus on window close - // NOWHERE ELSE!!! - if (FocusControl::focusedWindow() == &client) { - FocusControl::unfocusWindow(client); - // make sure nothing else uses this window before focus reverts - FocusControl::setFocusedWindow(0); - m_revert_screen = &screen; - m_revert_timer.start(); - } } } -- cgit v0.11.2