From 1a25be374f8db2c21345de232e83ff6012af8186 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Wed, 25 Jan 2017 03:29:11 +0100 Subject: [PATCH] refactor(xworkspaces): Cleanup --- include/modules/xworkspaces.hpp | 18 +- include/x11/ewmh.hpp | 6 + src/modules/xworkspaces.cpp | 304 +++++++++++++++++++------------- src/x11/ewmh.cpp | 54 +++--- 4 files changed, 235 insertions(+), 147 deletions(-) diff --git a/include/modules/xworkspaces.hpp b/include/modules/xworkspaces.hpp index 5d683fcf..e1f52426 100644 --- a/include/modules/xworkspaces.hpp +++ b/include/modules/xworkspaces.hpp @@ -31,8 +31,10 @@ namespace modules { }; struct desktop { - explicit desktop(size_t index, desktop_state state, label_t&& label) : index(index), state(state), label(label) {} - size_t index; + explicit desktop(unsigned int index, unsigned int offset, desktop_state state, label_t&& label) + : index(index), offset(offset), state(state), label(label) {} + unsigned int index; + unsigned int offset; desktop_state state; label_t label; }; @@ -60,8 +62,11 @@ namespace modules { protected: void handle(const evt::property_notify& evt); + + void rebuild_clientlist(); void rebuild_desktops(); - void set_current_desktop(); + void rebuild_desktop_states(); + bool input(string&& cmd); private: @@ -79,9 +84,14 @@ namespace modules { connection& m_connection; ewmh_connection_t m_ewmh; + vector m_monitors; bool m_monitorsupport{true}; + vector m_desktop_names; + unsigned int m_current_desktop; + + vector m_clientlist; vector> m_viewports; map m_labels; label_t m_monitorlabel; @@ -90,6 +100,8 @@ namespace modules { bool m_click{true}; bool m_scroll{true}; size_t m_index{0}; + + event_timer m_timer{0L, 25L}; }; } diff --git a/include/x11/ewmh.hpp b/include/x11/ewmh.hpp index 23e90c00..8591da9c 100644 --- a/include/x11/ewmh.hpp +++ b/include/x11/ewmh.hpp @@ -29,11 +29,17 @@ namespace ewmh_util { void change_current_desktop(unsigned int desktop); void set_wm_window_type(xcb_window_t win, vector types); + void set_wm_state(xcb_window_t win, vector states); + vector get_wm_state(xcb_window_t win); + void set_wm_pid(xcb_window_t win); void set_wm_pid(xcb_window_t win, unsigned int pid); + void set_wm_desktop(xcb_window_t win, unsigned int desktop = -1u); void set_wm_window_opacity(xcb_window_t win, unsigned long int values); + + vector get_client_list(int screen = 0); } POLYBAR_NS_END diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp index 38b7888e..98caedad 100644 --- a/src/modules/xworkspaces.cpp +++ b/src/modules/xworkspaces.cpp @@ -1,3 +1,4 @@ +#include #include #include "drawtypes/iconset.hpp" @@ -12,6 +13,15 @@ POLYBAR_NS +namespace { + inline bool operator==(const position& a, const position& b) { + return a.x + a.y == b.x + b.y; + } + inline bool operator!=(const position& a, const position& b) { + return !(a == b); + } +} + namespace modules { template class module; @@ -36,15 +46,10 @@ namespace modules { } // Check if the WM supports _NET_DESKTOP_VIEWPORT - if (!ewmh_util::supports(m_ewmh->_NET_DESKTOP_VIEWPORT) && m_pinworkspaces) { + if (!(m_monitorsupport = ewmh_util::supports(m_ewmh->_NET_DESKTOP_VIEWPORT)) && m_pinworkspaces) { throw module_error("The WM does not support _NET_DESKTOP_VIEWPORT (required when `pin-workspaces = true`)"); - } else if (!m_pinworkspaces) { - m_monitorsupport = false; } - // Get list of monitors - m_monitors = randr_util::get_monitors(m_connection, m_connection.root(), false); - // Add formats and elements m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE, TAG_LABEL_MONITOR}); @@ -74,137 +79,210 @@ namespace modules { m_icons->add(vec[0], factory_util::shared