2fd6d20999
While it shouldn't happen with compliant WMs, it was possibe to crash polybar with _NET_CURRENT_DESKTOP >= _NET_NUMBER_OF_DESKTOPS and this should not be possible. Includes polybar/xpp#31 Fixes #2398
126 lines
3.1 KiB
C++
126 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#include <bitset>
|
|
#include <mutex>
|
|
#include <set>
|
|
|
|
#include "components/config.hpp"
|
|
#include "components/types.hpp"
|
|
#include "modules/meta/event_handler.hpp"
|
|
#include "modules/meta/static_module.hpp"
|
|
#include "x11/ewmh.hpp"
|
|
#include "x11/icccm.hpp"
|
|
#include "x11/window.hpp"
|
|
|
|
POLYBAR_NS
|
|
|
|
class connection;
|
|
|
|
namespace modules {
|
|
enum class desktop_state {
|
|
NONE,
|
|
ACTIVE,
|
|
URGENT,
|
|
EMPTY,
|
|
OCCUPIED,
|
|
};
|
|
|
|
enum class viewport_state {
|
|
NONE,
|
|
FOCUSED,
|
|
UNFOCUSED,
|
|
};
|
|
|
|
struct desktop {
|
|
explicit desktop(unsigned int index, desktop_state state, label_t&& label)
|
|
: index(index), state(state), label(label) {}
|
|
unsigned int index;
|
|
desktop_state state;
|
|
label_t label;
|
|
};
|
|
|
|
struct viewport {
|
|
position pos;
|
|
string name;
|
|
vector<unique_ptr<desktop>> desktops;
|
|
viewport_state state;
|
|
label_t label;
|
|
};
|
|
|
|
/**
|
|
* Module used to display EWMH desktops
|
|
*/
|
|
class xworkspaces_module : public static_module<xworkspaces_module>, public event_handler<evt::property_notify> {
|
|
public:
|
|
explicit xworkspaces_module(const bar_settings& bar, string name_);
|
|
|
|
void update();
|
|
string get_output();
|
|
bool build(builder* builder, const string& tag) const;
|
|
|
|
static constexpr auto TYPE = "internal/xworkspaces";
|
|
|
|
static constexpr auto EVENT_FOCUS = "focus";
|
|
static constexpr auto EVENT_NEXT = "next";
|
|
static constexpr auto EVENT_PREV = "prev";
|
|
|
|
protected:
|
|
void handle(const evt::property_notify& evt) override;
|
|
|
|
void rebuild_clientlist();
|
|
void rebuild_urgent_hints();
|
|
void rebuild_desktops();
|
|
void rebuild_desktop_states();
|
|
void update_current_desktop();
|
|
|
|
void action_focus(const string& data);
|
|
void action_next();
|
|
void action_prev();
|
|
|
|
void focus_direction(bool next);
|
|
void focus_desktop(unsigned new_desktop);
|
|
|
|
private:
|
|
static vector<string> get_desktop_names();
|
|
|
|
static constexpr const char* DEFAULT_ICON{"icon-default"};
|
|
static constexpr const char* DEFAULT_LABEL_STATE{"%icon% %name%"};
|
|
static constexpr const char* DEFAULT_LABEL_MONITOR{"%name%"};
|
|
|
|
static constexpr const char* TAG_LABEL_MONITOR{"<label-monitor>"};
|
|
static constexpr const char* TAG_LABEL_STATE{"<label-state>"};
|
|
|
|
connection& m_connection;
|
|
ewmh_connection_t m_ewmh;
|
|
|
|
vector<monitor_t> m_monitors;
|
|
bool m_monitorsupport{true};
|
|
|
|
vector<string> m_desktop_names;
|
|
vector<bool> m_urgent_desktops;
|
|
unsigned int m_current_desktop;
|
|
string m_current_desktop_name;
|
|
|
|
/**
|
|
* Maps an xcb window to its desktop number
|
|
*/
|
|
map<xcb_window_t, unsigned int> m_clients;
|
|
map<unsigned int, unsigned int> m_windows;
|
|
vector<unique_ptr<viewport>> m_viewports;
|
|
map<desktop_state, label_t> m_labels;
|
|
label_t m_monitorlabel;
|
|
iconset_t m_icons;
|
|
bool m_pinworkspaces{false};
|
|
bool m_click{true};
|
|
bool m_scroll{true};
|
|
bool m_revscroll{false};
|
|
size_t m_index{0};
|
|
|
|
// The following mutex is here to protect the data of this modules.
|
|
// This can't be achieved using m_buildlock since we "CRTP override" get_output().
|
|
mutable mutex m_workspace_mutex;
|
|
};
|
|
} // namespace modules
|
|
|
|
POLYBAR_NS_END
|