Skip to content

Commit 90f60ce

Browse files
Issue 1399: style refactor Part 4: allow off-screen styling
requires new config "offscreen-text", if left empty, no styles are set. If config "all-outputs" is set, this has no effect.
1 parent d859b71 commit 90f60ce

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/modules/sway/window.cpp

+30-4
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,18 @@ std::pair<int, int> leafNodesInWorkspace(const Json::Value& node) {
126126
std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWithWorkspace(
127127
const Json::Value& nodes, std::string& output, const Json::Value& config_,
128128
const Bar& bar_, Json::Value& parentWorkspace) {
129+
bool found_visible = false;
129130
for(auto const& node : nodes) {
130131
if (node["output"].isString()) {
131132
output = node["output"].asString();
133+
if (!config_["all-outputs"].asBool() && output != bar_.output->name) {
134+
continue;
135+
}
132136
}
133-
// found node
134-
if (node["focused"].asBool() && (node["type"] == "con" || node["type"] == "floating_con")) {
135-
if ((!config_["all-outputs"].asBool() && output == bar_.output->name) ||
136-
config_["all-outputs"].asBool()) {
137+
if (node["type"] == "con" || node["type"] == "floating_con") {
138+
// found node
139+
if (node["focused"].asBool()) {
140+
spdlog::trace("actual output {}, output found {}, node (focused) found {}", bar_.output->name, output, node["name"].asString());
137141
auto app_id = node["app_id"].isString() ? node["app_id"].asString()
138142
: node["window_properties"]["instance"].asString();
139143
int nb = node.size();
@@ -154,7 +158,14 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
154158
app_id,
155159
workspace_layout};
156160
}
161+
//record visible nodes, but since we don't know if a focused node is yet found, we can't return anything yet
162+
else if (!config_["all-outputs"].asBool() && node["visible"].asBool()) {
163+
spdlog::trace("actual output {}, output found {}, node (visible) found {}", bar_.output->name, output, node["name"].asString());
164+
found_visible=true;
165+
}
157166
}
167+
168+
158169
// iterate
159170
if(node["type"] == "workspace")
160171
parentWorkspace = node;
@@ -168,6 +179,21 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
168179
return {nb, f, id, name, app_id,workspace_layout};
169180
}
170181
}
182+
if (found_visible) {
183+
int tiled_count = 0;
184+
int floating_count = 0;
185+
std::string workspace_layout = "";
186+
if(parentWorkspace != 0) {
187+
std::pair all_leaf_nodes = leafNodesInWorkspace(parentWorkspace);
188+
tiled_count = all_leaf_nodes.first;
189+
floating_count = all_leaf_nodes.second;
190+
if (parentWorkspace["layout"].isString()) {
191+
workspace_layout = parentWorkspace["layout"].asString();
192+
}
193+
}
194+
//using an empty string as default ensures that no window depending styles are set due to the checks above for !name.empty()
195+
return {tiled_count, floating_count, 0, config_["offscreen-text"].isString() ? config_["offscreen-text"].asString() : "", "", workspace_layout};
196+
}
171197
return {0, 0, -1, "", "", ""};
172198
}
173199

0 commit comments

Comments
 (0)