Skip to content

Commit

Permalink
feat(workspace): only show workspaces which are on same output as bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexays committed Aug 10, 2018
1 parent 2512d51 commit 424ebb3
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 58 deletions.
12 changes: 12 additions & 0 deletions include/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <json/json.h>
#include <gtkmm.h>
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"

namespace waybar {

Expand All @@ -17,9 +18,19 @@ namespace waybar {
struct zwlr_layer_surface_v1 *layerSurface;
std::unique_ptr<struct wl_output *> output;
bool visible = true;
std::string outputName;
auto setWidth(uint32_t) -> void;
auto toggle() -> void;
private:
static void _handleLogicalPosition(void *data,
struct zxdg_output_v1 *zxdg_output_v1, int32_t x, int32_t y);
static void _handleLogicalSize(void *data,
struct zxdg_output_v1 *zxdg_output_v1, int32_t width, int32_t height);
static void _handleDone(void *data, struct zxdg_output_v1 *zxdg_output_v1);
static void _handleName(void *data, struct zxdg_output_v1 *xdg_output,
const char *name);
static void _handleDescription(void *data,
struct zxdg_output_v1 *zxdg_output_v1, const char *description);
static void _handleGeometry(void *data, struct wl_output *wl_output,
int32_t x, int32_t y, int32_t physical_width, int32_t physical_height,
int32_t subpixel, const char *make, const char *model, int32_t transform);
Expand All @@ -41,6 +52,7 @@ namespace waybar {
Json::Value _config;
Glib::RefPtr<Gtk::StyleContext> _styleContext;
Glib::RefPtr<Gtk::CssProvider> _cssProvider;
struct zxdg_output_v1 *_xdgOutput;
};

}
3 changes: 1 addition & 2 deletions include/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <wayland-client.h>

#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "idle-client-protocol.h"

#include "util/ptr_vec.hpp"

Expand All @@ -32,7 +31,7 @@ namespace waybar {
struct wl_display *wlDisplay;
struct wl_registry *registry;
struct zwlr_layer_shell_v1 *layer_shell;
struct org_kde_kwin_idle *idle_manager;
struct zxdg_output_manager_v1 *xdg_output_manager;
struct wl_seat *seat;
util::ptr_vec<Bar> bars;

Expand Down
49 changes: 0 additions & 49 deletions protocol/idle.xml

This file was deleted.

2 changes: 1 addition & 1 deletion protocol/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ wayland_scanner_client = generator(

client_protocols = [
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
[wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'],
['wlr-layer-shell-unstable-v1.xml'],
['idle.xml'],
]

client_protos_src = []
Expand Down
41 changes: 40 additions & 1 deletion src/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ waybar::Bar::Bar(Client &client, std::unique_ptr<struct wl_output *> &&p_output)
.done = _handleDone,
.scale = _handleScale,
};

static const struct zxdg_output_v1_listener xdgOutputListener = {
.logical_position = _handleLogicalPosition,
.logical_size = _handleLogicalSize,
.done = _handleDone,
.name = _handleName,
.description = _handleDescription,
};
wl_output_add_listener(*output, &outputListener, this);
_xdgOutput =
zxdg_output_manager_v1_get_xdg_output(client.xdg_output_manager, *output);
zxdg_output_v1_add_listener(_xdgOutput, &xdgOutputListener, this);
window.set_title("waybar");
window.set_decorated(false);
_setupConfig();
Expand Down Expand Up @@ -48,6 +57,36 @@ waybar::Bar::Bar(Client &client, std::unique_ptr<struct wl_output *> &&p_output)
wl_surface_commit(surface);
}

void waybar::Bar::_handleLogicalPosition(void *data,
struct zxdg_output_v1 *zxdg_output_v1, int32_t x, int32_t y)
{
// Nothing here
}

void waybar::Bar::_handleLogicalSize(void *data,
struct zxdg_output_v1 *zxdg_output_v1, int32_t width, int32_t height)
{
// Nothing here
}

void waybar::Bar::_handleDone(void *data, struct zxdg_output_v1 *zxdg_output_v1)
{
// Nothing here
}

void waybar::Bar::_handleName(void *data, struct zxdg_output_v1 *xdg_output,
const char *name)
{
auto o = reinterpret_cast<waybar::Bar *>(data);
o->outputName = name;
}

void waybar::Bar::_handleDescription(void *data,
struct zxdg_output_v1 *zxdg_output_v1, const char *description)
{
// Nothing here
}

void waybar::Bar::_handleGeometry(void *data, struct wl_output *wl_output,
int32_t x, int32_t y, int32_t physical_width, int32_t physical_height,
int32_t subpixel, const char *make, const char *model, int32_t transform)
Expand Down
10 changes: 6 additions & 4 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ void waybar::Client::_handle_global(void *data, struct wl_registry *registry,
*output = (struct wl_output *)wl_registry_bind(registry, name,
&wl_output_interface, version);
o->bars.emplace_back(*o, std::move(output));
} else if (!strcmp(interface, org_kde_kwin_idle_interface.name)) {
o->idle_manager = (org_kde_kwin_idle *)wl_registry_bind(registry, name,
&org_kde_kwin_idle_interface, version);
} else if (!strcmp(interface, wl_seat_interface.name)) {
o->seat = (struct wl_seat *)wl_registry_bind(registry, name,
&wl_seat_interface, version);
}
} else if (!strcmp(interface, zxdg_output_manager_v1_interface.name)
&& version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) {
o->xdg_output_manager =
(struct zxdg_output_manager_v1 *)wl_registry_bind(registry, name,
&zxdg_output_manager_v1_interface, ZXDG_OUTPUT_V1_NAME_SINCE_VERSION);
}
}

void waybar::Client::_handle_global_remove(void *data,
Expand Down
3 changes: 2 additions & 1 deletion src/modules/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ waybar::modules::Workspaces::Workspaces(Bar &bar)

auto waybar::modules::Workspaces::update() -> void
{
if (_bar.outputName.empty()) return;
Json::Value workspaces = _getWorkspaces();
bool needReorder = false;
for (auto it = _buttons.begin(); it != _buttons.end(); ++it) {
Expand All @@ -34,7 +35,7 @@ auto waybar::modules::Workspaces::update() -> void
}
for (auto node : workspaces) {
auto it = _buttons.find(node["num"].asInt());
if (it == _buttons.end()) {
if (it == _buttons.end() && _bar.outputName == node["output"].asString()) {
_addWorkspace(node);
needReorder = true;
} else {
Expand Down

0 comments on commit 424ebb3

Please sign in to comment.