diff options
Diffstat (limited to 'src/fluxbox.cc')
-rw-r--r-- | src/fluxbox.cc | 145 |
1 files changed, 39 insertions, 106 deletions
diff --git a/src/fluxbox.cc b/src/fluxbox.cc index a1896e9..d62e5ca 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc | |||
@@ -307,7 +307,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile | |||
307 | // Create keybindings handler and load keys file | 307 | // Create keybindings handler and load keys file |
308 | // Note: this needs to be done before creating screens | 308 | // Note: this needs to be done before creating screens |
309 | m_key.reset(new Keys); | 309 | m_key.reset(new Keys); |
310 | m_key->load(StringUtil::expandFilename(*m_rc_keyfile).c_str()); | 310 | m_key->reconfigure(); |
311 | 311 | ||
312 | vector<int> screens; | 312 | vector<int> screens; |
313 | int i; | 313 | int i; |
@@ -399,7 +399,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile | |||
399 | //XSynchronize(disp, False); | 399 | //XSynchronize(disp, False); |
400 | sync(false); | 400 | sync(false); |
401 | 401 | ||
402 | m_reconfigure_wait = m_reread_menu_wait = false; | 402 | m_reconfigure_wait = false; |
403 | 403 | ||
404 | m_resourcemanager.unlock(); | 404 | m_resourcemanager.unlock(); |
405 | ungrab(); | 405 | ungrab(); |
@@ -437,8 +437,6 @@ Fluxbox::~Fluxbox() { | |||
437 | delete (*it).first; | 437 | delete (*it).first; |
438 | } | 438 | } |
439 | m_atomhandler.clear(); | 439 | m_atomhandler.clear(); |
440 | |||
441 | clearMenuFilenames(); | ||
442 | } | 440 | } |
443 | 441 | ||
444 | 442 | ||
@@ -523,13 +521,16 @@ void Fluxbox::ungrab() { | |||
523 | */ | 521 | */ |
524 | void Fluxbox::setupConfigFiles() { | 522 | void Fluxbox::setupConfigFiles() { |
525 | 523 | ||
526 | bool create_init = false, create_keys = false, create_menu = false; | 524 | bool create_init = false, create_keys = false, create_menu = false, |
525 | create_apps = false, create_overlay = false, create_windowmenu = false; | ||
527 | 526 | ||
528 | string dirname = getenv("HOME") + string("/.") + m_RC_PATH + "/"; | 527 | string dirname = getDefaultDataFilename(""); |
529 | string init_file, keys_file, menu_file, slitlist_file; | 528 | string init_file = getDefaultDataFilename(m_RC_INIT_FILE); |
530 | init_file = dirname + m_RC_INIT_FILE; | 529 | string keys_file = getDefaultDataFilename("keys"); |
531 | keys_file = dirname + "keys"; | 530 | string menu_file = getDefaultDataFilename("menu"); |
532 | menu_file = dirname + "menu"; | 531 | string apps_file = getDefaultDataFilename("apps"); |
532 | string overlay_file = getDefaultDataFilename("overlay"); | ||
533 | string windowmenu_file = getDefaultDataFilename("windowmenu"); | ||
533 | 534 | ||
534 | struct stat buf; | 535 | struct stat buf; |
535 | 536 | ||
@@ -543,6 +544,12 @@ void Fluxbox::setupConfigFiles() { | |||
543 | create_keys = true; | 544 | create_keys = true; |
544 | if (stat(menu_file.c_str(), &buf)) | 545 | if (stat(menu_file.c_str(), &buf)) |
545 | create_menu = true; | 546 | create_menu = true; |
547 | if (stat(apps_file.c_str(), &buf)) | ||
548 | create_apps = true; | ||
549 | if (stat(overlay_file.c_str(), &buf)) | ||
550 | create_overlay = true; | ||
551 | if (stat(windowmenu_file.c_str(), &buf)) | ||
552 | create_windowmenu = true; | ||
546 | 553 | ||
547 | } else { | 554 | } else { |
548 | #ifdef DEBUG | 555 | #ifdef DEBUG |
@@ -560,7 +567,8 @@ void Fluxbox::setupConfigFiles() { | |||
560 | } | 567 | } |
561 | 568 | ||
562 | //mark creation of files | 569 | //mark creation of files |
563 | create_init = create_keys = create_menu = true; | 570 | create_init = create_keys = create_menu = create_apps = create_overlay = |
571 | create_windowmenu = true; | ||
564 | } | 572 | } |
565 | 573 | ||
566 | 574 | ||
@@ -572,11 +580,22 @@ void Fluxbox::setupConfigFiles() { | |||
572 | if (create_menu) | 580 | if (create_menu) |
573 | FbTk::FileUtil::copyFile(DEFAULTMENU, menu_file.c_str()); | 581 | FbTk::FileUtil::copyFile(DEFAULTMENU, menu_file.c_str()); |
574 | 582 | ||
583 | // copy apps file | ||
584 | if (create_apps) | ||
585 | FbTk::FileUtil::copyFile(DEFAULT_APPSFILE, apps_file.c_str()); | ||
586 | |||
587 | // copy overlay file | ||
588 | if (create_overlay) | ||
589 | FbTk::FileUtil::copyFile(DEFAULT_OVERLAY, overlay_file.c_str()); | ||
590 | |||
575 | // copy init file | 591 | // copy init file |
576 | if (create_init) | 592 | if (create_init) |
577 | FbTk::FileUtil::copyFile(DEFAULT_INITFILE, init_file.c_str()); | 593 | FbTk::FileUtil::copyFile(DEFAULT_INITFILE, init_file.c_str()); |
578 | 594 | ||
579 | #define CONFIG_VERSION 7 | 595 | if (create_windowmenu) |
596 | FbTk::FileUtil::copyFile(DEFAULT_WINDOWMENU, windowmenu_file.c_str()); | ||
597 | |||
598 | #define CONFIG_VERSION 9 | ||
580 | FbTk::Resource<int> config_version(m_resourcemanager, 0, | 599 | FbTk::Resource<int> config_version(m_resourcemanager, 0, |
581 | "session.configVersion", "Session.ConfigVersion"); | 600 | "session.configVersion", "Session.ConfigVersion"); |
582 | if (*config_version < CONFIG_VERSION) { | 601 | if (*config_version < CONFIG_VERSION) { |
@@ -737,7 +756,7 @@ void Fluxbox::handleEvent(XEvent * const e) { | |||
737 | XRefreshKeyboardMapping(&e->xmapping); | 756 | XRefreshKeyboardMapping(&e->xmapping); |
738 | FbTk::KeyUtil::instance().init(); // reinitialise the key utils | 757 | FbTk::KeyUtil::instance().init(); // reinitialise the key utils |
739 | // reconfigure keys (if the mapping changes, they don't otherwise update | 758 | // reconfigure keys (if the mapping changes, they don't otherwise update |
740 | m_key->reconfigure(StringUtil::expandFilename(*m_rc_keyfile).c_str()); | 759 | m_key->reload(); |
741 | } | 760 | } |
742 | break; | 761 | break; |
743 | case CreateNotify: | 762 | case CreateNotify: |
@@ -1305,18 +1324,14 @@ void Fluxbox::save_rc() { | |||
1305 | 1324 | ||
1306 | /// @return filename of resource file | 1325 | /// @return filename of resource file |
1307 | string Fluxbox::getRcFilename() { | 1326 | string Fluxbox::getRcFilename() { |
1308 | 1327 | if (m_rc_file.empty()) | |
1309 | if (m_rc_file.empty()) { // set default filename | 1328 | return getDefaultDataFilename(m_RC_INIT_FILE); |
1310 | string defaultfile(getenv("HOME") + string("/.") + m_RC_PATH + string("/") + m_RC_INIT_FILE); | ||
1311 | return defaultfile; | ||
1312 | } | ||
1313 | |||
1314 | return m_rc_file; | 1329 | return m_rc_file; |
1315 | } | 1330 | } |
1316 | 1331 | ||
1317 | /// Provides default filename of data file | 1332 | /// Provides default filename of data file |
1318 | void Fluxbox::getDefaultDataFilename(const char *name, string &filename) const { | 1333 | string Fluxbox::getDefaultDataFilename(const char *name) const { |
1319 | filename = string(getenv("HOME") + string("/.") + m_RC_PATH + string("/") + name); | 1334 | return (getenv("HOME") + string("/.") + m_RC_PATH + string("/") + name); |
1320 | } | 1335 | } |
1321 | 1336 | ||
1322 | /// loads resources | 1337 | /// loads resources |
@@ -1345,8 +1360,7 @@ void Fluxbox::load_rc() { | |||
1345 | if (!m_rc_slitlistfile->empty()) { | 1360 | if (!m_rc_slitlistfile->empty()) { |
1346 | *m_rc_slitlistfile = StringUtil::expandFilename(*m_rc_slitlistfile); | 1361 | *m_rc_slitlistfile = StringUtil::expandFilename(*m_rc_slitlistfile); |
1347 | } else { | 1362 | } else { |
1348 | string filename; | 1363 | string filename = getDefaultDataFilename("slitlist"); |
1349 | getDefaultDataFilename("slitlist", filename); | ||
1350 | m_rc_slitlistfile.setFromString(filename.c_str()); | 1364 | m_rc_slitlistfile.setFromString(filename.c_str()); |
1351 | } | 1365 | } |
1352 | 1366 | ||
@@ -1429,7 +1443,7 @@ void Fluxbox::real_reconfigure() { | |||
1429 | for_each(m_screen_list.begin(), m_screen_list.end(), mem_fun(&BScreen::reconfigure)); | 1443 | for_each(m_screen_list.begin(), m_screen_list.end(), mem_fun(&BScreen::reconfigure)); |
1430 | 1444 | ||
1431 | //reconfigure keys | 1445 | //reconfigure keys |
1432 | m_key->reconfigure(StringUtil::expandFilename(*m_rc_keyfile).c_str()); | 1446 | m_key->reconfigure(); |
1433 | 1447 | ||
1434 | // and atomhandlers | 1448 | // and atomhandlers |
1435 | for (AtomHandlerContainerIt it= m_atomhandler.begin(); | 1449 | for (AtomHandlerContainerIt it= m_atomhandler.begin(); |
@@ -1453,92 +1467,11 @@ BScreen *Fluxbox::findScreen(int id) { | |||
1453 | return *it; | 1467 | return *it; |
1454 | } | 1468 | } |
1455 | 1469 | ||
1456 | bool Fluxbox::menuTimestampsChanged() const { | ||
1457 | list<MenuTimestamp *>::const_iterator it = m_menu_timestamps.begin(); | ||
1458 | list<MenuTimestamp *>::const_iterator it_end = m_menu_timestamps.end(); | ||
1459 | for (; it != it_end; ++it) { | ||
1460 | |||
1461 | time_t timestamp = FbTk::FileUtil::getLastStatusChangeTimestamp((*it)->filename.c_str()); | ||
1462 | |||
1463 | if (timestamp >= 0) { | ||
1464 | if (timestamp != (*it)->timestamp) | ||
1465 | return true; | ||
1466 | } else | ||
1467 | return true; | ||
1468 | } | ||
1469 | |||
1470 | // no timestamp changed | ||
1471 | return false; | ||
1472 | } | ||
1473 | |||
1474 | void Fluxbox::rereadMenu(bool show_after_reread) { | ||
1475 | m_reread_menu_wait = true; | ||
1476 | m_show_menu_after_reread = show_after_reread; | ||
1477 | m_reconfig_timer.start(); | ||
1478 | } | ||
1479 | |||
1480 | |||
1481 | void Fluxbox::real_rereadMenu() { | ||
1482 | |||
1483 | clearMenuFilenames(); | ||
1484 | |||
1485 | for_each(m_screen_list.begin(), | ||
1486 | m_screen_list.end(), | ||
1487 | mem_fun(&BScreen::rereadMenu)); | ||
1488 | |||
1489 | if(m_show_menu_after_reread) { | ||
1490 | |||
1491 | FbCommands::ShowRootMenuCmd showcmd; | ||
1492 | showcmd.execute(); | ||
1493 | |||
1494 | m_show_menu_after_reread = false; | ||
1495 | } | ||
1496 | } | ||
1497 | |||
1498 | void Fluxbox::saveMenuFilename(const char *filename) { | ||
1499 | if (filename == 0) | ||
1500 | return; | ||
1501 | |||
1502 | bool found = false; | ||
1503 | |||
1504 | list<MenuTimestamp *>::iterator it = m_menu_timestamps.begin(); | ||
1505 | list<MenuTimestamp *>::iterator it_end = m_menu_timestamps.end(); | ||
1506 | for (; it != it_end; ++it) { | ||
1507 | if ((*it)->filename == filename) { | ||
1508 | found = true; | ||
1509 | break; | ||
1510 | } | ||
1511 | } | ||
1512 | |||
1513 | if (! found) { | ||
1514 | time_t timestamp = FbTk::FileUtil::getLastStatusChangeTimestamp(filename); | ||
1515 | |||
1516 | if (timestamp >= 0) { | ||
1517 | MenuTimestamp *ts = new MenuTimestamp; | ||
1518 | |||
1519 | ts->filename = filename; | ||
1520 | ts->timestamp = timestamp; | ||
1521 | |||
1522 | m_menu_timestamps.push_back(ts); | ||
1523 | } | ||
1524 | } | ||
1525 | } | ||
1526 | |||
1527 | void Fluxbox::clearMenuFilenames() { | ||
1528 | while(!m_menu_timestamps.empty()) { | ||
1529 | delete m_menu_timestamps.back(); | ||
1530 | m_menu_timestamps.pop_back(); | ||
1531 | } | ||
1532 | } | ||
1533 | |||
1534 | void Fluxbox::timed_reconfigure() { | 1470 | void Fluxbox::timed_reconfigure() { |
1535 | if (m_reconfigure_wait) | 1471 | if (m_reconfigure_wait) |
1536 | real_reconfigure(); | 1472 | real_reconfigure(); |
1537 | 1473 | ||
1538 | if (m_reread_menu_wait) | 1474 | m_reconfigure_wait = false; |
1539 | real_rereadMenu(); | ||
1540 | |||
1541 | m_reconfigure_wait = m_reread_menu_wait = false; | ||
1542 | } | 1475 | } |
1543 | 1476 | ||
1544 | void Fluxbox::revertFocus() { | 1477 | void Fluxbox::revertFocus() { |