feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
#include "modules/xworkspaces.hpp"
|
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
#include <algorithm>
|
2020-05-01 15:43:14 +00:00
|
|
|
#include <set>
|
2016-11-26 08:38:55 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2016-11-26 05:14:58 +00:00
|
|
|
#include "drawtypes/iconset.hpp"
|
|
|
|
#include "drawtypes/label.hpp"
|
2020-01-07 12:40:24 +00:00
|
|
|
#include "modules/meta/base.inl"
|
2016-12-09 08:02:47 +00:00
|
|
|
#include "utils/factory.hpp"
|
2016-12-04 03:11:47 +00:00
|
|
|
#include "utils/math.hpp"
|
2016-11-26 05:14:58 +00:00
|
|
|
#include "x11/atoms.hpp"
|
|
|
|
#include "x11/connection.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
namespace {
|
|
|
|
inline bool operator==(const position& a, const position& b) {
|
|
|
|
return a.x + a.y == b.x + b.y;
|
|
|
|
}
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
} // namespace
|
2017-01-25 02:29:11 +00:00
|
|
|
|
2020-05-01 15:43:14 +00:00
|
|
|
/**
|
|
|
|
* Defines a lexicographical order on position
|
|
|
|
*/
|
|
|
|
bool operator<(const position& a, const position& b) {
|
|
|
|
return std::make_tuple(a.x, a.y) < std::make_tuple(b.x, b.y);
|
|
|
|
}
|
|
|
|
|
2016-11-26 05:14:58 +00:00
|
|
|
namespace modules {
|
|
|
|
template class module<xworkspaces_module>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct module
|
|
|
|
*/
|
2016-12-21 07:00:09 +00:00
|
|
|
xworkspaces_module::xworkspaces_module(const bar_settings& bar, string name_)
|
|
|
|
: static_module<xworkspaces_module>(bar, move(name_)), m_connection(connection::make()) {
|
2016-11-26 08:38:55 +00:00
|
|
|
// Load config values
|
2016-12-30 22:32:05 +00:00
|
|
|
m_pinworkspaces = m_conf.get(name(), "pin-workspaces", m_pinworkspaces);
|
|
|
|
m_click = m_conf.get(name(), "enable-click", m_click);
|
|
|
|
m_scroll = m_conf.get(name(), "enable-scroll", m_scroll);
|
2016-11-26 05:14:58 +00:00
|
|
|
|
|
|
|
// Initialize ewmh atoms
|
|
|
|
if ((m_ewmh = ewmh_util::initialize()) == nullptr) {
|
|
|
|
throw module_error("Failed to initialize ewmh atoms");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the WM supports _NET_CURRENT_DESKTOP
|
2017-01-24 07:49:27 +00:00
|
|
|
if (!ewmh_util::supports(m_ewmh->_NET_CURRENT_DESKTOP)) {
|
2016-11-26 08:38:55 +00:00
|
|
|
throw module_error("The WM does not support _NET_CURRENT_DESKTOP, aborting...");
|
2016-11-26 05:14:58 +00:00
|
|
|
}
|
|
|
|
|
2016-11-26 08:38:55 +00:00
|
|
|
// Check if the WM supports _NET_DESKTOP_VIEWPORT
|
2017-01-25 02:29:11 +00:00
|
|
|
if (!(m_monitorsupport = ewmh_util::supports(m_ewmh->_NET_DESKTOP_VIEWPORT)) && m_pinworkspaces) {
|
2016-11-26 08:38:55 +00:00
|
|
|
throw module_error("The WM does not support _NET_DESKTOP_VIEWPORT (required when `pin-workspaces = true`)");
|
|
|
|
}
|
|
|
|
|
2016-11-26 05:14:58 +00:00
|
|
|
// Add formats and elements
|
2016-11-26 08:38:55 +00:00
|
|
|
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE, TAG_LABEL_MONITOR});
|
2016-11-26 05:14:58 +00:00
|
|
|
|
2016-11-26 08:38:55 +00:00
|
|
|
if (m_formatter->has(TAG_LABEL_MONITOR)) {
|
|
|
|
m_monitorlabel = load_optional_label(m_conf, name(), "label-monitor", DEFAULT_LABEL_MONITOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_formatter->has(TAG_LABEL_STATE)) {
|
2016-12-03 12:45:22 +00:00
|
|
|
// clang-format off
|
|
|
|
m_labels.insert(make_pair(
|
|
|
|
desktop_state::ACTIVE, load_optional_label(m_conf, name(), "label-active", DEFAULT_LABEL_STATE)));
|
2016-11-26 08:38:55 +00:00
|
|
|
m_labels.insert(make_pair(
|
|
|
|
desktop_state::OCCUPIED, load_optional_label(m_conf, name(), "label-occupied", DEFAULT_LABEL_STATE)));
|
2016-12-03 12:45:22 +00:00
|
|
|
m_labels.insert(make_pair(
|
|
|
|
desktop_state::URGENT, load_optional_label(m_conf, name(), "label-urgent", DEFAULT_LABEL_STATE)));
|
|
|
|
m_labels.insert(make_pair(
|
|
|
|
desktop_state::EMPTY, load_optional_label(m_conf, name(), "label-empty", DEFAULT_LABEL_STATE)));
|
|
|
|
// clang-format on
|
2016-11-26 05:14:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
m_icons = factory_util::shared<iconset>();
|
2016-12-30 22:32:05 +00:00
|
|
|
m_icons->add(DEFAULT_ICON, factory_util::shared<label>(m_conf.get(name(), DEFAULT_ICON, ""s)));
|
2016-11-26 05:14:58 +00:00
|
|
|
|
|
|
|
for (const auto& workspace : m_conf.get_list<string>(name(), "icon", {})) {
|
2019-11-21 21:26:53 +00:00
|
|
|
auto vec = string_util::tokenize(workspace, ';');
|
2016-11-26 05:14:58 +00:00
|
|
|
if (vec.size() == 2) {
|
2016-12-05 19:41:00 +00:00
|
|
|
m_icons->add(vec[0], factory_util::shared<label>(vec[1]));
|
2016-11-26 05:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
|
|
|
|
// Get list of monitors
|
|
|
|
m_monitors = randr_util::get_monitors(m_connection, m_connection.root(), false);
|
|
|
|
|
|
|
|
// Get desktop details
|
2019-02-08 12:32:31 +00:00
|
|
|
m_desktop_names = get_desktop_names();
|
2017-01-25 02:29:11 +00:00
|
|
|
m_current_desktop = ewmh_util::get_current_desktop();
|
2019-04-01 16:04:44 +00:00
|
|
|
m_current_desktop_name = m_desktop_names[m_current_desktop];
|
2017-01-25 02:29:11 +00:00
|
|
|
|
|
|
|
rebuild_desktops();
|
|
|
|
|
|
|
|
// Get _NET_CLIENT_LIST
|
|
|
|
rebuild_clientlist();
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
rebuild_desktop_states();
|
2016-11-26 05:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for XCB_PROPERTY_NOTIFY events
|
|
|
|
*/
|
|
|
|
void xworkspaces_module::handle(const evt::property_notify& evt) {
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_workspace_mutex);
|
|
|
|
|
|
|
|
if (evt->atom == m_ewmh->_NET_CLIENT_LIST || evt->atom == m_ewmh->_NET_WM_DESKTOP) {
|
2017-01-25 02:29:11 +00:00
|
|
|
rebuild_clientlist();
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
rebuild_desktop_states();
|
2019-02-08 12:32:31 +00:00
|
|
|
} else if (evt->atom == m_ewmh->_NET_DESKTOP_NAMES || evt->atom == m_ewmh->_NET_NUMBER_OF_DESKTOPS) {
|
|
|
|
m_desktop_names = get_desktop_names();
|
2017-01-25 02:29:11 +00:00
|
|
|
rebuild_desktops();
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
rebuild_clientlist();
|
2017-01-25 02:29:11 +00:00
|
|
|
rebuild_desktop_states();
|
2016-11-26 08:38:55 +00:00
|
|
|
} else if (evt->atom == m_ewmh->_NET_CURRENT_DESKTOP) {
|
2017-01-25 02:29:11 +00:00
|
|
|
m_current_desktop = ewmh_util::get_current_desktop();
|
2019-04-01 16:04:44 +00:00
|
|
|
m_current_desktop_name = m_desktop_names[m_current_desktop];
|
2017-01-25 02:29:11 +00:00
|
|
|
rebuild_desktop_states();
|
2017-02-20 07:25:19 +00:00
|
|
|
} else if (evt->atom == WM_HINTS) {
|
|
|
|
if (icccm_util::get_wm_urgency(m_connection, evt->window)) {
|
|
|
|
set_desktop_urgent(evt->window);
|
|
|
|
}
|
2016-11-26 05:14:58 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
if (m_timer.allow(evt->time)) {
|
|
|
|
broadcast();
|
|
|
|
}
|
2016-11-26 05:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-25 02:29:11 +00:00
|
|
|
* Rebuild the list of managed clients
|
2016-11-26 05:14:58 +00:00
|
|
|
*/
|
2017-01-25 02:29:11 +00:00
|
|
|
void xworkspaces_module::rebuild_clientlist() {
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
vector<xcb_window_t> newclients = ewmh_util::get_client_list();
|
|
|
|
std::sort(newclients.begin(), newclients.end());
|
|
|
|
|
|
|
|
for (auto&& client : newclients) {
|
|
|
|
if (m_clients.count(client) == 0) {
|
|
|
|
// new client: listen for changes (wm_hint or desktop)
|
|
|
|
m_connection.ensure_event_mask(client, XCB_EVENT_MASK_PROPERTY_CHANGE);
|
2017-01-25 02:29:11 +00:00
|
|
|
}
|
2016-11-26 08:38:55 +00:00
|
|
|
}
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
|
|
|
|
// rebuild entire mapping of clients to desktops
|
|
|
|
m_clients.clear();
|
|
|
|
for (auto&& client : newclients) {
|
|
|
|
m_clients[client] = ewmh_util::get_desktop_from_window(client);
|
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
}
|
2016-11-26 08:38:55 +00:00
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
/**
|
|
|
|
* Rebuild the desktop tree
|
2020-05-01 15:43:14 +00:00
|
|
|
*
|
|
|
|
* This requires m_desktop_names to have an up-to-date value
|
2017-01-25 02:29:11 +00:00
|
|
|
*/
|
|
|
|
void xworkspaces_module::rebuild_desktops() {
|
2016-11-26 08:38:55 +00:00
|
|
|
m_viewports.clear();
|
|
|
|
|
2020-05-01 15:43:14 +00:00
|
|
|
/*
|
|
|
|
* Stores the _NET_DESKTOP_VIEWPORT hint
|
|
|
|
*
|
|
|
|
* For WMs that don't support that hint, we store an empty vector
|
|
|
|
*
|
|
|
|
* If the length of the vector is less than _NET_NUMBER_OF_DESKTOPS
|
|
|
|
* all desktops which aren't explicitly assigned a postion will be
|
|
|
|
* assigned (0, 0)
|
|
|
|
*
|
|
|
|
* We use this to map workspaces to viewports, desktop i is at position
|
|
|
|
* ws_positions[i].
|
|
|
|
*/
|
|
|
|
vector<position> ws_positions;
|
|
|
|
if (m_monitorsupport) {
|
|
|
|
ws_positions = ewmh_util::get_desktop_viewports();
|
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
|
2020-05-01 15:43:14 +00:00
|
|
|
/*
|
|
|
|
* Not all desktops were assigned a viewport, add (0, 0) for all missing
|
|
|
|
* desktops.
|
|
|
|
*/
|
|
|
|
if (ws_positions.size() < m_desktop_names.size()) {
|
|
|
|
auto num_insert = m_desktop_names.size() - ws_positions.size();
|
|
|
|
ws_positions.reserve(num_insert);
|
|
|
|
std::fill_n(std::back_inserter(ws_positions), num_insert, position{0, 0});
|
2019-01-03 17:59:55 +00:00
|
|
|
}
|
2020-05-01 15:43:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The list of viewports is the set of unique positions in ws_positions
|
|
|
|
* Using a set automatically removes duplicates.
|
|
|
|
*/
|
|
|
|
std::set<position> viewports(ws_positions.begin(), ws_positions.end());
|
|
|
|
|
|
|
|
for (auto&& viewport_pos : viewports) {
|
|
|
|
/*
|
|
|
|
* If pin-workspaces is set, we only add the viewport if it's in the
|
|
|
|
* monitor the bar is on.
|
|
|
|
* Generally viewport_pos is the same as the top-left coordinate of the
|
|
|
|
* monitor but we use `contains` here as a safety in case it isn't exactly.
|
|
|
|
*/
|
|
|
|
if (!m_pinworkspaces || m_bar.monitor->contains(viewport_pos)) {
|
2017-01-25 02:29:11 +00:00
|
|
|
auto viewport = make_unique<struct viewport>();
|
|
|
|
viewport->state = viewport_state::UNFOCUSED;
|
2020-05-01 15:43:14 +00:00
|
|
|
viewport->pos = viewport_pos;
|
2017-01-25 02:29:11 +00:00
|
|
|
|
|
|
|
for (auto&& m : m_monitors) {
|
2020-05-01 15:43:14 +00:00
|
|
|
if (m->contains(viewport->pos)) {
|
2017-01-25 02:29:11 +00:00
|
|
|
viewport->name = m->name;
|
|
|
|
viewport->state = viewport_state::FOCUSED;
|
|
|
|
}
|
|
|
|
}
|
2016-11-26 05:14:58 +00:00
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
viewport->label = [&] {
|
|
|
|
label_t label;
|
|
|
|
if (m_monitorlabel) {
|
|
|
|
label = m_monitorlabel->clone();
|
|
|
|
label->reset_tokens();
|
|
|
|
label->replace_token("%name%", viewport->name);
|
2016-11-26 08:38:55 +00:00
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
return label;
|
|
|
|
}();
|
|
|
|
|
2020-05-01 15:43:14 +00:00
|
|
|
for (size_t i = 0; i < ws_positions.size(); i++) {
|
|
|
|
auto&& ws_pos = ws_positions[i];
|
|
|
|
if (ws_pos == viewport_pos) {
|
2019-11-02 22:16:30 +00:00
|
|
|
viewport->desktops.emplace_back(make_unique<struct desktop>(i, desktop_state::EMPTY, label_t{}));
|
2020-05-01 15:43:14 +00:00
|
|
|
}
|
2016-11-26 08:38:55 +00:00
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
|
|
|
|
m_viewports.emplace_back(move(viewport));
|
2016-11-26 08:38:55 +00:00
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-26 05:14:58 +00:00
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
/**
|
|
|
|
* Update active state of current desktops
|
|
|
|
*/
|
|
|
|
void xworkspaces_module::rebuild_desktop_states() {
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
std::set<unsigned int> occupied_desks;
|
|
|
|
for (auto&& c : m_clients) {
|
|
|
|
occupied_desks.insert(c.second);
|
|
|
|
}
|
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
for (auto&& v : m_viewports) {
|
|
|
|
for (auto&& d : v->desktops) {
|
2020-05-01 15:43:14 +00:00
|
|
|
if (d->index == m_current_desktop) {
|
2017-01-25 02:29:11 +00:00
|
|
|
d->state = desktop_state::ACTIVE;
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
} else if (occupied_desks.count(d->index) > 0) {
|
|
|
|
d->state = desktop_state::OCCUPIED;
|
2017-05-17 03:34:03 +00:00
|
|
|
} else {
|
2017-01-25 02:29:11 +00:00
|
|
|
d->state = desktop_state::EMPTY;
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
}
|
2016-11-26 08:38:55 +00:00
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
d->label = m_labels.at(d->state)->clone();
|
|
|
|
d->label->reset_tokens();
|
2019-11-02 22:16:30 +00:00
|
|
|
d->label->replace_token("%index%", to_string(d->index + 1));
|
2017-01-25 02:29:11 +00:00
|
|
|
d->label->replace_token("%name%", m_desktop_names[d->index]);
|
|
|
|
d->label->replace_token("%icon%", m_icons->get(m_desktop_names[d->index], DEFAULT_ICON)->get());
|
|
|
|
}
|
2016-11-26 08:38:55 +00:00
|
|
|
}
|
2016-11-26 05:14:58 +00:00
|
|
|
}
|
|
|
|
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
vector<string> xworkspaces_module::get_desktop_names() {
|
2019-02-08 12:32:31 +00:00
|
|
|
vector<string> names = ewmh_util::get_desktop_names();
|
|
|
|
unsigned int desktops_number = ewmh_util::get_number_of_desktops();
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
if (desktops_number == names.size()) {
|
2019-02-08 12:32:31 +00:00
|
|
|
return names;
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
} else if (desktops_number < names.size()) {
|
|
|
|
names.erase(names.begin() + desktops_number, names.end());
|
2019-02-08 12:32:31 +00:00
|
|
|
return names;
|
|
|
|
}
|
2020-01-07 12:40:24 +00:00
|
|
|
for (unsigned int i = names.size(); i < desktops_number; i++) {
|
|
|
|
names.insert(names.end(), to_string(i + 1));
|
2019-02-08 12:32:31 +00:00
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2017-02-20 07:25:19 +00:00
|
|
|
/**
|
|
|
|
* Find window and set corresponding desktop to urgent
|
|
|
|
*/
|
|
|
|
void xworkspaces_module::set_desktop_urgent(xcb_window_t window) {
|
|
|
|
auto desk = ewmh_util::get_desktop_from_window(window);
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
if (desk == m_current_desktop)
|
2017-02-20 07:25:19 +00:00
|
|
|
// ignore if current desktop is urgent
|
|
|
|
return;
|
|
|
|
for (auto&& v : m_viewports) {
|
|
|
|
for (auto&& d : v->desktops) {
|
|
|
|
if (d->index == desk && d->state != desktop_state::URGENT) {
|
|
|
|
d->state = desktop_state::URGENT;
|
|
|
|
|
|
|
|
d->label = m_labels.at(d->state)->clone();
|
|
|
|
d->label->reset_tokens();
|
2019-11-02 22:16:30 +00:00
|
|
|
d->label->replace_token("%index%", to_string(d->index + 1));
|
2017-02-20 07:25:19 +00:00
|
|
|
d->label->replace_token("%name%", m_desktop_names[d->index]);
|
|
|
|
d->label->replace_token("%icon%", m_icons->get(m_desktop_names[d->index], DEFAULT_ICON)->get());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
/**
|
|
|
|
* Fetch and parse data
|
|
|
|
*/
|
|
|
|
void xworkspaces_module::update() {}
|
|
|
|
|
2016-11-26 05:14:58 +00:00
|
|
|
/**
|
|
|
|
* Generate module output
|
|
|
|
*/
|
|
|
|
string xworkspaces_module::get_output() {
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_workspace_mutex);
|
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
// Get the module output early so that
|
|
|
|
// the format prefix/suffix also gets wrapped
|
|
|
|
// with the cmd handlers
|
2016-11-26 05:14:58 +00:00
|
|
|
string output;
|
2016-11-26 08:38:55 +00:00
|
|
|
for (m_index = 0; m_index < m_viewports.size(); m_index++) {
|
2016-11-26 05:14:58 +00:00
|
|
|
if (m_index > 0) {
|
|
|
|
m_builder->space(m_formatter->get(DEFAULT_FORMAT)->spacing);
|
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
output += module::get_output();
|
2016-11-26 05:14:58 +00:00
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
|
2018-02-03 22:22:17 +00:00
|
|
|
if (m_scroll) {
|
2020-05-23 22:36:16 +00:00
|
|
|
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_PREV, "");
|
|
|
|
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_NEXT, "");
|
2018-02-03 22:22:17 +00:00
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
|
|
|
|
m_builder->append(output);
|
|
|
|
|
2020-05-24 16:35:12 +00:00
|
|
|
m_builder->action_close();
|
|
|
|
m_builder->action_close();
|
2017-01-25 02:29:11 +00:00
|
|
|
|
|
|
|
return m_builder->flush();
|
2016-11-26 05:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output content as defined in the config
|
|
|
|
*/
|
|
|
|
bool xworkspaces_module::build(builder* builder, const string& tag) const {
|
2017-01-25 02:29:11 +00:00
|
|
|
if (tag == TAG_LABEL_MONITOR) {
|
|
|
|
if (m_viewports[m_index]->state != viewport_state::NONE) {
|
|
|
|
builder->node(m_viewports[m_index]->label);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2016-11-26 09:33:32 +00:00
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
} else if (tag == TAG_LABEL_STATE) {
|
|
|
|
unsigned int added_states = 0;
|
2016-11-26 09:33:32 +00:00
|
|
|
for (auto&& desktop : m_viewports[m_index]->desktops) {
|
2017-01-25 02:29:11 +00:00
|
|
|
if (desktop->label.get()) {
|
|
|
|
if (m_click && desktop->state != desktop_state::ACTIVE) {
|
2020-05-23 22:36:16 +00:00
|
|
|
builder->action(mousebtn::LEFT, *this, EVENT_FOCUS, to_string(desktop->index), desktop->label);
|
2017-01-25 02:29:11 +00:00
|
|
|
} else {
|
|
|
|
builder->node(desktop->label);
|
|
|
|
}
|
|
|
|
added_states++;
|
2016-11-26 08:38:55 +00:00
|
|
|
}
|
2016-11-26 09:33:32 +00:00
|
|
|
}
|
2017-01-25 02:29:11 +00:00
|
|
|
return added_states > 0;
|
|
|
|
} else {
|
|
|
|
return false;
|
2016-11-26 05:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-26 09:33:32 +00:00
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
/**
|
|
|
|
* Handle user input event
|
|
|
|
*/
|
2020-05-31 19:11:36 +00:00
|
|
|
bool xworkspaces_module::input(const string& action, const string& data) {
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_workspace_mutex);
|
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
vector<unsigned int> indexes;
|
2016-12-03 12:45:22 +00:00
|
|
|
for (auto&& viewport : m_viewports) {
|
|
|
|
for (auto&& desktop : viewport->desktops) {
|
2017-01-25 02:29:11 +00:00
|
|
|
indexes.emplace_back(desktop->index);
|
2016-12-03 12:45:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-25 02:29:11 +00:00
|
|
|
std::sort(indexes.begin(), indexes.end());
|
|
|
|
|
|
|
|
unsigned int new_desktop{0};
|
|
|
|
unsigned int current_desktop{ewmh_util::get_current_desktop()};
|
|
|
|
|
2020-05-23 22:36:16 +00:00
|
|
|
if (action == EVENT_FOCUS) {
|
|
|
|
new_desktop = std::strtoul(data.c_str(), nullptr, 10);
|
|
|
|
} else if (action == EVENT_NEXT) {
|
2017-01-25 02:29:11 +00:00
|
|
|
new_desktop = math_util::min<unsigned int>(indexes.back(), current_desktop + 1);
|
|
|
|
new_desktop = new_desktop == current_desktop ? indexes.front() : new_desktop;
|
2020-05-23 22:36:16 +00:00
|
|
|
} else if (action == EVENT_PREV) {
|
2017-01-25 02:29:11 +00:00
|
|
|
new_desktop = math_util::max<unsigned int>(indexes.front(), current_desktop - 1);
|
|
|
|
new_desktop = new_desktop == current_desktop ? indexes.back() : new_desktop;
|
2016-11-26 09:33:32 +00:00
|
|
|
}
|
|
|
|
|
2016-12-03 12:45:22 +00:00
|
|
|
if (new_desktop != current_desktop) {
|
2016-12-23 19:43:52 +00:00
|
|
|
m_log.info("%s: Requesting change to desktop #%u", name(), new_desktop);
|
2017-01-24 07:49:27 +00:00
|
|
|
ewmh_util::change_current_desktop(new_desktop);
|
2016-12-03 12:45:22 +00:00
|
|
|
} else {
|
|
|
|
m_log.info("%s: Ignoring change to current desktop", name());
|
|
|
|
}
|
2016-11-26 09:33:32 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.
The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.
Closes #874
Fixes #1444
Fixes #1033
* Set Desktop OCCUPIED if a window moves there
This covers more of an edge-case. I did this first by accident, it might
vanish later on.
* Replace tracking change of WS with currently used WS
* Untrack occupied workspaces
* Track windows and their desktops in pairs
* Match type of occupied_desktops with current_desktop
Because the index needs to be matched later on, type mismatches would be non-ideal.
* Recreate the occupied desktops everytime and remove duplicates
* Readd support for moving windows to other desktops
* Use less characters to empty the vector
* Rename variable storing the desktops
* Recount windows on every occasion
This alone simplifies the management and the lookup for occupation of a
workspace
* Keep track of number of windows in every workspace
* Add debugging output that shall be removed before merging
* Remove obsolete TODO
* m_client_list should always be diff'd, since the desktop may change
Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...
* Add more logging-spam to understand window/desktop lifecycle
* Lock event-handler to serialize handling of events
* Fix occupied workspace counting and change to bool array
Also, performance improvements when diffing new and old client lists
* Fix crash when all clients are removed
* Conform to linter and styleguide
* Shorten conditional as it is standard enough
Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.
* Guard against multiple threads accessing and modifying data
Fixes #1444
Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.
The mutex should guard against this simultanuous access.
* Do not 'adopt_lock', because calls come from very different threads
To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.
See #1444
* Also listen to _NET_WM_DESKTOP
In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.
This change reloads the clientlist in order to correctly set the
desktop state "occupied".
* Describe need and use of mutex
It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.
* Give temporary variables better names
* Clarify purpose of loop
About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363
* Remove merge-remainder
* Use a simpler method to list occupied desktops.
Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>
* Document m_clients field
2019-10-21 08:00:38 +00:00
|
|
|
} // namespace modules
|
2016-11-26 05:14:58 +00:00
|
|
|
|
|
|
|
POLYBAR_NS_END
|