diff options
author | Gregor Bollerhey <gbsoftware@arcor.de> | 2014-01-05 22:55:23 (GMT) |
---|---|---|
committer | Jan Sucan <jan@jansucan.com> | 2020-04-05 07:47:18 (GMT) |
commit | 07d2137024877f5fdf99d733d5887fb3f62076c7 (patch) | |
tree | fcf5f754d46acf48ee7b8e3550f24994249de00b | |
parent | c65f2ec6fbaea0d844b29470d2ce2891ffc5d2c4 (diff) | |
download | fluxbox-07d2137024877f5fdf99d733d5887fb3f62076c7.zip fluxbox-07d2137024877f5fdf99d733d5887fb3f62076c7.tar.bz2 |
Store order in TrayWindow instead of using expensive comperator.
-rw-r--r-- | src/SystemTray.cc | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/SystemTray.cc b/src/SystemTray.cc index a5fcc79..6efb812 100644 --- a/src/SystemTray.cc +++ b/src/SystemTray.cc | |||
@@ -87,7 +87,7 @@ static SystemTray *s_theoneandonly = 0; | |||
87 | /// helper class for tray windows, so we dont call XDestroyWindow | 87 | /// helper class for tray windows, so we dont call XDestroyWindow |
88 | class SystemTray::TrayWindow : public FbTk::FbWindow { | 88 | class SystemTray::TrayWindow : public FbTk::FbWindow { |
89 | public: | 89 | public: |
90 | TrayWindow(Window win, bool using_xembed):FbTk::FbWindow(win), m_visible(false), m_xembedded(using_xembed) { | 90 | TrayWindow(Window win, bool using_xembed):FbTk::FbWindow(win), m_order(0), m_visible(false), m_xembedded(using_xembed) { |
91 | setEventMask(PropertyChangeMask); | 91 | setEventMask(PropertyChangeMask); |
92 | } | 92 | } |
93 | 93 | ||
@@ -127,6 +127,7 @@ public: | |||
127 | return true; | 127 | return true; |
128 | } | 128 | } |
129 | 129 | ||
130 | int m_order; | ||
130 | private: | 131 | private: |
131 | bool m_visible; | 132 | bool m_visible; |
132 | bool m_xembedded; // using xembed protocol? (i.e. unmap when done) | 133 | bool m_xembedded; // using xembed protocol? (i.e. unmap when done) |
@@ -569,6 +570,8 @@ void SystemTray::showClient(TrayWindow *traywin) { | |||
569 | 570 | ||
570 | static std::string trim(const std::string& str) | 571 | static std::string trim(const std::string& str) |
571 | { | 572 | { |
573 | // removes trailing and leading whitespace from a string | ||
574 | |||
572 | const std::string whitespace(" \t"); | 575 | const std::string whitespace(" \t"); |
573 | const auto strBegin = str.find_first_not_of(whitespace); | 576 | const auto strBegin = str.find_first_not_of(whitespace); |
574 | if (strBegin == std::string::npos) | 577 | if (strBegin == std::string::npos) |
@@ -581,6 +584,8 @@ static std::string trim(const std::string& str) | |||
581 | } | 584 | } |
582 | 585 | ||
583 | static void parse_order(const std::string s, std::vector<std::string> &out) { | 586 | static void parse_order(const std::string s, std::vector<std::string> &out) { |
587 | // splits a comma seperated list and performs trimming | ||
588 | |||
584 | std::stringstream ss(s); | 589 | std::stringstream ss(s); |
585 | std::string item; | 590 | std::string item; |
586 | 591 | ||
@@ -591,6 +596,8 @@ static void parse_order(const std::string s, std::vector<std::string> &out) { | |||
591 | static int client_to_ordinal(const std::vector<std::string> left, | 596 | static int client_to_ordinal(const std::vector<std::string> left, |
592 | const std::vector<std::string> right, | 597 | const std::vector<std::string> right, |
593 | TrayWindow *i) { | 598 | TrayWindow *i) { |
599 | // based on the parsed order list and a given window returns an | ||
600 | // ordinal used to sort the tray icons. | ||
594 | 601 | ||
595 | auto Xdeleter = [](XClassHint *x){XFree(x);}; | 602 | auto Xdeleter = [](XClassHint *x){XFree(x);}; |
596 | 603 | ||
@@ -617,24 +624,16 @@ static int client_to_ordinal(const std::vector<std::string> left, | |||
617 | return 0; | 624 | return 0; |
618 | } | 625 | } |
619 | 626 | ||
620 | static bool client_comperator(const std::vector<std::string> left, | ||
621 | const std::vector<std::string> right, | ||
622 | TrayWindow *item1, TrayWindow *item2) { | ||
623 | const int a = client_to_ordinal(left, right, item1); | ||
624 | const int b = client_to_ordinal(left, right, item2); | ||
625 | return a<b; | ||
626 | } | ||
627 | |||
628 | |||
629 | void SystemTray::sortClients() { | 627 | void SystemTray::sortClients() { |
630 | std::vector<std::string> pinleft, pinright; | 628 | std::vector<std::string> pinleft, pinright; |
631 | 629 | ||
632 | parse_order(m_rc_systray_pinleft, pinleft); | 630 | parse_order(m_rc_systray_pinleft, pinleft); |
633 | parse_order(m_rc_systray_pinright, pinright); | 631 | parse_order(m_rc_systray_pinright, pinright); |
634 | 632 | ||
635 | m_clients.sort(std::bind(client_comperator, | 633 | for(TrayWindow *i: m_clients) |
636 | pinleft, pinright, | 634 | i->m_order = client_to_ordinal(pinleft, pinright, i); |
637 | std::placeholders::_1, std::placeholders::_2)); | 635 | |
636 | m_clients.sort([](TrayWindow *a, TrayWindow *b){return a->m_order < b->m_order;}); | ||
638 | 637 | ||
639 | rearrangeClients(); | 638 | rearrangeClients(); |
640 | } | 639 | } |