fix urgent window icons
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
ColumnLimit: 0
|
ColumnLimit: 0
|
||||||
|
AlignConsecutiveAssignments: true
|
||||||
@@ -10,6 +10,9 @@
|
|||||||
class HyprlandService {
|
class HyprlandService {
|
||||||
public:
|
public:
|
||||||
static constexpr int kWorkspaceSlotCount = 7;
|
static constexpr int kWorkspaceSlotCount = 7;
|
||||||
|
const char *kMonitorCommand = "hyprctl monitors -j";
|
||||||
|
const char *kWorkspaceCommand = "hyprctl workspaces -j";
|
||||||
|
const char *kClientsCommand = "hyprctl clients -j";
|
||||||
|
|
||||||
struct WindowState {
|
struct WindowState {
|
||||||
int hyprId = -1;
|
int hyprId = -1;
|
||||||
@@ -20,12 +23,12 @@ class HyprlandService {
|
|||||||
int monitorId = -1;
|
int monitorId = -1;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
bool focused = false;
|
bool focused = false;
|
||||||
std::vector<int> urgentWindows;
|
std::vector<std::string> urgentWindows;
|
||||||
std::string label;
|
std::string label;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Monitor {
|
struct Monitor {
|
||||||
std::map<int, WorkspaceState*> workspaceStates;
|
std::map<int, WorkspaceState *> workspaceStates;
|
||||||
std::string name;
|
std::string name;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
@@ -38,7 +41,6 @@ class HyprlandService {
|
|||||||
|
|
||||||
void start();
|
void start();
|
||||||
void on_hyprland_event(std::string event, std::string data);
|
void on_hyprland_event(std::string event, std::string data);
|
||||||
|
|
||||||
void printMonitor(const Monitor &mon) const;
|
void printMonitor(const Monitor &mon) const;
|
||||||
|
|
||||||
sigc::signal<void(std::string, std::string)> socketEventSignal;
|
sigc::signal<void(std::string, std::string)> socketEventSignal;
|
||||||
@@ -46,24 +48,23 @@ class HyprlandService {
|
|||||||
sigc::signal<void()> monitorStateChanged;
|
sigc::signal<void()> monitorStateChanged;
|
||||||
|
|
||||||
Monitor *getMonitorById(int id);
|
Monitor *getMonitorById(int id);
|
||||||
const Monitor *getMonitorById(int id) const;
|
|
||||||
Monitor *getMonitorByIndex(std::size_t index);
|
Monitor *getMonitorByIndex(std::size_t index);
|
||||||
const Monitor *getMonitorByIndex(std::size_t index) const;
|
|
||||||
void switchToWorkspace(int workspaceId);
|
void switchToWorkspace(int workspaceId);
|
||||||
|
|
||||||
std::map<int, WorkspaceState*> getAllWorkspaces() const {
|
std::map<int, WorkspaceState *> getAllWorkspaces() const {
|
||||||
return this->workspaces;
|
return this->workspaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
std::map<int, Monitor> monitors;
|
std::map<int, Monitor> monitors;
|
||||||
std::map<int, WorkspaceState*> workspaces;
|
std::map<int, WorkspaceState *> workspaces;
|
||||||
|
|
||||||
std::string get_socket_path();
|
std::string get_socket_path();
|
||||||
bool on_socket_read(Glib::IOCondition condition);
|
bool on_socket_read(Glib::IOCondition condition);
|
||||||
void parse_message(const std::string &line);
|
void parse_message(const std::string &line);
|
||||||
void refresh_monitors();
|
void refresh_monitors();
|
||||||
void refresh_workspaces();
|
void refresh_workspaces();
|
||||||
void handle_urgent_window(std::string windowAddress);
|
void onUrgentEvent(std::string windowAddress);
|
||||||
|
void onActiveWindowEvent(std::string windowAddress);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ window {
|
|||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.workspace-pill:hover {
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
.workspace-pill-focused {
|
.workspace-pill-focused {
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
color: #1e1e1e;
|
color: #1e1e1e;
|
||||||
@@ -42,10 +46,6 @@ window {
|
|||||||
margin-right: 0;
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill:hover {
|
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.minimized {
|
.minimized {
|
||||||
background-color: rgba(50, 50, 50, 0.5);
|
background-color: rgba(50, 50, 50, 0.5);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,16 +14,6 @@
|
|||||||
|
|
||||||
#include "helpers/systemHelper.hpp"
|
#include "helpers/systemHelper.hpp"
|
||||||
|
|
||||||
namespace {
|
|
||||||
const char *kMonitorCommand = "hyprctl monitors -j";
|
|
||||||
const char *kWorkspaceCommand = "hyprctl workspaces -j";
|
|
||||||
const char *kClientsCommand = "hyprctl clients -j";
|
|
||||||
|
|
||||||
bool is_workspace_event(const std::string &event) {
|
|
||||||
return event.find("workspace") != std::string::npos;
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
HyprlandService::HyprlandService() = default;
|
HyprlandService::HyprlandService() = default;
|
||||||
|
|
||||||
HyprlandService::~HyprlandService() {
|
HyprlandService::~HyprlandService() {
|
||||||
@@ -39,13 +29,19 @@ void HyprlandService::on_hyprland_event(std::string event, std::string data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event == "urgent") {
|
if (event == "urgent") {
|
||||||
handle_urgent_window(data);
|
onUrgentEvent(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event == "workspace" || event == "focusedmon" || event == "monitoradded" ||
|
if (event == "workspace" || event == "movewindow") {
|
||||||
event == "monitorremoved" || event == "movewindow" || event == "activewindow") {
|
|
||||||
refresh_workspaces();
|
refresh_workspaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use for
|
||||||
|
// event == "focusedmon"
|
||||||
|
|
||||||
|
if (event == "activewindowv2") {
|
||||||
|
onActiveWindowEvent(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::start() {
|
void HyprlandService::start() {
|
||||||
@@ -145,8 +141,6 @@ void HyprlandService::refresh_monitors() {
|
|||||||
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
|
|
||||||
for (const auto &monitorJson : monitorsJson) {
|
for (const auto &monitorJson : monitorsJson) {
|
||||||
assert(monitorJson.is_object());
|
|
||||||
|
|
||||||
Monitor monitor;
|
Monitor monitor;
|
||||||
monitor.id = monitorJson.value("id", -1);
|
monitor.id = monitorJson.value("id", -1);
|
||||||
monitor.name = monitorJson.value("name", "");
|
monitor.name = monitorJson.value("name", "");
|
||||||
@@ -194,14 +188,11 @@ void HyprlandService::refresh_workspaces() {
|
|||||||
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
|
|
||||||
for (const auto &monitorJson : monitorsJson) {
|
for (const auto &monitorJson : monitorsJson) {
|
||||||
|
|
||||||
|
|
||||||
const int monitorId = monitorJson.value("id", -1);
|
const int monitorId = monitorJson.value("id", -1);
|
||||||
const int focusedWorkspaceId = monitorJson["activeWorkspace"].value("id", -1);
|
const int focusedWorkspaceId = monitorJson["activeWorkspace"].value("id", -1);
|
||||||
|
|
||||||
auto monitorIt = this->monitors.find(monitorId);
|
auto monitor = this->monitors[monitorId];
|
||||||
|
monitor.focusedWorkspaceId = focusedWorkspaceId;
|
||||||
monitorIt->second.focusedWorkspaceId = focusedWorkspaceId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &workspaceJson : workspacesJson) {
|
for (const auto &workspaceJson : workspacesJson) {
|
||||||
@@ -209,50 +200,13 @@ void HyprlandService::refresh_workspaces() {
|
|||||||
std::map<int, WorkspaceState *>::iterator workspaceStateIt = this->workspaces.find(workspaceId);
|
std::map<int, WorkspaceState *>::iterator workspaceStateIt = this->workspaces.find(workspaceId);
|
||||||
WorkspaceState *workspaceState = workspaceStateIt->second;
|
WorkspaceState *workspaceState = workspaceStateIt->second;
|
||||||
|
|
||||||
|
workspaceState->focused = monitors[workspaceState->monitorId].focusedWorkspaceId == workspaceId;
|
||||||
workspaceState->focused = monitors
|
|
||||||
.at(workspaceState->monitorId)
|
|
||||||
.focusedWorkspaceId ==
|
|
||||||
workspaceId;
|
|
||||||
workspaceState->active = true;
|
workspaceState->active = true;
|
||||||
|
|
||||||
this->workspaces[workspaceId] = workspaceState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
workspaceStateChanged.emit();
|
workspaceStateChanged.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
HyprlandService::Monitor *HyprlandService::getMonitorById(int id) {
|
|
||||||
auto it = monitors.find(id);
|
|
||||||
if (it == monitors.end()) {
|
|
||||||
throw std::runtime_error("Monitor with ID " + std::to_string(id) +
|
|
||||||
" not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return &it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
const HyprlandService::Monitor *HyprlandService::getMonitorById(int id) const {
|
|
||||||
auto it = monitors.find(id);
|
|
||||||
if (it == monitors.end()) {
|
|
||||||
throw std::runtime_error("Monitor with ID " + std::to_string(id) +
|
|
||||||
" not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return &it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
HyprlandService::Monitor *HyprlandService::getMonitorByIndex(std::size_t index) {
|
|
||||||
if (index >= monitors.size()) {
|
|
||||||
throw std::runtime_error("Monitor index out of bounds: " + std::to_string(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto it = monitors.begin();
|
|
||||||
std::advance(it, static_cast<long>(index));
|
|
||||||
|
|
||||||
return &it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HyprlandService::switchToWorkspace(int workspaceId) {
|
void HyprlandService::switchToWorkspace(int workspaceId) {
|
||||||
std::string cmd =
|
std::string cmd =
|
||||||
"hyprctl dispatch workspace " + std::to_string(workspaceId);
|
"hyprctl dispatch workspace " + std::to_string(workspaceId);
|
||||||
@@ -265,36 +219,51 @@ void HyprlandService::switchToWorkspace(int workspaceId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::handle_urgent_window(std::string windowAddress) {
|
void HyprlandService::onUrgentEvent(std::string windowAddress) {
|
||||||
std::string output = SystemHelper::get_command_output(kClientsCommand);
|
std::string output = SystemHelper::get_command_output(kClientsCommand);
|
||||||
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
|
|
||||||
for (const auto &clientJson : clientsJson) {
|
for (const auto &clientJson : clientsJson) {
|
||||||
if (!clientJson.is_object()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string addr = clientJson.value("address", "");
|
const std::string addr = clientJson.value("address", "");
|
||||||
if (addr != windowAddress) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int workspaceId = clientJson.value("workspace", -1);
|
if (addr == "0x" + windowAddress) {
|
||||||
if (workspaceId < 0) {
|
int workspaceId = clientJson["workspace"].value("id", -1);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto workspaceIt = this->workspaces.find(workspaceId);
|
WorkspaceState *ws = this->workspaces[workspaceId];
|
||||||
if (workspaceIt == this->workspaces.end()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkspaceState *wsState = workspaceIt->second;
|
// todo: maybee better method of access
|
||||||
wsState->urgentWindows.push_back(1);
|
if (ws) {
|
||||||
|
ws->urgentWindows.push_back(windowAddress);
|
||||||
|
workspaceStateChanged.emit();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HyprlandService::onActiveWindowEvent(std::string windowAddress) {
|
||||||
|
std::string output = SystemHelper::get_command_output(kClientsCommand);
|
||||||
|
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
|
|
||||||
|
for (const auto &clientJson : clientsJson) {
|
||||||
|
const std::string addr = clientJson.value("address", "");
|
||||||
|
|
||||||
|
if (addr == "0x" + windowAddress) {
|
||||||
|
int workspaceId = clientJson["workspace"]["id"];
|
||||||
|
WorkspaceState *ws = this->workspaces[workspaceId];
|
||||||
|
|
||||||
|
if (ws) {
|
||||||
|
auto it = std::find(ws->urgentWindows.begin(), ws->urgentWindows.end(), windowAddress);
|
||||||
|
if (it != ws->urgentWindows.end()) {
|
||||||
|
ws->urgentWindows.erase(it);
|
||||||
workspaceStateChanged.emit();
|
workspaceStateChanged.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::printMonitor(const Monitor &mon) const {
|
void HyprlandService::printMonitor(const Monitor &mon) const {
|
||||||
@@ -335,3 +304,24 @@ void HyprlandService::printMonitor(const Monitor &mon) const {
|
|||||||
|
|
||||||
std::cout << "====================\n";
|
std::cout << "====================\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HyprlandService::Monitor *HyprlandService::getMonitorById(int id) {
|
||||||
|
auto it = monitors.find(id);
|
||||||
|
if (it == monitors.end()) {
|
||||||
|
throw std::runtime_error("Monitor with ID " + std::to_string(id) +
|
||||||
|
" not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
HyprlandService::Monitor *HyprlandService::getMonitorByIndex(std::size_t index) {
|
||||||
|
if (index >= monitors.size()) {
|
||||||
|
throw std::runtime_error("Monitor index out of bounds: " + std::to_string(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = monitors.begin();
|
||||||
|
std::advance(it, static_cast<long>(index));
|
||||||
|
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ void WorkspaceIndicator::rebuild() {
|
|||||||
HyprlandService::Monitor *mon = service.getMonitorById(this->monitorId);
|
HyprlandService::Monitor *mon = service.getMonitorById(this->monitorId);
|
||||||
|
|
||||||
for (auto [id, workspaceState] : mon->workspaceStates) {
|
for (auto [id, workspaceState] : mon->workspaceStates) {
|
||||||
assert(id > 0);
|
|
||||||
Gtk::Label *label = workspaceLabels[id];
|
Gtk::Label *label = workspaceLabels[id];
|
||||||
this->refreshLabel(label, *workspaceState);
|
this->refreshLabel(label, *workspaceState);
|
||||||
}
|
}
|
||||||
|
|||||||
13
tmp_test.cpp
13
tmp_test.cpp
@@ -1,13 +0,0 @@
|
|||||||
#include <gio/gdbusmenumodel.h>
|
|
||||||
#include <gio/gio.h>
|
|
||||||
#include <giomm/menumodel.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
GDBusMenuModel *dbusModel = g_dbus_menu_model_get_for_bus_sync(
|
|
||||||
G_BUS_TYPE_SESSION, G_DBUS_MENU_MODEL_FLAGS_NONE,
|
|
||||||
"org.freedesktop.Notifications", "/Menu", nullptr, nullptr);
|
|
||||||
if (!dbusModel)
|
|
||||||
return 0;
|
|
||||||
Glib::RefPtr<Gio::MenuModel> model = Glib::wrap(G_MENU_MODEL(dbusModel));
|
|
||||||
return model ? 0 : 1;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user