-
-
Notifications
You must be signed in to change notification settings - Fork 728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/Hyprland: Allow matching against Window Titles for Rewrite #2563
Merged
Alexays
merged 8 commits into
Alexays:master
from
Syndelis:feat/hyprland-window-rename-by-title
Oct 15, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8d057e6
refactor: separate regex rule matching and caching in separate class
Syndelis fad43d4
feat: listen to windowtitle IPC event condiationally to update window…
Syndelis 387e544
docs: document new regex collection class
Syndelis f9a7ecf
feat: optimize cache usage when window titles aren't involved
Syndelis 592d564
docs: include new feature in manual
Syndelis f8340d8
chore: lint unrelated file
Syndelis ee65267
feat: ignore windows with empty classes or titles (if any rule uses t…
Syndelis c59264d
fix: clang < 16 can't emplace back struct with no constructor
Syndelis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include <json/json.h> | ||
|
||
#include <functional> | ||
#include <regex> | ||
#include <string> | ||
|
||
namespace waybar::util { | ||
|
||
struct Rule { | ||
std::regex rule; | ||
std::string repr; | ||
int priority; | ||
|
||
// Fix for Clang < 16 | ||
// See https://en.cppreference.com/w/cpp/compiler_support/20 "Parenthesized initialization of | ||
// aggregates" | ||
Rule(std::regex rule, std::string repr, int priority) | ||
: rule(rule), repr(repr), priority(priority) {} | ||
}; | ||
|
||
int default_priority_function(std::string& key); | ||
|
||
/* A collection of regexes and strings, with a default string to return if no regexes. | ||
* When a regex is matched, the corresponding string is returned. | ||
* All regexes that are matched are cached, so that the regexes are only | ||
* evaluated once against a given string. | ||
* Regexes may be given a higher priority than others, so that they are matched | ||
* first. The priority function is given the regex string, and should return a | ||
* higher number for higher priority regexes. | ||
*/ | ||
class RegexCollection { | ||
private: | ||
std::vector<Rule> rules; | ||
std::map<std::string, std::string> regex_cache; | ||
std::string default_repr; | ||
|
||
std::string& find_match(std::string& value, bool& matched_any); | ||
|
||
public: | ||
RegexCollection() = default; | ||
RegexCollection(const Json::Value& map, std::string default_repr = "", | ||
std::function<int(std::string&)> priority_function = default_priority_function); | ||
~RegexCollection() = default; | ||
|
||
std::string& get(std::string& value, bool& matched_any); | ||
std::string& get(std::string& value); | ||
}; | ||
|
||
} // namespace waybar::util |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is unrelated to this PR and was simply linted it in f8340d8