hyprland/workspace: sort methods
This commit is contained in:
parent
56319a4705
commit
82ae474002
|
@ -12,42 +12,6 @@
|
||||||
|
|
||||||
namespace waybar::modules::hyprland {
|
namespace waybar::modules::hyprland {
|
||||||
|
|
||||||
void Workspace::initializeWindowMap(const Json::Value &clients_data) {
|
|
||||||
m_windowMap.clear();
|
|
||||||
for (auto client : clients_data) {
|
|
||||||
if (client["workspace"]["id"].asInt() == id()) {
|
|
||||||
insertWindow({client});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Workspace::insertWindow(WindowCreationPayload create_window_paylod) {
|
|
||||||
if (!create_window_paylod.isEmpty(m_workspaceManager)) {
|
|
||||||
m_windowMap[create_window_paylod.getAddress()] = create_window_paylod.repr(m_workspaceManager);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string Workspace::removeWindow(WindowAddress const &addr) {
|
|
||||||
std::string windowRepr = m_windowMap[addr];
|
|
||||||
m_windowMap.erase(addr);
|
|
||||||
return windowRepr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_paylod) {
|
|
||||||
if (create_window_paylod.getWorkspaceName() == name()) {
|
|
||||||
insertWindow(create_window_paylod);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<std::string> Workspace::closeWindow(WindowAddress const &addr) {
|
|
||||||
if (m_windowMap.contains(addr)) {
|
|
||||||
return removeWindow(addr);
|
|
||||||
}
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_manager,
|
Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_manager,
|
||||||
const Json::Value &clients_data)
|
const Json::Value &clients_data)
|
||||||
: m_workspaceManager(workspace_manager),
|
: m_workspaceManager(workspace_manager),
|
||||||
|
@ -85,45 +49,68 @@ void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext> &context, bool condi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Workspace::update(const std::string &format, const std::string &icon) {
|
std::optional<std::string> Workspace::closeWindow(WindowAddress const &addr) {
|
||||||
// clang-format off
|
if (m_windowMap.contains(addr)) {
|
||||||
if (this->m_workspaceManager.activeOnly() && \
|
return removeWindow(addr);
|
||||||
!this->isActive() && \
|
|
||||||
!this->isPersistent() && \
|
|
||||||
!this->isVisible() && \
|
|
||||||
!this->isSpecial()) {
|
|
||||||
// clang-format on
|
|
||||||
// if activeOnly is true, hide if not active, persistent, visible or special
|
|
||||||
m_button.hide();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
m_button.show();
|
return std::nullopt;
|
||||||
|
|
||||||
auto styleContext = m_button.get_style_context();
|
|
||||||
addOrRemoveClass(styleContext, isActive(), "active");
|
|
||||||
addOrRemoveClass(styleContext, isSpecial(), "special");
|
|
||||||
addOrRemoveClass(styleContext, isEmpty(), "empty");
|
|
||||||
addOrRemoveClass(styleContext, isPersistent(), "persistent");
|
|
||||||
addOrRemoveClass(styleContext, isUrgent(), "urgent");
|
|
||||||
addOrRemoveClass(styleContext, isVisible(), "visible");
|
|
||||||
addOrRemoveClass(styleContext, m_workspaceManager.getBarOutput() == output(), "hosting-monitor");
|
|
||||||
|
|
||||||
std::string windows;
|
|
||||||
auto windowSeparator = m_workspaceManager.getWindowSeparator();
|
|
||||||
|
|
||||||
bool isNotFirst = false;
|
|
||||||
|
|
||||||
for (auto &[_pid, window_repr] : m_windowMap) {
|
|
||||||
if (isNotFirst) {
|
|
||||||
windows.append(windowSeparator);
|
|
||||||
}
|
|
||||||
isNotFirst = true;
|
|
||||||
windows.append(window_repr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_label.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()),
|
bool Workspace::handleClicked(GdkEventButton *bt) const {
|
||||||
fmt::arg("name", name()), fmt::arg("icon", icon),
|
if (bt->type == GDK_BUTTON_PRESS) {
|
||||||
fmt::arg("windows", windows)));
|
try {
|
||||||
|
if (id() > 0) { // normal
|
||||||
|
if (m_workspaceManager.moveToMonitor()) {
|
||||||
|
gIPC->getSocket1Reply("dispatch focusworkspaceoncurrentmonitor " + std::to_string(id()));
|
||||||
|
} else {
|
||||||
|
gIPC->getSocket1Reply("dispatch workspace " + std::to_string(id()));
|
||||||
|
}
|
||||||
|
} else if (!isSpecial()) { // named (this includes persistent)
|
||||||
|
if (m_workspaceManager.moveToMonitor()) {
|
||||||
|
gIPC->getSocket1Reply("dispatch focusworkspaceoncurrentmonitor name:" + name());
|
||||||
|
} else {
|
||||||
|
gIPC->getSocket1Reply("dispatch workspace name:" + name());
|
||||||
|
}
|
||||||
|
} else if (id() != -99) { // named special
|
||||||
|
gIPC->getSocket1Reply("dispatch togglespecialworkspace " + name());
|
||||||
|
} else { // special
|
||||||
|
gIPC->getSocket1Reply("dispatch togglespecialworkspace");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
spdlog::error("Failed to dispatch workspace: {}", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Workspace::initializeWindowMap(const Json::Value &clients_data) {
|
||||||
|
m_windowMap.clear();
|
||||||
|
for (auto client : clients_data) {
|
||||||
|
if (client["workspace"]["id"].asInt() == id()) {
|
||||||
|
insertWindow({client});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Workspace::insertWindow(WindowCreationPayload create_window_paylod) {
|
||||||
|
if (!create_window_paylod.isEmpty(m_workspaceManager)) {
|
||||||
|
m_windowMap[create_window_paylod.getAddress()] = create_window_paylod.repr(m_workspaceManager);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_paylod) {
|
||||||
|
if (create_window_paylod.getWorkspaceName() == name()) {
|
||||||
|
insertWindow(create_window_paylod);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Workspace::removeWindow(WindowAddress const &addr) {
|
||||||
|
std::string windowRepr = m_windowMap[addr];
|
||||||
|
m_windowMap.erase(addr);
|
||||||
|
return windowRepr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map) {
|
std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map) {
|
||||||
|
@ -183,31 +170,45 @@ std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Workspace::handleClicked(GdkEventButton *bt) const {
|
void Workspace::update(const std::string &format, const std::string &icon) {
|
||||||
if (bt->type == GDK_BUTTON_PRESS) {
|
// clang-format off
|
||||||
try {
|
if (this->m_workspaceManager.activeOnly() && \
|
||||||
if (id() > 0) { // normal
|
!this->isActive() && \
|
||||||
if (m_workspaceManager.moveToMonitor()) {
|
!this->isPersistent() && \
|
||||||
gIPC->getSocket1Reply("dispatch focusworkspaceoncurrentmonitor " + std::to_string(id()));
|
!this->isVisible() && \
|
||||||
} else {
|
!this->isSpecial()) {
|
||||||
gIPC->getSocket1Reply("dispatch workspace " + std::to_string(id()));
|
// clang-format on
|
||||||
|
// if activeOnly is true, hide if not active, persistent, visible or special
|
||||||
|
m_button.hide();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else if (!isSpecial()) { // named (this includes persistent)
|
m_button.show();
|
||||||
if (m_workspaceManager.moveToMonitor()) {
|
|
||||||
gIPC->getSocket1Reply("dispatch focusworkspaceoncurrentmonitor name:" + name());
|
auto styleContext = m_button.get_style_context();
|
||||||
} else {
|
addOrRemoveClass(styleContext, isActive(), "active");
|
||||||
gIPC->getSocket1Reply("dispatch workspace name:" + name());
|
addOrRemoveClass(styleContext, isSpecial(), "special");
|
||||||
|
addOrRemoveClass(styleContext, isEmpty(), "empty");
|
||||||
|
addOrRemoveClass(styleContext, isPersistent(), "persistent");
|
||||||
|
addOrRemoveClass(styleContext, isUrgent(), "urgent");
|
||||||
|
addOrRemoveClass(styleContext, isVisible(), "visible");
|
||||||
|
addOrRemoveClass(styleContext, m_workspaceManager.getBarOutput() == output(), "hosting-monitor");
|
||||||
|
|
||||||
|
std::string windows;
|
||||||
|
auto windowSeparator = m_workspaceManager.getWindowSeparator();
|
||||||
|
|
||||||
|
bool isNotFirst = false;
|
||||||
|
|
||||||
|
for (auto &[_pid, window_repr] : m_windowMap) {
|
||||||
|
if (isNotFirst) {
|
||||||
|
windows.append(windowSeparator);
|
||||||
}
|
}
|
||||||
} else if (id() != -99) { // named special
|
isNotFirst = true;
|
||||||
gIPC->getSocket1Reply("dispatch togglespecialworkspace " + name());
|
windows.append(window_repr);
|
||||||
} else { // special
|
|
||||||
gIPC->getSocket1Reply("dispatch togglespecialworkspace");
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
} catch (const std::exception &e) {
|
m_label.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()),
|
||||||
spdlog::error("Failed to dispatch workspace: {}", e.what());
|
fmt::arg("name", name()), fmt::arg("icon", icon),
|
||||||
}
|
fmt::arg("windows", windows)));
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace waybar::modules::hyprland
|
} // namespace waybar::modules::hyprland
|
||||||
|
|
Loading…
Reference in New Issue