aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2015-01-16 07:44:49 (GMT)
committerMathias Gumz <akira@fluxbox.org>2015-01-16 07:45:11 (GMT)
commitb30438c311a356f7bb1621f1ed3cb9a99e7d96c9 (patch)
treeb99b2d5cf07ec7cb700e4ece58d86a93f8236cd5
parent6d5781ce7198a8a82fd0cae8554e4c120d01df3d (diff)
downloadfluxbox-b30438c311a356f7bb1621f1ed3cb9a99e7d96c9.zip
fluxbox-b30438c311a356f7bb1621f1ed3cb9a99e7d96c9.tar.bz2
Refactor: bundle xinerama-info together, simpler code
Part of this massive looking but simple rather simple change is a the way we check for active Xinerama: XineramaIsActive() was used before. The docs for XineramaQueryScreens() state that XineramaQueryScreens() returns NULL and sets number to 0 if Xinerama is not active. Sold.
-rw-r--r--src/Screen.cc84
-rw-r--r--src/Screen.hh29
2 files changed, 52 insertions, 61 deletions
diff --git a/src/Screen.cc b/src/Screen.cc
index 296fec0..6ddcded 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -227,7 +227,6 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
227 m_focus_control(new FocusControl(*this)), 227 m_focus_control(new FocusControl(*this)),
228 m_placement_strategy(new ScreenPlacement(*this)), 228 m_placement_strategy(new ScreenPlacement(*this)),
229 m_cycling(false), m_cycle_opts(0), 229 m_cycling(false), m_cycle_opts(0),
230 m_xinerama_headinfo(0),
231 m_restart(false), 230 m_restart(false),
232 m_shutdown(false) { 231 m_shutdown(false) {
233 232
@@ -468,8 +467,8 @@ BScreen::~BScreen() {
468 tmp.pop_back(); 467 tmp.pop_back();
469 } 468 }
470 469
471 if (hasXinerama() && m_xinerama_headinfo) { 470 if (hasXinerama()) {
472 delete [] m_xinerama_headinfo; 471 m_xinerama.heads.clear();
473 } 472 }
474 473
475 // slit must be destroyed before headAreas (Struts) 474 // slit must be destroyed before headAreas (Struts)
@@ -1608,51 +1607,42 @@ WinClient *BScreen::findGroupRight(WinClient &winclient) {
1608void BScreen::clearXinerama() { 1607void BScreen::clearXinerama() {
1609 fbdbg<<"BScreen::initXinerama(): dont have Xinerama"<<endl; 1608 fbdbg<<"BScreen::initXinerama(): dont have Xinerama"<<endl;
1610 1609
1611 m_xinerama_avail = false; 1610 m_xinerama.avail = false;
1612 if (m_xinerama_headinfo) 1611 m_xinerama.heads.clear();
1613 delete [] m_xinerama_headinfo;
1614 m_xinerama_headinfo = 0;
1615 m_xinerama_num_heads = 0;
1616} 1612}
1617 1613
1618void BScreen::initXinerama() { 1614void BScreen::initXinerama() {
1619#ifdef XINERAMA 1615#ifdef XINERAMA
1620 Display *display = FbTk::App::instance()->display(); 1616 Display* display = FbTk::App::instance()->display();
1617 int number = 0;
1618 XineramaScreenInfo *si = XineramaQueryScreens(display, &number);
1621 1619
1622 if (!XineramaIsActive(display)) { 1620 if (!si && number == 0) {
1623 clearXinerama(); 1621 clearXinerama();
1624 return; 1622 return;
1625 } 1623 }
1626 1624
1627 fbdbg<<"BScreen::initXinerama(): have Xinerama"<<endl; 1625 m_xinerama.avail = true;
1628
1629 m_xinerama_avail = true;
1630 1626
1631 XineramaScreenInfo *screen_info; 1627 fbdbg<<"BScreen::initXinerama(): have Xinerama"<<endl;
1632 int number;
1633 screen_info = XineramaQueryScreens(display, &number);
1634 1628
1635 /* The call may have actually failed. If this is the first time we init 1629 /* The call may have actually failed. If this is the first time we init
1636 * Xinerama, fall back to turning it off. If not, pretend nothing 1630 * Xinerama, fall back to turning it off. If not, pretend nothing
1637 * happened -- another event will tell us and it will work then. */ 1631 * happened -- another event will tell us and it will work then. */
1638 if (!screen_info) { 1632 if (!si) {
1639 if (!m_xinerama_headinfo) 1633 if (m_xinerama.heads.empty())
1640 clearXinerama(); 1634 clearXinerama();
1641 return; 1635 return;
1642 } 1636 }
1643 1637
1644 if (m_xinerama_headinfo) 1638 m_xinerama.heads.resize(number);
1645 delete [] m_xinerama_headinfo; 1639 for (int i = 0; i < number; i++) {
1646 1640 m_xinerama.heads[i]._x = si[i].x_org;
1647 m_xinerama_headinfo = new XineramaHeadInfo[number]; 1641 m_xinerama.heads[i]._y = si[i].y_org;
1648 m_xinerama_num_heads = number; 1642 m_xinerama.heads[i]._width = si[i].width;
1649 for (int i=0; i < number; i++) { 1643 m_xinerama.heads[i]._height = si[i].height;
1650 m_xinerama_headinfo[i]._x = screen_info[i].x_org;
1651 m_xinerama_headinfo[i]._y = screen_info[i].y_org;
1652 m_xinerama_headinfo[i]._width = screen_info[i].width;
1653 m_xinerama_headinfo[i]._height = screen_info[i].height;
1654 } 1644 }
1655 XFree(screen_info); 1645 XFree(si);
1656 1646
1657 fbdbg<<"BScreen::initXinerama(): number of heads ="<<number<<endl; 1647 fbdbg<<"BScreen::initXinerama(): number of heads ="<<number<<endl;
1658 1648
@@ -1670,11 +1660,8 @@ void BScreen::initXinerama() {
1670 } 1660 }
1671 1661
1672#else // XINERAMA 1662#else // XINERAMA
1673 // no xinerama 1663 m_xinerama.avail = false;
1674 m_xinerama_avail = false;
1675 m_xinerama_num_heads = 0;
1676#endif // XINERAMA 1664#endif // XINERAMA
1677
1678} 1665}
1679 1666
1680/* Move windows out of inactive heads */ 1667/* Move windows out of inactive heads */
@@ -1691,8 +1678,8 @@ void BScreen::clearHeads() {
1691 // check if the window is invisible 1678 // check if the window is invisible
1692 bool invisible = true; 1679 bool invisible = true;
1693 int j; 1680 int j;
1694 for (j = 0; j < m_xinerama_num_heads; ++j) { 1681 for (j = 0; j < numHeads(); ++j) {
1695 XineramaHeadInfo& hi = m_xinerama_headinfo[j]; 1682 XineramaHeadInfo& hi = m_xinerama.heads[j];
1696 if (RectangleUtil::overlapRectangles(hi, w)) { 1683 if (RectangleUtil::overlapRectangles(hi, w)) {
1697 invisible = false; 1684 invisible = false;
1698 break; 1685 break;
@@ -1711,11 +1698,10 @@ void BScreen::clearHeads() {
1711} 1698}
1712 1699
1713int BScreen::getHead(int x, int y) const { 1700int BScreen::getHead(int x, int y) const {
1714
1715#ifdef XINERAMA 1701#ifdef XINERAMA
1716 if (hasXinerama()) { 1702 if (hasXinerama()) {
1717 for (int i=0; i < m_xinerama_num_heads; i++) { 1703 for (int i = 0; i < numHeads(); i++) {
1718 if (RectangleUtil::insideBorder(m_xinerama_headinfo[i], x, y, 0)) { 1704 if (RectangleUtil::insideBorder(m_xinerama.heads[i], x, y, 0)) {
1719 return i+1; 1705 return i+1;
1720 } 1706 }
1721 } 1707 }
@@ -1743,9 +1729,9 @@ int BScreen::getHead(const FbTk::FbWindow &win) const {
1743 // the head which center is nearest to the window center 1729 // the head which center is nearest to the window center
1744 long dist = -1; 1730 long dist = -1;
1745 int i; 1731 int i;
1746 for (i = 0; i < m_xinerama_num_heads; ++i) { 1732 for (i = 0; i < numHeads(); ++i) {
1747 XineramaHeadInfo& hi = m_xinerama_headinfo[i]; 1733 const XineramaHeadInfo& hi = m_xinerama.heads[i];
1748 int d = calcSquareDistance(cx, cy, 1734 long d = calcSquareDistance(cx, cy,
1749 hi.x() + (hi.width() / 2), hi.y() + (hi.height() / 2)); 1735 hi.x() + (hi.width() / 2), hi.y() + (hi.height() / 2));
1750 if (dist == -1 || d < dist) { // found a closer head 1736 if (dist == -1 || d < dist) { // found a closer head
1751 head = i + 1; 1737 head = i + 1;
@@ -1779,8 +1765,8 @@ int BScreen::getCurrHead() const {
1779 1765
1780int BScreen::getHeadX(int head) const { 1766int BScreen::getHeadX(int head) const {
1781#ifdef XINERAMA 1767#ifdef XINERAMA
1782 if (head == 0 || head > m_xinerama_num_heads) return 0; 1768 if (head == 0 || head > numHeads()) return 0;
1783 return m_xinerama_headinfo[head-1].x(); 1769 return m_xinerama.heads[head-1].x();
1784#else 1770#else
1785 return 0; 1771 return 0;
1786#endif // XINERAMA 1772#endif // XINERAMA
@@ -1788,8 +1774,8 @@ int BScreen::getHeadX(int head) const {
1788 1774
1789int BScreen::getHeadY(int head) const { 1775int BScreen::getHeadY(int head) const {
1790#ifdef XINERAMA 1776#ifdef XINERAMA
1791 if (head == 0 || head > m_xinerama_num_heads) return 0; 1777 if (head == 0 || head > numHeads()) return 0;
1792 return m_xinerama_headinfo[head-1].y(); 1778 return m_xinerama.heads[head-1].y();
1793#else 1779#else
1794 return 0; 1780 return 0;
1795#endif // XINERAMA 1781#endif // XINERAMA
@@ -1797,8 +1783,8 @@ int BScreen::getHeadY(int head) const {
1797 1783
1798int BScreen::getHeadWidth(int head) const { 1784int BScreen::getHeadWidth(int head) const {
1799#ifdef XINERAMA 1785#ifdef XINERAMA
1800 if (head == 0 || head > m_xinerama_num_heads) return width(); 1786 if (head == 0 || head > numHeads()) return width();
1801 return m_xinerama_headinfo[head-1].width(); 1787 return m_xinerama.heads[head-1].width();
1802#else 1788#else
1803 return width(); 1789 return width();
1804#endif // XINERAMA 1790#endif // XINERAMA
@@ -1806,8 +1792,8 @@ int BScreen::getHeadWidth(int head) const {
1806 1792
1807int BScreen::getHeadHeight(int head) const { 1793int BScreen::getHeadHeight(int head) const {
1808#ifdef XINERAMA 1794#ifdef XINERAMA
1809 if (head == 0 || head > m_xinerama_num_heads) return height(); 1795 if (head == 0 || head > numHeads()) return height();
1810 return m_xinerama_headinfo[head-1].height(); 1796 return m_xinerama.heads[head-1].height();
1811#else 1797#else
1812 return height(); 1798 return height();
1813#endif // XINERAMA 1799#endif // XINERAMA
diff --git a/src/Screen.hh b/src/Screen.hh
index eb2a306..771899f 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -370,14 +370,14 @@ public:
370 // Xinerama-related functions 370 // Xinerama-related functions
371 371
372 /// @return true if xinerama is available 372 /// @return true if xinerama is available
373 bool hasXinerama() const { return m_xinerama_avail; } 373 bool hasXinerama() const { return m_xinerama.avail; }
374 /// @return umber of xinerama heads 374 /// @return umber of xinerama heads
375 int numHeads() const { return m_xinerama_num_heads; } 375 int numHeads() const { return m_xinerama.heads.size(); }
376 376
377 void initXinerama(); 377 void initXinerama();
378 void clearXinerama();
378 void clearHeads(); 379 void clearHeads();
379 /// clean up xinerama 380 /// clean up xinerama
380 void clearXinerama();
381 381
382 /** 382 /**
383 * Determines head number for a position 383 * Determines head number for a position
@@ -475,7 +475,7 @@ private:
475 475
476 FbTk::MultLayers m_layermanager; 476 FbTk::MultLayers m_layermanager;
477 477
478 bool root_colormap_installed, managed; 478 bool root_colormap_installed;
479 479
480 std::auto_ptr<FbTk::ImageControl> m_image_control; 480 std::auto_ptr<FbTk::ImageControl> m_image_control;
481 std::auto_ptr<FbMenu> m_configmenu, m_rootmenu, m_workspacemenu, m_windowmenu; 481 std::auto_ptr<FbMenu> m_configmenu, m_rootmenu, m_workspacemenu, m_windowmenu;
@@ -525,21 +525,26 @@ private:
525 const ClientPattern *m_cycle_opts; 525 const ClientPattern *m_cycle_opts;
526 526
527 // Xinerama related private data 527 // Xinerama related private data
528 bool m_xinerama_avail;
529 int m_xinerama_num_heads;
530 int m_xinerama_center_x, m_xinerama_center_y;
531
532 std::vector<HeadArea *> m_head_areas;
533
534 struct XineramaHeadInfo { 528 struct XineramaHeadInfo {
535 int _x, _y, _width, _height; 529 int _x, _y, _width, _height;
536 int x() const { return _x; } 530 int x() const { return _x; }
537 int y() const { return _y; } 531 int y() const { return _y; }
538 int width() const { return _width; } 532 int width() const { return _width; }
539 int height() const { return _height; } 533 int height() const { return _height; }
540 } *m_xinerama_headinfo; 534 };
535 struct {
536 bool avail;
537 int center_x;
538 int center_y;
539 std::vector<XineramaHeadInfo> heads;
540 } m_xinerama;
541
542 std::vector<HeadArea*> m_head_areas;
543
541 544
542 bool m_restart, m_shutdown; 545 bool m_restart;
546 bool m_shutdown;
547 bool managed;
543}; 548};
544 549
545 550