Changed helper function for workspace->num assignment to a static method of Workspaces class
and adapted comments/method name to be consistent with the rest
This commit is contained in:
parent
15fe73a252
commit
006850ea5e
|
@ -22,6 +22,8 @@ class Workspaces : public AModule, public sigc::trackable {
|
||||||
private:
|
private:
|
||||||
static inline const std::string workspace_switch_cmd_ = "workspace --no-auto-back-and-forth \"{}\"";
|
static inline const std::string workspace_switch_cmd_ = "workspace --no-auto-back-and-forth \"{}\"";
|
||||||
|
|
||||||
|
static int convertWorkspaceNameToNum(std::string name);
|
||||||
|
|
||||||
void onCmd(const struct Ipc::ipc_response&);
|
void onCmd(const struct Ipc::ipc_response&);
|
||||||
void onEvent(const struct Ipc::ipc_response&);
|
void onEvent(const struct Ipc::ipc_response&);
|
||||||
bool filterButtons();
|
bool filterButtons();
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
#include "modules/sway/workspaces.hpp"
|
#include "modules/sway/workspaces.hpp"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <cctype>
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <cctype>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
// this is the code that sway uses to assign a number to a workspace. This is
|
// Helper function to to assign a number to a workspace, just like sway. In fact
|
||||||
// taken quite verbatim from `sway/ipc-json.c`.
|
// this is taken quite verbatim from `sway/ipc-json.c`.
|
||||||
int sway_wsname_to_num(std::string name) {
|
int Workspaces::convertWorkspaceNameToNum(std::string name) {
|
||||||
if (isdigit(name[0])) {
|
if (isdigit(name[0])) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
char * endptr = NULL;
|
char * endptr = NULL;
|
||||||
|
@ -121,21 +121,23 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||||
// the "num" property (integer type):
|
// the "num" property (integer type):
|
||||||
// The workspace number or -1 for workspaces that do
|
// The workspace number or -1 for workspaces that do
|
||||||
// not start with a number.
|
// not start with a number.
|
||||||
//auto l = lhs["num"].asInt();
|
// We could rely on sway providing this property:
|
||||||
//auto r = rhs["num"].asInt();
|
//
|
||||||
|
// auto l = lhs["num"].asInt();
|
||||||
|
// auto r = rhs["num"].asInt();
|
||||||
|
//
|
||||||
// We cannot rely on the "num" property as provided by sway
|
// We cannot rely on the "num" property as provided by sway
|
||||||
// via IPC, because persistent workspace might not exist in
|
// via IPC, because persistent workspace might not exist in
|
||||||
// sway's view. However, we need this property also for
|
// sway's view. However, we need this property also for
|
||||||
// not-yet created persistent workspace. As such, we simply
|
// not-yet created persistent workspace. As such, we simply
|
||||||
// duplicate sway's logic of assigning the "num" property
|
// duplicate sway's logic of assigning the "num" property
|
||||||
// into waybar (see sway_wsname_to_num). This way the
|
// into waybar (see convertWorkspaceNameToNum). This way the
|
||||||
// sorting should work out even when we include workspaces
|
// sorting should work out even when we include workspaces
|
||||||
// that do not currently exist.
|
// that do not currently exist.
|
||||||
auto lname = lhs["name"].asString();
|
auto lname = lhs["name"].asString();
|
||||||
auto rname = rhs["name"].asString();
|
auto rname = rhs["name"].asString();
|
||||||
auto l = sway_wsname_to_num(lname);
|
int l = convertWorkspaceNameToNum(lname);
|
||||||
auto r = sway_wsname_to_num(rname);
|
int r = convertWorkspaceNameToNum(rname);
|
||||||
|
|
||||||
if (l == r) {
|
if (l == r) {
|
||||||
// in case both integers are the same, lexicographical
|
// in case both integers are the same, lexicographical
|
||||||
|
|
Loading…
Reference in New Issue