From bdc74e79958ee5af9f191edefbdc5652320d1ad7 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 18 Mar 2006 21:58:24 +0000 Subject: We now create titlebar resource session.screen.titlbar.left/right on the fly here instead of fluxbox.cc --- src/Window.cc | 180 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 124 insertions(+), 56 deletions(-) diff --git a/src/Window.cc b/src/Window.cc index fbec829..b03ee6f 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -3814,74 +3814,142 @@ void FluxboxWindow::setupWindow() { // clear old buttons from frame frame().removeAllButtons(); - //!! TODO: fix this ugly hack - // get titlebar configuration - const vector *dir = &Fluxbox::instance()->getTitlebarLeft(); - for (char c=0; c<2; c++) { - for (size_t i=0; i< dir->size(); ++i) { + + typedef FbTk::Resource > WinButtonsResource; + + std::string titlebar_name[2]; + std::string titlebar_alt_name[2]; + titlebar_name[0] = screen().name() + ".titlebar.left"; + titlebar_alt_name[0] = screen().altName() + ".Titlebar.Left"; + titlebar_name[1] = screen().name() + ".titlebar.right"; + titlebar_alt_name[1] = screen().altName() + ".Titlebar.Right"; + + WinButtonsResource *titlebar_side[2]; + + + + ResourceManager &rm = screen().resourceManager(); + + // create resource for titlebar + for (int i=0; i < 2; ++i) { + titlebar_side[i] = dynamic_cast( + rm.findResource( titlebar_name[i] ) ); + + if (titlebar_side[i] != 0) + continue; // find next resource too + + WinButton::Type titlebar_left[] = { + WinButton::STICK + }; + + WinButton::Type titlebar_right[] = { + WinButton::MINIMIZE, + WinButton::MAXIMIZE, + WinButton::CLOSE + }; + + WinButton::Type *begin = 0; + WinButton::Type *end = 0; + + if (i == 0) { + begin = titlebar_left; + end = titlebar_left + 1; + } else { + begin = titlebar_right; + end = titlebar_right + 3; + } + + titlebar_side[i] = + new WinButtonsResource(rm, + WinButtonsResource::Type(begin, end), + titlebar_name[i], titlebar_alt_name[i]); + + + screen().addManagedResource(titlebar_side[i]); + } + + + + + for (char c = 0; c < 2 ; c++) { + // get titlebar configuration for current side + const std::vector &dir = *(*titlebar_side[c]); + + for (size_t i=0; i < dir.size(); ++i) { //create new buttons - FbTk::Button *newbutton = 0; - if (isIconifiable() && (*dir)[i] == Fluxbox::MINIMIZE) { - newbutton = new WinButton(*this, winbutton_theme, - WinButton::MINIMIZE, - frame().titlebar(), - 0, 0, 10, 10); - newbutton->setOnClick(iconify_cmd); - - } else if (isMaximizable() && (*dir)[i] == Fluxbox::MAXIMIZE) { - newbutton = new WinButton(*this, winbutton_theme, - WinButton::MAXIMIZE, - frame().titlebar(), - 0, 0, 10, 10); - - newbutton->setOnClick(maximize_cmd, 1); - newbutton->setOnClick(maximize_horiz_cmd, 3); - newbutton->setOnClick(maximize_vert_cmd, 2); - - } else if (m_client->isClosable() && (*dir)[i] == Fluxbox::CLOSE) { - newbutton = new WinButton(*this, winbutton_theme, - WinButton::CLOSE, - frame().titlebar(), - 0, 0, 10, 10); - - newbutton->setOnClick(close_cmd); - - } else if ((*dir)[i] == Fluxbox::STICK) { - WinButton *winbtn = new WinButton(*this, winbutton_theme, - WinButton::STICK, - frame().titlebar(), - 0, 0, 10, 10); - stateSig().attach(winbtn); + WinButton *winbtn = 0; + + switch (dir[i]) { + case WinButton::MINIMIZE: + if (isIconifiable()) { + winbtn = new WinButton(*this, winbutton_theme, + WinButton::MINIMIZE, + frame().titlebar(), + 0, 0, 10, 10); + winbtn->setOnClick(iconify_cmd); + } + break; + case WinButton::MAXIMIZE: + if (isMaximizable()) { + winbtn = new WinButton(*this, winbutton_theme, + dir[i], + frame().titlebar(), + 0, 0, 10, 10); + winbtn->setOnClick(maximize_cmd, 1); + winbtn->setOnClick(maximize_horiz_cmd, 3); + winbtn->setOnClick(maximize_vert_cmd, 2); + + } + break; + case WinButton::CLOSE: + if (m_client->isClosable()) { + winbtn = new WinButton(*this, winbutton_theme, + dir[i], + frame().titlebar(), + 0, 0, 10, 10); + + winbtn->setOnClick(close_cmd); + stateSig().attach(winbtn); + } + break; + case WinButton::STICK: + winbtn = new WinButton(*this, winbutton_theme, + dir[i], + frame().titlebar(), + 0, 0, 10, 10); + winbtn->setOnClick(stick_cmd); - newbutton = winbtn; - } else if ((*dir)[i] == Fluxbox::SHADE) { - WinButton *winbtn = new WinButton(*this, winbutton_theme, - WinButton::SHADE, - frame().titlebar(), - 0, 0, 10, 10); + break; + case WinButton::SHADE: + winbtn = new WinButton(*this, winbutton_theme, + dir[i], + frame().titlebar(), + 0, 0, 10, 10); stateSig().attach(winbtn); - winbtn->setOnClick(shade_cmd); - newbutton = winbtn; - } else if ((*dir)[i] == Fluxbox::MENUICON) { - WinButton* winbtn = new WinButton(*this, winbutton_theme, - WinButton::MENUICON, - frame().titlebar(), - 0, 0, 10, 10); + winbtn->setOnClick(shade_cmd); + break; + case WinButton::MENUICON: + winbtn = new WinButton(*this, winbutton_theme, + dir[i], + frame().titlebar(), + 0, 0, 10, 10); hintSig().attach(winbtn); titleSig().attach(winbtn); winbtn->setOnClick(show_menu_cmd); - newbutton = winbtn; + break; } - if (newbutton != 0) { - newbutton->show(); + + if (winbtn != 0) { + winbtn->show(); if (c == 0) - frame().addLeftButton(newbutton); + frame().addLeftButton(winbtn); else - frame().addRightButton(newbutton); + frame().addRightButton(winbtn); } } //end for i - dir = &Fluxbox::instance()->getTitlebarRight(); + + } // end for c frame().reconfigure(); -- cgit v0.11.2