diff options
author | fluxgen <fluxgen> | 2002-02-17 18:56:14 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-02-17 18:56:14 (GMT) |
commit | 0cfdcba5c71722c769a254bebf5ef4497c51616e (patch) | |
tree | b9e8619d866e0fee498902f726d4026f9acb4c05 /src/Screen.cc | |
parent | fc82549383dffc6e4011bd3f732290338023aa07 (diff) | |
download | fluxbox-0cfdcba5c71722c769a254bebf5ef4497c51616e.zip fluxbox-0cfdcba5c71722c769a254bebf5ef4497c51616e.tar.bz2 |
clean menu parsing
Diffstat (limited to 'src/Screen.cc')
-rw-r--r-- | src/Screen.cc | 222 |
1 files changed, 116 insertions, 106 deletions
diff --git a/src/Screen.cc b/src/Screen.cc index 52eca9c..e90400e 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -22,7 +22,7 @@ | |||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
24 | 24 | ||
25 | // $Id: Screen.cc,v 1.23 2002/02/11 11:52:07 fluxgen Exp $ | 25 | // $Id: Screen.cc,v 1.24 2002/02/17 18:56:14 fluxgen Exp $ |
26 | 26 | ||
27 | // stupid macros needed to access some functions in version 2 of the GNU C | 27 | // stupid macros needed to access some functions in version 2 of the GNU C |
28 | // library | 28 | // library |
@@ -224,6 +224,9 @@ toolbar_placement(rm, Toolbar::BOTTOMCENTER, scrname+".toolbar.placement", altsc | |||
224 | BScreen::BScreen(ResourceManager &rm, Fluxbox *b, | 224 | BScreen::BScreen(ResourceManager &rm, Fluxbox *b, |
225 | const string &screenname, const string &altscreenname, | 225 | const string &screenname, const string &altscreenname, |
226 | int scrn) : ScreenInfo(b, scrn), | 226 | int scrn) : ScreenInfo(b, scrn), |
227 | #ifdef GNOME | ||
228 | gnome_win(None), | ||
229 | #endif | ||
227 | theme(0), | 230 | theme(0), |
228 | resource(rm, screenname, altscreenname) | 231 | resource(rm, screenname, altscreenname) |
229 | { | 232 | { |
@@ -231,7 +234,7 @@ resource(rm, screenname, altscreenname) | |||
231 | 234 | ||
232 | event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask | | 235 | event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask | |
233 | SubstructureRedirectMask | KeyPressMask | KeyReleaseMask | | 236 | SubstructureRedirectMask | KeyPressMask | KeyReleaseMask | |
234 | ButtonPressMask | ButtonReleaseMask;//| SubstructureNotifyMask; | 237 | ButtonPressMask | ButtonReleaseMask| SubstructureNotifyMask; |
235 | 238 | ||
236 | XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning); | 239 | XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning); |
237 | XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask); | 240 | XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask); |
@@ -487,6 +490,9 @@ namespace { | |||
487 | } | 490 | } |
488 | 491 | ||
489 | BScreen::~BScreen(void) { | 492 | BScreen::~BScreen(void) { |
493 | #ifdef GNOME | ||
494 | XDestroyWindow(getBaseDisplay()->getXDisplay(), gnome_win); | ||
495 | #endif | ||
490 | if (! managed) return; | 496 | if (! managed) return; |
491 | 497 | ||
492 | if (geom_pixmap != None) | 498 | if (geom_pixmap != None) |
@@ -675,7 +681,7 @@ void BScreen::updateWorkspaceNamesAtom(void) { | |||
675 | 681 | ||
676 | for (int i = 0; i < number_of_desks; i++) | 682 | for (int i = 0; i < number_of_desks; i++) |
677 | delete names[i]; | 683 | delete names[i]; |
678 | 684 | ||
679 | #endif | 685 | #endif |
680 | 686 | ||
681 | } | 687 | } |
@@ -1055,31 +1061,38 @@ void BScreen::nextFocus(void) { | |||
1055 | Bool have_focused = False; | 1061 | Bool have_focused = False; |
1056 | int focused_window_number = -1; | 1062 | int focused_window_number = -1; |
1057 | FluxboxWindow *next; | 1063 | FluxboxWindow *next; |
1058 | 1064 | const int num_windows = getCurrentWorkspace()->getCount(); | |
1059 | if (fluxbox->getFocusedWindow()) | 1065 | |
1066 | if (fluxbox->getFocusedWindow()) { | ||
1060 | if (fluxbox->getFocusedWindow()->getScreen()->getScreenNumber() == | 1067 | if (fluxbox->getFocusedWindow()->getScreen()->getScreenNumber() == |
1061 | getScreenNumber()) { | 1068 | getScreenNumber()) { |
1062 | have_focused = True; | 1069 | have_focused = True; |
1063 | focused_window_number = fluxbox->getFocusedWindow()->getWindowNumber(); | 1070 | focused_window_number = fluxbox->getFocusedWindow()->getWindowNumber(); |
1064 | } | 1071 | } |
1072 | } | ||
1065 | 1073 | ||
1066 | if ((getCurrentWorkspace()->getCount() > 1) && have_focused) { | 1074 | if (num_windows > 1 && have_focused) { |
1067 | int next_window_number = focused_window_number; | 1075 | int next_window_number = focused_window_number; |
1076 | |||
1077 | //try to set next window to focus | ||
1068 | do { | 1078 | do { |
1069 | if ((++next_window_number) >= getCurrentWorkspace()->getCount()) | 1079 | if ((++next_window_number) >= num_windows) |
1070 | next_window_number = 0; | 1080 | next_window_number = 0; |
1071 | |||
1072 | next = getCurrentWorkspace()->getWindow(next_window_number); | 1081 | next = getCurrentWorkspace()->getWindow(next_window_number); |
1073 | } while ((! next->setInputFocus()) && (next_window_number != | 1082 | } while ((!next->setInputFocus()) && next_window_number != |
1074 | focused_window_number)); | 1083 | focused_window_number); |
1075 | 1084 | ||
1076 | if (next_window_number != focused_window_number) | 1085 | if (next_window_number != focused_window_number) { |
1086 | next->setInputFocus(); | ||
1077 | getCurrentWorkspace()->raiseWindow(next); | 1087 | getCurrentWorkspace()->raiseWindow(next); |
1078 | } else if (getCurrentWorkspace()->getCount() >= 1) { | 1088 | } |
1079 | next = current_workspace->getWindow(0); | ||
1080 | 1089 | ||
1081 | current_workspace->raiseWindow(next); | 1090 | } else if (num_windows >= 1) { |
1082 | next->setInputFocus(); | 1091 | next = current_workspace->getWindow(0); |
1092 | |||
1093 | //don't raise next window if input focus fails | ||
1094 | if (next->setInputFocus()) | ||
1095 | current_workspace->raiseWindow(next); | ||
1083 | } | 1096 | } |
1084 | } | 1097 | } |
1085 | 1098 | ||
@@ -1100,7 +1113,7 @@ void BScreen::prevFocus(void) { | |||
1100 | int prev_window_number = focused_window_number; | 1113 | int prev_window_number = focused_window_number; |
1101 | do { | 1114 | do { |
1102 | if ((--prev_window_number) < 0) | 1115 | if ((--prev_window_number) < 0) |
1103 | prev_window_number = getCurrentWorkspace()->getCount() - 1; | 1116 | prev_window_number = getCurrentWorkspace()->getCount() - 1; |
1104 | 1117 | ||
1105 | prev = getCurrentWorkspace()->getWindow(prev_window_number); | 1118 | prev = getCurrentWorkspace()->getWindow(prev_window_number); |
1106 | } while ((! prev->setInputFocus()) && (prev_window_number != | 1119 | } while ((! prev->setInputFocus()) && (prev_window_number != |
@@ -1135,8 +1148,6 @@ void BScreen::raiseFocus(void) { | |||
1135 | raiseWindow(fluxbox->getFocusedWindow()); | 1148 | raiseWindow(fluxbox->getFocusedWindow()); |
1136 | } | 1149 | } |
1137 | 1150 | ||
1138 | |||
1139 | // XXX - no good parsing here | ||
1140 | void BScreen::InitMenu(void) { | 1151 | void BScreen::InitMenu(void) { |
1141 | I18n *i18n = I18n::instance(); | 1152 | I18n *i18n = I18n::instance(); |
1142 | 1153 | ||
@@ -1462,91 +1473,7 @@ Bool BScreen::parseMenuFile(ifstream &file, Rootmenu *menu, int &row) { | |||
1462 | " error, no directory defined\n")); | 1473 | " error, no directory defined\n")); |
1463 | cerr<<"Row: "<<row<<endl; | 1474 | cerr<<"Row: "<<row<<endl; |
1464 | } else { // else 'y' | 1475 | } else { // else 'y' |
1465 | char *stylesdir; | 1476 | createStyleMenu(menu, newmenu, str_label.c_str(), (newmenu) ? str_cmd.c_str() : str_label.c_str()); |
1466 | const char *directory = ((newmenu) ? str_cmd.c_str() : str_label.c_str()); | ||
1467 | |||
1468 | // perform shell style ~ home directory expansion | ||
1469 | stylesdir = StringUtil::expandFilename(directory); | ||
1470 | |||
1471 | struct stat statbuf; | ||
1472 | |||
1473 | if (! stat(stylesdir, &statbuf)) { // stat | ||
1474 | if (S_ISDIR(statbuf.st_mode)) { // dir | ||
1475 | Rootmenu *stylesmenu; | ||
1476 | if (newmenu) | ||
1477 | stylesmenu = new Rootmenu(this); | ||
1478 | else | ||
1479 | stylesmenu = menu; | ||
1480 | |||
1481 | DIR *d = opendir(stylesdir); | ||
1482 | int entries = 0; | ||
1483 | struct dirent *p; | ||
1484 | |||
1485 | // get the total number of directory entries | ||
1486 | while ((p = readdir(d))) entries++; | ||
1487 | rewinddir(d); | ||
1488 | |||
1489 | char **ls = new char* [entries]; | ||
1490 | int index = 0; | ||
1491 | while ((p = readdir(d))) | ||
1492 | ls[index++] = StringUtil::strdup(p->d_name); | ||
1493 | |||
1494 | qsort(ls, entries, sizeof(char *), dcmp); | ||
1495 | |||
1496 | int n, slen = strlen(stylesdir); | ||
1497 | for (n = 0; n < entries; n++) { // for | ||
1498 | int nlen = strlen(ls[n]); | ||
1499 | char style[MAXPATHLEN + 1]; | ||
1500 | |||
1501 | strncpy(style, stylesdir, slen); | ||
1502 | *(style + slen) = '/'; | ||
1503 | strncpy(style + slen + 1, ls[n], nlen + 1); | ||
1504 | |||
1505 | if ((! stat(style, &statbuf)) && S_ISREG(statbuf.st_mode)) | ||
1506 | stylesmenu->insert(ls[n], BScreen::SETSTYLE, style); | ||
1507 | delete [] ls[n]; | ||
1508 | } // end for | ||
1509 | |||
1510 | delete [] ls; | ||
1511 | |||
1512 | stylesmenu->update(); | ||
1513 | |||
1514 | if (newmenu) { | ||
1515 | stylesmenu->setLabel(str_label.c_str()); | ||
1516 | menu->insert(str_label.c_str(), stylesmenu); | ||
1517 | rootmenuList.push_back(stylesmenu); | ||
1518 | } | ||
1519 | |||
1520 | fluxbox->saveMenuFilename(stylesdir); | ||
1521 | } else { // dir | ||
1522 | fprintf(stderr, | ||
1523 | i18n-> | ||
1524 | getMessage( | ||
1525 | #ifdef NLS | ||
1526 | ScreenSet, ScreenSTYLESDIRErrorNotDir, | ||
1527 | #else // !NLS | ||
1528 | 0, 0, | ||
1529 | #endif // NLS | ||
1530 | "BScreen::parseMenuFile:" | ||
1531 | " [stylesdir/stylesmenu] error, %s is not a" | ||
1532 | " directory\n"), stylesdir); | ||
1533 | cerr<<"Row: "<<row<<endl; | ||
1534 | } // end of 'dir' | ||
1535 | } else { // stat | ||
1536 | fprintf(stderr, | ||
1537 | i18n-> | ||
1538 | getMessage( | ||
1539 | #ifdef NLS | ||
1540 | ScreenSet, ScreenSTYLESDIRErrorNoExist, | ||
1541 | #else // !NLS | ||
1542 | 0, 0, | ||
1543 | #endif // NLS | ||
1544 | "BScreen::parseMenuFile: [stylesdir/stylesmenu]" | ||
1545 | " error, %s does not exist\n"), stylesdir); | ||
1546 | cerr<<"Row: "<<row<<endl; | ||
1547 | } // end of 'stat' | ||
1548 | |||
1549 | delete stylesdir; | ||
1550 | } // end of else 'y' | 1477 | } // end of else 'y' |
1551 | } // end of stylesdir | 1478 | } // end of stylesdir |
1552 | else if (str_key == "workspaces") { | 1479 | else if (str_key == "workspaces") { |
@@ -1571,6 +1498,87 @@ Bool BScreen::parseMenuFile(ifstream &file, Rootmenu *menu, int &row) { | |||
1571 | return ((menu->getCount() == 0) ? true : false); | 1498 | return ((menu->getCount() == 0) ? true : false); |
1572 | } | 1499 | } |
1573 | 1500 | ||
1501 | void BScreen::createStyleMenu(Rootmenu *menu, bool newmenu, const char *label, const char *directory) { | ||
1502 | I18n *i18n = I18n::instance(); | ||
1503 | |||
1504 | // perform shell style ~ home directory expansion | ||
1505 | auto_ptr<char> stylesdir(StringUtil::expandFilename(directory)); | ||
1506 | |||
1507 | struct stat statbuf; | ||
1508 | |||
1509 | if (! stat(stylesdir.get(), &statbuf)) { // stat | ||
1510 | if (S_ISDIR(statbuf.st_mode)) { // dir | ||
1511 | Rootmenu *stylesmenu; | ||
1512 | if (newmenu) | ||
1513 | stylesmenu = new Rootmenu(this); | ||
1514 | else | ||
1515 | stylesmenu = menu; | ||
1516 | |||
1517 | DIR *d = opendir(stylesdir.get()); | ||
1518 | int entries = 0; | ||
1519 | struct dirent *p; | ||
1520 | |||
1521 | // get the total number of directory entries | ||
1522 | while ((p = readdir(d))) entries++; | ||
1523 | |||
1524 | rewinddir(d); | ||
1525 | |||
1526 | char **ls = new char* [entries]; | ||
1527 | int index = 0; | ||
1528 | while ((p = readdir(d))) | ||
1529 | ls[index++] = StringUtil::strdup(p->d_name); | ||
1530 | |||
1531 | qsort(ls, entries, sizeof(char *), dcmp); | ||
1532 | |||
1533 | int n, slen = strlen(stylesdir.get()); | ||
1534 | for (n = 0; n < entries; n++) { // for | ||
1535 | int nlen = strlen(ls[n]); | ||
1536 | char style[MAXPATHLEN + 1]; | ||
1537 | strncpy(style, stylesdir.get(), slen); | ||
1538 | *(style + slen) = '/'; | ||
1539 | strncpy(style + slen + 1, ls[n], nlen + 1); | ||
1540 | if ((! stat(style, &statbuf)) && S_ISREG(statbuf.st_mode)) | ||
1541 | stylesmenu->insert(ls[n], BScreen::SETSTYLE, style); | ||
1542 | delete [] ls[n]; | ||
1543 | } | ||
1544 | |||
1545 | delete [] ls; | ||
1546 | |||
1547 | stylesmenu->update(); | ||
1548 | if (newmenu) { | ||
1549 | stylesmenu->setLabel(label); | ||
1550 | menu->insert(label, stylesmenu); | ||
1551 | rootmenuList.push_back(stylesmenu); | ||
1552 | } | ||
1553 | |||
1554 | fluxbox->saveMenuFilename(stylesdir.get()); | ||
1555 | } else { // dir | ||
1556 | fprintf(stderr, | ||
1557 | i18n-> | ||
1558 | getMessage( | ||
1559 | #ifdef NLS | ||
1560 | ScreenSet, ScreenSTYLESDIRErrorNotDir, | ||
1561 | #else // !NLS | ||
1562 | 0, 0, | ||
1563 | #endif // NLS | ||
1564 | "BScreen::parseMenuFile:" | ||
1565 | " [stylesdir/stylesmenu] error, %s is not a" | ||
1566 | " directory\n"), stylesdir.get()); | ||
1567 | } // end of 'dir' | ||
1568 | } else { // stat | ||
1569 | fprintf(stderr, | ||
1570 | i18n-> | ||
1571 | getMessage( | ||
1572 | #ifdef NLS | ||
1573 | ScreenSet, ScreenSTYLESDIRErrorNoExist, | ||
1574 | #else // !NLS | ||
1575 | 0, 0, | ||
1576 | #endif // NLS | ||
1577 | "BScreen::parseMenuFile: [stylesdir/stylesmenu]" | ||
1578 | " error, %s does not exist\n"), stylesdir.get()); | ||
1579 | } // end of 'stat' | ||
1580 | |||
1581 | } | ||
1574 | 1582 | ||
1575 | void BScreen::shutdown(void) { | 1583 | void BScreen::shutdown(void) { |
1576 | fluxbox->grab(); | 1584 | fluxbox->grab(); |
@@ -1727,7 +1735,7 @@ void BScreen::leftWorkspace(void) { | |||
1727 | void BScreen::initGnomeAtoms(void) { | 1735 | void BScreen::initGnomeAtoms(void) { |
1728 | 1736 | ||
1729 | /* create the GNOME window */ | 1737 | /* create the GNOME window */ |
1730 | Window gnome_win = XCreateSimpleWindow(getBaseDisplay()->getXDisplay(), | 1738 | gnome_win = XCreateSimpleWindow(getBaseDisplay()->getXDisplay(), |
1731 | getRootWindow(), 0, 0, 5, 5, 0, 0, 0); | 1739 | getRootWindow(), 0, 0, 5, 5, 0, 0, 0); |
1732 | 1740 | ||
1733 | /* supported WM check */ | 1741 | /* supported WM check */ |
@@ -1738,14 +1746,16 @@ void BScreen::initGnomeAtoms(void) { | |||
1738 | XChangeProperty(getBaseDisplay()->getXDisplay(), gnome_win, | 1746 | XChangeProperty(getBaseDisplay()->getXDisplay(), gnome_win, |
1739 | getBaseDisplay()->getGnomeSupportingWMCheckAtom(), | 1747 | getBaseDisplay()->getGnomeSupportingWMCheckAtom(), |
1740 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &gnome_win, 1); | 1748 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &gnome_win, 1); |
1741 | 1749 | ||
1742 | Atom gnomeatomlist[] = { | 1750 | Atom gnomeatomlist[] = { |
1743 | getBaseDisplay()->getGnomeWorkspaceAtom(), | 1751 | getBaseDisplay()->getGnomeWorkspaceAtom(), |
1744 | getBaseDisplay()->getGnomeWorkspaceCountAtom(), | 1752 | getBaseDisplay()->getGnomeWorkspaceCountAtom(), |
1745 | getBaseDisplay()->getGnomeStateAtom(), | 1753 | getBaseDisplay()->getGnomeStateAtom(), |
1754 | getBaseDisplay()->getGnomeWorkspaceNamesAtom(), | ||
1746 | getBaseDisplay()->getGnomeHintsAtom() | 1755 | getBaseDisplay()->getGnomeHintsAtom() |
1747 | }; | 1756 | }; |
1748 | 1757 | ||
1758 | //list atoms that we support | ||
1749 | XChangeProperty(getBaseDisplay()->getXDisplay(), getRootWindow(), | 1759 | XChangeProperty(getBaseDisplay()->getXDisplay(), getRootWindow(), |
1750 | getBaseDisplay()->getGnomeProtAtom(), XA_ATOM, 32, PropModeReplace, | 1760 | getBaseDisplay()->getGnomeProtAtom(), XA_ATOM, 32, PropModeReplace, |
1751 | (unsigned char *)gnomeatomlist, (sizeof gnomeatomlist)/sizeof gnomeatomlist[0]); | 1761 | (unsigned char *)gnomeatomlist, (sizeof gnomeatomlist)/sizeof gnomeatomlist[0]); |