refactor(client): cleanup

pull/25/head
Alexis 2018-08-15 17:31:45 +02:00
parent be66cc2dd1
commit 9b75302d22
3 changed files with 15 additions and 24 deletions

View File

@ -23,10 +23,9 @@ namespace waybar {
Glib::RefPtr<Gdk::Display> gdk_display; Glib::RefPtr<Gdk::Display> gdk_display;
struct wl_display *wlDisplay = nullptr; struct wl_display *wlDisplay = nullptr;
struct wl_registry *registry = nullptr; struct wl_registry *registry = nullptr;
struct zwlr_layer_shell_v1 *layer_shell = nullptr; struct zwlr_layer_shell_v1 *layerShell = nullptr;
struct zxdg_output_manager_v1 *xdg_output_manager = nullptr; struct zxdg_output_manager_v1 *xdgOutputManager = nullptr;
struct wl_seat *seat = nullptr; struct wl_seat *seat = nullptr;
struct wl_output *wlOutput = nullptr;
std::vector<std::unique_ptr<Bar>> bars; std::vector<std::unique_ptr<Bar>> bars;
Client(int argc, char* argv[]); Client(int argc, char* argv[]);

View File

@ -15,7 +15,7 @@ waybar::Bar::Bar(Client &client, std::unique_ptr<struct wl_output *> &&p_output)
.description = _handleDescription, .description = _handleDescription,
}; };
_xdgOutput = _xdgOutput =
zxdg_output_manager_v1_get_xdg_output(client.xdg_output_manager, *output); zxdg_output_manager_v1_get_xdg_output(client.xdgOutputManager, *output);
zxdg_output_v1_add_listener(_xdgOutput, &xdgOutputListener, this); zxdg_output_v1_add_listener(_xdgOutput, &xdgOutputListener, this);
window.set_title("waybar"); window.set_title("waybar");
window.set_decorated(false); window.set_decorated(false);
@ -31,7 +31,7 @@ waybar::Bar::Bar(Client &client, std::unique_ptr<struct wl_output *> &&p_output)
gdk_wayland_window_set_use_custom_surface(gdkWindow); gdk_wayland_window_set_use_custom_surface(gdkWindow);
surface = gdk_wayland_window_get_wl_surface(gdkWindow); surface = gdk_wayland_window_get_wl_surface(gdkWindow);
layerSurface = zwlr_layer_shell_v1_get_layer_surface( layerSurface = zwlr_layer_shell_v1_get_layer_surface(
client.layer_shell, surface, *output, client.layerShell, surface, *output,
(layerTop ? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM), (layerTop ? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM),
"waybar"); "waybar");
zwlr_layer_surface_v1_set_anchor(layerSurface, zwlr_layer_surface_v1_set_anchor(layerSurface,

View File

@ -14,9 +14,8 @@ waybar::Client::Client(int argc, char* argv[])
std::string result = p.we_wordv[0]; std::string result = p.we_wordv[0];
wordfree(&p); wordfree(&p);
return result; return result;
} else {
wordfree(&p);
} }
wordfree(&p);
} }
} }
@ -42,30 +41,23 @@ void waybar::Client::_handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version) uint32_t name, const char *interface, uint32_t version)
{ {
auto o = reinterpret_cast<waybar::Client *>(data); auto o = reinterpret_cast<waybar::Client *>(data);
if (!strcmp(interface, zwlr_layer_shell_v1_interface.name)) { if (!strcmp(interface, zwlr_layer_shell_v1_interface.name))
o->layer_shell = (zwlr_layer_shell_v1 *)wl_registry_bind(registry, name, o->layerShell = (zwlr_layer_shell_v1 *)wl_registry_bind(registry, name,
&zwlr_layer_shell_v1_interface, version); &zwlr_layer_shell_v1_interface, version);
} else if (!strcmp(interface, wl_output_interface.name)) { else if (!strcmp(interface, wl_output_interface.name)) {
o->wlOutput = (struct wl_output *)wl_registry_bind(registry, name,
&wl_output_interface, version);
auto output = std::make_unique<struct wl_output *>(); auto output = std::make_unique<struct wl_output *>();
*output = o->wlOutput; *output = (struct wl_output *)wl_registry_bind(registry, name,
if (o->xdg_output_manager) &wl_output_interface, version);
if (o->xdgOutputManager)
o->bars.emplace_back(std::make_unique<Bar>(*o, std::move(output))); o->bars.emplace_back(std::make_unique<Bar>(*o, std::move(output)));
} else if (!strcmp(interface, wl_seat_interface.name)) { } else if (!strcmp(interface, wl_seat_interface.name))
o->seat = (struct wl_seat *)wl_registry_bind(registry, name, o->seat = (struct wl_seat *)wl_registry_bind(registry, name,
&wl_seat_interface, version); &wl_seat_interface, version);
} else if (!strcmp(interface, zxdg_output_manager_v1_interface.name) else if (!strcmp(interface, zxdg_output_manager_v1_interface.name)
&& version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { && version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)
o->xdg_output_manager = o->xdgOutputManager =
(struct zxdg_output_manager_v1 *)wl_registry_bind(registry, name, (struct zxdg_output_manager_v1 *)wl_registry_bind(registry, name,
&zxdg_output_manager_v1_interface, ZXDG_OUTPUT_V1_NAME_SINCE_VERSION); &zxdg_output_manager_v1_interface, ZXDG_OUTPUT_V1_NAME_SINCE_VERSION);
if (o->wlOutput) {
auto output = std::make_unique<struct wl_output *>();
*output = o->wlOutput;
o->bars.emplace_back(std::make_unique<Bar>(*o, std::move(output)));
}
}
} }
void waybar::Client::_handle_global_remove(void *data, void waybar::Client::_handle_global_remove(void *data,