-
-
Notifications
You must be signed in to change notification settings - Fork 921
WLR Workspace manager implementation #805
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
Merged
Alexays
merged 13 commits into
Alexays:master
from
Anakael:workspace-manager-implementation
Nov 23, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2b11b7e
Base wlr impl (Manager, Group)
Anakael edd4d8e
Finish implement wlr
Anakael 7638f5c
Add base name representation
Anakael 4c25157
Add formatting and states handling
Anakael 0ad29a5
Finish base implementation
Anakael 42b6c08
Add docs and adjust sorting
Anakael 22409d2
Fix docs typos
Anakael 15761ef
Merge branch 'master' of https://github.com/Alexays/Waybar into works…
Anakael ffeecf6
Update names
Anakael ef4c6a9
Update to proto. Fix displaying. Rename classes.
Anakael 23991b6
Finish
Anakael 98f7a10
Fix sort
Anakael 0a48413
Merge branch 'master' into workspace-manager-implementation
Alexays 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 hidden or 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 hidden or 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,160 @@ | ||
| #pragma once | ||
|
|
||
| #include <fmt/format.h> | ||
| #include <gtkmm/button.h> | ||
| #include <gtkmm/image.h> | ||
| #include <gtkmm/label.h> | ||
|
|
||
| #include <functional> | ||
| #include <map> | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "AModule.hpp" | ||
| #include "bar.hpp" | ||
| #include "ext-workspace-unstable-v1-client-protocol.h" | ||
|
|
||
| namespace waybar::modules::wlr { | ||
|
|
||
| class WorkspaceManager; | ||
| class WorkspaceGroup; | ||
|
|
||
| class Workspace { | ||
| public: | ||
| Workspace(const waybar::Bar &bar, const Json::Value &config, WorkspaceGroup &workspace_group, | ||
| zext_workspace_handle_v1 *workspace, uint32_t id); | ||
| ~Workspace(); | ||
| auto update() -> void; | ||
|
|
||
| auto id() const -> uint32_t { return id_; } | ||
| auto is_active() const -> bool { return state_ & static_cast<uint32_t>(State::ACTIVE); } | ||
| auto is_urgent() const -> bool { return state_ & static_cast<uint32_t>(State::URGENT); } | ||
| auto is_hidden() const -> bool { return state_ & static_cast<uint32_t>(State::HIDDEN); } | ||
| // wlr stuff | ||
| auto handle_name(const std::string &name) -> void; | ||
| auto handle_coordinates(const std::vector<uint32_t> &coordinates) -> void; | ||
| auto handle_state(const std::vector<uint32_t> &state) -> void; | ||
| auto handle_remove() -> void; | ||
|
|
||
| auto handle_done() -> void; | ||
| auto handle_clicked(GdkEventButton *bt) -> bool; | ||
| auto show() -> void; | ||
| auto hide() -> void; | ||
| auto get_button_ref() -> Gtk::Button & { return button_; } | ||
| auto get_name() -> std::string & { return name_; } | ||
| auto get_coords() -> std::vector<uint32_t> & { return coordinates_; } | ||
|
|
||
| enum class State { | ||
| ACTIVE = (1 << 0), | ||
| URGENT = (1 << 1), | ||
| HIDDEN = (1 << 2), | ||
| }; | ||
|
|
||
| private: | ||
| auto get_icon() -> std::string; | ||
|
|
||
| const Bar &bar_; | ||
| const Json::Value &config_; | ||
| WorkspaceGroup &workspace_group_; | ||
|
|
||
| // wlr stuff | ||
| zext_workspace_handle_v1 *workspace_handle_; | ||
| uint32_t state_ = 0; | ||
|
|
||
| uint32_t id_; | ||
| std::string name_; | ||
| std::vector<uint32_t> coordinates_; | ||
| static std::map<std::string, std::string> icons_map_; | ||
| std::string format_; | ||
| bool with_icon_ = false; | ||
|
|
||
| Gtk::Button button_; | ||
| Gtk::Box content_; | ||
| Gtk::Label label_; | ||
| }; | ||
|
|
||
| class WorkspaceGroup { | ||
| public: | ||
| WorkspaceGroup(const waybar::Bar &bar, Gtk::Box &box, const Json::Value &config, | ||
| WorkspaceManager &manager, zext_workspace_group_handle_v1 *workspace_group_handle, | ||
| uint32_t id); | ||
| ~WorkspaceGroup(); | ||
| auto update() -> void; | ||
|
|
||
| auto id() const -> uint32_t { return id_; } | ||
| auto is_visible() const -> bool; | ||
| auto remove_workspace(uint32_t id_) -> void; | ||
| auto active_only() const -> bool; | ||
| auto creation_delayed() const -> bool; | ||
| auto workspaces() -> std::vector<std::unique_ptr<Workspace>> & { return workspaces_; } | ||
|
|
||
| auto sort_workspaces() -> void; | ||
| auto set_need_to_sort() -> void { need_to_sort = true; } | ||
| auto add_button(Gtk::Button &button) -> void; | ||
| auto remove_button(Gtk::Button &button) -> void; | ||
|
|
||
| // wlr stuff | ||
| auto handle_workspace_create(zext_workspace_handle_v1 *workspace_handle) -> void; | ||
| auto handle_remove() -> void; | ||
| auto handle_output_enter(wl_output *output) -> void; | ||
| auto handle_output_leave() -> void; | ||
| auto handle_done() -> void; | ||
| auto commit() -> void; | ||
|
|
||
| private: | ||
| static uint32_t workspace_global_id; | ||
| const waybar::Bar &bar_; | ||
| Gtk::Box &box_; | ||
| const Json::Value &config_; | ||
| WorkspaceManager &workspace_manager_; | ||
|
|
||
| // wlr stuff | ||
| zext_workspace_group_handle_v1 *workspace_group_handle_; | ||
| wl_output *output_ = nullptr; | ||
|
|
||
| uint32_t id_; | ||
| std::vector<std::unique_ptr<Workspace>> workspaces_; | ||
| bool need_to_sort = false; | ||
| }; | ||
|
|
||
| class WorkspaceManager : public AModule { | ||
| public: | ||
| WorkspaceManager(const std::string &id, const waybar::Bar &bar, const Json::Value &config); | ||
| ~WorkspaceManager() override; | ||
| auto update() -> void override; | ||
|
|
||
| auto all_outputs() const -> bool { return all_outputs_; } | ||
| auto active_only() const -> bool { return active_only_; } | ||
| auto workspace_comparator() const | ||
| -> std::function<bool(std::unique_ptr<Workspace> &, std::unique_ptr<Workspace> &)>; | ||
| auto creation_delayed() const -> bool { return creation_delayed_; } | ||
|
|
||
| auto sort_workspaces() -> void; | ||
| auto remove_workspace_group(uint32_t id_) -> void; | ||
|
|
||
| // wlr stuff | ||
| auto register_manager(wl_registry *registry, uint32_t name, uint32_t version) -> void; | ||
| auto handle_workspace_group_create(zext_workspace_group_handle_v1 *workspace_group_handle) | ||
| -> void; | ||
| auto handle_done() -> void; | ||
| auto handle_finished() -> void; | ||
| auto commit() -> void; | ||
|
|
||
| private: | ||
| const waybar::Bar &bar_; | ||
| Gtk::Box box_; | ||
| std::vector<std::unique_ptr<WorkspaceGroup>> groups_; | ||
|
|
||
| // wlr stuff | ||
| zext_workspace_manager_v1 *workspace_manager_ = nullptr; | ||
|
|
||
| static uint32_t group_global_id; | ||
|
|
||
| bool sort_by_name_ = true; | ||
| bool sort_by_coordinates_ = true; | ||
| bool all_outputs_ = false; | ||
| bool active_only_ = false; | ||
| bool creation_delayed_ = false; | ||
| }; | ||
|
|
||
| } // namespace waybar::modules::wlr |
This file contains hidden or 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,8 @@ | ||
| #include "ext-workspace-unstable-v1-client-protocol.h" | ||
|
|
||
| namespace waybar::modules::wlr { | ||
| void add_registry_listener(void *data); | ||
| void add_workspace_listener(zext_workspace_handle_v1 *workspace_handle, void *data); | ||
| void add_workspace_group_listener(zext_workspace_group_handle_v1 *workspace_group_handle, void *data); | ||
| zext_workspace_manager_v1* workspace_manager_bind(wl_registry *registry, uint32_t name, uint32_t version, void *data); | ||
| } |
This file contains hidden or 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,87 @@ | ||
| waybar-wlr-workspaces(5) | ||
|
|
||
| # NAME | ||
|
|
||
| waybar - wlr workspaces module | ||
|
|
||
| # DESCRIPTION | ||
|
|
||
| The *workspaces* module displays the currently used workspaces in wayland compositor. | ||
|
|
||
| # CONFIGURATION | ||
|
|
||
| Addressed by *wlr/workspaces* | ||
|
|
||
| *format*: ++ | ||
| typeof: string ++ | ||
| default: {name} ++ | ||
| The format, how information should be displayed. | ||
|
|
||
| *format-icons*: ++ | ||
| typeof: array ++ | ||
| Based on the workspace name and state, the corresponding icon gets selected. See *icons*. | ||
|
|
||
| *sort-by-name*: ++ | ||
| typeof: bool ++ | ||
| default: true ++ | ||
| Should workspaces be sorted by name. | ||
|
|
||
| *sort-by-coordinates*: ++ | ||
| typeof: bool ++ | ||
| default: true ++ | ||
| Should workspaces be sorted by coordinates. | ||
| Note that if both *sort-by-name* and *sort-by-coordinates* are true sort by name will be first. | ||
| If both are false - sort by id will be performed. | ||
|
|
||
| *all-outputs*: ++ | ||
| typeof: bool ++ | ||
| default: false ++ | ||
| If set to false workspaces group will be shown only in assigned output. Otherwise all workspace groups are shown. | ||
|
|
||
| *active-only*: ++ | ||
| typeof: bool ++ | ||
| default: false ++ | ||
| If set to true only active or urgent workspaces will be shown. | ||
|
|
||
| # FORMAT REPLACEMENTS | ||
|
|
||
| *{name}*: Name of workspace assigned by compositor | ||
|
|
||
| *{icon}*: Icon, as defined in *format-icons*. | ||
|
|
||
| # CLICK ACTIONS | ||
|
|
||
| *activate*: Switch to workspace. | ||
| *close*: Close the workspace. | ||
|
|
||
| # ICONS | ||
|
|
||
| Additional to workspace name matching, the following *format-icons* can be set. | ||
|
|
||
| - *default*: Will be shown, when no string match is found. | ||
| - *focused*: Will be shown, when workspace is focused | ||
|
|
||
| # EXAMPLES | ||
|
|
||
| ``` | ||
| "wlr/workspaces": { | ||
| "format": "{name}: {icon}", | ||
| "format-icons": { | ||
| "1": "", | ||
| "2": "", | ||
| "3": "", | ||
| "4": "", | ||
| "5": "", | ||
| "focused": "", | ||
| "default": "" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| # Style | ||
|
|
||
| - *#workspaces* | ||
| - *#workspaces button* | ||
| - *#workspaces button.active* | ||
| - *#workspaces button.urgent* | ||
| - *#workspaces button.hidden* | ||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.