fixed style menu and some minor indentation

This commit is contained in:
fluxgen 2003-02-15 02:03:09 +00:00
parent 0a01f73b51
commit 6d159ae8c7

View file

@ -22,7 +22,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: Screen.cc,v 1.103 2003/02/09 14:11:12 rathnor Exp $ // $Id: Screen.cc,v 1.104 2003/02/15 02:03:09 fluxgen Exp $
#include "Screen.hh" #include "Screen.hh"
@ -130,10 +130,6 @@ int anotherWMRunning(Display *display, XErrorEvent *) {
return(-1); return(-1);
} }
int dcmp(const void *one, const void *two) {
return (strcmp((*(char **) one), (*(char **) two)));
}
FbTk::Menu *createMenuFromScreen(BScreen &screen) { FbTk::Menu *createMenuFromScreen(BScreen &screen) {
FbTk::Menu *menu = new LayeredMenu(*screen.menuTheme(), FbTk::Menu *menu = new LayeredMenu(*screen.menuTheme(),
screen.getScreenNumber(), screen.getScreenNumber(),
@ -306,13 +302,18 @@ template <>
void FbTk::ThemeItem<std::string>::load() { } void FbTk::ThemeItem<std::string>::load() { }
template <> template <>
void FbTk::ThemeItem<std::string>::setDefaultValue() { *(*this) = ""; } void FbTk::ThemeItem<std::string>::setDefaultValue() {
*(*this) = "";
}
template <> template <>
void FbTk::ThemeItem<std::string>::setFromString(const char *str) { *(*this) = (str ? str : ""); } void FbTk::ThemeItem<std::string>::setFromString(const char *str) {
*(*this) = (str ? str : "");
}
BScreen::ScreenResource::ScreenResource(ResourceManager &rm, BScreen::ScreenResource::ScreenResource(ResourceManager &rm,
const std::string &scrname, const std::string &altscrname): const std::string &scrname,
const std::string &altscrname):
toolbar_on_top(rm, false, scrname+".toolbar.onTop", altscrname+".Toolbar.OnTop"), toolbar_on_top(rm, false, scrname+".toolbar.onTop", altscrname+".Toolbar.OnTop"),
toolbar_auto_hide(rm, false, scrname+".toolbar.autoHide", altscrname+".Toolbar.AutoHide"), toolbar_auto_hide(rm, false, scrname+".toolbar.autoHide", altscrname+".Toolbar.AutoHide"),
image_dither(rm, false, scrname+".imageDither", altscrname+".ImageDither"), image_dither(rm, false, scrname+".imageDither", altscrname+".ImageDither"),
@ -418,7 +419,7 @@ BScreen::BScreen(ResourceManager &rm,
const char *s = i18n->getMessage( const char *s = i18n->getMessage(
FBNLS::ScreenSet, FBNLS::ScreenPositionLength, FBNLS::ScreenSet, FBNLS::ScreenPositionLength,
"W: 0000 x H: 0000"); // W is wide! "W: 0000 x H: 0000");
int l = strlen(s); int l = strlen(s);
@ -503,6 +504,7 @@ BScreen::BScreen(ResourceManager &rm,
//update menus //update menus
m_rootmenu->update(); m_rootmenu->update();
m_configmenu->update(); m_configmenu->update();
#ifdef SLIT #ifdef SLIT
if (m_slit.get()) if (m_slit.get())
m_slit->reconfigure(); m_slit->reconfigure();
@ -692,7 +694,8 @@ void BScreen::reconfigure() {
geom_window, geom_pixmap); geom_window, geom_pixmap);
} }
} }
if (tmp) image_control->removeImage(tmp); if (tmp)
image_control->removeImage(tmp);
XSetWindowBorderWidth(getBaseDisplay()->getXDisplay(), geom_window, XSetWindowBorderWidth(getBaseDisplay()->getXDisplay(), geom_window,
theme->getBorderWidth()); theme->getBorderWidth());
@ -704,11 +707,11 @@ void BScreen::reconfigure() {
m_configmenu->reconfigure(); m_configmenu->reconfigure();
{ {
int remember_sub = m_rootmenu->currentSubmenu(); //int remember_sub = m_rootmenu->currentSubmenu();
initMenu(); initMenu();
raiseWindows(Workspace::Stack()); raiseWindows(Workspace::Stack());
m_rootmenu->reconfigure(); m_rootmenu->reconfigure();
m_rootmenu->drawSubmenu(remember_sub); //m_rootmenu->drawSubmenu(remember_sub);
} }
// m_toolbar->setPlacement(*resource.toolbar_placement); // m_toolbar->setPlacement(*resource.toolbar_placement);
@ -1132,7 +1135,8 @@ void BScreen::setupWindowActions(FluxboxWindow &win) {
//create new buttons //create new buttons
if (win.isIconifiable()) { if (win.isIconifiable()) {
FbTk::Button *iconifybtn = new WinButton(WinButton::MINIMIZE, frame.titlebar(), 0, 0, 10, 10); FbTk::Button *iconifybtn = new WinButton(WinButton::MINIMIZE, frame.titlebar(),
0, 0, 10, 10);
iconifybtn->setOnClick(iconify_cmd); iconifybtn->setOnClick(iconify_cmd);
iconifybtn->show(); iconifybtn->show();
frame.addRightButton(iconifybtn); frame.addRightButton(iconifybtn);
@ -1142,7 +1146,8 @@ void BScreen::setupWindowActions(FluxboxWindow &win) {
} }
if (win.isMaximizable()) { if (win.isMaximizable()) {
FbTk::Button *maximizebtn = new WinButton(WinButton::MAXIMIZE, frame.titlebar(), 0, 0, 10, 10); FbTk::Button *maximizebtn = new WinButton(WinButton::MAXIMIZE, frame.titlebar(),
0, 0, 10, 10);
maximizebtn->setOnClick(maximize_cmd, 1); maximizebtn->setOnClick(maximize_cmd, 1);
maximizebtn->setOnClick(maximize_horiz_cmd, 3); maximizebtn->setOnClick(maximize_horiz_cmd, 3);
@ -1173,7 +1178,7 @@ void BScreen::setupWindowActions(FluxboxWindow &win) {
// setup menu // setup menu
FbTk::Menu &menu = win.getWindowmenu(); FbTk::Menu &menu = win.getWindowmenu();
menu.removeAll(); // clear old items menu.removeAll(); // clear old items
menu.disableTitle(); menu.disableTitle(); // not titlebar
// set new menu items // set new menu items
menu.insert("Shade", shade_cmd); menu.insert("Shade", shade_cmd);
@ -1252,7 +1257,6 @@ string BScreen::getNameOfWorkspace(unsigned int workspace) const {
} else { } else {
return ""; return "";
} }
} }
void BScreen::reassociateGroup(FluxboxWindow *w, unsigned int wkspc_id, bool ignore_sticky) { void BScreen::reassociateGroup(FluxboxWindow *w, unsigned int wkspc_id, bool ignore_sticky) {
@ -1374,9 +1378,7 @@ void BScreen::prevFocus(int opts) {
} }
} }
//--------- raiseFocus -----------
// Raise the current focused window
//--------------------------------
void BScreen::raiseFocus() { void BScreen::raiseFocus() {
bool have_focused = false; bool have_focused = false;
int focused_window_number = -1; int focused_window_number = -1;
@ -1466,7 +1468,7 @@ void BScreen::initMenu() {
fb->saveMenuFilename(fb->getMenuFilename()); fb->saveMenuFilename(fb->getMenuFilename());
} }
// looks through a menufile and adds correct items to the root-menu. /// looks through a menufile and adds correct items to the root-menu.
bool BScreen::parseMenuFile(ifstream &file, FbTk::Menu &menu, int &row) { bool BScreen::parseMenuFile(ifstream &file, FbTk::Menu &menu, int &row) {
string line; string line;
@ -1524,8 +1526,7 @@ bool BScreen::parseMenuFile(ifstream &file, FbTk::Menu &menu, int &row) {
FbTk::RefCount<FbTk::Command> exit_fb_cmd(new FbCommands::ExitFluxboxCmd()); FbTk::RefCount<FbTk::Command> exit_fb_cmd(new FbCommands::ExitFluxboxCmd());
menu.insert(str_label.c_str(), exit_fb_cmd); menu.insert(str_label.c_str(), exit_fb_cmd);
} }
} // end of exit } else if (str_key == "style") { // style
/*else if (str_key == "style") { // style
if (!( str_label.size() && str_cmd.size())) { if (!( str_label.size() && str_cmd.size())) {
fprintf(stderr, fprintf(stderr,
i18n-> i18n->
@ -1537,13 +1538,14 @@ bool BScreen::parseMenuFile(ifstream &file, FbTk::Menu &menu, int &row) {
} else { } else {
// perform shell style ~ home directory expansion // perform shell style ~ home directory expansion
// and insert style // and insert style
menu->insert(str_label.c_str(), BScreen::SETSTYLE, FbTk::RefCount<FbTk::Command>
StringUtil::expandFilename(str_cmd).c_str()); setstyle_cmd(new FbCommands::
SetStyleCmd(StringUtil::
expandFilename(str_cmd)));
menu.insert(str_label.c_str(), setstyle_cmd);
} }
} // end of style } else if (str_key == "config") {
*/
else if (str_key == "config") {
if (! str_label.size()) { if (! str_label.size()) {
fprintf(stderr, fprintf(stderr,
i18n-> i18n->
@ -1580,9 +1582,12 @@ bool BScreen::parseMenuFile(ifstream &file, FbTk::Menu &menu, int &row) {
fprintf(stderr, fprintf(stderr,
i18n-> i18n->
getMessage( getMessage(
FBNLS::ScreenSet, FBNLS::ScreenINCLUDEErrorReg, FBNLS::ScreenSet,
FBNLS::ScreenINCLUDEErrorReg,
"BScreen::parseMenuFile: [include] error: " "BScreen::parseMenuFile: [include] error: "
"'%s' is not a regular file\n"), newfile.c_str()); "'%s' is not a regular file\n"),
newfile.c_str());
cerr<<"Row: "<<row<<endl; cerr<<"Row: "<<row<<endl;
} }
@ -1653,9 +1658,10 @@ bool BScreen::parseMenuFile(ifstream &file, FbTk::Menu &menu, int &row) {
FbTk::RefCount<FbTk::Command> reconfig_fb_cmd(new FbCommands::ReconfigureFluxboxCmd()); FbTk::RefCount<FbTk::Command> reconfig_fb_cmd(new FbCommands::ReconfigureFluxboxCmd());
menu.insert(str_label.c_str(), reconfig_fb_cmd); menu.insert(str_label.c_str(), reconfig_fb_cmd);
} }
} // end of reconf } else if (str_key == "stylesdir" || str_key == "stylesmenu") {
/* else if (str_key == "stylesdir" || str_key == "stylesmenu") {
bool newmenu = (str_key == "stylesmenu"); bool newmenu = (str_key == "stylesmenu");
if (!( str_label.size() && str_cmd.size()) && newmenu) { if (!( str_label.size() && str_cmd.size()) && newmenu) {
fprintf(stderr, fprintf(stderr,
i18n-> i18n->
@ -1664,11 +1670,11 @@ bool BScreen::parseMenuFile(ifstream &file, FbTk::Menu &menu, int &row) {
"BScreen::parseMenuFile: [stylesdir/stylesmenu]" "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
" error, no directory defined\n")); " error, no directory defined\n"));
cerr<<"Row: "<<row<<endl; cerr<<"Row: "<<row<<endl;
} else { // else 'y' } else {
createStyleMenu(menu, newmenu, str_label.c_str(), createStyleMenu(menu, newmenu, str_label.c_str(),
(newmenu) ? str_cmd.c_str() : str_label.c_str()); (newmenu) ? str_cmd.c_str() : str_label.c_str());
} // end of else 'y' }
} */// end of stylesdir } // end of stylesdir
else if (str_key == "workspaces") { else if (str_key == "workspaces") {
if (!str_label.size()) { if (!str_label.size()) {
fprintf(stderr, fprintf(stderr,
@ -1692,15 +1698,18 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
using namespace FBNLS; using namespace FBNLS;
FbTk::MacroCommand *s_a_reconf_macro = new FbTk::MacroCommand(); FbTk::MacroCommand *s_a_reconf_macro = new FbTk::MacroCommand();
FbTk::RefCount<FbTk::Command> saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(*Fluxbox::instance(), &Fluxbox::save_rc)); FbTk::RefCount<FbTk::Command> saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(*Fluxbox::instance(),
&Fluxbox::save_rc));
FbTk::RefCount<FbTk::Command> reconf_cmd(new FbCommands::ReconfigureFluxboxCmd()); FbTk::RefCount<FbTk::Command> reconf_cmd(new FbCommands::ReconfigureFluxboxCmd());
s_a_reconf_macro->add(saverc_cmd); s_a_reconf_macro->add(saverc_cmd);
s_a_reconf_macro->add(reconf_cmd); s_a_reconf_macro->add(reconf_cmd);
FbTk::RefCount<FbTk::Command> save_and_reconfigure(s_a_reconf_macro); FbTk::RefCount<FbTk::Command> save_and_reconfigure(s_a_reconf_macro);
#ifdef SLIT #ifdef SLIT
if (getSlit() != 0) if (getSlit() != 0)
menu.insert("Slit", &getSlit()->menu()); menu.insert("Slit", &getSlit()->menu());
#endif // SLIT #endif // SLIT
menu.insert(i18n->getMessage( menu.insert(i18n->getMessage(
ToolbarSet, ToolbarToolbarTitle, ToolbarSet, ToolbarToolbarTitle,
"Toolbar"), &m_toolbar->menu()); "Toolbar"), &m_toolbar->menu());
@ -1751,59 +1760,41 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
menu.update(); menu.update();
} }
void BScreen::createStyleMenu(FbTk::Menu &menu, bool newmenu, const char *label, const char *directory) { void BScreen::createStyleMenu(FbTk::Menu &menu, bool newmenu,
/* const char *label, const char *directory) {
// perform shell style ~ home directory expansion // perform shell style ~ home directory expansion
string stylesdir(StringUtil::expandFilename(directory ? directory : "")); string stylesdir(StringUtil::expandFilename(directory ? directory : ""));
I18n *i18n = I18n::instance(); I18n *i18n = I18n::instance();
struct stat statbuf; struct stat statbuf;
if (! stat(stylesdir.c_str(), &statbuf)) { // stat if (! stat(stylesdir.c_str(), &statbuf)) {
if (S_ISDIR(statbuf.st_mode)) { // dir if (S_ISDIR(statbuf.st_mode)) { // is a directory?
Rootmenu *stylesmenu;
if (newmenu)
stylesmenu = new Rootmenu(this);
else
stylesmenu = menu;
DirHelper d(stylesdir.c_str()); DirHelper d(stylesdir.c_str());
int entries = 0; std::vector<std::string> filelist(d.entries());
struct dirent *p; for (size_t file_index = 0; file_index < d.entries(); ++file_index)
filelist[file_index] = d.readFilename();
// get the total number of directory entries std::sort(filelist.begin(), filelist.end(), greater<string>());
while ((p = d.read())) entries++;
d.rewind(); int slen = stylesdir.size();
for (size_t file_index = 0; file_index < d.entries(); file_index++) {
char **ls = new char* [entries]; int nlen = filelist[file_index].size();
int index = 0;
while ((p = d.read()))
ls[index++] = StringUtil::strdup(p->d_name);
qsort(ls, entries, sizeof(char *), dcmp);
int n, slen = strlen(stylesdir.c_str());
for (n = 0; n < entries; n++) { // for
int nlen = strlen(ls[n]);
char style[MAXPATHLEN + 1]; char style[MAXPATHLEN + 1];
strncpy(style, stylesdir.c_str(), slen); strncpy(style, stylesdir.c_str(), slen);
*(style + slen) = '/'; *(style + slen) = '/';
strncpy(style + slen + 1, ls[n], nlen + 1); strncpy(style + slen + 1, filelist[file_index].c_str(), nlen + 1);
if ((! stat(style, &statbuf)) && S_ISREG(statbuf.st_mode)) if ( !stat(style, &statbuf) && S_ISREG(statbuf.st_mode)) {
stylesmenu->insert(ls[n], BScreen::SETSTYLE, style); FbTk::RefCount<FbTk::Command> setstyle_cmd(new FbCommands::
delete [] ls[n]; SetStyleCmd(style));
} menu.insert(filelist[file_index].c_str(), setstyle_cmd);
}
delete [] ls;
stylesmenu->update();
if (newmenu) {
stylesmenu->setLabel(label);
menu->insert(label, stylesmenu);
// rootmenuList.push_back(stylesmenu);
} }
menu.update();
// ??
Fluxbox::instance()->saveMenuFilename(stylesdir.c_str()); Fluxbox::instance()->saveMenuFilename(stylesdir.c_str());
} else { // dir } else { // dir
fprintf(stderr, fprintf(stderr,
@ -1821,28 +1812,28 @@ void BScreen::createStyleMenu(FbTk::Menu &menu, bool newmenu, const char *label,
FBNLS::ScreenSet, FBNLS::ScreenSTYLESDIRErrorNoExist, FBNLS::ScreenSet, FBNLS::ScreenSTYLESDIRErrorNoExist,
"BScreen::parseMenuFile: [stylesdir/stylesmenu]" "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
" error, %s does not exist\n"), stylesdir.c_str()); " error, %s does not exist\n"), stylesdir.c_str());
} // end of 'stat' } // end of stat
*/
} }
void BScreen::shutdown() { void BScreen::shutdown() {
XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), NoEventMask); XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), NoEventMask);
XSync(getBaseDisplay()->getXDisplay(), False); XSync(getBaseDisplay()->getXDisplay(), False);
{
Workspaces::iterator it = workspacesList.begin(); Workspaces::iterator it = workspacesList.begin();
Workspaces::iterator it_end = workspacesList.end(); Workspaces::iterator it_end = workspacesList.end();
for (; it != it_end; ++it) { for (; it != it_end; ++it) {
(*it)->shutdown(); (*it)->shutdown();
} }
}
{
while (!iconList.empty()) { while (!iconList.empty()) {
iconList.back()->restore(true); // restore with remap iconList.back()->restore(true); // restore with remap
delete iconList.back(); // the window removes it self from iconlist delete iconList.back(); // the window removes it self from iconlist
} }
}
#ifdef SLIT #ifdef SLIT
if (m_slit.get()) if (m_slit.get())