Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
chore: swap push_back to emplace_back
  • Loading branch information
Syndelis committed Oct 16, 2023
1 parent 67c0c9a commit e70a67d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
5 changes: 2 additions & 3 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class Workspaces;
class CreateWindow {
public:
CreateWindow(std::string workspace_name, WindowAddress window_address, std::string window_repr);
CreateWindow(std::string workspace_name, WindowAddress window_address, std::string window_class, std::string window_title);
CreateWindow(std::string workspace_name, WindowAddress window_address, std::string window_class,
std::string window_title);
CreateWindow(Json::Value& client_data);

int increment_time_spent_uncreated();
Expand All @@ -41,7 +42,6 @@ class CreateWindow {
WindowAddress addr() const { return window_address_; }

private:

void clear_addr();

using Repr = std::string;
Expand All @@ -52,7 +52,6 @@ class CreateWindow {
WindowAddress window_address_;
std::string workspace_name_;
int time_spent_uncreated_ = 0;

};

class Workspace {
Expand Down
44 changes: 20 additions & 24 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ void Workspaces::onEvent(const std::string &ev) {
});

if (!client->empty()) {
(*window_workspace)
->insert_window({*client});
(*window_workspace)->insert_window({*client});
}
}
}
Expand All @@ -346,7 +345,8 @@ void Workspaces::on_window_opened(std::string payload) {

std::string window_title = payload.substr(next_comma_idx + 1, payload.length() - next_comma_idx);

windows_to_create_.push_back({workspace_name, window_address, window_class, window_title});
windows_to_create_.emplace_back(
CreateWindow(workspace_name, window_address, window_class, window_title));
}

void Workspaces::on_window_closed(std::string addr) {
Expand Down Expand Up @@ -379,7 +379,7 @@ void Workspaces::on_window_moved(std::string payload) {
}

// ...and add it to the new workspace
windows_to_create_.push_back({workspace_name, window_address, window_repr});
windows_to_create_.emplace_back(CreateWindow(workspace_name, window_address, window_repr));
}

void Workspaces::update_window_count() {
Expand Down Expand Up @@ -854,28 +854,28 @@ std::string Workspaces::get_rewrite(std::string window_class, std::string window
return window_rewrite_rules_.get(window_repr_key);
}

CreateWindow::CreateWindow(std::string workspace_name, WindowAddress window_address, std::string window_repr)
: window_(window_repr),
window_address_(window_address),
workspace_name_(workspace_name) {
clear_addr();
CreateWindow::CreateWindow(std::string workspace_name, WindowAddress window_address,
std::string window_repr)
: window_(window_repr), window_address_(window_address), workspace_name_(workspace_name) {
clear_addr();
}

CreateWindow::CreateWindow(std::string workspace_name, WindowAddress window_address, std::string window_class, std::string window_title)
: window_(std::make_pair(window_class, window_title)),
window_address_(window_address),
workspace_name_(workspace_name) {
clear_addr();
CreateWindow::CreateWindow(std::string workspace_name, WindowAddress window_address,
std::string window_class, std::string window_title)
: window_(std::make_pair(window_class, window_title)),
window_address_(window_address),
workspace_name_(workspace_name) {
clear_addr();
}

CreateWindow::CreateWindow(Json::Value& client_data) {
CreateWindow::CreateWindow(Json::Value &client_data) {
window_address_ = client_data["address"].asString();
workspace_name_ = client_data["workspace"]["name"].asString();
window_ = std::make_pair(client_data["class"].asString(), client_data["title"].asString());
clear_addr();
}

std::string CreateWindow::repr(Workspaces& workspace_manager) {
std::string CreateWindow::repr(Workspaces &workspace_manager) {
if (std::holds_alternative<Repr>(window_)) {
return std::get<Repr>(window_);
} else if (std::holds_alternative<ClassAndTitle>(window_)) {
Expand All @@ -887,24 +887,20 @@ std::string CreateWindow::repr(Workspaces& workspace_manager) {
}
}

bool CreateWindow::is_empty(Workspaces& workspace_manager) {
bool CreateWindow::is_empty(Workspaces &workspace_manager) {
if (std::holds_alternative<Repr>(window_)) {
return std::get<Repr>(window_).empty();
} else if (std::holds_alternative<ClassAndTitle>(window_)) {
auto [window_class, window_title] = std::get<ClassAndTitle>(window_);
return (
window_class.empty() &&
(!workspace_manager.window_rewrite_config_uses_title() || window_title.empty())
);
return (window_class.empty() &&
(!workspace_manager.window_rewrite_config_uses_title() || window_title.empty()));
} else {
// Unreachable
return true;
}
}

int CreateWindow::increment_time_spent_uncreated() {
return time_spent_uncreated_++;
}
int CreateWindow::increment_time_spent_uncreated() { return time_spent_uncreated_++; }

void CreateWindow::clear_addr() {
// substr(2, ...) is necessary because Hyprland's JSON follows this format:
Expand Down

0 comments on commit e70a67d

Please sign in to comment.