mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Update to proto. Fix displaying. Rename classes.
This commit is contained in:
parent
ffeecf626c
commit
ef4c6a9ba3
@ -27,6 +27,8 @@ class Workspace {
|
|||||||
|
|
||||||
auto id() const -> uint32_t { return id_; }
|
auto id() const -> uint32_t { return id_; }
|
||||||
auto is_active() const -> bool { return state_ & static_cast<uint32_t>(State::ACTIVE); }
|
auto is_active() const -> bool { return state_ & static_cast<uint32_t>(State::ACTIVE); }
|
||||||
|
auto is_urgent() const -> bool { return state_ & static_cast<uint32_t>(State::URGENT); }
|
||||||
|
auto is_hidden() const -> bool { return state_ & static_cast<uint32_t>(State::HIDDEN); }
|
||||||
// wlr stuff
|
// wlr stuff
|
||||||
auto handle_name(const std::string &name) -> void;
|
auto handle_name(const std::string &name) -> void;
|
||||||
auto handle_coordinates(const std::vector<uint32_t> &coordinates) -> void;
|
auto handle_coordinates(const std::vector<uint32_t> &coordinates) -> void;
|
||||||
@ -34,14 +36,19 @@ class Workspace {
|
|||||||
auto handle_remove() -> void;
|
auto handle_remove() -> void;
|
||||||
|
|
||||||
auto handle_done() -> void;
|
auto handle_done() -> void;
|
||||||
auto handle_clicked() -> void;
|
auto handle_clicked(GdkEventButton *bt) -> bool;
|
||||||
auto show() -> void { button_.show(); }
|
auto show() -> void { button_.show(); }
|
||||||
auto hide() -> void { button_.hide(); }
|
auto hide() -> void { button_.hide(); }
|
||||||
auto get_button_ref() -> Gtk::Button & { return button_; }
|
auto get_button_ref() -> Gtk::Button & { return button_; }
|
||||||
auto get_name() -> std::string & { return name_; }
|
auto get_name() -> std::string & { return name_; }
|
||||||
auto get_coords() -> std::vector<uint32_t> & { return coordinates_; }
|
auto get_coords() -> std::vector<uint32_t> & { return coordinates_; }
|
||||||
|
|
||||||
enum class State { ACTIVE = 1 << 0 };
|
enum class State
|
||||||
|
{
|
||||||
|
ACTIVE = 1 << 0,
|
||||||
|
URGENT = 1 << 1,
|
||||||
|
HIDDEN = 1 << 2,
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
auto get_icon() -> std::string;
|
auto get_icon() -> std::string;
|
||||||
@ -75,7 +82,7 @@ class WorkspaceGroup {
|
|||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
|
|
||||||
auto id() const -> uint32_t { return id_; }
|
auto id() const -> uint32_t { return id_; }
|
||||||
auto is_visible() const -> bool { return output_ != nullptr; }
|
auto is_visible() const -> bool;
|
||||||
auto remove_workspace(uint32_t id_) -> void;
|
auto remove_workspace(uint32_t id_) -> void;
|
||||||
|
|
||||||
// wlr stuff
|
// wlr stuff
|
||||||
@ -89,6 +96,7 @@ class WorkspaceGroup {
|
|||||||
auto handle_done() -> void;
|
auto handle_done() -> void;
|
||||||
auto commit() -> void;
|
auto commit() -> void;
|
||||||
auto sort_workspaces() -> void;
|
auto sort_workspaces() -> void;
|
||||||
|
auto set_need_to_sort() -> void { need_to_sort = true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static uint32_t workspace_global_id;
|
static uint32_t workspace_global_id;
|
||||||
@ -105,6 +113,7 @@ class WorkspaceGroup {
|
|||||||
std::vector<std::unique_ptr<Workspace>> workspaces_;
|
std::vector<std::unique_ptr<Workspace>> workspaces_;
|
||||||
bool sort_by_name = true;
|
bool sort_by_name = true;
|
||||||
bool sort_by_coordinates = true;
|
bool sort_by_coordinates = true;
|
||||||
|
bool need_to_sort = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WorkspaceManager : public AModule {
|
class WorkspaceManager : public AModule {
|
||||||
|
@ -28,7 +28,7 @@ Addressed by *wlr/workspaces*
|
|||||||
|
|
||||||
*sort-by-coordinates*: ++
|
*sort-by-coordinates*: ++
|
||||||
typeof: bool ++
|
typeof: bool ++
|
||||||
default: false ++
|
default: true ++
|
||||||
Should workspaces be sorted by coordinates.
|
Should workspaces be sorted by coordinates.
|
||||||
Note that if both *sort-by-name* and *sort-by-coordinates* are true sort by name will be first.
|
Note that if both *sort-by-name* and *sort-by-coordinates* are true sort by name will be first.
|
||||||
If both are false - sort by id will be performed.
|
If both are false - sort by id will be performed.
|
||||||
@ -39,6 +39,11 @@ Addressed by *wlr/workspaces*
|
|||||||
|
|
||||||
*{icon}*: Icon, as defined in *format-icons*.
|
*{icon}*: Icon, as defined in *format-icons*.
|
||||||
|
|
||||||
|
# CLICK ACTIONS
|
||||||
|
|
||||||
|
*activate*: Switch to workspace.
|
||||||
|
*close*: Close the workspace.
|
||||||
|
|
||||||
# ICONS
|
# ICONS
|
||||||
|
|
||||||
Additional to workspace name matching, the following *format-icons* can be set.
|
Additional to workspace name matching, the following *format-icons* can be set.
|
||||||
@ -67,4 +72,6 @@ Additional to workspace name matching, the following *format-icons* can be set.
|
|||||||
|
|
||||||
- *#workspaces*
|
- *#workspaces*
|
||||||
- *#workspaces button*
|
- *#workspaces button*
|
||||||
- *#workspaces button.focused*
|
- *#workspaces button.active*
|
||||||
|
- *#workspaces button.urgent*
|
||||||
|
- *#workspaces button.hidden*
|
||||||
|
@ -143,15 +143,19 @@ auto WorkspaceGroup::handle_output_enter(wl_output *output) -> void {
|
|||||||
spdlog::debug("Output {} assigned to {} group", (void *)output, id_);
|
spdlog::debug("Output {} assigned to {} group", (void *)output, id_);
|
||||||
output_ = output;
|
output_ = output;
|
||||||
|
|
||||||
if (output != gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj())) {
|
if (!is_visible()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &workspace : workspaces_) {
|
for (auto &workspace : workspaces_) {
|
||||||
workspace->show();
|
add_button(workspace->get_button_ref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto WorkspaceGroup::is_visible() const -> bool {
|
||||||
|
return output_ != nullptr && output_ == gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||||
|
}
|
||||||
|
|
||||||
auto WorkspaceGroup::handle_output_leave() -> void {
|
auto WorkspaceGroup::handle_output_leave() -> void {
|
||||||
spdlog::debug("Output {} remove from {} group", (void *)output_, id_);
|
spdlog::debug("Output {} remove from {} group", (void *)output_, id_);
|
||||||
output_ = nullptr;
|
output_ = nullptr;
|
||||||
@ -161,7 +165,7 @@ auto WorkspaceGroup::handle_output_leave() -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto &workspace : workspaces_) {
|
for (auto &workspace : workspaces_) {
|
||||||
workspace->hide();
|
remove_button(workspace->get_button_ref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,9 +189,16 @@ auto WorkspaceGroup::remove_workspace(uint32_t id) -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto WorkspaceGroup::handle_done() -> void {
|
auto WorkspaceGroup::handle_done() -> void {
|
||||||
|
need_to_sort = false;
|
||||||
|
if (!is_visible()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &workspace : workspaces_) {
|
for (auto &workspace : workspaces_) {
|
||||||
workspace->handle_done();
|
workspace->handle_done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort_workspaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto WorkspaceGroup::commit() -> void { workspace_manager_.commit(); }
|
auto WorkspaceGroup::commit() -> void { workspace_manager_.commit(); }
|
||||||
@ -215,9 +226,7 @@ auto WorkspaceGroup::sort_workspaces() -> void {
|
|||||||
|
|
||||||
std::sort(workspaces_.begin(), workspaces_.end(), cmp);
|
std::sort(workspaces_.begin(), workspaces_.end(), cmp);
|
||||||
for (size_t i = 0; i < workspaces_.size(); ++i) {
|
for (size_t i = 0; i < workspaces_.size(); ++i) {
|
||||||
for (auto &workspace : workspaces_) {
|
box_.reorder_child(workspaces_[i]->get_button_ref(), i);
|
||||||
box_.reorder_child(workspace->get_button_ref(), i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,16 +255,23 @@ Workspace::Workspace(const Bar &bar, const Json::Value &config, WorkspaceGroup &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button_.signal_clicked().connect(sigc::mem_fun(this, &Workspace::handle_clicked));
|
/* Handle click events if configured */
|
||||||
|
if (config_["on-click"].isString() || config_["on-click-middle"].isString()
|
||||||
|
|| config_["on-click-right"].isString()) {
|
||||||
|
button_.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||||
|
button_.signal_button_press_event().connect(
|
||||||
|
sigc::mem_fun(*this, &Workspace::handle_clicked), false);
|
||||||
|
}
|
||||||
|
|
||||||
workspace_group.add_button(button_);
|
|
||||||
button_.set_relief(Gtk::RELIEF_NONE);
|
button_.set_relief(Gtk::RELIEF_NONE);
|
||||||
content_.set_center_widget(label_);
|
content_.set_center_widget(label_);
|
||||||
button_.add(content_);
|
button_.add(content_);
|
||||||
|
|
||||||
if (!workspace_group.is_visible()) {
|
if (!workspace_group.is_visible()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workspace_group.add_button(button_);
|
||||||
button_.show();
|
button_.show();
|
||||||
label_.show();
|
label_.show();
|
||||||
content_.show();
|
content_.show();
|
||||||
@ -283,6 +299,12 @@ auto Workspace::handle_state(const std::vector<uint32_t> &state) -> void {
|
|||||||
case ZEXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE:
|
case ZEXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE:
|
||||||
state_ |= (uint32_t)State::ACTIVE;
|
state_ |= (uint32_t)State::ACTIVE;
|
||||||
break;
|
break;
|
||||||
|
case ZEXT_WORKSPACE_HANDLE_V1_STATE_URGENT:
|
||||||
|
state_ |= (uint32_t)State::URGENT;
|
||||||
|
break;
|
||||||
|
case ZEXT_WORKSPACE_HANDLE_V1_STATE_HIDDEN:
|
||||||
|
state_ |= (uint32_t)State::URGENT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,21 +315,27 @@ auto Workspace::handle_remove() -> void {
|
|||||||
workspace_group_.remove_workspace(id_);
|
workspace_group_.remove_workspace(id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto add_or_remove_class(Glib::RefPtr<Gtk::StyleContext> context, bool condition, const std::string& class_name) {
|
||||||
|
if (condition) {
|
||||||
|
context->add_class(class_name);
|
||||||
|
} else {
|
||||||
|
context->remove_class(class_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto Workspace::handle_done() -> void {
|
auto Workspace::handle_done() -> void {
|
||||||
spdlog::debug("Workspace {} changed to state {}", id_, state_);
|
spdlog::debug("Workspace {} changed to state {}", id_, state_);
|
||||||
auto style_context = button_.get_style_context();
|
auto style_context = button_.get_style_context();
|
||||||
if (is_active()) {
|
add_or_remove_class(style_context, is_active(), "active");
|
||||||
style_context->add_class("focused");
|
add_or_remove_class(style_context, is_urgent(), "urgent");
|
||||||
} else {
|
add_or_remove_class(style_context, is_hidden(), "hidden");
|
||||||
style_context->remove_class("focused");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Workspace::get_icon() -> std::string {
|
auto Workspace::get_icon() -> std::string {
|
||||||
if (is_active()) {
|
if (is_active()) {
|
||||||
auto focused_icon_it = icons_map_.find("focused");
|
auto active_icon_it = icons_map_.find("active");
|
||||||
if (focused_icon_it != icons_map_.end()) {
|
if (active_icon_it != icons_map_.end()) {
|
||||||
return focused_icon_it->second;
|
return active_icon_it->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,19 +352,46 @@ auto Workspace::get_icon() -> std::string {
|
|||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Workspace::handle_clicked() -> void {
|
auto Workspace::handle_clicked(GdkEventButton *bt) -> bool {
|
||||||
spdlog::debug("Workspace {} clicked", (void *)workspace_handle_);
|
std::string action;
|
||||||
|
if (config_["on-click"].isString() && bt->button == 1) {
|
||||||
|
action = config_["on-click"].asString();
|
||||||
|
}
|
||||||
|
else if (config_["on-click-middle"].isString() && bt->button == 2) {
|
||||||
|
action = config_["on-click-middle"].asString();
|
||||||
|
}
|
||||||
|
else if (config_["on-click-right"].isString() && bt->button == 3) {
|
||||||
|
action = config_["on-click-right"].asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action.empty())
|
||||||
|
return true;
|
||||||
|
else if (action == "activate") {
|
||||||
zext_workspace_handle_v1_activate(workspace_handle_);
|
zext_workspace_handle_v1_activate(workspace_handle_);
|
||||||
|
}
|
||||||
|
else if (action == "close") {
|
||||||
|
zext_workspace_handle_v1_remove(workspace_handle_);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
spdlog::warn("Unknown action {}", action);
|
||||||
|
}
|
||||||
|
|
||||||
workspace_group_.commit();
|
workspace_group_.commit();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Workspace::handle_name(const std::string &name) -> void {
|
auto Workspace::handle_name(const std::string &name) -> void {
|
||||||
|
if (name_ != name) {
|
||||||
|
workspace_group_.set_need_to_sort();
|
||||||
|
}
|
||||||
name_ = name;
|
name_ = name;
|
||||||
workspace_group_.sort_workspaces();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Workspace::handle_coordinates(const std::vector<uint32_t> &coordinates) -> void {
|
auto Workspace::handle_coordinates(const std::vector<uint32_t> &coordinates) -> void {
|
||||||
|
if (coordinates_ != coordinates) {
|
||||||
|
workspace_group_.set_need_to_sort();
|
||||||
|
}
|
||||||
coordinates_ = coordinates;
|
coordinates_ = coordinates;
|
||||||
workspace_group_.sort_workspaces();
|
|
||||||
}
|
}
|
||||||
} // namespace waybar::modules::wlr
|
} // namespace waybar::modules::wlr
|
||||||
|
@ -112,12 +112,6 @@ void workspace_handle_state(void *data, struct zext_workspace_handle_v1 *workspa
|
|||||||
std::vector<uint32_t> state_vec;
|
std::vector<uint32_t> state_vec;
|
||||||
auto states = static_cast<uint32_t *>(state->data);
|
auto states = static_cast<uint32_t *>(state->data);
|
||||||
for (size_t i = 0; i < state->size; ++i) {
|
for (size_t i = 0; i < state->size; ++i) {
|
||||||
// To sync server and pending states
|
|
||||||
if (states[i] == ZEXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE) {
|
|
||||||
zext_workspace_handle_v1_activate(workspace_handle);
|
|
||||||
} else {
|
|
||||||
zext_workspace_handle_v1_deactivate(workspace_handle);
|
|
||||||
}
|
|
||||||
state_vec.push_back(states[i]);
|
state_vec.push_back(states[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user