iconmenu is now handled in IconMenu which is created in WorkspaceMenu, moved all parsing of menu file to MenuCreator

This commit is contained in:
fluxgen 2004-05-02 21:12:22 +00:00
parent 347689ba69
commit 745dcf42c3
2 changed files with 105 additions and 520 deletions

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.276 2004/04/28 14:59:11 rathnor Exp $ // $Id: Screen.cc,v 1.277 2004/05/02 21:12:22 fluxgen Exp $
#include "Screen.hh" #include "Screen.hh"
@ -32,26 +32,34 @@
#include "Window.hh" #include "Window.hh"
#include "Workspace.hh" #include "Workspace.hh"
#include "Netizen.hh" #include "Netizen.hh"
// themes
#include "FbWinFrameTheme.hh" #include "FbWinFrameTheme.hh"
#include "MenuTheme.hh" #include "MenuTheme.hh"
#include "RootTheme.hh" #include "RootTheme.hh"
#include "WinButtonTheme.hh" #include "WinButtonTheme.hh"
#include "FbCommands.hh" #include "SlitTheme.hh"
// menu items
#include "BoolMenuItem.hh" #include "BoolMenuItem.hh"
#include "IntResMenuItem.hh" #include "IntResMenuItem.hh"
#include "FocusModelMenuItem.hh"
// menus
#include "FbMenu.hh" #include "FbMenu.hh"
#include "LayerMenu.hh" #include "LayerMenu.hh"
#include "MenuCreator.hh"
#include "WinClient.hh" #include "WinClient.hh"
#include "FbWinFrame.hh" #include "FbWinFrame.hh"
#include "FbWindow.hh"
#include "Strut.hh" #include "Strut.hh"
#include "SlitTheme.hh"
#include "CommandParser.hh" #include "CommandParser.hh"
#include "IconMenuItem.hh"
#include "AtomHandler.hh" #include "AtomHandler.hh"
#include "FbTk/Subject.hh" #include "FbTk/Subject.hh"
#include "FbTk/Directory.hh" #include "FbTk/FbWindow.hh"
#include "FbTk/SimpleCommand.hh" #include "FbTk/SimpleCommand.hh"
#include "FbTk/MultLayers.hh" #include "FbTk/MultLayers.hh"
#include "FbTk/XLayerItem.hh" #include "FbTk/XLayerItem.hh"
@ -119,6 +127,7 @@ extern "C" {
#include <memory> #include <memory>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <stack>
using namespace std; using namespace std;
@ -136,70 +145,9 @@ int anotherWMRunning(Display *display, XErrorEvent *) {
return -1; return -1;
} }
class FocusModelMenuItem : public FbTk::MenuItem {
public:
FocusModelMenuItem(const char *label, BScreen &screen,
BScreen::FocusModel model,
FbTk::RefCount<FbTk::Command> &cmd):
FbTk::MenuItem(label, cmd), m_screen(screen), m_focusmodel(model) {
}
bool isEnabled() const { return m_screen.getFocusModel() != m_focusmodel; }
void click(int button, int time) {
m_screen.saveFocusModel(m_focusmodel);
FbTk::MenuItem::click(button, time);
}
private:
BScreen &m_screen;
BScreen::FocusModel m_focusmodel;
};
} // End anonymous namespace } // end anonymous namespace
namespace {
class StyleMenuItem: public FbTk::MenuItem {
public:
StyleMenuItem(const std::string &label, const std::string &filename):
FbTk::MenuItem(label.c_str()),
m_filename(FbTk::StringUtil::
expandFilename(filename)) {
// perform shell style ~ home directory expansion
// and insert style
FbTk::RefCount<FbTk::Command>
setstyle_cmd(new FbCommands::
SetStyleCmd(m_filename));
setCommand(setstyle_cmd);
setToggleItem(true);
}
bool isSelected() const {
return Fluxbox::instance()->getStyleFilename() == m_filename;
}
private:
const std::string m_filename;
};
void setupWorkspacemenu(BScreen &scr, FbTk::Menu &menu) {
menu.removeAll(); // clear all items
using namespace FbTk;
menu.setLabel("Workspace");
RefCount<Command> new_workspace(new FbTk::SimpleCommand<BScreen, int>(scr, &BScreen::addWorkspace));
RefCount<Command> remove_last(new FbTk::SimpleCommand<BScreen, int>(scr, &BScreen::removeLastWorkspace));
//!! TODO: NLS
menu.insert("New Workspace", new_workspace);
menu.insert("Remove Last", remove_last);
// for each workspace add workspace name and it's menu to our workspace menu
for (size_t workspace = 0; workspace < scr.getCount(); ++workspace) {
Workspace *wkspc = scr.getWorkspace(workspace);
menu.insert(wkspc->name().c_str(), &wkspc->menu());
}
// update graphics
menu.update();
}
};
BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager &rm, BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager &rm,
@ -221,6 +169,7 @@ BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager &rm,
decorate_transient(rm, false, scrname+".decorateTransient", altscrname+".DecorateTransient"), decorate_transient(rm, false, scrname+".decorateTransient", altscrname+".DecorateTransient"),
rootcommand(rm, "", scrname+".rootCommand", altscrname+".RootCommand"), rootcommand(rm, "", scrname+".rootCommand", altscrname+".RootCommand"),
resizemode(rm, "", scrname+".resizeMode", altscrname+".ResizeMode"), resizemode(rm, "", scrname+".resizeMode", altscrname+".ResizeMode"),
windowmenufile(rm, "", scrname+".windowMenu", altscrname+".WindowMenu"),
focus_model(rm, CLICKTOFOCUS, scrname+".focusModel", altscrname+".FocusModel"), focus_model(rm, CLICKTOFOCUS, scrname+".focusModel", altscrname+".FocusModel"),
workspaces(rm, 1, scrname+".workspaces", altscrname+".Workspaces"), workspaces(rm, 1, scrname+".workspaces", altscrname+".Workspaces"),
edge_snap_threshold(rm, 0, scrname+".edgeSnapThreshold", altscrname+".EdgeSnapThreshold"), edge_snap_threshold(rm, 0, scrname+".edgeSnapThreshold", altscrname+".EdgeSnapThreshold"),
@ -387,12 +336,6 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
// setup workspaces and workspace menu // setup workspaces and workspace menu
workspacemenu.reset(createMenu(""));
workspacemenu->setInternalMenu();
//!! TODO: NLS
m_iconmenu.reset(createMenu("Icons"));
m_iconmenu->setInternalMenu();
if (*resource.workspaces != 0) { if (*resource.workspaces != 0) {
for (int i = 0; i < *resource.workspaces; ++i) { for (int i = 0; i < *resource.workspaces; ++i) {
Workspace *wkspc = new Workspace(*this, m_layermanager, Workspace *wkspc = new Workspace(*this, m_layermanager,
@ -407,10 +350,6 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
m_workspaces_list.push_back(wkspc); m_workspaces_list.push_back(wkspc);
} }
setupWorkspacemenu(*this, *workspacemenu);
//!! TODO: NLS
workspacemenu->insert("Icons", m_iconmenu.get());
workspacemenu->update();
m_current_workspace = m_workspaces_list.front(); m_current_workspace = m_workspaces_list.front();
@ -428,12 +367,6 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
setupConfigmenu(*m_configmenu.get()); setupConfigmenu(*m_configmenu.get());
m_configmenu->setInternalMenu(); m_configmenu->setInternalMenu();
workspacemenu->setItemSelected(2, true);
// create and initiate rootmenu
rereadMenu();
m_configmenu->update();
// start with workspace 0 // start with workspace 0
changeWorkspaceID(0); changeWorkspaceID(0);
updateNetizenWorkspaceCount(); updateNetizenWorkspaceCount();
@ -456,7 +389,6 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
rm.unlock(); rm.unlock();
XFlush(disp); XFlush(disp);
} }
@ -702,7 +634,7 @@ void BScreen::reconfigure() {
renderPosWindow(); renderPosWindow();
//reconfigure menus //reconfigure menus
workspacemenu->reconfigure(); m_workspacemenu->reconfigure();
m_configmenu->reconfigure(); m_configmenu->reconfigure();
// We need to check to see if the timestamps // We need to check to see if the timestamps
@ -780,17 +712,17 @@ void BScreen::updateWorkspaceNamesAtom() {
} }
void BScreen::addIcon(FluxboxWindow *w) { void BScreen::addIcon(FluxboxWindow *w) {
if (! w) return; if (w == 0)
return;
m_icon_list.push_back(w); m_icon_list.push_back(w);
updateIconMenu(); // notify listeners
m_iconlist_sig.notify(); m_iconlist_sig.notify();
} }
void BScreen::removeIcon(FluxboxWindow *w) { void BScreen::removeIcon(FluxboxWindow *w) {
if (! w) if (w == 0)
return; return;
Icons::iterator erase_it = remove_if(m_icon_list.begin(), Icons::iterator erase_it = remove_if(m_icon_list.begin(),
@ -798,26 +730,10 @@ void BScreen::removeIcon(FluxboxWindow *w) {
bind2nd(equal_to<FluxboxWindow *>(), w)); bind2nd(equal_to<FluxboxWindow *>(), w));
if (erase_it != m_icon_list.end()) if (erase_it != m_icon_list.end())
m_icon_list.erase(erase_it); m_icon_list.erase(erase_it);
updateIconMenu();
m_iconlist_sig.notify(); m_iconlist_sig.notify();
} }
void BScreen::updateIconMenu() {
m_iconmenu->removeAll();
Icons::iterator it = m_icon_list.begin();
Icons::iterator it_end = m_icon_list.end();
for (; it != it_end; ++it) {
FluxboxWindow::ClientList::iterator client_it = (*it)->clientList().begin();
FluxboxWindow::ClientList::iterator client_it_end = (*it)->clientList().end();
for (; client_it != client_it_end; ++client_it)
m_iconmenu->insert(new IconMenuItem(**client_it));
}
m_iconmenu->update();
}
void BScreen::removeWindow(FluxboxWindow *win) { void BScreen::removeWindow(FluxboxWindow *win) {
if (win->isIconic()) if (win->isIconic())
removeIcon(win); removeIcon(win);
@ -855,7 +771,8 @@ void BScreen::removeClient(WinClient &client) {
} }
} }
// the client could be on icon menu so we update it // the client could be on icon menu so we update it
updateIconMenu(); //!! TODO: check this with the new icon menu
// updateIconMenu();
} }
@ -872,11 +789,6 @@ int BScreen::addWorkspace() {
m_workspaces_list.size()); m_workspaces_list.size());
m_workspaces_list.push_back(wkspc); m_workspaces_list.push_back(wkspc);
addWorkspaceName(wkspc->name().c_str()); // update names addWorkspaceName(wkspc->name().c_str()); // update names
//add workspace to workspacemenu
workspacemenu->insert(wkspc->name().c_str(), &wkspc->menu(),
wkspc->workspaceID() + 2); //+2 so we add it after "remove last" item
workspacemenu->update();
saveWorkspaces(m_workspaces_list.size()); saveWorkspaces(m_workspaces_list.size());
updateNetizenWorkspaceCount(); updateNetizenWorkspaceCount();
@ -897,9 +809,6 @@ int BScreen::removeLastWorkspace() {
wkspc->removeAll(); wkspc->removeAll();
workspacemenu->remove(wkspc->workspaceID()+2); // + 2 is where workspaces starts
workspacemenu->update();
//remove last workspace //remove last workspace
m_workspaces_list.pop_back(); m_workspaces_list.pop_back();
delete wkspc; delete wkspc;
@ -944,12 +853,9 @@ void BScreen::changeWorkspaceID(unsigned int id) {
currentWorkspace()->hideAll(); currentWorkspace()->hideAll();
workspacemenu->setItemSelected(currentWorkspace()->workspaceID() + 2, false);
// set new workspace // set new workspace
m_current_workspace = getWorkspace(id); m_current_workspace = getWorkspace(id);
workspacemenu->setItemSelected(currentWorkspace()->workspaceID() + 2, true);
// This is a little tricks to reduce flicker // This is a little tricks to reduce flicker
// this way we can set focus pixmap on frame before we show it // this way we can set focus pixmap on frame before we show it
// and using ExposeEvent to redraw without flicker // and using ExposeEvent to redraw without flicker
@ -1066,7 +972,6 @@ void BScreen::updateNetizenWorkspaceCount() {
for_each(m_netizen_list.begin(), for_each(m_netizen_list.begin(),
m_netizen_list.end(), m_netizen_list.end(),
mem_fun(&Netizen::sendWorkspaceCount)); mem_fun(&Netizen::sendWorkspaceCount));
m_workspacecount_sig.notify(); m_workspacecount_sig.notify();
} }
@ -1165,6 +1070,7 @@ bool BScreen::addKdeDockapp(Window client) {
sprintf(intbuff, "%d", screenNumber()); sprintf(intbuff, "%d", screenNumber());
std::string atom_name("_NET_SYSTEM_TRAY_S"); std::string atom_name("_NET_SYSTEM_TRAY_S");
atom_name += intbuff; // append number atom_name += intbuff; // append number
// find the right atomhandler that has the name: _NET_SYSTEM_TRAY_S<num>
AtomHandler *handler = Fluxbox::instance()->getAtomHandler(atom_name); AtomHandler *handler = Fluxbox::instance()->getAtomHandler(atom_name);
FbTk::EventHandler *evh = 0; FbTk::EventHandler *evh = 0;
FbTk::EventManager *evm = FbTk::EventManager::instance(); FbTk::EventManager *evm = FbTk::EventManager::instance();
@ -1176,6 +1082,8 @@ bool BScreen::addKdeDockapp(Window client) {
#endif // SLIT #endif // SLIT
return false; return false;
} else { } else {
// this handler is a special case
// so we call setupClient in it
WinClient winclient(client, *this); WinClient winclient(client, *this);
handler->setupClient(winclient); handler->setupClient(winclient);
// we need to save old handler and re-add it later // we need to save old handler and re-add it later
@ -1732,6 +1640,10 @@ void BScreen::dirFocus(FluxboxWindow &win, const FocusDir dir) {
if (foundwin) if (foundwin)
foundwin->setInputFocus(); foundwin->setInputFocus();
} }
void BScreen::initMenus() {
m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber()));
initMenu();
}
void BScreen::initMenu() { void BScreen::initMenu() {
I18n *i18n = I18n::instance(); I18n *i18n = I18n::instance();
@ -1746,62 +1658,20 @@ void BScreen::initMenu() {
} else } else
m_rootmenu.reset(createMenu("")); m_rootmenu.reset(createMenu(""));
bool defaultMenu = true;
Fluxbox * const fb = Fluxbox::instance(); Fluxbox * const fb = Fluxbox::instance();
if (fb->getMenuFilename().size() > 0) { if (fb->getMenuFilename().size() > 0) {
std::string menufilestr = fb->getMenuFilename(); m_rootmenu.reset(MenuCreator::createFromFile(fb->getMenuFilename(),
menufilestr = FbTk::StringUtil::expandFilename(menufilestr); screenNumber()));
ifstream menu_file(menufilestr.c_str());
if (!menu_file.fail()) {
if (! menu_file.eof()) {
string line;
int row = 0;
while (getline(menu_file, line) && ! menu_file.eof()) {
row++;
if (line[0] != '#') {
string key;
int pos=0;
int err = FbTk::StringUtil::
getStringBetween(key,
line.c_str(),
'[', ']');
if (key == "begin") {
pos += err;
string label;
err = FbTk::StringUtil::
getStringBetween(label,
line.c_str()+pos,
'(', ')');
if (err>0) {
m_rootmenu->setLabel(label.c_str());
defaultMenu = parseMenuFile(menu_file, *m_rootmenu.get(), row);
// save filename so we can check timestamp on the root menu
if (!defaultMenu)
fb->saveMenuFilename(menufilestr.c_str());
} else
cerr<<"Error in menufile. Line("<<row<<")"<<endl;
break;
}
}
}
} else {
fprintf(stderr,
i18n->getMessage(
FBNLS::ScreenSet, FBNLS::ScreenEmptyMenuFile,
"%s: Empty menu file"),
menufilestr.c_str());
}
menu_file.close();
} else
perror(menufilestr.c_str());
} }
if (defaultMenu) {
FbTk::RefCount<FbTk::Command> restart_fb(new FbCommands::RestartFluxboxCmd(""));
FbTk::RefCount<FbTk::Command> exit_fb(new FbCommands::ExitFluxboxCmd()); if (m_rootmenu.get() == 0) {
FbTk::RefCount<FbTk::Command> execute_xterm(new FbCommands::ExecuteCmd("xterm", screenNumber())); m_rootmenu.reset(createMenu("Fluxbox default menu"));
FbTk::RefCount<FbTk::Command> restart_fb(CommandParser::instance().parseLine("restart"));
FbTk::RefCount<FbTk::Command> exit_fb(CommandParser::instance().parseLine("exit"));
FbTk::RefCount<FbTk::Command> execute_xterm(CommandParser::instance().parseLine("exec xterm"));
m_rootmenu->setInternalMenu(); m_rootmenu->setInternalMenu();
m_rootmenu->insert(i18n->getMessage(FBNLS::ScreenSet, FBNLS::Screenxterm, m_rootmenu->insert(i18n->getMessage(FBNLS::ScreenSet, FBNLS::Screenxterm,
"xterm"), "xterm"),
@ -1813,231 +1683,9 @@ void BScreen::initMenu() {
"Exit"), "Exit"),
exit_fb); exit_fb);
} }
} }
/// looks through a menufile and adds correct items to the root-menu.
bool BScreen::parseMenuFile(ifstream &file, FbTk::Menu &menu, int &row) {
string line;
FbTk::RefCount<FbTk::Command>
hide_menu(new FbTk::SimpleCommand<FbTk::Menu>(menu, &FbTk::Menu::hide));
while (! file.eof()) {
if (!getline(file, line))
continue;
row++;
if (line[0] == '#') //the line is commented
continue;
int parse_pos = 0, err = 0;
std::string str_key, str_label, str_cmd;
err = FbTk::StringUtil::
getStringBetween(str_key,
line.c_str(),
'[', ']');
if (err > 0 ) {
parse_pos += err;
err = FbTk::StringUtil::
getStringBetween(str_label,
line.c_str() + parse_pos,
'(', ')');
if (err>0) {
parse_pos += err;
FbTk::StringUtil::
getStringBetween(str_cmd,
line.c_str() + parse_pos,
'{', '}');
}
} else
continue; //read next line
if (!str_key.size())
continue; //read next line
I18n *i18n = I18n::instance();
if (str_key == "end") {
return ((menu.numberOfItems() == 0) ? true : false);
} else if (str_key == "nop") {
menu.insert(str_label.c_str());
} else if (str_key == "exec") { // exec
if (!(str_label.size() && str_cmd.size())) {
fprintf(stderr,
i18n->getMessage(FBNLS::ScreenSet, FBNLS::ScreenEXECError,
"BScreen::parseMenuFile: [exec] error, "
"no menu label and/or command defined\n"));
cerr<<"Row: "<<row<<endl;
} else {
FbTk::RefCount<FbTk::Command> exec_cmd(new FbCommands::ExecuteCmd(str_cmd, screenNumber()));
FbTk::MacroCommand *exec_and_hide = new FbTk::MacroCommand();
exec_and_hide->add(hide_menu);
exec_and_hide->add(exec_cmd);
FbTk::RefCount<FbTk::Command> exec_and_hide_cmd(exec_and_hide);
menu.insert(str_label.c_str(), exec_and_hide_cmd);
}
} else if (str_key == "exit") { // exit
if (!str_label.size()) {
fprintf(stderr,
i18n->getMessage(FBNLS::ScreenSet, FBNLS::ScreenEXITError,
"BScreen::parseMenuFile: [exit] error, "
"no menu label defined\n"));
cerr<<"Row: "<<row<<endl;
} else {
FbTk::RefCount<FbTk::Command> exit_fb_cmd(new FbCommands::ExitFluxboxCmd());
menu.insert(str_label.c_str(), exit_fb_cmd);
}
} else if (str_key == "style") { // style
if (!( str_label.size() && str_cmd.size())) {
fprintf(stderr,
i18n->
getMessage(FBNLS::ScreenSet, FBNLS::ScreenSTYLEError,
"BScreen::parseMenuFile: [style] error, "
"no menu label and/or filename defined\n"));
cerr<<"Row: "<<row<<endl;
} else
menu.insert(new StyleMenuItem(str_label, str_cmd));
} else if (str_key == "config") {
if (! str_label.size()) {
fprintf(stderr,
i18n->
getMessage(FBNLS::ScreenSet, FBNLS::ScreenCONFIGError,
"BScreen::parseMenufile: [config] error, "
"no label defined"));
cerr<<"Row: "<<row<<endl;
} else {
#ifdef DEBUG
cerr<<__FILE__<<"("<<__FUNCTION__<<
"): inserts configmenu: "<<m_configmenu.get()<<endl;
#endif // DEBUG
menu.insert(str_label.c_str(), m_configmenu.get());
}
} // end of config
else if ( str_key == "include") { // include
if (!str_label.size()) {
fprintf(stderr,
i18n->
getMessage(FBNLS::ScreenSet, FBNLS::ScreenINCLUDEError,
"BScreen::parseMenuFile: [include] error, "
"no filename defined\n"));
cerr<<"Row: "<<row<<endl;
} else { // start of else 'x'
// perform shell style ~ home directory expansion
string newfile(FbTk::StringUtil::expandFilename(str_label));
if (!newfile.empty()) {
if (!FbTk::Directory::isRegularFile(newfile)) {
fprintf(stderr,
i18n->
getMessage(
FBNLS::ScreenSet,
FBNLS::ScreenINCLUDEErrorReg,
"BScreen::parseMenuFile: [include] error: "
"'%s' is not a regular file\n"),
newfile.c_str());
cerr<<"Row: "<<row<<endl;
} else {
// the file is a regular file, lets open and parse it
ifstream subfile(newfile.c_str());
if (!parseMenuFile(subfile, menu, row))
Fluxbox::instance()->saveMenuFilename(newfile.c_str());
}
}
} // end of else 'x'
} // end of include
else if (str_key == "submenu") { // sub
if (!str_label.size()) {
fprintf(stderr,
i18n->
getMessage(FBNLS::ScreenSet, FBNLS::ScreenSUBMENUError,
"BScreen::parseMenuFile: [submenu] error, "
"no menu label defined\n"));
cerr<<"Row: "<<row<<endl;
} else {
FbTk::Menu *submenu = createMenu("");
if (str_cmd.size())
submenu->setLabel(str_cmd.c_str());
else
submenu->setLabel(str_label.c_str());
parseMenuFile(file, *submenu, row);
submenu->update();
menu.insert(str_label.c_str(), submenu);
// save to list so we can delete it later
m_rootmenu_list.push_back(submenu);
}
} // end of sub
else if (str_key == "restart") {
if (!str_label.size()) {
fprintf(stderr,
i18n->
getMessage(FBNLS::ScreenSet, FBNLS::ScreenRESTARTError,
"BScreen::parseMenuFile: [restart] error, "
"no menu label defined\n"));
cerr<<"Row: "<<row<<endl;
} else {
FbTk::RefCount<FbTk::Command> restart_fb(new FbCommands::RestartFluxboxCmd(str_cmd));
menu.insert(str_label.c_str(), restart_fb);
}
} // end of restart
else if (str_key == "reconfig") { // reconf
if (!str_label.c_str()) {
fprintf(stderr,
i18n->
getMessage(FBNLS::ScreenSet, FBNLS::ScreenRECONFIGError,
"BScreen::parseMenuFile: [reconfig] error, "
"no menu label defined\n"));
cerr<<"Row: "<<row<<endl;
} else {
FbTk::RefCount<FbTk::Command>
reconfig_fb_cmd(new FbCommands::ReconfigureFluxboxCmd());
menu.insert(str_label.c_str(), reconfig_fb_cmd);
}
} else if (str_key == "stylesdir" || str_key == "stylesmenu") {
bool newmenu = (str_key == "stylesmenu");
if (!( str_label.size() && str_cmd.size()) && newmenu) {
fprintf(stderr,
i18n->
getMessage(FBNLS::ScreenSet, FBNLS::ScreenSTYLESDIRError,
"BScreen::parseMenuFile: [stylesdir/stylesmenu]"
" error, no directory defined\n"));
cerr<<"Row: "<<row<<endl;
} else {
createStyleMenu(menu, str_label.c_str(),
newmenu ? str_cmd.c_str() : str_label.c_str());
}
} // end of stylesdir
else if (str_key == "workspaces") {
if (!str_label.size()) {
fprintf(stderr,
i18n->getMessage(FBNLS::ScreenSet, FBNLS::ScreenWORKSPACESError,
"BScreen:parseMenuFile: [workspaces] error, "
"no menu label defined\n"));
cerr<<"Row: "<<row<<endl;
} else
menu.insert(str_label.c_str(), workspacemenu.get());
} else if (str_key == "separator") {
menu.insert("---"); //!! TODO: this will be better in the future
}
else { // ok, if we didn't find any special menu item we try with command parser
// we need to attach command with arguments so command parser can parse it
string line = str_key + " " + str_cmd;
FbTk::RefCount<FbTk::Command> command(CommandParser::instance().parseLine(line));
if (*command != 0)
menu.insert(str_label.c_str(), command);
}
} // end of while not eof
return ((menu.numberOfItems() == 0) ? true : false);
}
void BScreen::addConfigMenu(const char *label, FbTk::Menu &menu) { void BScreen::addConfigMenu(const char *label, FbTk::Menu &menu) {
m_configmenu_list.push_back(std::make_pair(label, &menu)); m_configmenu_list.push_back(std::make_pair(label, &menu));
@ -2065,7 +1713,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
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(), FbTk::RefCount<FbTk::Command> saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(*Fluxbox::instance(),
&Fluxbox::save_rc)); &Fluxbox::save_rc));
FbTk::RefCount<FbTk::Command> reconf_cmd(new FbCommands::ReconfigureFluxboxCmd()); FbTk::RefCount<FbTk::Command> reconf_cmd(CommandParser::instance().parseLine("reconfigure"));
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);
@ -2076,26 +1724,18 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
"Focus Model"); "Focus Model");
FbTk::Menu *focus_menu = createMenu(focusmenu_label ? focusmenu_label : ""); FbTk::Menu *focus_menu = createMenu(focusmenu_label ? focusmenu_label : "");
focus_menu->insert(new FocusModelMenuItem(i18n->getMessage(ConfigmenuSet, #define _FOCUSITEM(a, b, c, d) focus_menu->insert(new FocusModelMenuItem(i18n->getMessage(a, b, c), *this, d, save_and_reconfigure))
ConfigmenuClickToFocus,
"Click To Focus"),
*this,
CLICKTOFOCUS,
save_and_reconfigure));
focus_menu->insert(new FocusModelMenuItem(i18n->getMessage(ConfigmenuSet, _FOCUSITEM(ConfigmenuSet, ConfigmenuClickToFocus,
ConfigmenuSloppyFocus, "Click To Focus",
"Sloppy Focus"), CLICKTOFOCUS);
*this, _FOCUSITEM(ConfigmenuSet, ConfigmenuSloppyFocus,
SLOPPYFOCUS, "Sloppy Focus",
save_and_reconfigure)); SLOPPYFOCUS);
_FOCUSITEM(ConfigmenuSet, ConfigmenuSemiSloppyFocus,
focus_menu->insert(new FocusModelMenuItem(i18n->getMessage(ConfigmenuSet, "Semi Sloppy Focus",
ConfigmenuSemiSloppyFocus, SEMISLOPPYFOCUS);
"Semi Sloppy Focus"), #undef _FOCUSITEM
*this,
SEMISLOPPYFOCUS,
save_and_reconfigure));
focus_menu->insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, focus_menu->insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet,
ConfigmenuAutoRaise, ConfigmenuAutoRaise,
@ -2118,48 +1758,42 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
for (; it != it_end; ++it) for (; it != it_end; ++it)
menu.insert(it->first, it->second); menu.insert(it->first, it->second);
menu.insert(new #define _BOOLITEM(a, b, c, d, e) menu.insert(new BoolMenuItem(i18n->getMessage(a, b, c), d, e))
BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuImageDithering,
"Image Dithering"), _BOOLITEM(ConfigmenuSet, ConfigmenuImageDithering,
*resource.image_dither, save_and_reconfigure)); "Image Dithering",
menu.insert(new *resource.image_dither, save_and_reconfigure);
BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuOpaqueMove, _BOOLITEM(ConfigmenuSet, ConfigmenuOpaqueMove,
"Opaque Window Moving"), "Opaque Window Moving",
*resource.opaque_move, saverc_cmd)); *resource.opaque_move, saverc_cmd);
menu.insert(new _BOOLITEM(ConfigmenuSet, ConfigmenuFullMax,
BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuFullMax, "Full Maximization",
"Full Maximization"), *resource.full_max, saverc_cmd);
*resource.full_max, saverc_cmd)); _BOOLITEM(ConfigmenuSet, ConfigmenuFocusNew,
menu.insert(new "Focus New Windows",
BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusNew, *resource.focus_new, saverc_cmd);
"Focus New Windows"), _BOOLITEM(ConfigmenuSet, ConfigmenuFocusLast,
*resource.focus_new, saverc_cmd)); "Focus Last Window on Workspace",
menu.insert(new *resource.focus_last, saverc_cmd);
BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusLast, _BOOLITEM(ConfigmenuSet, ConfigmenuWorkspaceWarping,
"Focus Last Window on Workspace"), "Workspace Warping",
*resource.focus_last, saverc_cmd)); *resource.workspace_warping, saverc_cmd);
_BOOLITEM(ConfigmenuSet, ConfigmenuDesktopWheeling,
menu.insert(new "Desktop MouseWheel Switching",
BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuWorkspaceWarping, *resource.desktop_wheeling, saverc_cmd);
"Workspace Warping"), _BOOLITEM(ConfigmenuSet, ConfigmenuDecorateTransient,
*resource.workspace_warping, saverc_cmd)); "Decorate Transient Windows",
menu.insert(new *resource.decorate_transient, saverc_cmd);
BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuDesktopWheeling, _BOOLITEM(ConfigmenuSet, ConfigmenuClickRaises,
"Desktop MouseWheel Switching"), "Click Raises",
*resource.desktop_wheeling, saverc_cmd)); *resource.click_raises, saverc_cmd);
menu.insert(new
BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuDecorateTransient,
"Decorate Transient Windows"),
*resource.decorate_transient, saverc_cmd));
menu.insert(new BoolMenuItem("Click Raises",
*resource.click_raises,
saverc_cmd));
// setup antialias cmd to reload style and save resource on toggle // setup antialias cmd to reload style and save resource on toggle
menu.insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuAntiAlias, _BOOLITEM(ConfigmenuSet, ConfigmenuAntiAlias,
"AntiAlias"), "AntiAlias",
*resource.antialias, *resource.antialias, save_and_reconfigure);
save_and_reconfigure));
#undef _BOOLITEM
//!! TODO: antialias //!! TODO: antialias
FbTk::MenuItem *menu_alpha_item = new IntResMenuItem("Menu Alpha", resource.menu_alpha, FbTk::MenuItem *menu_alpha_item = new IntResMenuItem("Menu Alpha", resource.menu_alpha,
0, 255); 0, 255);
@ -2172,45 +1806,6 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
menu.update(); menu.update();
} }
void BScreen::createStyleMenu(FbTk::Menu &menu,
const char *label, const char *directory) {
// perform shell style ~ home directory expansion
string stylesdir(FbTk::StringUtil::expandFilename(directory ? directory : ""));
if (!FbTk::Directory::isDirectory(stylesdir)) {
//!! TODO: NLS
cerr<<"Error creating style menu! Stylesdir: "<<stylesdir<<" does not exist or is not a directory!"<<endl;
return;
}
FbTk::Directory dir(stylesdir.c_str());
// create a vector of all the filenames in the directory
// add sort it
std::vector<std::string> filelist(dir.entries());
for (size_t file_index = 0; file_index < dir.entries(); ++file_index)
filelist[file_index] = dir.readFilename();
std::sort(filelist.begin(), filelist.end(), less<string>());
// for each file in directory add filename and path to menu
for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
std::string style(stylesdir + '/' + filelist[file_index]);
// add to menu only if the file is a regular file, and not a
// .file or a backup~ file
if ((FbTk::Directory::isRegularFile(style) &&
(filelist[file_index][0] != '.') &&
(style[style.length() - 1] != '~')
) || FbTk::Directory::isRegularFile(style + "/theme.cfg"))
menu.insert(new StyleMenuItem(filelist[file_index], style));
}
// update menu graphics
menu.update();
Fluxbox::instance()->saveMenuFilename(stylesdir.c_str());
}
void BScreen::shutdown() { void BScreen::shutdown() {
rootWindow().setEventMask(NoEventMask); rootWindow().setEventMask(NoEventMask);

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.hh,v 1.140 2004/04/28 14:59:11 rathnor Exp $ // $Id: Screen.hh,v 1.141 2004/05/02 21:10:30 fluxgen Exp $
#ifndef SCREEN_HH #ifndef SCREEN_HH
#define SCREEN_HH #define SCREEN_HH
@ -74,9 +74,13 @@ class BScreen : public FbTk::Observer, private FbTk::NotCopyable {
public: public:
enum FocusModel { SLOPPYFOCUS=0, SEMISLOPPYFOCUS, CLICKTOFOCUS }; enum FocusModel { SLOPPYFOCUS=0, SEMISLOPPYFOCUS, CLICKTOFOCUS };
enum FocusDir { FOCUSUP, FOCUSDOWN, FOCUSLEFT, FOCUSRIGHT }; enum FocusDir { FOCUSUP, FOCUSDOWN, FOCUSLEFT, FOCUSRIGHT };
enum PlacementPolicy { ROWSMARTPLACEMENT, COLSMARTPLACEMENT, CASCADEPLACEMENT, UNDERMOUSEPLACEMENT}; enum PlacementPolicy { ROWSMARTPLACEMENT, COLSMARTPLACEMENT,
CASCADEPLACEMENT, UNDERMOUSEPLACEMENT};
enum RowDirection { LEFTRIGHT, RIGHTLEFT}; enum RowDirection { LEFTRIGHT, RIGHTLEFT};
enum ColumnDirection { TOPBOTTOM, BOTTOMTOP}; enum ColumnDirection { TOPBOTTOM, BOTTOMTOP};
// prevFocus/nextFocus option bits
enum { CYCLEGROUPS = 0x01, CYCLESKIPSTUCK = 0x02, CYCLESKIPSHADED = 0x04,
CYCLELINEAR = 0x08, CYCLEDEFAULT = 0x00 };
typedef std::vector<FluxboxWindow *> Icons; typedef std::vector<FluxboxWindow *> Icons;
typedef std::list<WinClient *> FocusedWindows; typedef std::list<WinClient *> FocusedWindows;
@ -89,6 +93,7 @@ public:
~BScreen(); ~BScreen();
void initWindows(); void initWindows();
void initMenus();
inline bool isSloppyFocus() const { return (*resource.focus_model == SLOPPYFOCUS); } inline bool isSloppyFocus() const { return (*resource.focus_model == SLOPPYFOCUS); }
inline bool isSemiSloppyFocus() const { return (*resource.focus_model == SEMISLOPPYFOCUS); } inline bool isSemiSloppyFocus() const { return (*resource.focus_model == SEMISLOPPYFOCUS); }
inline bool isRootColormapInstalled() const { return root_colormap_installed; } inline bool isRootColormapInstalled() const { return root_colormap_installed; }
@ -105,11 +110,13 @@ public:
inline bool doShowWindowPos() const { return *resource.show_window_pos; } inline bool doShowWindowPos() const { return *resource.show_window_pos; }
inline bool antialias() const { return *resource.antialias; } inline bool antialias() const { return *resource.antialias; }
inline bool decorateTransient() const { return *resource.decorate_transient; } inline bool decorateTransient() const { return *resource.decorate_transient; }
inline const std::string &windowMenuFilename() const { return *resource.windowmenufile; }
inline FbTk::ImageControl &imageControl() { return *m_image_control.get(); } inline FbTk::ImageControl &imageControl() { return *m_image_control.get(); }
const FbTk::Menu &getRootmenu() const { return *m_rootmenu.get(); } const FbTk::Menu &getRootmenu() const { return *m_rootmenu.get(); }
FbTk::Menu &getRootmenu() { return *m_rootmenu.get(); } FbTk::Menu &getRootmenu() { return *m_rootmenu.get(); }
const FbTk::Menu &configMenu() const { return *m_configmenu.get(); }
FbTk::Menu &configMenu() { return *m_configmenu.get(); }
inline const std::string &getRootCommand() const { return *resource.rootcommand; } inline const std::string &getRootCommand() const { return *resource.rootcommand; }
inline const std::string &getResizeMode() const { return *resource.resizemode; } inline const std::string &getResizeMode() const { return *resource.resizemode; }
inline FocusModel getFocusModel() const { return *resource.focus_model; } inline FocusModel getFocusModel() const { return *resource.focus_model; }
@ -121,9 +128,8 @@ public:
inline Workspace *currentWorkspace() { return m_current_workspace; } inline Workspace *currentWorkspace() { return m_current_workspace; }
inline const Workspace *currentWorkspace() const { return m_current_workspace; } inline const Workspace *currentWorkspace() const { return m_current_workspace; }
const FbTk::Menu &getWorkspacemenu() const { return *workspacemenu.get(); } const FbTk::Menu &getWorkspacemenu() const { return *m_workspacemenu.get(); }
FbTk::Menu &getWorkspacemenu() { return *workspacemenu.get(); } FbTk::Menu &getWorkspacemenu() { return *m_workspacemenu.get(); }
unsigned int currentWorkspaceID() const; unsigned int currentWorkspaceID() const;
@ -200,6 +206,7 @@ public:
inline void saveFocusModel(FocusModel model) { resource.focus_model = model; } inline void saveFocusModel(FocusModel model) { resource.focus_model = model; }
inline void saveWorkspaces(int w) { *resource.workspaces = w; } inline void saveWorkspaces(int w) { *resource.workspaces = w; }
void saveMenu(FbTk::Menu &menu) { m_rootmenu_list.push_back(&menu); }
void setAntialias(bool value); void setAntialias(bool value);
@ -338,13 +345,6 @@ public:
// prevFocus/nextFocus option bits
enum { CYCLEGROUPS = 0x01, CYCLESKIPSTUCK = 0x02, CYCLESKIPSHADED = 0x04,
CYCLELINEAR = 0x08, CYCLEDEFAULT = 0x00 };
class ScreenSubject:public FbTk::Subject { class ScreenSubject:public FbTk::Subject {
public: public:
ScreenSubject(BScreen &scr):m_scr(scr) { } ScreenSubject(BScreen &scr):m_scr(scr) { }
@ -356,17 +356,10 @@ public:
private: private:
void setupConfigmenu(FbTk::Menu &menu); void setupConfigmenu(FbTk::Menu &menu);
void createStyleMenu(FbTk::Menu &menu, const char *label, const char *directory);
bool parseMenuFile(std::ifstream &filestream, FbTk::Menu &menu, int &row);
void initMenu(); void initMenu();
bool doSkipWindow(const WinClient &winclient, int options); bool doSkipWindow(const WinClient &winclient, int options);
void renderGeomWindow(); void renderGeomWindow();
void renderPosWindow(); void renderPosWindow();
void updateIconMenu();
ScreenSubject ScreenSubject
m_clientlist_sig, ///< client signal m_clientlist_sig, ///< client signal
@ -387,9 +380,7 @@ private:
FbTk::FbWindow m_geom_window, m_pos_window; FbTk::FbWindow m_geom_window, m_pos_window;
std::auto_ptr<FbTk::ImageControl> m_image_control; std::auto_ptr<FbTk::ImageControl> m_image_control;
std::auto_ptr<FbTk::Menu> m_configmenu; std::auto_ptr<FbTk::Menu> m_configmenu, m_rootmenu, m_workspacemenu;
std::auto_ptr<FbTk::Menu> m_rootmenu;
typedef std::list<FbTk::Menu *> Rootmenus; typedef std::list<FbTk::Menu *> Rootmenus;
typedef std::list<Netizen *> Netizens; typedef std::list<Netizen *> Netizens;
@ -410,8 +401,6 @@ private:
std::auto_ptr<Slit> m_slit; std::auto_ptr<Slit> m_slit;
Workspace *m_current_workspace; Workspace *m_current_workspace;
std::auto_ptr<FbTk::Menu> workspacemenu;
std::auto_ptr<FbTk::Menu> m_iconmenu;
WorkspaceNames m_workspace_names; WorkspaceNames m_workspace_names;
Workspaces m_workspaces_list; Workspaces m_workspaces_list;
@ -434,6 +423,7 @@ private:
antialias, auto_raise, click_raises, decorate_transient; antialias, auto_raise, click_raises, decorate_transient;
FbTk::Resource<std::string> rootcommand; FbTk::Resource<std::string> rootcommand;
FbTk::Resource<std::string> resizemode; FbTk::Resource<std::string> resizemode;
FbTk::Resource<std::string> windowmenufile;
FbTk::Resource<FocusModel> focus_model; FbTk::Resource<FocusModel> focus_model;
bool ordered_dither; bool ordered_dither;
FbTk::Resource<int> workspaces, edge_snap_threshold, menu_alpha, menu_delay, menu_delay_close; FbTk::Resource<int> workspaces, edge_snap_threshold, menu_alpha, menu_delay, menu_delay_close;