2003-04-26 07:57:00 +00:00
|
|
|
// Remember.cc for Fluxbox Window Manager
|
|
|
|
// Copyright (c) 2002 Xavier Brouckaert
|
|
|
|
// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
|
2003-05-10 22:47:55 +00:00
|
|
|
// and Simon Bowden (rathnor at users.sourceforge.net)
|
2003-04-26 07:57:00 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2003-07-04 01:03:41 +00:00
|
|
|
// $Id: Remember.cc,v 1.25 2003/07/04 01:03:40 rathnor Exp $
|
2003-04-26 07:57:00 +00:00
|
|
|
|
|
|
|
#include "Remember.hh"
|
2003-06-12 15:12:19 +00:00
|
|
|
#include "ClientPattern.hh"
|
2003-04-26 07:57:00 +00:00
|
|
|
#include "StringUtil.hh"
|
2003-04-26 12:46:18 +00:00
|
|
|
#include "Screen.hh"
|
|
|
|
#include "Window.hh"
|
2003-04-26 07:57:00 +00:00
|
|
|
#include "WinClient.hh"
|
|
|
|
#include "FbMenu.hh"
|
|
|
|
#include "MenuItem.hh"
|
2003-04-26 12:46:18 +00:00
|
|
|
#include "App.hh"
|
2003-04-26 07:57:00 +00:00
|
|
|
|
2003-04-26 12:46:18 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
//use GNU extensions
|
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif // _GNU_SOURCE
|
|
|
|
|
2003-04-26 12:46:18 +00:00
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <fstream>
|
2003-04-26 11:24:55 +00:00
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2003-07-04 01:03:41 +00:00
|
|
|
#include <set>
|
2003-04-26 07:57:00 +00:00
|
|
|
|
2003-04-26 12:46:18 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
#ifndef MAXPATHLEN
|
|
|
|
#define MAXPATHLEN 255
|
|
|
|
#endif // MAXPATHLEN
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class RememberMenuItem : public FbTk::MenuItem {
|
|
|
|
public:
|
|
|
|
RememberMenuItem(const char *label, Remember &remember,
|
|
|
|
FluxboxWindow &fbwin,
|
|
|
|
Remember::Attribute attrib) :
|
|
|
|
FbTk::MenuItem(label), m_remember(remember),
|
|
|
|
m_win(fbwin), m_attrib(attrib) {}
|
|
|
|
|
|
|
|
bool isSelected() const {
|
|
|
|
return m_remember.isRemembered(m_win.winClient(), m_attrib);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isEnabled() const {
|
|
|
|
if (m_attrib != Remember::REM_JUMPWORKSPACE)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return (m_remember.isRemembered(m_win.winClient(), Remember::REM_WORKSPACE));
|
|
|
|
}
|
|
|
|
|
|
|
|
void click(int button, int time) {
|
|
|
|
if (isSelected()) {
|
|
|
|
m_remember.forgetAttrib(m_win.winClient(), m_attrib);
|
|
|
|
} else {
|
|
|
|
m_remember.rememberAttrib(m_win.winClient(), m_attrib);
|
|
|
|
}
|
|
|
|
m_remember.save();
|
|
|
|
FbTk::MenuItem::click(button, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// my remember manager
|
|
|
|
Remember &m_remember;
|
|
|
|
FluxboxWindow &m_win;
|
|
|
|
Remember::Attribute m_attrib;
|
|
|
|
};
|
|
|
|
|
|
|
|
FbTk::Menu *createRememberMenu(Remember &remember, FluxboxWindow &win) {
|
|
|
|
// each fluxboxwindow has its own windowmenu
|
|
|
|
// so we also create a remember menu just for it...
|
2003-05-11 13:36:12 +00:00
|
|
|
BScreen &screen = win.screen();
|
2003-04-26 07:57:00 +00:00
|
|
|
FbTk::Menu *menu = new FbMenu(*screen.menuTheme(),
|
2003-05-15 12:00:46 +00:00
|
|
|
screen.screenNumber(),
|
2003-05-15 23:30:07 +00:00
|
|
|
screen.imageControl(),
|
2003-04-26 07:57:00 +00:00
|
|
|
*screen.layerManager().getLayer(Fluxbox::instance()->getMenuLayer()));
|
2003-05-08 10:55:33 +00:00
|
|
|
menu->disableTitle();
|
2003-04-26 07:57:00 +00:00
|
|
|
// TODO: nls
|
|
|
|
menu->insert(new RememberMenuItem("Workspace", remember, win,
|
2003-04-26 12:46:18 +00:00
|
|
|
Remember::REM_WORKSPACE));
|
2003-04-26 07:57:00 +00:00
|
|
|
menu->insert(new RememberMenuItem("Jump to workspace", remember, win,
|
2003-04-26 12:46:18 +00:00
|
|
|
Remember::REM_JUMPWORKSPACE));
|
2003-04-26 07:57:00 +00:00
|
|
|
menu->insert(new RememberMenuItem("Dimensions", remember, win,
|
2003-04-26 12:46:18 +00:00
|
|
|
Remember::REM_DIMENSIONS));
|
2003-04-26 07:57:00 +00:00
|
|
|
menu->insert(new RememberMenuItem("Position", remember, win,
|
2003-04-26 12:46:18 +00:00
|
|
|
Remember::REM_POSITION));
|
2003-04-26 07:57:00 +00:00
|
|
|
menu->insert(new RememberMenuItem("Sticky", remember, win,
|
2003-04-26 12:46:18 +00:00
|
|
|
Remember::REM_STUCKSTATE));
|
2003-04-26 07:57:00 +00:00
|
|
|
menu->insert(new RememberMenuItem("Decorations", remember, win,
|
2003-04-26 12:46:18 +00:00
|
|
|
Remember::REM_DECOSTATE));
|
2003-04-26 07:57:00 +00:00
|
|
|
menu->insert(new RememberMenuItem("Shaded", remember, win,
|
2003-04-26 12:46:18 +00:00
|
|
|
Remember::REM_SHADEDSTATE));
|
2003-04-26 13:47:53 +00:00
|
|
|
menu->insert(new RememberMenuItem("Layer", remember, win,
|
|
|
|
Remember::REM_LAYER));
|
2003-04-26 12:46:18 +00:00
|
|
|
// menu->insert(new RememberMenuItem("Tab", remember, win,
|
|
|
|
// Remember::REM_TABSTATE));
|
2003-04-26 07:57:00 +00:00
|
|
|
menu->insert(new RememberMenuItem("Save on close", remember, win,
|
2003-04-26 12:46:18 +00:00
|
|
|
Remember::REM_SAVEONCLOSE));
|
2003-04-26 07:57:00 +00:00
|
|
|
|
|
|
|
menu->update();
|
|
|
|
return menu;
|
|
|
|
};
|
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
}; // end anonymous namespace
|
2003-04-26 12:46:18 +00:00
|
|
|
|
2003-07-04 01:03:41 +00:00
|
|
|
Application::Application(bool grouped)
|
|
|
|
: is_grouped(grouped),
|
|
|
|
group(0)
|
|
|
|
{
|
2003-04-26 12:46:18 +00:00
|
|
|
workspace_remember =
|
|
|
|
dimensions_remember =
|
|
|
|
position_remember =
|
|
|
|
stuckstate_remember =
|
|
|
|
decostate_remember =
|
|
|
|
shadedstate_remember =
|
|
|
|
tabstate_remember =
|
|
|
|
jumpworkspace_remember =
|
2003-04-26 13:47:53 +00:00
|
|
|
layer_remember =
|
2003-04-26 12:46:18 +00:00
|
|
|
save_on_close_remember = false;
|
|
|
|
}
|
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
/********************************************************
|
|
|
|
* Remember *
|
|
|
|
************/
|
|
|
|
|
2003-04-26 12:46:18 +00:00
|
|
|
Remember::Remember() {
|
2003-07-04 01:03:41 +00:00
|
|
|
enableUpdate();
|
2003-04-26 12:46:18 +00:00
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
Remember::~Remember() {
|
|
|
|
// free our resources
|
|
|
|
|
|
|
|
// the patterns free the "Application"s
|
|
|
|
// the client mapping shouldn't need cleaning
|
|
|
|
Patterns::iterator it;
|
2003-07-04 01:03:41 +00:00
|
|
|
std::set<Application *> all_apps; // no duplicates
|
2003-06-12 15:12:19 +00:00
|
|
|
while (!m_pats.empty()) {
|
|
|
|
it = m_pats.begin();
|
|
|
|
delete it->first; // ClientPattern
|
2003-07-04 01:03:41 +00:00
|
|
|
all_apps.insert(it->second); // Application, not necessarily unique
|
2003-06-12 15:12:19 +00:00
|
|
|
m_pats.erase(it);
|
|
|
|
}
|
2003-07-04 01:03:41 +00:00
|
|
|
|
|
|
|
std::set<Application *>::iterator ait = all_apps.begin(); // no duplicates
|
|
|
|
while (ait != all_apps.end()) {
|
|
|
|
delete (*ait);
|
|
|
|
++ait;
|
|
|
|
}
|
2003-04-26 12:46:18 +00:00
|
|
|
}
|
2003-04-26 07:57:00 +00:00
|
|
|
|
|
|
|
Application* Remember::find(WinClient &winclient) {
|
2003-06-12 15:12:19 +00:00
|
|
|
// if it is already associated with a application, return that one
|
|
|
|
// otherwise, check it against every pattern that we've got
|
|
|
|
Clients::iterator wc_it = m_clients.find(&winclient);
|
|
|
|
if (wc_it != m_clients.end())
|
|
|
|
return wc_it->second;
|
|
|
|
else {
|
|
|
|
Patterns::iterator it = m_pats.begin();
|
|
|
|
for (; it != m_pats.end(); it++)
|
|
|
|
if (it->first->match(winclient)) {
|
|
|
|
it->first->addMatch();
|
|
|
|
m_clients[&winclient] = it->second;
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// oh well, no matches
|
|
|
|
return 0;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
Application * Remember::add(WinClient &winclient) {
|
|
|
|
ClientPattern *p = new ClientPattern();
|
2003-07-04 01:03:41 +00:00
|
|
|
Application *app = new Application(false);
|
2003-06-12 15:12:19 +00:00
|
|
|
// by default, we match against the WMClass of a window.
|
|
|
|
p->addTerm(p->getProperty(ClientPattern::NAME, winclient), ClientPattern::NAME);
|
|
|
|
m_clients[&winclient] = app;
|
|
|
|
p->addMatch();
|
|
|
|
m_pats.push_back(make_pair(p, app));
|
|
|
|
return app;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
2003-07-04 01:03:41 +00:00
|
|
|
int Remember::parseApp(ifstream &file, Application &app, string *first_line) {
|
2003-04-26 12:01:55 +00:00
|
|
|
string line;
|
2003-04-26 07:57:00 +00:00
|
|
|
int row = 0;
|
|
|
|
while (! file.eof()) {
|
2003-07-04 01:03:41 +00:00
|
|
|
if (first_line || getline(file, line)) {
|
|
|
|
if (first_line) {
|
|
|
|
line = *first_line;
|
|
|
|
first_line = 0;
|
|
|
|
}
|
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
row++;
|
|
|
|
if (line[0] != '#') { //the line is commented
|
|
|
|
int parse_pos = 0, err = 0;
|
2003-04-26 12:01:55 +00:00
|
|
|
string str_key, str_label;
|
2003-04-26 18:58:30 +00:00
|
|
|
err = FbTk::StringUtil::getStringBetween(str_key,
|
|
|
|
line.c_str(),
|
|
|
|
'[', ']');
|
2003-04-26 07:57:00 +00:00
|
|
|
if (err > 0 ) {
|
|
|
|
parse_pos += err;
|
2003-04-26 18:58:30 +00:00
|
|
|
err = FbTk::StringUtil::getStringBetween(str_label,
|
2003-04-26 12:46:18 +00:00
|
|
|
line.c_str() + parse_pos,
|
|
|
|
'{', '}');
|
2003-04-26 07:57:00 +00:00
|
|
|
if (err>0) {
|
|
|
|
parse_pos += err;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
continue; //read next line
|
2003-05-10 22:47:55 +00:00
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
if (!str_key.size())
|
|
|
|
continue; //read next line
|
|
|
|
if (str_key == "Workspace") {
|
|
|
|
unsigned int w;
|
2003-04-26 12:01:55 +00:00
|
|
|
istringstream iss(str_label.c_str());
|
2003-04-26 07:57:00 +00:00
|
|
|
iss >> w;
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberWorkspace(w);
|
2003-04-26 13:47:53 +00:00
|
|
|
} else if (str_key == "Layer") {
|
|
|
|
unsigned int l;
|
|
|
|
istringstream iss(str_label.c_str());
|
|
|
|
iss >> l;
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberLayer(l);
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_key == "Dimensions") {
|
|
|
|
unsigned int h,w;
|
2003-04-26 12:01:55 +00:00
|
|
|
istringstream iss(str_label.c_str());
|
2003-04-26 07:57:00 +00:00
|
|
|
iss >> w >> h;
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberDimensions(w,h);
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_key == "Position") {
|
|
|
|
unsigned int x,y;
|
2003-04-26 12:01:55 +00:00
|
|
|
istringstream iss(str_label);
|
2003-04-26 07:57:00 +00:00
|
|
|
iss >> x >> y;
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberPosition(x,y);
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_key == "Shaded") {
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberShadedstate((str_label=="yes"));
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_key == "Tab") {
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberTabstate((str_label=="yes"));
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_key == "Deco") {
|
|
|
|
if (str_label == "NONE") {
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberDecostate((unsigned int) 0);
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_label == "NORMAL") {
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberDecostate((unsigned int) 0xfffffff);
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_label == "TINY") {
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberDecostate((unsigned int)
|
2003-04-26 12:46:18 +00:00
|
|
|
FluxboxWindow::DECORM_TITLEBAR
|
|
|
|
| FluxboxWindow::DECORM_ICONIFY
|
|
|
|
| FluxboxWindow::DECORM_MENU
|
|
|
|
);
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_label == "TOOL") {
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberDecostate((unsigned int)
|
2003-04-26 12:46:18 +00:00
|
|
|
FluxboxWindow::DECORM_TITLEBAR
|
|
|
|
| FluxboxWindow::DECORM_MENU
|
|
|
|
);
|
2003-05-26 04:24:24 +00:00
|
|
|
} else if (str_label == "BORDER") {
|
|
|
|
app.rememberDecostate((unsigned int)
|
|
|
|
FluxboxWindow::DECORM_BORDER
|
|
|
|
| FluxboxWindow::DECORM_MENU
|
|
|
|
);
|
2003-04-26 07:57:00 +00:00
|
|
|
} else {
|
|
|
|
unsigned int mask;
|
|
|
|
const char * str = str_label.c_str();
|
|
|
|
// it'll have at least one char and \0, so this is safe
|
2003-04-26 12:01:55 +00:00
|
|
|
istringstream iss(str);
|
2003-04-26 07:57:00 +00:00
|
|
|
// check for hex
|
|
|
|
if (str[0] == '0' && str[1] == 'x') {
|
|
|
|
iss.seekg(2);
|
|
|
|
iss >> hex;
|
|
|
|
}
|
|
|
|
iss >> mask ;
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberDecostate(mask);
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
|
|
|
} else if (str_key == "Sticky") {
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberStuckstate((str_label=="yes"));
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_key == "Jump") {
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberJumpworkspace((str_label=="yes"));
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_key == "Close") {
|
2003-05-10 22:47:55 +00:00
|
|
|
app.rememberSaveOnClose((str_label=="yes"));
|
2003-04-26 07:57:00 +00:00
|
|
|
} else if (str_key == "end") {
|
|
|
|
return row;
|
|
|
|
} else {
|
|
|
|
cerr << "Unsupported apps key = " << str_key << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Remember::load() {
|
2003-04-26 12:46:18 +00:00
|
|
|
|
2003-05-27 11:55:23 +00:00
|
|
|
string apps_string;
|
|
|
|
Fluxbox::instance()->getDefaultDataFilename("apps", apps_string);
|
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
#ifdef DEBUG
|
2003-04-26 12:46:18 +00:00
|
|
|
cerr<<__FILE__<<"("<<__FUNCTION__<<"): Loading apps file ["<<apps_string<<"]"<<endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
#endif // DEBUG
|
2003-04-26 12:01:55 +00:00
|
|
|
ifstream apps_file(apps_string.c_str());
|
2003-04-26 12:46:18 +00:00
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
if (!apps_file.fail()) {
|
|
|
|
if (!apps_file.eof()) {
|
2003-04-26 12:01:55 +00:00
|
|
|
string line;
|
2003-04-26 07:57:00 +00:00
|
|
|
int row = 0;
|
2003-07-04 01:03:41 +00:00
|
|
|
bool in_group = false;
|
|
|
|
std::list<ClientPattern *> grouped_pats;
|
2003-04-26 07:57:00 +00:00
|
|
|
while (getline(apps_file, line) && ! apps_file.eof()) {
|
|
|
|
row++;
|
|
|
|
if (line[0] == '#')
|
|
|
|
continue;
|
2003-04-26 12:01:55 +00:00
|
|
|
string key;
|
2003-06-12 15:12:19 +00:00
|
|
|
int err=0;
|
|
|
|
int pos = FbTk::StringUtil::getStringBetween(key,
|
2003-04-26 18:58:30 +00:00
|
|
|
line.c_str(),
|
|
|
|
'[', ']');
|
2003-04-26 07:57:00 +00:00
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
if (pos > 0 && key == "app") {
|
|
|
|
ClientPattern *pat = new ClientPattern(line.c_str() + pos);
|
2003-07-04 01:03:41 +00:00
|
|
|
if (!in_group) {
|
|
|
|
if ((err = pat->error()) == 0) {
|
|
|
|
Application *app = new Application(false);
|
|
|
|
m_pats.push_back(make_pair(pat, app));
|
|
|
|
row += parseApp(apps_file, *app);
|
|
|
|
} else {
|
|
|
|
cerr<<"Error reading apps file at line "<<row<<", column "<<(err+pos)<<"."<<endl;
|
|
|
|
delete pat; // since it didn't work
|
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
} else {
|
2003-07-04 01:03:41 +00:00
|
|
|
grouped_pats.push_back(pat);
|
|
|
|
}
|
|
|
|
} else if (pos > 0 && key == "group") {
|
|
|
|
in_group = true;
|
|
|
|
} else if (in_group) {
|
|
|
|
// otherwise assume that it is the start of the attributes
|
|
|
|
Application *app = new Application(true);
|
|
|
|
while (!grouped_pats.empty()) {
|
|
|
|
// associate all the patterns with this app
|
|
|
|
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
|
|
|
|
if (!(pos>0 && key == "end")) {
|
|
|
|
row += parseApp(apps_file, *app, &line);
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
2003-07-04 01:03:41 +00:00
|
|
|
in_group = false;
|
2003-04-26 07:57:00 +00:00
|
|
|
} else
|
2003-06-12 15:12:19 +00:00
|
|
|
cerr<<"Error in apps file on line "<<row<<"."<<endl;
|
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
2003-04-26 12:46:18 +00:00
|
|
|
cerr<<__FILE__<<"("<<__FUNCTION__<< ") Empty apps file" << endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cerr << "apps file failure" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Remember::save() {
|
|
|
|
#ifdef DEBUG
|
2003-04-26 12:46:18 +00:00
|
|
|
cerr<<__FILE__<<"("<<__FUNCTION__<<"): Saving apps file..."<<endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
#endif // DEBUG
|
2003-05-27 11:55:23 +00:00
|
|
|
string apps_string;
|
|
|
|
Fluxbox::instance()->getDefaultDataFilename("apps", apps_string);
|
2003-04-26 12:01:55 +00:00
|
|
|
ofstream apps_file(apps_string.c_str());
|
2003-06-12 15:12:19 +00:00
|
|
|
Patterns::iterator it = m_pats.begin();
|
|
|
|
Patterns::iterator it_end = m_pats.end();
|
2003-07-04 01:03:41 +00:00
|
|
|
|
|
|
|
std::set<Application *> grouped_apps; // no duplicates
|
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
for (; it != it_end; ++it) {
|
2003-06-12 15:12:19 +00:00
|
|
|
Application &a = *it->second;
|
2003-07-04 01:03:41 +00:00
|
|
|
if (a.is_grouped) {
|
|
|
|
// if already processed
|
|
|
|
if (grouped_apps.find(&a) != grouped_apps.end())
|
|
|
|
continue;
|
|
|
|
// otherwise output this whole group
|
|
|
|
apps_file << "[group]" << endl;
|
|
|
|
Patterns::iterator git = m_pats.begin();
|
|
|
|
Patterns::iterator git_end = m_pats.end();
|
|
|
|
for (; git != git_end; git++) {
|
|
|
|
if (git->second->group == a.group) {
|
|
|
|
apps_file << " [app]"<<git->first->toString()<<endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
apps_file << "[app]"<<it->first->toString()<<endl;
|
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.workspace_remember) {
|
|
|
|
apps_file << " [Workspace]\t{" << a.workspace << "}" << endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.dimensions_remember) {
|
|
|
|
apps_file << " [Dimensions]\t{" << a.w << " " << a.h << "}" << endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.position_remember) {
|
|
|
|
apps_file << " [Position]\t{" << a.x << " " << a.y << "}" << endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.shadedstate_remember) {
|
|
|
|
apps_file << " [Shaded]\t{" << ((a.shadedstate)?"yes":"no") << "}" << endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.tabstate_remember) {
|
|
|
|
apps_file << " [Tab]\t\t{" << ((a.tabstate)?"yes":"no") << "}" << endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.decostate_remember) {
|
|
|
|
switch (a.decostate) {
|
2003-04-26 07:57:00 +00:00
|
|
|
case (0) :
|
|
|
|
apps_file << " [Deco]\t{NONE}" << endl;
|
|
|
|
break;
|
|
|
|
case (0xffffffff):
|
|
|
|
case (FluxboxWindow::DECORM_LAST - 1):
|
|
|
|
apps_file << " [Deco]\t{NORMAL}" << endl;
|
|
|
|
break;
|
|
|
|
case (FluxboxWindow::DECORM_TITLEBAR
|
|
|
|
| FluxboxWindow::DECORM_ICONIFY
|
|
|
|
| FluxboxWindow::DECORM_MENU):
|
|
|
|
apps_file << " [Deco]\t{TOOL}" << endl;
|
|
|
|
break;
|
|
|
|
case (FluxboxWindow::DECORM_TITLEBAR
|
|
|
|
| FluxboxWindow::DECORM_MENU):
|
|
|
|
apps_file << " [Deco]\t{TINY}" << endl;
|
|
|
|
break;
|
2003-05-26 11:27:31 +00:00
|
|
|
case (FluxboxWindow::DECORM_BORDER
|
|
|
|
| FluxboxWindow::DECORM_MENU):
|
|
|
|
apps_file << " [Deco]\t{BORDER}" << endl;
|
|
|
|
break;
|
2003-04-26 07:57:00 +00:00
|
|
|
default:
|
2003-06-12 15:12:19 +00:00
|
|
|
apps_file << " [Deco]\t{0x"<<hex<<a.decostate<<dec<<"}"<<endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.stuckstate_remember) {
|
|
|
|
apps_file << " [Sticky]\t{" << ((a.stuckstate)?"yes":"no") << "}" << endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.jumpworkspace_remember) {
|
|
|
|
apps_file << " [Jump]\t{" << ((a.jumpworkspace)?"yes":"no") << "}" << endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.layer_remember) {
|
|
|
|
apps_file << " [Layer]\t{" << a.layer << "}" << endl;
|
2003-04-26 13:47:53 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
if (a.save_on_close_remember) {
|
|
|
|
apps_file << " [Close]\t{" << ((a.save_on_close)?"yes":"no") << "}" << endl;
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
|
|
|
apps_file << "[end]" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Remember::isRemembered(WinClient &winclient, Attribute attrib) {
|
|
|
|
Application *app = find(winclient);
|
|
|
|
if (!app) return false;
|
|
|
|
switch (attrib) {
|
|
|
|
case REM_WORKSPACE:
|
|
|
|
return app->workspace_remember;
|
|
|
|
break;
|
|
|
|
case REM_DIMENSIONS:
|
|
|
|
return app->dimensions_remember;
|
|
|
|
break;
|
|
|
|
case REM_POSITION:
|
|
|
|
return app->position_remember;
|
|
|
|
break;
|
|
|
|
case REM_STUCKSTATE:
|
|
|
|
return app->stuckstate_remember;
|
|
|
|
break;
|
|
|
|
case REM_DECOSTATE:
|
|
|
|
return app->decostate_remember;
|
|
|
|
break;
|
|
|
|
case REM_SHADEDSTATE:
|
|
|
|
return app->shadedstate_remember;
|
|
|
|
break;
|
2003-04-26 12:46:18 +00:00
|
|
|
// case REM_TABSTATE:
|
|
|
|
// return app->tabstate_remember;
|
|
|
|
// break;
|
2003-04-26 07:57:00 +00:00
|
|
|
case REM_JUMPWORKSPACE:
|
|
|
|
return app->jumpworkspace_remember;
|
|
|
|
break;
|
2003-04-26 13:47:53 +00:00
|
|
|
case REM_LAYER:
|
|
|
|
return app->layer_remember;
|
|
|
|
break;
|
2003-04-26 07:57:00 +00:00
|
|
|
case REM_SAVEONCLOSE:
|
|
|
|
return app->save_on_close_remember;
|
|
|
|
break;
|
|
|
|
case REM_LASTATTRIB:
|
|
|
|
default:
|
|
|
|
return false; // should never get here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Remember::rememberAttrib(WinClient &winclient, Attribute attrib) {
|
|
|
|
FluxboxWindow *win = winclient.fbwindow();
|
|
|
|
if (!win) return;
|
|
|
|
Application *app = find(winclient);
|
|
|
|
if (!app) {
|
|
|
|
app = add(winclient);
|
|
|
|
if (!app) return;
|
|
|
|
}
|
|
|
|
switch (attrib) {
|
|
|
|
case REM_WORKSPACE:
|
2003-05-15 11:17:29 +00:00
|
|
|
app->rememberWorkspace(win->workspaceNumber());
|
2003-04-26 07:57:00 +00:00
|
|
|
break;
|
|
|
|
case REM_DIMENSIONS:
|
2003-05-11 13:36:12 +00:00
|
|
|
app->rememberDimensions(win->width(), win->height());
|
2003-04-26 07:57:00 +00:00
|
|
|
break;
|
|
|
|
case REM_POSITION:
|
2003-05-15 11:17:29 +00:00
|
|
|
app->rememberPosition(win->x(), win->y());
|
2003-04-26 07:57:00 +00:00
|
|
|
break;
|
2003-05-31 01:07:36 +00:00
|
|
|
case REM_SHADEDSTATE:
|
2003-04-26 07:57:00 +00:00
|
|
|
app->rememberShadedstate(win->isShaded());
|
|
|
|
break;
|
|
|
|
case REM_DECOSTATE:
|
2003-05-15 11:17:29 +00:00
|
|
|
app->rememberDecostate(win->decorationMask());
|
2003-04-26 07:57:00 +00:00
|
|
|
break;
|
2003-05-31 01:07:36 +00:00
|
|
|
case REM_STUCKSTATE:
|
2003-04-26 07:57:00 +00:00
|
|
|
app->rememberStuckstate(win->isStuck());
|
|
|
|
break;
|
2003-04-26 12:46:18 +00:00
|
|
|
// case REM_TABSTATE:
|
|
|
|
// break;
|
2003-04-26 07:57:00 +00:00
|
|
|
case REM_JUMPWORKSPACE:
|
|
|
|
app->rememberJumpworkspace(true);
|
|
|
|
break;
|
2003-04-26 13:47:53 +00:00
|
|
|
case REM_LAYER:
|
2003-05-15 11:17:29 +00:00
|
|
|
app->rememberLayer(win->layerNum());
|
2003-04-26 13:47:53 +00:00
|
|
|
break;
|
2003-04-26 07:57:00 +00:00
|
|
|
case REM_SAVEONCLOSE:
|
|
|
|
app->rememberSaveOnClose(true);
|
|
|
|
break;
|
|
|
|
case REM_LASTATTRIB:
|
|
|
|
default:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Remember::forgetAttrib(WinClient &winclient, Attribute attrib) {
|
|
|
|
FluxboxWindow *win = winclient.fbwindow();
|
|
|
|
if (!win) return;
|
|
|
|
Application *app = find(winclient);
|
|
|
|
if (!app) {
|
|
|
|
app = add(winclient);
|
|
|
|
if (!app) return;
|
|
|
|
}
|
|
|
|
switch (attrib) {
|
|
|
|
case REM_WORKSPACE:
|
|
|
|
app->forgetWorkspace();
|
|
|
|
break;
|
|
|
|
case REM_DIMENSIONS:
|
|
|
|
app->forgetDimensions();
|
|
|
|
break;
|
|
|
|
case REM_POSITION:
|
|
|
|
app->forgetPosition();
|
|
|
|
break;
|
|
|
|
case REM_STUCKSTATE:
|
|
|
|
app->forgetStuckstate();
|
|
|
|
break;
|
|
|
|
case REM_DECOSTATE:
|
|
|
|
app->forgetDecostate();
|
|
|
|
break;
|
|
|
|
case REM_SHADEDSTATE:
|
|
|
|
app->forgetShadedstate();
|
|
|
|
break;
|
|
|
|
// case REM_TABSTATE:
|
|
|
|
// break;
|
|
|
|
case REM_JUMPWORKSPACE:
|
|
|
|
app->forgetJumpworkspace();
|
|
|
|
break;
|
2003-04-26 13:47:53 +00:00
|
|
|
case REM_LAYER:
|
|
|
|
app->forgetLayer();
|
|
|
|
break;
|
2003-04-26 07:57:00 +00:00
|
|
|
case REM_SAVEONCLOSE:
|
|
|
|
app->forgetSaveOnClose();
|
|
|
|
break;
|
|
|
|
case REM_LASTATTRIB:
|
|
|
|
default:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-04 01:03:41 +00:00
|
|
|
void Remember::setupFrame(FluxboxWindow &win) {
|
2003-04-26 07:57:00 +00:00
|
|
|
WinClient &winclient = win.winClient();
|
|
|
|
|
2003-04-27 15:53:53 +00:00
|
|
|
// we don't touch the window if it is a transient
|
|
|
|
// of something else
|
2003-05-15 11:17:29 +00:00
|
|
|
int menupos = win.menu().numberOfItems()-2;
|
2003-05-10 22:47:55 +00:00
|
|
|
if (menupos < -1)
|
|
|
|
menupos = -1;
|
|
|
|
|
2003-04-27 15:53:53 +00:00
|
|
|
if (winclient.transientFor()) {
|
|
|
|
// still put something in the menu so people don't get confused
|
|
|
|
// so, we add a disabled item...
|
2003-06-12 15:12:19 +00:00
|
|
|
// TODO: nls
|
2003-04-27 15:53:53 +00:00
|
|
|
FbTk::MenuItem *item = new FbTk::MenuItem("Remember...");
|
|
|
|
item->setEnabled(false);
|
2003-05-15 11:17:29 +00:00
|
|
|
win.menu().insert(item, menupos);
|
|
|
|
win.menu().update();
|
2003-04-27 15:53:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-26 14:36:21 +00:00
|
|
|
// add the menu, this -2 is somewhat dodgy... :-/
|
|
|
|
// All windows get the remember menu.
|
|
|
|
// TODO: nls
|
2003-05-15 11:17:29 +00:00
|
|
|
win.menu().insert("Remember...",
|
2003-04-26 14:36:21 +00:00
|
|
|
createRememberMenu(*this, win),
|
2003-04-28 12:58:08 +00:00
|
|
|
menupos);
|
2003-05-15 11:17:29 +00:00
|
|
|
win.menu().reconfigure();
|
2003-04-26 14:36:21 +00:00
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
Application *app = find(winclient);
|
2003-05-10 22:47:55 +00:00
|
|
|
if (app == 0)
|
|
|
|
return; // nothing to do
|
2003-04-26 07:57:00 +00:00
|
|
|
|
2003-07-04 01:03:41 +00:00
|
|
|
if (app->is_grouped && app->group == 0)
|
|
|
|
app->group = &win;
|
|
|
|
|
|
|
|
BScreen &screen = winclient.screen();
|
2003-04-26 07:57:00 +00:00
|
|
|
|
|
|
|
if (app->workspace_remember) {
|
|
|
|
// TODO: fix placement to initialise properly
|
|
|
|
screen.reassociateWindow(&win, app->workspace, true);
|
|
|
|
if (app->jumpworkspace_remember)
|
|
|
|
screen.changeWorkspaceID(app->workspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (app->dimensions_remember)
|
|
|
|
win.resize(app->w, app->h);
|
|
|
|
|
|
|
|
if (app->position_remember)
|
|
|
|
win.move(app->x, app->y);
|
|
|
|
|
|
|
|
if (app->shadedstate_remember)
|
|
|
|
// if inconsistent...
|
|
|
|
if (win.isShaded() && !app->shadedstate ||
|
|
|
|
!win.isShaded() && app->shadedstate)
|
|
|
|
win.shade(); // toggles
|
|
|
|
|
|
|
|
// external tabs aren't available atm...
|
|
|
|
//if (app->tabstate_remember) ...
|
|
|
|
|
|
|
|
if (app->decostate_remember)
|
|
|
|
win.setDecorationMask(app->decostate);
|
|
|
|
|
|
|
|
if (app->stuckstate_remember)
|
|
|
|
// if inconsistent...
|
|
|
|
if (win.isStuck() && !app->stuckstate ||
|
|
|
|
!win.isStuck() && app->stuckstate)
|
|
|
|
win.stick(); // toggles
|
|
|
|
|
2003-04-26 13:47:53 +00:00
|
|
|
if (app->layer_remember)
|
|
|
|
win.moveToLayer(app->layer);
|
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
2003-07-04 01:03:41 +00:00
|
|
|
void Remember::setupClient(WinClient &winclient) {
|
|
|
|
|
|
|
|
Application *app = find(winclient);
|
|
|
|
if (app == 0)
|
|
|
|
return; // nothing to do
|
|
|
|
|
|
|
|
if (winclient.fbwindow() == 0 && app->is_grouped && app->group) {
|
|
|
|
app->group->attachClient(winclient);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
void Remember::updateWindowClose(FluxboxWindow &win) {
|
|
|
|
// This doesn't work at present since fluxbox.cc is missing the windowclose stuff.
|
|
|
|
// I don't trust it (particularly winClient()) while this is the case
|
2003-06-12 15:12:19 +00:00
|
|
|
|
2003-07-04 01:03:41 +00:00
|
|
|
// scan all winclients and remove this fbw
|
|
|
|
Patterns::iterator it = m_pats.begin();
|
|
|
|
while (it != m_pats.end()) {
|
|
|
|
if (&win == it->second->group)
|
|
|
|
it->second->group = 0;
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
WinClient &winclient = win.winClient();
|
|
|
|
Application *app = find(winclient);
|
2003-06-12 15:12:19 +00:00
|
|
|
Clients::iterator wc_it = m_clients.find(&win.winClient());
|
|
|
|
|
|
|
|
if (wc_it != m_clients.end())
|
|
|
|
m_clients.erase(wc_it);
|
2003-04-26 07:57:00 +00:00
|
|
|
|
|
|
|
if (!app || !(app->save_on_close_remember && app->save_on_close))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int attrib = 0; attrib <= REM_LASTATTRIB; attrib++) {
|
|
|
|
if (isRemembered(winclient, (Attribute) attrib)) {
|
|
|
|
rememberAttrib(winclient, (Attribute) attrib);
|
|
|
|
}
|
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
|
2003-04-26 07:57:00 +00:00
|
|
|
save();
|
|
|
|
}
|