diff --git a/include/modules/xworkspaces.hpp b/include/modules/xworkspaces.hpp index 2d5447db..191f7f4e 100644 --- a/include/modules/xworkspaces.hpp +++ b/include/modules/xworkspaces.hpp @@ -69,6 +69,7 @@ namespace modules { void set_desktop_urgent(xcb_window_t window); bool input(string&& cmd); + vector get_desktop_names(); private: static constexpr const char* DEFAULT_ICON{"icon-default"}; diff --git a/include/x11/ewmh.hpp b/include/x11/ewmh.hpp index bced1347..e6fb1371 100644 --- a/include/x11/ewmh.hpp +++ b/include/x11/ewmh.hpp @@ -24,6 +24,7 @@ namespace ewmh_util { vector get_desktop_viewports(int screen = 0); vector get_desktop_names(int screen = 0); unsigned int get_current_desktop(int screen = 0); + unsigned int get_number_of_desktops(int screen = 0); xcb_window_t get_active_window(int screen = 0); void change_current_desktop(unsigned int desktop); diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp index 7f2a9a46..22587a1f 100644 --- a/src/modules/xworkspaces.cpp +++ b/src/modules/xworkspaces.cpp @@ -81,7 +81,7 @@ namespace modules { m_monitors = randr_util::get_monitors(m_connection, m_connection.root(), false); // Get desktop details - m_desktop_names = ewmh_util::get_desktop_names(); + m_desktop_names = get_desktop_names(); m_current_desktop = ewmh_util::get_current_desktop(); rebuild_desktops(); @@ -97,8 +97,8 @@ namespace modules { void xworkspaces_module::handle(const evt::property_notify& evt) { if (evt->atom == m_ewmh->_NET_CLIENT_LIST) { rebuild_clientlist(); - } else if (evt->atom == m_ewmh->_NET_DESKTOP_NAMES) { - m_desktop_names = ewmh_util::get_desktop_names(); + } else if (evt->atom == m_ewmh->_NET_DESKTOP_NAMES || evt->atom == m_ewmh->_NET_NUMBER_OF_DESKTOPS) { + m_desktop_names = get_desktop_names(); rebuild_desktops(); rebuild_desktop_states(); } else if (evt->atom == m_ewmh->_NET_CURRENT_DESKTOP) { @@ -224,6 +224,22 @@ namespace modules { } } + vector xworkspaces_module::get_desktop_names(){ + vector names = ewmh_util::get_desktop_names(); + unsigned int desktops_number = ewmh_util::get_number_of_desktops(); + if(desktops_number == names.size()) { + return names; + } + else if(desktops_number < names.size()) { + names.erase(names.begin()+desktops_number, names.end()); + return names; + } + for (unsigned int i = names.size(); i < desktops_number + 1; i++) { + names.insert(names.end(), to_string(i)); + } + return names; + } + /** * Find window and set corresponding desktop to urgent */ diff --git a/src/x11/ewmh.cpp b/src/x11/ewmh.cpp index 1c4fb2f6..143ad99a 100644 --- a/src/x11/ewmh.cpp +++ b/src/x11/ewmh.cpp @@ -77,6 +77,13 @@ namespace ewmh_util { return desktop; } + unsigned int get_number_of_desktops(int screen) { + auto conn = initialize().get(); + unsigned int desktops = XCB_NONE; + xcb_ewmh_get_number_of_desktops_reply(conn, xcb_ewmh_get_number_of_desktops(conn, screen), &desktops, nullptr); + return desktops; + } + vector get_desktop_viewports(int screen) { auto conn = initialize().get(); vector viewports;