From 6dffafc39e4b11542705e2d4cd8477545967f5fc Mon Sep 17 00:00:00 2001 From: mathias Date: Tue, 21 Dec 2004 16:09:36 +0000 Subject: * added new command: sethead which sets the current window to head * added remembering of the head to apps-file: [Head] {} --- src/CurrentWindowCmd.cc | 4 ++ src/CurrentWindowCmd.hh | 9 ++++ src/FbCommandFactory.cc | 3 ++ src/Remember.cc | 130 +++++++++++++++++++++++++++++------------------- src/Remember.hh | 17 +++++-- src/Screen.cc | 13 ++++- 6 files changed, 119 insertions(+), 57 deletions(-) diff --git a/src/CurrentWindowCmd.cc b/src/CurrentWindowCmd.cc index a07dbb2..68bead7 100644 --- a/src/CurrentWindowCmd.cc +++ b/src/CurrentWindowCmd.cc @@ -42,6 +42,10 @@ void KillWindowCmd::real_execute() { winclient().sendClose(true); } +void SetHeadCmd::real_execute() { + fbwindow().screen().setOnHead(fbwindow(), m_head); +} + void SendToWorkspaceCmd::real_execute() { if (m_workspace_num >= 0 && m_workspace_num < fbwindow().screen().getNumberOfWorkspaces()) fbwindow().screen().sendToWorkspace(m_workspace_num, &fbwindow()); diff --git a/src/CurrentWindowCmd.hh b/src/CurrentWindowCmd.hh index 9b8e8fb..4b05030 100644 --- a/src/CurrentWindowCmd.hh +++ b/src/CurrentWindowCmd.hh @@ -60,6 +60,15 @@ protected: void real_execute(); }; +class SetHeadCmd : public WindowHelperCmd { +public: + explicit SetHeadCmd(int head) : m_head(head) { } +protected: + void real_execute(); +private: + const int m_head; +}; + class SendToWorkspaceCmd: public WindowHelperCmd { public: explicit SendToWorkspaceCmd(int workspace_num):m_workspace_num(workspace_num) { } diff --git a/src/FbCommandFactory.cc b/src/FbCommandFactory.cc index a70e09b..d3e3757 100644 --- a/src/FbCommandFactory.cc +++ b/src/FbCommandFactory.cc @@ -118,6 +118,7 @@ FbCommandFactory::FbCommandFactory() { "rootmenu", "saverc", "setenv", + "sethead", "sendtoworkspace", "sendtonextworkspace", "sendtoprevworkspace", @@ -279,6 +280,8 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, return new CurrentWindowCmd(&FluxboxWindow::stick); else if (command == "toggledecor") return new CurrentWindowCmd(&FluxboxWindow::toggleDecoration); + else if (command == "sethead") + return new SetHeadCmd(atoi(arguments.c_str())); else if (command == "sendtoworkspace") return new SendToWorkspaceCmd(atoi(arguments.c_str()) - 1); // make 1-indexed to user else if (command == "sendtonextworkspace") diff --git a/src/Remember.cc b/src/Remember.cc index e74ace2..21e078e 100644 --- a/src/Remember.cc +++ b/src/Remember.cc @@ -59,7 +59,7 @@ #ifdef HAVE_SSTREAM #include #define FB_istringstream istringstream -#elif HAVE_STRSTREAM +#elif HAVE_STRSTREAM #include #define FB_istringstream istrstream #else @@ -75,9 +75,9 @@ public: RememberMenuItem(const char *label, Remember &remember, FluxboxWindow &fbwin, Remember::Attribute attrib) : - FbTk::MenuItem(label), m_remember(remember), + FbTk::MenuItem(label), m_remember(remember), m_win(fbwin), m_attrib(attrib) { - setToggleItem(true); + setToggleItem(true); } bool isSelected() const { @@ -88,7 +88,7 @@ public: } bool isEnabled() const { - if (m_attrib != Remember::REM_JUMPWORKSPACE) + if (m_attrib != Remember::REM_JUMPWORKSPACE) return true; else if (m_win.numClients()) return (m_remember.isRemembered(m_win.winClient(), Remember::REM_WORKSPACE)); @@ -126,17 +126,19 @@ FbTk::Menu *createRememberMenu(Remember &remember, FluxboxWindow &win, bool enab menu->updateMenu(); return menu; } - + _FB_USES_NLS; - menu->insert(new RememberMenuItem(_FBTEXT(Remember, Workspace, "Workspace", "Remember Workspace"), + menu->insert(new RememberMenuItem(_FBTEXT(Remember, Workspace, "Workspace", "Remember Workspace"), remember, win, Remember::REM_WORKSPACE)); menu->insert(new RememberMenuItem(_FBTEXT(Remember, JumpToWorkspace, "Jump to workspace", "Change active workspace to remembered one on open"), remember, win, Remember::REM_JUMPWORKSPACE)); - menu->insert(new RememberMenuItem(_FBTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - windth width and height"), + menu->insert(new RememberMenuItem(_FBTEXT(Remember, Head, "Head", "Remember Head"), + remember, win, Remember::REM_HEAD)); + menu->insert(new RememberMenuItem(_FBTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - with width and height"), remember, win, Remember::REM_DIMENSIONS)); - menu->insert(new RememberMenuItem(_FBTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"), + menu->insert(new RememberMenuItem(_FBTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"), remember, win, Remember::REM_POSITION)); - menu->insert(new RememberMenuItem(_FBTEXT(Remember, Sticky, "Sticky", "Remember Sticky"), + menu->insert(new RememberMenuItem(_FBTEXT(Remember, Sticky, "Sticky", "Remember Sticky"), remember, win, Remember::REM_STUCKSTATE)); menu->insert(new RememberMenuItem(_FBTEXT(Remember, Decorations, "Decorations", "Remember window decorations"), remember, win, Remember::REM_DECOSTATE)); @@ -160,8 +162,8 @@ bool handleStartupItem(const string &line, int offset) { // accept some options, for now only "screen=NN" // these option are given in parentheses before the command - next = FbTk::StringUtil::getStringBetween(str, - line.c_str() + offset, + next = FbTk::StringUtil::getStringBetween(str, + line.c_str() + offset, '(', ')'); if (next > 0) { // there are some options @@ -187,8 +189,8 @@ bool handleStartupItem(const string &line, int offset) { next = 0; } - next = FbTk::StringUtil::getStringBetween(str, - line.c_str() + offset + next, + next = FbTk::StringUtil::getStringBetween(str, + line.c_str() + offset + next, '{', '}'); if (next <= 0) { @@ -212,17 +214,18 @@ Application::Application(bool grouped) : is_grouped(grouped), group(0) { - decostate_remember = + decostate_remember = dimensions_remember = - focushiddenstate_remember = + focushiddenstate_remember = iconhiddenstate_remember = - jumpworkspace_remember = - layer_remember = + jumpworkspace_remember = + layer_remember = position_remember = shadedstate_remember = - stuckstate_remember = + stuckstate_remember = tabstate_remember = - workspace_remember = + workspace_remember = + head_remember = save_on_close_remember = false; } @@ -264,7 +267,7 @@ Application* Remember::find(WinClient &winclient) { return wc_it->second; else { Patterns::iterator it = m_pats.begin(); - for (; it != m_pats.end(); it++) + for (; it != m_pats.end(); it++) if (it->first->match(winclient)) { it->first->addMatch(); m_clients[&winclient] = it->second; @@ -304,8 +307,8 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { continue; //the line is commented or blank int parse_pos = 0, err = 0; string str_key, str_option, str_label; - err = FbTk::StringUtil::getStringBetween(str_key, - line.c_str(), + err = FbTk::StringUtil::getStringBetween(str_key, + line.c_str(), '[', ']'); if (err > 0) { int tmp; @@ -317,8 +320,8 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { } if (err > 0 ) { parse_pos += err; - err = FbTk::StringUtil::getStringBetween(str_label, - line.c_str() + parse_pos, + err = FbTk::StringUtil::getStringBetween(str_label, + line.c_str() + parse_pos, '{', '}'); if (err>0) { parse_pos += err; @@ -333,6 +336,9 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { FB_istringstream iss(str_label.c_str()); iss >> w; app.rememberWorkspace(w); + } else if (str_key == "Head") { + int h = atoi(str_label.c_str()); + app.rememberHead(h); } else if (str_key == "Layer") { unsigned int l; if (str_label == "DESKTOP") { @@ -366,7 +372,7 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { unsigned int y= 0; // more info about the parameter // in ::rememberPosition - + if ( str_option.length() ) { if ( str_option == "UPPERLEFT" ) r= POS_UPPERLEFT; @@ -389,9 +395,9 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { } else if (str_key == "Tab") { app.rememberTabstate((str_label=="yes")); } else if (str_key == "FocusHidden") { - app.rememberFocusHiddenstate((str_label=="yes")); + app.rememberFocusHiddenstate((str_label=="yes")); } else if (str_key == "IconHidden") { - app.rememberIconHiddenstate((str_label=="yes")); + app.rememberIconHiddenstate((str_label=="yes")); } else if (str_key == "Hidden") { app.rememberIconHiddenstate((str_label=="yes")); app.rememberFocusHiddenstate((str_label=="yes")); @@ -402,7 +408,7 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { app.rememberDecostate((unsigned int) 0xfffffff); } else if (str_label == "TINY") { app.rememberDecostate((unsigned int) - FluxboxWindow::DECORM_TITLEBAR + FluxboxWindow::DECORM_TITLEBAR | FluxboxWindow::DECORM_ICONIFY | FluxboxWindow::DECORM_MENU ); @@ -468,8 +474,8 @@ void Remember::load() { continue; string key; int err=0; - int pos = FbTk::StringUtil::getStringBetween(key, - line.c_str(), + int pos = FbTk::StringUtil::getStringBetween(key, + line.c_str(), '[', ']'); if (pos > 0 && key == "app") { @@ -502,7 +508,7 @@ void Remember::load() { m_pats.push_back(make_pair(grouped_pats.front(), app)); grouped_pats.pop_front(); } - + // we hit end... probably don't have attribs for the group // so finish it off with an empty application // otherwise parse the app @@ -512,7 +518,7 @@ void Remember::load() { in_group = false; } else cerr<<"Error in apps file on line "<workspace_remember; break; + case REM_HEAD: + return app->head_remember; + break; case REM_DIMENSIONS: return app->dimensions_remember; break; @@ -690,6 +702,9 @@ void Remember::rememberAttrib(WinClient &winclient, Attribute attrib) { case REM_WORKSPACE: app->rememberWorkspace(win->workspaceNumber()); break; + case REM_HEAD: + app->rememberHead(win->screen().getHead(win->fbWindow())); + break; case REM_DIMENSIONS: app->rememberDimensions(win->width(), win->height()); break; @@ -741,6 +756,9 @@ void Remember::forgetAttrib(WinClient &winclient, Attribute attrib) { case REM_WORKSPACE: app->forgetWorkspace(); break; + case REM_HEAD: + app->forgetHead(); + break; case REM_DIMENSIONS: app->forgetDimensions(); break; @@ -790,11 +808,11 @@ void Remember::setupFrame(FluxboxWindow &win) { win.addExtraMenu(_FBTEXT(Remember, MenuItemName, "Remember...", "Remember item in menu"), createRememberMenu(*this, win, (winclient.transientFor() == 0))); - if (winclient.transientFor()) + if (winclient.transientFor()) return; Application *app = find(winclient); - if (app == 0) + if (app == 0) return; // nothing to do if (app->is_grouped && app->group == 0) @@ -804,41 +822,51 @@ void Remember::setupFrame(FluxboxWindow &win) { if (app->workspace_remember) { // TODO: fix placement to initialise properly - screen.reassociateWindow(&win, app->workspace, true); + screen.reassociateWindow(&win, app->workspace, true); if (app->jumpworkspace_remember) screen.changeWorkspaceID(app->workspace); } + if (app->head_remember) { + win.screen().setOnHead(win, app->head); + } + if (app->decostate_remember) win.setDecorationMask(app->decostate); if (app->dimensions_remember) win.resize(app->w, app->h); - + + int head = screen.getHead(win.fbWindow()); + if (app->position_remember) { + switch (app->refc) { default: case POS_UPPERLEFT: // upperleft corner - win.move(app->x, app->y); + win.move(screen.getHeadX(head) + app->x, + screen.getHeadY(head) + app->y); break; case POS_UPPERRIGHT: // upperright corner - win.move(screen.width() - win.width() - app->x, app->y); + win.move(screen.getHeadX(head) + screen.getHeadWidth(head) - win.width() - app->x, + screen.getHeadY(head) + app->y); break; case POS_LOWERLEFT: // lowerleft corner - win.move(app->x, screen.height() - win.height() - app->y); + win.move(screen.getHeadX(head) + app->x, + screen.getHeadHeight(head) - win.height() - app->y); break; case POS_LOWERRIGHT: // lowerright corner - win.move(screen.width() - win.width() - app->x, - screen.height() - win.height() - app->y); + win.move(screen.getHeadWidth(head) - win.width() - app->x, + screen.getHeadHeight(head) - win.height() - app->y); break; case POS_CENTER: // center of the screen, windows topleft corner is on the center - win.move((screen.width() / 2) + app->x, - (screen.height() / 2) + app->y); + win.move((screen.getHeadWidth(head) / 2) + app->x, + (screen.getHeadHeight(head) / 2) + app->y); break; case POS_WINCENTER: // the window is centered REALLY upon the center - win.move((screen.width() / 2) - ( win.width() / 2 ) + app->x, - (screen.height() / 2) - ( win.height() / 2 ) + app->y); + win.move((screen.getHeadWidth(head) / 2) - ( win.width() / 2 ) + app->x, + (screen.getHeadHeight(head) / 2) - ( win.height() / 2 ) + app->y); break; }; } @@ -870,7 +898,7 @@ void Remember::setupFrame(FluxboxWindow &win) { void Remember::setupClient(WinClient &winclient) { Application *app = find(winclient); - if (app == 0) + if (app == 0) return; // nothing to do if (winclient.fbwindow() == 0 && app->is_grouped && app->group) { diff --git a/src/Remember.hh b/src/Remember.hh index 0d1cff9..4822bc5 100644 --- a/src/Remember.hh +++ b/src/Remember.hh @@ -45,6 +45,7 @@ class Application { public: Application(bool grouped); inline void forgetWorkspace() { workspace_remember = false; } + inline void forgetHead() { head_remember = false; } inline void forgetDimensions() { dimensions_remember = false; } inline void forgetPosition() { position_remember = false; } inline void forgetShadedstate() { shadedstate_remember = false; } @@ -56,10 +57,12 @@ public: inline void forgetJumpworkspace() { jumpworkspace_remember = false; } inline void forgetLayer() { layer_remember = false; } inline void forgetSaveOnClose() { save_on_close_remember = false; } - - inline void rememberWorkspace(int ws) + + inline void rememberWorkspace(int ws) { workspace = ws; workspace_remember = true; } - inline void rememberDimensions(int width, int height) + inline void rememberHead(int h) + { head = h; head_remember = true; } + inline void rememberDimensions(int width, int height) { w = width; h = height; dimensions_remember = true; } inline void rememberFocusHiddenstate(bool state) { focushiddenstate= state; focushiddenstate_remember= true; } @@ -86,6 +89,9 @@ public: bool workspace_remember; unsigned int workspace; + bool head_remember; + int head; + bool dimensions_remember; int w,h; // width, height @@ -153,6 +159,7 @@ public: REM_STUCKSTATE, //REM_TABSTATE, ... external tabs disabled atm REM_WORKSPACE, + REM_HEAD, REM_LASTATTRIB // not actually used }; @@ -176,7 +183,7 @@ public: // We keep track of which app is assigned to a winclient // particularly useful to update counters etc on windowclose typedef std::map Clients; - + // we have to remember any startups we did so that they are saved again typedef std::list Startups; @@ -194,7 +201,7 @@ public: void forgetAttrib(WinClient &win, Attribute attrib); // Functions relating to AtomHandler - + // Functions we actually use void setupFrame(FluxboxWindow &win); void setupClient(WinClient &winclient); diff --git a/src/Screen.cc b/src/Screen.cc index 9c0493b..2cf3292 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -2372,7 +2372,7 @@ pair BScreen::clampToHead(int head, int x, int y, int w, int h) const { // this can be gone and a consistent interface for the two used // on the actual objects - +/* FIXME: dead code? #ifdef SLIT template <> int BScreen::getOnHead(Slit &slit) { @@ -2385,3 +2385,14 @@ void BScreen::setOnHead(Slit &slit, int head) { slit.reconfigure(); } #endif // SLIT +*/ + +template<> +void BScreen::setOnHead(FluxboxWindow& win, int head) { + if (head > 0 && head <= numHeads()) { + int current_head = getHead(win.fbWindow()); + win.move(getHeadX(head) + win.frame().x() - getHeadX(current_head), + getHeadY(head) + win.frame().y() - getHeadY(current_head)); + } +} + -- cgit v0.11.2