@@ -49,7 +49,7 @@ void waybar::Client::handleGlobalRemove(void * data, struct wl_registry * /*re
49
49
// Nothing here
50
50
}
51
51
52
- void waybar::Client::handleOutput (std::unique_ptr< struct waybar_output > &output) {
52
+ void waybar::Client::handleOutput (struct waybar_output &output) {
53
53
static const struct zxdg_output_v1_listener xdgOutputListener = {
54
54
.logical_position = [](void *, struct zxdg_output_v1 *, int32_t , int32_t ) {},
55
55
.logical_size = [](void *, struct zxdg_output_v1 *, int32_t , int32_t ) {},
@@ -58,42 +58,39 @@ void waybar::Client::handleOutput(std::unique_ptr<struct waybar_output> &output)
58
58
.description = [](void *, struct zxdg_output_v1 *, const char *) {},
59
59
};
60
60
// owned by output->monitor; no need to destroy
61
- auto wl_output = gdk_wayland_monitor_get_wl_output (output-> monitor ->gobj ());
62
- output-> xdg_output .reset (zxdg_output_manager_v1_get_xdg_output (xdg_output_manager, wl_output));
63
- zxdg_output_v1_add_listener (output-> xdg_output .get (), &xdgOutputListener, output. get () );
61
+ auto wl_output = gdk_wayland_monitor_get_wl_output (output. monitor ->gobj ());
62
+ output. xdg_output .reset (zxdg_output_manager_v1_get_xdg_output (xdg_output_manager, wl_output));
63
+ zxdg_output_v1_add_listener (output. xdg_output .get (), &xdgOutputListener, & output);
64
64
}
65
65
66
- bool waybar::Client::isValidOutput (const Json::Value & config,
67
- std::unique_ptr<struct waybar_output > &output) {
66
+ bool waybar::Client::isValidOutput (const Json::Value &config, struct waybar_output &output) {
68
67
bool found = true ;
69
68
if (config[" output" ].isArray ()) {
70
69
bool in_array = false ;
71
70
for (auto const &output_conf : config[" output" ]) {
72
- if (output_conf.isString () && output_conf.asString () == output-> name ) {
71
+ if (output_conf.isString () && output_conf.asString () == output. name ) {
73
72
in_array = true ;
74
73
break ;
75
74
}
76
75
}
77
76
found = in_array;
78
77
}
79
- if (config[" output" ].isString () && config[" output" ].asString () != output-> name ) {
78
+ if (config[" output" ].isString () && config[" output" ].asString () != output. name ) {
80
79
found = false ;
81
80
}
82
81
return found;
83
82
}
84
83
85
- std::unique_ptr<struct waybar ::waybar_output> &waybar::Client::getOutput (void *addr) {
86
- auto it = std::find_if (outputs_.begin (), outputs_.end (), [&addr](const auto &output) {
87
- return output.get () == addr;
88
- });
84
+ struct waybar ::waybar_output &waybar::Client::getOutput (void *addr) {
85
+ auto it = std::find_if (
86
+ outputs_.begin (), outputs_.end (), [&addr](const auto &output) { return &output == addr; });
89
87
if (it == outputs_.end ()) {
90
88
throw std::runtime_error (" Unable to find valid output" );
91
89
}
92
90
return *it;
93
91
}
94
92
95
- std::vector<Json::Value> waybar::Client::getOutputConfigs (
96
- std::unique_ptr<struct waybar_output > &output) {
93
+ std::vector<Json::Value> waybar::Client::getOutputConfigs (struct waybar_output &output) {
97
94
std::vector<Json::Value> configs;
98
95
if (config_.isArray ()) {
99
96
for (auto const &config : config_) {
@@ -112,18 +109,18 @@ void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 *
112
109
auto client = waybar::Client::inst ();
113
110
try {
114
111
auto &output = client->getOutput (data);
115
- output-> name = name;
112
+ output. name = name;
116
113
spdlog::debug (" Output detected: {} ({} {})" ,
117
114
name,
118
- output-> monitor ->get_manufacturer (),
119
- output-> monitor ->get_model ());
115
+ output. monitor ->get_manufacturer (),
116
+ output. monitor ->get_model ());
120
117
auto configs = client->getOutputConfigs (output);
121
118
if (configs.empty ()) {
122
- output-> xdg_output .reset ();
119
+ output. xdg_output .reset ();
123
120
} else {
124
121
wl_display_roundtrip (client->wl_display );
125
122
for (const auto &config : configs) {
126
- client->bars .emplace_back (std::make_unique<Bar>(output. get () , config));
123
+ client->bars .emplace_back (std::make_unique<Bar>(& output, config));
127
124
Glib::RefPtr<Gdk::Screen> screen = client->bars .back ()->window .get_screen ();
128
125
client->style_context_ ->add_provider_for_screen (
129
126
screen, client->css_provider_ , GTK_STYLE_PROVIDER_PRIORITY_USER);
@@ -135,7 +132,8 @@ void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 *
135
132
}
136
133
137
134
void waybar::Client::handleMonitorAdded (Glib::RefPtr<Gdk::Monitor> monitor) {
138
- auto &output = outputs_.emplace_back (new struct waybar_output ({monitor}));
135
+ auto &output = outputs_.emplace_back ();
136
+ output.monitor = monitor;
139
137
handleOutput (output);
140
138
}
141
139
@@ -152,7 +150,7 @@ void waybar::Client::handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor) {
152
150
}
153
151
}
154
152
std::remove_if (outputs_.begin (), outputs_.end (), [&monitor](const auto &output) {
155
- return output-> monitor == monitor;
153
+ return output. monitor == monitor;
156
154
});
157
155
}
158
156
0 commit comments