Compare commits
6 Commits
0a94acb8f4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c245fa7277 | |||
| 9b0a036925 | |||
| 11ccd55a52 | |||
| a912cb9687 | |||
| f1c68321a7 | |||
| e1eeb370da |
@@ -1 +1,3 @@
|
|||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
|
ColumnLimit: 0
|
||||||
|
AlignConsecutiveAssignments: true
|
||||||
5
.clangd
Normal file
5
.clangd
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Remove:
|
||||||
|
- -fmodules-ts
|
||||||
|
- -fmodule-mapper=*
|
||||||
|
- -fdeps-format=*
|
||||||
@@ -34,6 +34,7 @@ target_sources(bar_lib
|
|||||||
src/app.cpp
|
src/app.cpp
|
||||||
src/bar/bar.cpp
|
src/bar/bar.cpp
|
||||||
src/widgets/clock.cpp
|
src/widgets/clock.cpp
|
||||||
|
src/widgets/date.cpp
|
||||||
src/widgets/workspaceIndicator.cpp
|
src/widgets/workspaceIndicator.cpp
|
||||||
src/widgets/volumeWidget.cpp
|
src/widgets/volumeWidget.cpp
|
||||||
src/widgets/webWidget.cpp
|
src/widgets/webWidget.cpp
|
||||||
@@ -52,6 +53,7 @@ target_link_libraries(bar bar_lib ${GTKMM_LIBRARIES} ${LAYERSHELL_LIBRARIES} ${W
|
|||||||
# Copy `resources/bar.css` into the build directory when it changes
|
# Copy `resources/bar.css` into the build directory when it changes
|
||||||
set(RES_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/bar.css")
|
set(RES_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/bar.css")
|
||||||
set(RES_DST "${CMAKE_CURRENT_BINARY_DIR}/resources/bar.css")
|
set(RES_DST "${CMAKE_CURRENT_BINARY_DIR}/resources/bar.css")
|
||||||
|
set(USER_CONFIG_CSS "$ENV{HOME}/.config/bar/bar.css")
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${RES_DST}
|
OUTPUT ${RES_DST}
|
||||||
@@ -62,5 +64,14 @@ add_custom_command(
|
|||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(copy_resources ALL DEPENDS ${RES_DST})
|
add_custom_command(
|
||||||
|
OUTPUT ${USER_CONFIG_CSS}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "$ENV{HOME}/.config/bar"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${RES_SRC}" "${USER_CONFIG_CSS}"
|
||||||
|
DEPENDS "${RES_SRC}"
|
||||||
|
COMMENT "Copy resources/bar.css to ~/.config/bar/bar.css"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(copy_resources ALL DEPENDS ${RES_DST} ${USER_CONFIG_CSS})
|
||||||
add_dependencies(bar copy_resources)
|
add_dependencies(bar copy_resources)
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include <gtk4-layer-shell/gtk4-layer-shell.h>
|
#include <gtk4-layer-shell/gtk4-layer-shell.h>
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
|
#include "icons.hpp"
|
||||||
#include "services/hyprland.hpp"
|
#include "services/hyprland.hpp"
|
||||||
#include "services/tray.hpp"
|
#include "services/tray.hpp"
|
||||||
#include "widgets/clock.hpp"
|
#include "widgets/clock.hpp"
|
||||||
|
#include "widgets/date.hpp"
|
||||||
#include "widgets/tray.hpp"
|
#include "widgets/tray.hpp"
|
||||||
#include "widgets/webWidget.hpp"
|
#include "widgets/webWidget.hpp"
|
||||||
#include "widgets/workspaceIndicator.hpp"
|
#include "widgets/workspaceIndicator.hpp"
|
||||||
@@ -23,8 +24,9 @@ class Bar : public Gtk::Window {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Clock clock;
|
Clock clock;
|
||||||
WebWidget homeAssistant {"HA", "Home Assistant",
|
Date date;
|
||||||
"https://home.rivercry.com"};
|
WebWidget homeAssistant{ICON_HOME, "Home Assistant",
|
||||||
|
"https://home.rivercry.com"};
|
||||||
TrayService &trayService;
|
TrayService &trayService;
|
||||||
HyprlandService &hyprlandService;
|
HyprlandService &hyprlandService;
|
||||||
int monitorId;
|
int monitorId;
|
||||||
|
|||||||
3
include/icons.hpp
Normal file
3
include/icons.hpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define ICON_HOME "\ue88a"
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
class IUpdatable {
|
class IUpdatable {
|
||||||
public:
|
public:
|
||||||
virtual ~IUpdatable() = default;
|
virtual ~IUpdatable() = default;
|
||||||
|
|||||||
@@ -2,30 +2,37 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <glibmm.h>
|
#include <glibmm.h>
|
||||||
#include <iostream>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sigc++/sigc++.h>
|
#include <sigc++/sigc++.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class HyprlandService {
|
class HyprlandService {
|
||||||
public:
|
public:
|
||||||
static constexpr int kWorkspaceSlotCount = 5;
|
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 {
|
||||||
|
int hyprId = -1;
|
||||||
|
};
|
||||||
|
|
||||||
struct WorkspaceState {
|
struct WorkspaceState {
|
||||||
int id = -1;
|
int hyprId = -1;
|
||||||
int hyprId = -1;
|
int monitorId = -1;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
bool focused = false;
|
bool focused = false;
|
||||||
bool urgent = false;
|
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;
|
||||||
int id = -1;
|
int id = -1;
|
||||||
int focusedWorkspaceId = -1;
|
int focusedWorkspaceId = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,68 +41,32 @@ 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;
|
||||||
sigc::signal<void(int)> workspaceStateChanged;
|
sigc::signal<void()> workspaceStateChanged;
|
||||||
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;
|
|
||||||
// Switch to a workspace slot on a given monitor. If the workspace has an
|
|
||||||
// associated Hyprland workspace id (hyprId >= 0) that id will be used.
|
|
||||||
// Otherwise the slot and monitor name will be used to request creation
|
|
||||||
// / activation via `hyprctl`.
|
|
||||||
void switchToWorkspace(int workspaceId);
|
void switchToWorkspace(int workspaceId);
|
||||||
|
|
||||||
|
std::map<int, WorkspaceState *> getAllWorkspaces() const {
|
||||||
|
return this->workspaces;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
std::string buffer;
|
|
||||||
std::map<int, Monitor> monitors;
|
std::map<int, Monitor> monitors;
|
||||||
|
std::map<int, WorkspaceState *> workspaces;
|
||||||
|
// persistent buffer for socket reads to handle partial messages
|
||||||
|
std::string socket_buffer;
|
||||||
|
|
||||||
|
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);
|
||||||
std::string get_socket_path();
|
|
||||||
void refresh_monitors();
|
void refresh_monitors();
|
||||||
void refresh_workspaces();
|
void refresh_workspaces();
|
||||||
|
void onUrgentEvent(std::string windowAddress);
|
||||||
|
void onActiveWindowEvent(std::string windowAddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void HyprlandService::printMonitor(const Monitor &mon) const {
|
|
||||||
std::cout << "=== Monitor Info ===\n";
|
|
||||||
std::cout << "Name: " << mon.name << " (ID: " << mon.id << ")\n";
|
|
||||||
std::cout << "Position: (" << mon.x << ", " << mon.y << ")\n";
|
|
||||||
std::cout << "Focused Workspace ID: " << mon.focusedWorkspaceId << "\n";
|
|
||||||
|
|
||||||
std::cout << "Workspaces:\n";
|
|
||||||
|
|
||||||
if (mon.workspaceStates.empty()) {
|
|
||||||
std::cout << " (None)\n";
|
|
||||||
} else {
|
|
||||||
for (int slot = 1; slot <= HyprlandService::kWorkspaceSlotCount;
|
|
||||||
++slot) {
|
|
||||||
const auto it = mon.workspaceStates.find(slot);
|
|
||||||
if (it == mon.workspaceStates.end()) {
|
|
||||||
std::cout << " - [Slot: " << slot << " | HyprID: n/a]"
|
|
||||||
<< " Label: <none> | Active: No | Focused: No | "
|
|
||||||
"Urgent: No\n";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const WorkspaceState &ws = it->second;
|
|
||||||
std::cout << " - [Slot: " << ws.id << " | HyprID: "
|
|
||||||
<< (ws.hyprId >= 0 ? std::to_string(ws.hyprId)
|
|
||||||
: std::string("n/a"))
|
|
||||||
<< "] "
|
|
||||||
<< "Label: " << (ws.label.empty() ? "<none>" : ws.label)
|
|
||||||
<< " | "
|
|
||||||
<< "Active: " << (ws.active ? "Yes" : "No") << " | "
|
|
||||||
<< "Focused: " << (ws.focused ? "Yes" : "No") << " | "
|
|
||||||
<< "Urgent: " << (ws.urgent ? "Yes" : "No") << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "====================\n";
|
|
||||||
}
|
|
||||||
|
|||||||
12
include/widgets/date.hpp
Normal file
12
include/widgets/date.hpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtk4-layer-shell/gtk4-layer-shell.h>
|
||||||
|
#include <gtkmm.h>
|
||||||
|
#include <gtkmm/label.h>
|
||||||
|
|
||||||
|
#include "interface/updateable.ipp"
|
||||||
|
|
||||||
|
class Date : public Gtk::Label, public IUpdatable {
|
||||||
|
public:
|
||||||
|
bool onUpdate();
|
||||||
|
};
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
class WebWidget : public Gtk::Button {
|
class WebWidget : public Gtk::Button {
|
||||||
public:
|
public:
|
||||||
WebWidget(std::string label, std::string title, std::string url);
|
WebWidget(std::string icon, std::string title, std::string url);
|
||||||
~WebWidget() override;
|
~WebWidget() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <gtkmm/box.h>
|
#include <gtkmm/box.h>
|
||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
|
#include <gtkmm/gestureclick.h>
|
||||||
#include <sigc++/connection.h>
|
#include <sigc++/connection.h>
|
||||||
|
|
||||||
#include "services/hyprland.hpp"
|
#include "services/hyprland.hpp"
|
||||||
@@ -16,9 +17,11 @@ class WorkspaceIndicator : public Gtk::Box {
|
|||||||
int monitorId;
|
int monitorId;
|
||||||
sigc::connection workspaceConnection;
|
sigc::connection workspaceConnection;
|
||||||
sigc::connection monitorConnection;
|
sigc::connection monitorConnection;
|
||||||
|
std::map<int, Gtk::Label *> workspaceLabels;
|
||||||
|
std::map<int, Glib::RefPtr<Gtk::GestureClick>> workspaceGestures;
|
||||||
|
|
||||||
void rebuild();
|
void rebuild();
|
||||||
void on_workspace_update(int monitorId);
|
void on_workspace_update();
|
||||||
void on_monitor_update();
|
void on_monitor_update();
|
||||||
void clear_children();
|
void refreshLabel(Gtk::Label *label, const HyprlandService::WorkspaceState &state);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
all: unset;
|
all: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
window {
|
window {
|
||||||
background-color: rgba(30, 30, 30, 0.8);
|
background-color: rgba(30, 30, 30, 0.8);
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
@@ -22,23 +23,49 @@ window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill:hover {
|
.workspace-pill:hover {
|
||||||
background-color: rgba(104, 104, 104, 0.2);
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
}
|
|
||||||
.workspace-pill:last-child {
|
|
||||||
margin-right: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill-focused {
|
.workspace-pill-focused {
|
||||||
background-color: rgba(104, 104, 104, 0.3);
|
background-color: #ffffff;
|
||||||
|
color: #1e1e1e;
|
||||||
|
font-weight: bold;
|
||||||
|
box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.workspace-pill-focused:hover {
|
||||||
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill-active {
|
.workspace-pill-active {
|
||||||
background-color: rgba(168, 168, 168, 0.4);
|
background-color: rgba(255, 255, 255, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill-urgent {
|
.workspace-pill-urgent {
|
||||||
background-color: #ff5555;
|
background-color: #ff5555;
|
||||||
color: #111;
|
color: #fff;
|
||||||
|
|
||||||
|
/* base glow (will be animated) */
|
||||||
|
animation: workspace-blink 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* blinking animation for urgent workspaces */
|
||||||
|
@keyframes workspace-blink {
|
||||||
|
0% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.workspace-pill:last-child {
|
||||||
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.minimized {
|
.minimized {
|
||||||
@@ -49,7 +76,6 @@ window {
|
|||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
button {
|
button {
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
margin: 0 2px;
|
margin: 0 2px;
|
||||||
@@ -59,13 +85,10 @@ button {
|
|||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hover effect: slightly brighten background and show pointer */
|
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: #111111;
|
background-color: #111111;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#spacer {
|
#spacer {
|
||||||
color: rgba(255, 255, 255, 0.3);
|
color: rgba(255, 255, 255, 0.3);
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
@@ -82,4 +105,9 @@ tooltip {
|
|||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
font-family: "IBMPlexSans-Regular", sans-serif;
|
font-family: "IBMPlexSans-Regular", sans-serif;
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-label {
|
||||||
|
font-family: "Material Icons, Font Awesome 7 Brands, Hack Nerd Font Mono";
|
||||||
|
font-size: 19px;
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ App::App() {
|
|||||||
this->app = Gtk::Application::create("org.example.mybar");
|
this->app = Gtk::Application::create("org.example.mybar");
|
||||||
|
|
||||||
app->signal_activate().connect([&]() {
|
app->signal_activate().connect([&]() {
|
||||||
auto display = Gdk::Display::get_default();
|
auto display = Gdk::Display::get_default();
|
||||||
auto monitors = display->get_monitors();
|
auto monitors = display->get_monitors();
|
||||||
|
|
||||||
for (guint i = 0; i < monitors->get_n_items(); ++i) {
|
for (guint i = 0; i < monitors->get_n_items(); ++i) {
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
#include "bar/bar.hpp"
|
#include "bar/bar.hpp"
|
||||||
|
|
||||||
#include "gtk/gtk.h"
|
#include "gtk/gtk.h"
|
||||||
|
|
||||||
|
#include "widgets/date.hpp"
|
||||||
#include "widgets/spacer.hpp"
|
#include "widgets/spacer.hpp"
|
||||||
#include "widgets/volumeWidget.hpp"
|
#include "widgets/volumeWidget.hpp"
|
||||||
#include "widgets/workspaceIndicator.hpp"
|
#include "widgets/workspaceIndicator.hpp"
|
||||||
|
|
||||||
#include "helpers/systemHelper.hpp"
|
#include "helpers/systemHelper.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <gtkmm/enums.h>
|
#include <gtkmm/enums.h>
|
||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
#include <gtkmm/window.h>
|
#include <gtkmm/window.h>
|
||||||
@@ -28,11 +32,14 @@ Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
|
|||||||
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_TOP, true);
|
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_TOP, true);
|
||||||
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_LEFT, true);
|
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_LEFT, true);
|
||||||
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, true);
|
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, true);
|
||||||
|
gtk_layer_set_layer(this->gobj(), GTK_LAYER_SHELL_LAYER_TOP);
|
||||||
|
|
||||||
gtk_layer_auto_exclusive_zone_enable(this->gobj());
|
gtk_layer_auto_exclusive_zone_enable(this->gobj());
|
||||||
|
|
||||||
set_child(main_box);
|
set_child(main_box);
|
||||||
|
|
||||||
|
this->volumeWidget = Gtk::make_managed<VolumeWidget>();
|
||||||
|
|
||||||
load_css();
|
load_css();
|
||||||
setup_ui();
|
setup_ui();
|
||||||
|
|
||||||
@@ -41,6 +48,9 @@ Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
|
|||||||
Glib::signal_timeout().connect(sigc::mem_fun(clock, &Clock::onUpdate),
|
Glib::signal_timeout().connect(sigc::mem_fun(clock, &Clock::onUpdate),
|
||||||
1000);
|
1000);
|
||||||
|
|
||||||
|
date.onUpdate();
|
||||||
|
|
||||||
|
Glib::signal_timeout().connect(sigc::mem_fun(date, &Date::onUpdate), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bar::setup_ui() {
|
void Bar::setup_ui() {
|
||||||
@@ -53,27 +63,22 @@ void Bar::setup_ui() {
|
|||||||
|
|
||||||
left_box.set_valign(Gtk::Align::CENTER);
|
left_box.set_valign(Gtk::Align::CENTER);
|
||||||
|
|
||||||
// Don't expand the center box — keep it centered by alignment
|
|
||||||
center_box.set_hexpand(false);
|
center_box.set_hexpand(false);
|
||||||
center_box.set_valign(Gtk::Align::CENTER);
|
center_box.set_valign(Gtk::Align::CENTER);
|
||||||
center_box.set_halign(Gtk::Align::CENTER);
|
center_box.set_halign(Gtk::Align::CENTER);
|
||||||
|
|
||||||
right_box.set_valign(Gtk::Align::CENTER);
|
right_box.set_valign(Gtk::Align::CENTER);
|
||||||
|
|
||||||
workspaceIndicator =
|
workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(hyprlandService, monitorId);
|
||||||
Gtk::make_managed<WorkspaceIndicator>(hyprlandService, monitorId);
|
|
||||||
left_box.append(*workspaceIndicator);
|
left_box.append(*workspaceIndicator);
|
||||||
|
|
||||||
clock.set_name("clock-label");
|
clock.set_name("clock-label");
|
||||||
clock.set_hexpand(false);
|
center_box.append(this->date);
|
||||||
clock.set_halign(Gtk::Align::CENTER);
|
|
||||||
clock.set_valign(Gtk::Align::CENTER);
|
|
||||||
center_box.append(clock);
|
|
||||||
center_box.append(*(new Spacer()));
|
center_box.append(*(new Spacer()));
|
||||||
|
center_box.append(this->clock);
|
||||||
volumeWidget = Gtk::make_managed<VolumeWidget>();
|
center_box.append(*(new Spacer()));
|
||||||
center_box.append(*volumeWidget);
|
center_box.append(*this->volumeWidget);
|
||||||
|
|
||||||
|
|
||||||
trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
||||||
right_box.append(*trayWidget);
|
right_box.append(*trayWidget);
|
||||||
@@ -83,8 +88,17 @@ void Bar::setup_ui() {
|
|||||||
void Bar::load_css() {
|
void Bar::load_css() {
|
||||||
auto css_provider = Gtk::CssProvider::create();
|
auto css_provider = Gtk::CssProvider::create();
|
||||||
|
|
||||||
const std::string css =
|
std::string css_path = "resources/bar.css";
|
||||||
SystemHelper::read_file_to_string("resources/bar.css");
|
const char *home = std::getenv("HOME");
|
||||||
|
if (home) {
|
||||||
|
std::filesystem::path config_path =
|
||||||
|
std::filesystem::path(home) / ".config/bar/bar.css";
|
||||||
|
if (std::filesystem::exists(config_path)) {
|
||||||
|
css_path = config_path.string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string css = SystemHelper::read_file_to_string(css_path);
|
||||||
css_provider->load_from_data(css);
|
css_provider->load_from_data(css);
|
||||||
|
|
||||||
Gtk::StyleContext::add_provider_for_display(
|
Gtk::StyleContext::add_provider_for_display(
|
||||||
|
|||||||
@@ -14,15 +14,6 @@
|
|||||||
|
|
||||||
#include "helpers/systemHelper.hpp"
|
#include "helpers/systemHelper.hpp"
|
||||||
|
|
||||||
namespace {
|
|
||||||
const char *kMonitorCommand = "hyprctl monitors -j";
|
|
||||||
const char *kWorkspaceCommand = "hyprctl workspaces -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() {
|
||||||
@@ -30,15 +21,35 @@ HyprlandService::~HyprlandService() {
|
|||||||
close(fd);
|
close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// free allocated workspace pointers
|
||||||
|
for (auto &p : this->workspaces) {
|
||||||
|
delete p.second;
|
||||||
|
}
|
||||||
|
this->workspaces.clear();
|
||||||
|
this->monitors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::on_hyprland_event(std::string event,
|
void HyprlandService::on_hyprland_event(std::string event, std::string data) {
|
||||||
std::string /*data*/) {
|
|
||||||
if (is_workspace_event(event) || event == "focusedmon" ||
|
if (event == "urgent") {
|
||||||
event == "monitoradded" || event == "monitorremoved") {
|
onUrgentEvent(data);
|
||||||
refresh_monitors();
|
}
|
||||||
|
|
||||||
|
if (event == "activewindowv2") {
|
||||||
|
onActiveWindowEvent(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event == "workspace" || event == "movewindow") {
|
||||||
refresh_workspaces();
|
refresh_workspaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use for
|
||||||
|
// event == "focusedmon"
|
||||||
|
|
||||||
|
if (event == "monitoradded" || event == "monitorremoved") {
|
||||||
|
refresh_monitors();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::start() {
|
void HyprlandService::start() {
|
||||||
@@ -75,34 +86,41 @@ void HyprlandService::start() {
|
|||||||
Glib::IOCondition::IO_ERR);
|
Glib::IOCondition::IO_ERR);
|
||||||
|
|
||||||
refresh_monitors();
|
refresh_monitors();
|
||||||
refresh_workspaces();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HyprlandService::on_socket_read(Glib::IOCondition condition) {
|
bool HyprlandService::on_socket_read(Glib::IOCondition condition) {
|
||||||
const auto error_mask =
|
const auto error_mask = Glib::IOCondition::IO_HUP | Glib::IOCondition::IO_ERR;
|
||||||
Glib::IOCondition::IO_HUP | Glib::IOCondition::IO_ERR;
|
|
||||||
|
|
||||||
if (static_cast<int>(condition & error_mask) != 0) {
|
if (static_cast<int>(condition & error_mask) != 0) {
|
||||||
std::cerr << "[Hyprland] Socket disconnected." << std::endl;
|
std::cerr << "[Hyprland] Socket disconnected." << std::endl;
|
||||||
close(fd);
|
if (fd != -1) {
|
||||||
fd = -1;
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[4096];
|
char temp_buffer[4096];
|
||||||
const ssize_t bytes_read = read(fd, buffer, sizeof(buffer) - 1);
|
const ssize_t bytes_read = read(fd, temp_buffer, sizeof(temp_buffer));
|
||||||
|
|
||||||
if (bytes_read > 0) {
|
if (bytes_read <= 0) {
|
||||||
buffer[bytes_read] = '\0';
|
// peer closed or error
|
||||||
this->buffer.append(buffer);
|
std::cerr << "[Hyprland] Socket read returned " << bytes_read << std::endl;
|
||||||
|
if (fd != -1) {
|
||||||
size_t pos = 0;
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
while ((pos = this->buffer.find('\n')) != std::string::npos) {
|
|
||||||
const std::string line = this->buffer.substr(0, pos);
|
|
||||||
parse_message(line);
|
|
||||||
this->buffer.erase(0, pos + 1);
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// append exactly bytes_read bytes (may contain embedded nulls)
|
||||||
|
this->socket_buffer.append(temp_buffer, static_cast<size_t>(bytes_read));
|
||||||
|
|
||||||
|
size_t pos = 0;
|
||||||
|
while ((pos = this->socket_buffer.find('\n')) != std::string::npos) {
|
||||||
|
const std::string line = this->socket_buffer.substr(0, pos);
|
||||||
|
parse_message(line);
|
||||||
|
this->socket_buffer.erase(0, pos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -119,7 +137,7 @@ void HyprlandService::parse_message(const std::string &line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string HyprlandService::get_socket_path() {
|
std::string HyprlandService::get_socket_path() {
|
||||||
const char *sig = std::getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
const char *sig = std::getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
||||||
const char *runtime = std::getenv("XDG_RUNTIME_DIR");
|
const char *runtime = std::getenv("XDG_RUNTIME_DIR");
|
||||||
|
|
||||||
if (!sig || !runtime) {
|
if (!sig || !runtime) {
|
||||||
@@ -131,177 +149,94 @@ std::string HyprlandService::get_socket_path() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::refresh_monitors() {
|
void HyprlandService::refresh_monitors() {
|
||||||
std::string output;
|
// free any previously allocated WorkspaceState objects before rebuilding
|
||||||
|
for (auto &p : this->workspaces) {
|
||||||
try {
|
delete p.second;
|
||||||
output = SystemHelper::get_command_output(kMonitorCommand);
|
|
||||||
} catch (const std::exception &ex) {
|
|
||||||
std::cerr << "[Hyprland] Failed to query monitors: " << ex.what()
|
|
||||||
<< std::endl;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
this->workspaces.clear();
|
||||||
|
this->monitors.clear();
|
||||||
|
|
||||||
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
std::string output = SystemHelper::get_command_output(kMonitorCommand);
|
||||||
if (!monitorsJson.is_array()) {
|
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
std::cerr << "[Hyprland] Unexpected monitor payload" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<int, Monitor> updated;
|
|
||||||
|
|
||||||
for (const auto &monitorJson : monitorsJson) {
|
for (const auto &monitorJson : monitorsJson) {
|
||||||
if (!monitorJson.is_object()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
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", "");
|
||||||
monitor.x = monitorJson.value("x", 0);
|
monitor.x = monitorJson.value("x", 0);
|
||||||
monitor.y = monitorJson.value("y", 0);
|
monitor.y = monitorJson.value("y", 0);
|
||||||
|
|
||||||
if (monitorJson.contains("activeWorkspace") &&
|
monitor.focusedWorkspaceId = monitorJson["activeWorkspace"].value("id", -1);
|
||||||
monitorJson["activeWorkspace"].is_object()) {
|
|
||||||
monitor.focusedWorkspaceId =
|
|
||||||
monitorJson["activeWorkspace"].value("id", -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (monitor.id >= 0) {
|
if (monitor.id >= 0) {
|
||||||
updated.emplace(monitor.id, std::move(monitor));
|
this->monitors[monitor.id] = monitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int slot = 1; slot <= HyprlandService::kWorkspaceSlotCount; ++slot) {
|
||||||
|
WorkspaceState wsState;
|
||||||
|
wsState.focused = false;
|
||||||
|
wsState.active = false;
|
||||||
|
wsState.label = std::to_string(slot);
|
||||||
|
wsState.monitorId = monitor.id;
|
||||||
|
|
||||||
|
int id = slot + monitor.id * HyprlandService::kWorkspaceSlotCount;
|
||||||
|
wsState.hyprId = id;
|
||||||
|
this->workspaces[id] = new WorkspaceState(wsState);
|
||||||
|
if (monitor.id >= 0) {
|
||||||
|
this->monitors[monitor.id].workspaceStates[slot] = this->workspaces[id];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
monitors.swap(updated);
|
this->refresh_workspaces();
|
||||||
monitorStateChanged.emit();
|
monitorStateChanged.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called every time when workspace changes have been detected.
|
||||||
|
* Used to Update the internal state for the Workspaces,
|
||||||
|
*/
|
||||||
void HyprlandService::refresh_workspaces() {
|
void HyprlandService::refresh_workspaces() {
|
||||||
if (monitors.empty()) {
|
std::string output = SystemHelper::get_command_output(kWorkspaceCommand);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string output;
|
|
||||||
|
|
||||||
try {
|
|
||||||
output = SystemHelper::get_command_output(kWorkspaceCommand);
|
|
||||||
} catch (const std::exception &ex) {
|
|
||||||
std::cerr << "[Hyprland] Failed to query workspaces: " << ex.what()
|
|
||||||
<< std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto workspacesJson = nlohmann::json::parse(output, nullptr, false);
|
auto workspacesJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
if (!workspacesJson.is_array()) {
|
|
||||||
std::cerr << "[Hyprland] Unexpected workspace payload" << std::endl;
|
for (auto &[id, ws] : this->workspaces) {
|
||||||
return;
|
ws->focused = false;
|
||||||
|
ws->active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &pair : monitors) {
|
output = SystemHelper::get_command_output(kMonitorCommand);
|
||||||
auto &monitor = pair.second;
|
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
monitor.workspaceStates.clear();
|
|
||||||
|
|
||||||
int focusedSlot = -1;
|
for (const auto &monitorJson : monitorsJson) {
|
||||||
if (monitor.focusedWorkspaceId > 0) {
|
const int monitorId = monitorJson.value("id", -1);
|
||||||
focusedSlot = ((monitor.focusedWorkspaceId - 1) %
|
const int focusedWorkspaceId = monitorJson["activeWorkspace"].value("id", -1);
|
||||||
HyprlandService::kWorkspaceSlotCount) +
|
|
||||||
1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int slot = 1; slot <= HyprlandService::kWorkspaceSlotCount;
|
// write into the stored monitor (use reference)
|
||||||
++slot) {
|
auto it = this->monitors.find(monitorId);
|
||||||
WorkspaceState state;
|
if (it != this->monitors.end()) {
|
||||||
state.id = slot;
|
it->second.focusedWorkspaceId = focusedWorkspaceId;
|
||||||
state.hyprId = -1;
|
|
||||||
state.label = std::to_string(slot);
|
|
||||||
state.focused = (slot == focusedSlot);
|
|
||||||
state.active = state.focused;
|
|
||||||
state.urgent = false;
|
|
||||||
monitor.workspaceStates.emplace(slot, state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &workspaceJson : workspacesJson) {
|
for (const auto &workspaceJson : workspacesJson) {
|
||||||
if (!workspaceJson.is_object()) {
|
const int workspaceId = workspaceJson.value("id", -1);
|
||||||
|
auto workspaceStateIt = this->workspaces.find(workspaceId);
|
||||||
|
if (workspaceStateIt == this->workspaces.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int monitorId = workspaceJson.value("monitorID", -1);
|
WorkspaceState *workspaceState = workspaceStateIt->second;
|
||||||
const int workspaceId = workspaceJson.value("id", -1);
|
auto mit = this->monitors.find(workspaceState->monitorId);
|
||||||
|
if (mit != this->monitors.end()) {
|
||||||
auto monitorIt = monitors.find(monitorId);
|
workspaceState->focused = mit->second.focusedWorkspaceId == workspaceId;
|
||||||
if (monitorIt == monitors.end() || workspaceId < 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto &monitor = monitorIt->second;
|
|
||||||
const int slot =
|
|
||||||
((workspaceId - 1) % HyprlandService::kWorkspaceSlotCount) + 1;
|
|
||||||
auto &workspaceState = monitor.workspaceStates[slot];
|
|
||||||
|
|
||||||
workspaceState.id = slot;
|
|
||||||
workspaceState.hyprId = workspaceId;
|
|
||||||
workspaceState.focused = (monitor.focusedWorkspaceId == workspaceId);
|
|
||||||
workspaceState.active =
|
|
||||||
workspaceState.focused || workspaceJson.value("windows", 0) > 0;
|
|
||||||
workspaceState.urgent = false;
|
|
||||||
|
|
||||||
std::string labelCandidate;
|
|
||||||
if (workspaceJson.contains("name") &&
|
|
||||||
workspaceJson["name"].is_string()) {
|
|
||||||
labelCandidate = workspaceJson["name"].get<std::string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (labelCandidate.empty() ||
|
|
||||||
labelCandidate == std::to_string(workspaceId)) {
|
|
||||||
workspaceState.label = std::to_string(slot);
|
|
||||||
} else {
|
} else {
|
||||||
workspaceState.label = labelCandidate;
|
workspaceState->focused = false;
|
||||||
}
|
|
||||||
|
|
||||||
if (workspaceJson.contains("urgent") &&
|
|
||||||
workspaceJson["urgent"].is_boolean()) {
|
|
||||||
workspaceState.urgent = workspaceJson["urgent"].get<bool>();
|
|
||||||
} else if (workspaceJson.contains("hasurgent") &&
|
|
||||||
workspaceJson["hasurgent"].is_boolean()) {
|
|
||||||
workspaceState.urgent = workspaceJson["hasurgent"].get<bool>();
|
|
||||||
}
|
}
|
||||||
|
workspaceState->active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &pair : monitors) {
|
workspaceStateChanged.emit();
|
||||||
workspaceStateChanged.emit(pair.first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
||||||
@@ -316,14 +251,113 @@ void HyprlandService::switchToWorkspace(int workspaceId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const HyprlandService::Monitor *
|
void HyprlandService::onUrgentEvent(std::string windowAddress) {
|
||||||
HyprlandService::getMonitorByIndex(std::size_t index) const {
|
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"].value("id", -1);
|
||||||
|
|
||||||
|
auto it = this->workspaces.find(workspaceId);
|
||||||
|
if (it != this->workspaces.end() && it->second) {
|
||||||
|
|
||||||
|
if (std::find(it->second->urgentWindows.begin(),
|
||||||
|
it->second->urgentWindows.end(), windowAddress) ==
|
||||||
|
it->second->urgentWindows.end()) {
|
||||||
|
it->second->urgentWindows.push_back(windowAddress);
|
||||||
|
workspaceStateChanged.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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"];
|
||||||
|
auto it = this->workspaces.find(workspaceId);
|
||||||
|
if (it != this->workspaces.end() && it->second) {
|
||||||
|
WorkspaceState *ws = it->second;
|
||||||
|
auto uit = std::find(ws->urgentWindows.begin(), ws->urgentWindows.end(), windowAddress);
|
||||||
|
if (uit != ws->urgentWindows.end()) {
|
||||||
|
ws->urgentWindows.erase(uit);
|
||||||
|
workspaceStateChanged.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HyprlandService::printMonitor(const Monitor &mon) const {
|
||||||
|
std::cout << "=== Monitor Info ===\n";
|
||||||
|
std::cout << "Name: " << mon.name << " (ID: " << mon.id << ")\n";
|
||||||
|
std::cout << "Position: (" << mon.x << ", " << mon.y << ")\n";
|
||||||
|
std::cout << "Focused Workspace ID: " << mon.focusedWorkspaceId << "\n";
|
||||||
|
|
||||||
|
std::cout << "Workspaces:\n";
|
||||||
|
|
||||||
|
if (mon.workspaceStates.empty()) {
|
||||||
|
std::cout << " (None)\n";
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int slot = 1; slot <= HyprlandService::kWorkspaceSlotCount; ++slot) {
|
||||||
|
const auto it = mon.workspaceStates.find(slot);
|
||||||
|
if (it == mon.workspaceStates.end()) {
|
||||||
|
std::cout << " - [Slot: " << slot << " | HyprID: n/a]"
|
||||||
|
<< " Label: <none> | Active: No | Focused: No | "
|
||||||
|
"Urgent: No\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const WorkspaceState *ws = it->second;
|
||||||
|
std::cout << " - [HyprID: "
|
||||||
|
<< (ws->hyprId >= 0 ? std::to_string(ws->hyprId)
|
||||||
|
: std::string("n/a"))
|
||||||
|
<< "] "
|
||||||
|
<< "Label: " << (ws->label.empty() ? "<none>" : ws->label)
|
||||||
|
<< " | "
|
||||||
|
<< "Active: " << (ws->active ? "Yes" : "No") << " | "
|
||||||
|
<< "Focused: " << (ws->focused ? "Yes" : "No") << " | "
|
||||||
|
<< "Urgent: " << (ws->urgentWindows.size() > 0 ? "Yes" : "No")
|
||||||
|
<< "\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()) {
|
if (index >= monitors.size()) {
|
||||||
throw std::runtime_error("Monitor index out of bounds: " +
|
throw std::runtime_error("Monitor index out of bounds: " + std::to_string(index));
|
||||||
std::to_string(index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = monitors.begin();
|
auto it = monitors.begin();
|
||||||
std::advance(it, static_cast<long>(index));
|
std::advance(it, static_cast<long>(index));
|
||||||
|
|
||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,12 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr const char *kWatcherBusName = "org.kde.StatusNotifierWatcher";
|
constexpr const char *kWatcherBusName = "org.kde.StatusNotifierWatcher";
|
||||||
constexpr const char *kWatcherObjectPath = "/StatusNotifierWatcher";
|
constexpr const char *kWatcherObjectPath = "/StatusNotifierWatcher";
|
||||||
constexpr const char *kWatcherInterface = "org.kde.StatusNotifierWatcher";
|
constexpr const char *kWatcherInterface = "org.kde.StatusNotifierWatcher";
|
||||||
constexpr const char *kItemInterface = "org.kde.StatusNotifierItem";
|
constexpr const char *kItemInterface = "org.kde.StatusNotifierItem";
|
||||||
constexpr const char *kDBusPropertiesIface = "org.freedesktop.DBus.Properties";
|
constexpr const char *kDBusPropertiesIface = "org.freedesktop.DBus.Properties";
|
||||||
constexpr const char *kDBusMenuInterface = "com.canonical.dbusmenu";
|
constexpr const char *kDBusMenuInterface = "com.canonical.dbusmenu";
|
||||||
|
|
||||||
const char *kWatcherIntrospection =
|
const char *kWatcherIntrospection =
|
||||||
R"(<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
R"(<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||||
@@ -55,25 +55,25 @@ ParsedService parse_service_identifier(const Glib::ustring &sender,
|
|||||||
ParsedService parsed;
|
ParsedService parsed;
|
||||||
|
|
||||||
if (service.empty()) {
|
if (service.empty()) {
|
||||||
parsed.busName = sender;
|
parsed.busName = sender;
|
||||||
parsed.objectPath = "/StatusNotifierItem";
|
parsed.objectPath = "/StatusNotifierItem";
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (service.front() == '/') {
|
if (service.front() == '/') {
|
||||||
parsed.busName = sender;
|
parsed.busName = sender;
|
||||||
parsed.objectPath = service;
|
parsed.objectPath = service;
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto slash = service.find('/');
|
const auto slash = service.find('/');
|
||||||
if (slash == std::string::npos) {
|
if (slash == std::string::npos) {
|
||||||
parsed.busName = service;
|
parsed.busName = service;
|
||||||
parsed.objectPath = "/StatusNotifierItem";
|
parsed.objectPath = "/StatusNotifierItem";
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed.busName = service.substr(0, slash);
|
parsed.busName = service.substr(0, slash);
|
||||||
parsed.objectPath = service.substr(slash);
|
parsed.objectPath = service.substr(slash);
|
||||||
|
|
||||||
if (parsed.busName.empty()) {
|
if (parsed.busName.empty()) {
|
||||||
@@ -90,8 +90,8 @@ ParsedService parse_service_identifier(const Glib::ustring &sender,
|
|||||||
GVariant *create_property_list_variant() {
|
GVariant *create_property_list_variant() {
|
||||||
GVariantBuilder builder;
|
GVariantBuilder builder;
|
||||||
g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));
|
g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));
|
||||||
const char *properties[] = {"label", "label-markup", "enabled",
|
const char *properties[] = {"label", "label-markup", "enabled",
|
||||||
"visible", "children-display", "type",
|
"visible", "children-display", "type",
|
||||||
"toggle-type", "toggle-state"};
|
"toggle-type", "toggle-state"};
|
||||||
for (const char *prop : properties) {
|
for (const char *prop : properties) {
|
||||||
g_variant_builder_add(&builder, "s", prop);
|
g_variant_builder_add(&builder, "s", prop);
|
||||||
@@ -106,7 +106,7 @@ void call_about_to_show(const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
GVariant *result = g_dbus_connection_call_sync(
|
GVariant *result = g_dbus_connection_call_sync(
|
||||||
connection->gobj(), busName.c_str(), menuPath.c_str(),
|
connection->gobj(), busName.c_str(), menuPath.c_str(),
|
||||||
kDBusMenuInterface, "AboutToShow", g_variant_new("(i)", id), nullptr,
|
kDBusMenuInterface, "AboutToShow", g_variant_new("(i)", id), nullptr,
|
||||||
@@ -137,7 +137,7 @@ GVariant *call_get_layout(const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
|||||||
GVariant *params = g_variant_new("(ii@as)", 0, -1, properties);
|
GVariant *params = g_variant_new("(ii@as)", 0, -1, properties);
|
||||||
g_variant_ref_sink(properties);
|
g_variant_ref_sink(properties);
|
||||||
|
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
GVariant *result = g_dbus_connection_call_sync(
|
GVariant *result = g_dbus_connection_call_sync(
|
||||||
connection->gobj(), busName.c_str(), menuPath.c_str(),
|
connection->gobj(), busName.c_str(), menuPath.c_str(),
|
||||||
kDBusMenuInterface, "GetLayout", params, nullptr,
|
kDBusMenuInterface, "GetLayout", params, nullptr,
|
||||||
@@ -174,15 +174,15 @@ void parse_menu_node(GVariant *tuple, TrayService::MenuNode &outNode) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
GVariant *propsVariant = nullptr;
|
GVariant *propsVariant = nullptr;
|
||||||
GVariant *childrenVariant = nullptr;
|
GVariant *childrenVariant = nullptr;
|
||||||
|
|
||||||
g_variant_get(tuple, "(i@a{sv}@av)", &id, &propsVariant, &childrenVariant);
|
g_variant_get(tuple, "(i@a{sv}@av)", &id, &propsVariant, &childrenVariant);
|
||||||
|
|
||||||
outNode.id = id;
|
outNode.id = id;
|
||||||
outNode.enabled = true;
|
outNode.enabled = true;
|
||||||
outNode.visible = true;
|
outNode.visible = true;
|
||||||
outNode.separator = false;
|
outNode.separator = false;
|
||||||
outNode.label.clear();
|
outNode.label.clear();
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ void parse_menu_node(GVariant *tuple, TrayService::MenuNode &outNode) {
|
|||||||
GVariantIter iter;
|
GVariantIter iter;
|
||||||
g_variant_iter_init(&iter, propsVariant);
|
g_variant_iter_init(&iter, propsVariant);
|
||||||
const gchar *key = nullptr;
|
const gchar *key = nullptr;
|
||||||
GVariant *value = nullptr;
|
GVariant *value = nullptr;
|
||||||
|
|
||||||
while (g_variant_iter_next(&iter, "{sv}", &key, &value)) {
|
while (g_variant_iter_next(&iter, "{sv}", &key, &value)) {
|
||||||
if (!key || !value) {
|
if (!key || !value) {
|
||||||
@@ -214,13 +214,13 @@ void parse_menu_node(GVariant *tuple, TrayService::MenuNode &outNode) {
|
|||||||
if (std::strcmp(key, "label") == 0) {
|
if (std::strcmp(key, "label") == 0) {
|
||||||
if (g_variant_is_of_type(unboxed, G_VARIANT_TYPE_STRING)) {
|
if (g_variant_is_of_type(unboxed, G_VARIANT_TYPE_STRING)) {
|
||||||
const gchar *str = g_variant_get_string(unboxed, nullptr);
|
const gchar *str = g_variant_get_string(unboxed, nullptr);
|
||||||
outNode.label = str ? str : "";
|
outNode.label = str ? str : "";
|
||||||
}
|
}
|
||||||
} else if (std::strcmp(key, "label-markup") == 0 &&
|
} else if (std::strcmp(key, "label-markup") == 0 &&
|
||||||
outNode.label.empty()) {
|
outNode.label.empty()) {
|
||||||
if (g_variant_is_of_type(unboxed, G_VARIANT_TYPE_STRING)) {
|
if (g_variant_is_of_type(unboxed, G_VARIANT_TYPE_STRING)) {
|
||||||
const gchar *str = g_variant_get_string(unboxed, nullptr);
|
const gchar *str = g_variant_get_string(unboxed, nullptr);
|
||||||
outNode.label = str ? str : "";
|
outNode.label = str ? str : "";
|
||||||
}
|
}
|
||||||
} else if (std::strcmp(key, "enabled") == 0) {
|
} else if (std::strcmp(key, "enabled") == 0) {
|
||||||
if (g_variant_is_of_type(unboxed, G_VARIANT_TYPE_BOOLEAN)) {
|
if (g_variant_is_of_type(unboxed, G_VARIANT_TYPE_BOOLEAN)) {
|
||||||
@@ -362,7 +362,7 @@ void TrayService::activate(const std::string &id, int32_t x, int32_t y) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
GVariant *result = g_dbus_connection_call_sync(
|
GVariant *result = g_dbus_connection_call_sync(
|
||||||
connection->gobj(), it->second->publicData.busName.c_str(),
|
connection->gobj(), it->second->publicData.busName.c_str(),
|
||||||
it->second->publicData.objectPath.c_str(), kItemInterface, "Activate",
|
it->second->publicData.objectPath.c_str(), kItemInterface, "Activate",
|
||||||
@@ -387,7 +387,7 @@ void TrayService::secondaryActivate(const std::string &id, int32_t x,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
GVariant *result = g_dbus_connection_call_sync(
|
GVariant *result = g_dbus_connection_call_sync(
|
||||||
connection->gobj(), it->second->publicData.busName.c_str(),
|
connection->gobj(), it->second->publicData.busName.c_str(),
|
||||||
it->second->publicData.objectPath.c_str(), kItemInterface,
|
it->second->publicData.objectPath.c_str(), kItemInterface,
|
||||||
@@ -411,7 +411,7 @@ void TrayService::contextMenu(const std::string &id, int32_t x, int32_t y) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
GVariant *result = g_dbus_connection_call_sync(
|
GVariant *result = g_dbus_connection_call_sync(
|
||||||
connection->gobj(), it->second->publicData.busName.c_str(),
|
connection->gobj(), it->second->publicData.busName.c_str(),
|
||||||
it->second->publicData.objectPath.c_str(), kItemInterface,
|
it->second->publicData.objectPath.c_str(), kItemInterface,
|
||||||
@@ -566,7 +566,7 @@ bool TrayService::activate_menu_item(const std::string &id, int itemId) {
|
|||||||
"(isvu)", itemId, "clicked", g_variant_new_variant(emptyData),
|
"(isvu)", itemId, "clicked", g_variant_new_variant(emptyData),
|
||||||
static_cast<guint32>(g_get_monotonic_time() / 1000));
|
static_cast<guint32>(g_get_monotonic_time() / 1000));
|
||||||
|
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
GVariant *result = g_dbus_connection_call_sync(
|
GVariant *result = g_dbus_connection_call_sync(
|
||||||
connection->gobj(), item.publicData.busName.c_str(),
|
connection->gobj(), item.publicData.busName.c_str(),
|
||||||
item.publicData.menuPath.c_str(), kDBusMenuInterface, "Event", params,
|
item.publicData.menuPath.c_str(), kDBusMenuInterface, "Event", params,
|
||||||
@@ -723,16 +723,16 @@ void TrayService::register_item(const Glib::ustring &sender,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::string id = parsed.busName + parsed.objectPath;
|
const std::string id = parsed.busName + parsed.objectPath;
|
||||||
auto existing = items.find(id);
|
auto existing = items.find(id);
|
||||||
if (existing != items.end()) {
|
if (existing != items.end()) {
|
||||||
refresh_item(*existing->second);
|
refresh_item(*existing->second);
|
||||||
itemUpdatedSignal.emit(existing->second->publicData);
|
itemUpdatedSignal.emit(existing->second->publicData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto item = std::make_unique<TrackedItem>();
|
auto item = std::make_unique<TrackedItem>();
|
||||||
item->publicData.id = id;
|
item->publicData.id = id;
|
||||||
item->publicData.busName = parsed.busName;
|
item->publicData.busName = parsed.busName;
|
||||||
item->publicData.objectPath = parsed.objectPath;
|
item->publicData.objectPath = parsed.objectPath;
|
||||||
|
|
||||||
refresh_item(*item);
|
refresh_item(*item);
|
||||||
@@ -789,7 +789,7 @@ void TrayService::refresh_item(TrackedItem &item) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
GVariant *reply = g_dbus_connection_call_sync(
|
GVariant *reply = g_dbus_connection_call_sync(
|
||||||
connection->gobj(), item.publicData.busName.c_str(),
|
connection->gobj(), item.publicData.busName.c_str(),
|
||||||
item.publicData.objectPath.c_str(), kDBusPropertiesIface, "GetAll",
|
item.publicData.objectPath.c_str(), kDBusPropertiesIface, "GetAll",
|
||||||
@@ -816,7 +816,7 @@ void TrayService::refresh_item(TrackedItem &item) {
|
|||||||
g_variant_iter_init(&iter, dictVariant);
|
g_variant_iter_init(&iter, dictVariant);
|
||||||
|
|
||||||
const gchar *key = nullptr;
|
const gchar *key = nullptr;
|
||||||
GVariant *value = nullptr;
|
GVariant *value = nullptr;
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Paintable> iconTexture;
|
Glib::RefPtr<Gdk::Paintable> iconTexture;
|
||||||
Glib::RefPtr<Gdk::Paintable> attentionTexture;
|
Glib::RefPtr<Gdk::Paintable> attentionTexture;
|
||||||
@@ -836,23 +836,23 @@ void TrayService::refresh_item(TrackedItem &item) {
|
|||||||
|
|
||||||
if (std::strcmp(key, "Title") == 0) {
|
if (std::strcmp(key, "Title") == 0) {
|
||||||
const gchar *str = g_variant_get_string(value, nullptr);
|
const gchar *str = g_variant_get_string(value, nullptr);
|
||||||
title = str ? str : "";
|
title = str ? str : "";
|
||||||
} else if (std::strcmp(key, "Status") == 0) {
|
} else if (std::strcmp(key, "Status") == 0) {
|
||||||
const gchar *str = g_variant_get_string(value, nullptr);
|
const gchar *str = g_variant_get_string(value, nullptr);
|
||||||
status = str ? str : "";
|
status = str ? str : "";
|
||||||
} else if (std::strcmp(key, "Menu") == 0) {
|
} else if (std::strcmp(key, "Menu") == 0) {
|
||||||
if (g_variant_is_of_type(value, G_VARIANT_TYPE_OBJECT_PATH)) {
|
if (g_variant_is_of_type(value, G_VARIANT_TYPE_OBJECT_PATH)) {
|
||||||
const gchar *str = g_variant_get_string(value, nullptr);
|
const gchar *str = g_variant_get_string(value, nullptr);
|
||||||
menuPath = str ? str : "";
|
menuPath = str ? str : "";
|
||||||
} else {
|
} else {
|
||||||
const gchar *str = g_variant_get_string(value, nullptr);
|
const gchar *str = g_variant_get_string(value, nullptr);
|
||||||
menuPath = str ? str : "";
|
menuPath = str ? str : "";
|
||||||
}
|
}
|
||||||
} else if (std::strcmp(key, "IconName") == 0) {
|
} else if (std::strcmp(key, "IconName") == 0) {
|
||||||
const gchar *str = g_variant_get_string(value, nullptr);
|
const gchar *str = g_variant_get_string(value, nullptr);
|
||||||
iconName = str ? str : "";
|
iconName = str ? str : "";
|
||||||
} else if (std::strcmp(key, "AttentionIconName") == 0) {
|
} else if (std::strcmp(key, "AttentionIconName") == 0) {
|
||||||
const gchar *str = g_variant_get_string(value, nullptr);
|
const gchar *str = g_variant_get_string(value, nullptr);
|
||||||
attentionIconName = str ? str : "";
|
attentionIconName = str ? str : "";
|
||||||
} else if (std::strcmp(key, "IconPixmap") == 0) {
|
} else if (std::strcmp(key, "IconPixmap") == 0) {
|
||||||
iconTexture = parse_icon_pixmap(value);
|
iconTexture = parse_icon_pixmap(value);
|
||||||
@@ -864,10 +864,10 @@ void TrayService::refresh_item(TrackedItem &item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_variant_unref(dictVariant);
|
g_variant_unref(dictVariant);
|
||||||
const bool menuPathChanged = (item.publicData.menuPath != menuPath);
|
const bool menuPathChanged = (item.publicData.menuPath != menuPath);
|
||||||
item.publicData.title = title;
|
item.publicData.title = title;
|
||||||
item.publicData.status = status;
|
item.publicData.status = status;
|
||||||
item.publicData.menuPath = menuPath;
|
item.publicData.menuPath = menuPath;
|
||||||
item.publicData.menuAvailable = !menuPath.empty();
|
item.publicData.menuAvailable = !menuPath.empty();
|
||||||
|
|
||||||
if (menuPathChanged || !item.publicData.menuAvailable) {
|
if (menuPathChanged || !item.publicData.menuAvailable) {
|
||||||
@@ -1029,7 +1029,7 @@ Glib::RefPtr<Gdk::Paintable> TrayService::parse_icon_pixmap(GVariant *variant) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t width = 0;
|
int32_t width = 0;
|
||||||
int32_t height = 0;
|
int32_t height = 0;
|
||||||
g_variant_get_child(entry, 0, "i", &width);
|
g_variant_get_child(entry, 0, "i", &width);
|
||||||
g_variant_get_child(entry, 1, "i", &height);
|
g_variant_get_child(entry, 1, "i", &height);
|
||||||
@@ -1045,7 +1045,7 @@ Glib::RefPtr<Gdk::Paintable> TrayService::parse_icon_pixmap(GVariant *variant) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
gsize rawLength = 0;
|
gsize rawLength = 0;
|
||||||
const guint8 *rawBytes = static_cast<const guint8 *>(
|
const guint8 *rawBytes = static_cast<const guint8 *>(
|
||||||
g_variant_get_fixed_array(bytesVariant, &rawLength, sizeof(guint8)));
|
g_variant_get_fixed_array(bytesVariant, &rawLength, sizeof(guint8)));
|
||||||
if (!rawBytes || rawLength < static_cast<gsize>(width * height * 4)) {
|
if (!rawBytes || rawLength < static_cast<gsize>(width * height * 4)) {
|
||||||
@@ -1062,16 +1062,16 @@ Glib::RefPtr<Gdk::Paintable> TrayService::parse_icon_pixmap(GVariant *variant) {
|
|||||||
const guint32 *pixels = reinterpret_cast<const guint32 *>(rawBytes);
|
const guint32 *pixels = reinterpret_cast<const guint32 *>(rawBytes);
|
||||||
for (std::size_t idx = 0; idx < pixelCount; ++idx) {
|
for (std::size_t idx = 0; idx < pixelCount; ++idx) {
|
||||||
const guint32 pixel = pixels[idx];
|
const guint32 pixel = pixels[idx];
|
||||||
const guint8 a = static_cast<guint8>((pixel >> 24) & 0xFF);
|
const guint8 a = static_cast<guint8>((pixel >> 24) & 0xFF);
|
||||||
const guint8 r = static_cast<guint8>((pixel >> 16) & 0xFF);
|
const guint8 r = static_cast<guint8>((pixel >> 16) & 0xFF);
|
||||||
const guint8 g = static_cast<guint8>((pixel >> 8) & 0xFF);
|
const guint8 g = static_cast<guint8>((pixel >> 8) & 0xFF);
|
||||||
const guint8 b = static_cast<guint8>(pixel & 0xFF);
|
const guint8 b = static_cast<guint8>(pixel & 0xFF);
|
||||||
|
|
||||||
const std::size_t base = idx * 4;
|
const std::size_t base = idx * 4;
|
||||||
rgba[base + 0] = r;
|
rgba[base + 0] = r;
|
||||||
rgba[base + 1] = g;
|
rgba[base + 1] = g;
|
||||||
rgba[base + 2] = b;
|
rgba[base + 2] = b;
|
||||||
rgba[base + 3] = a;
|
rgba[base + 3] = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pixbuf =
|
auto pixbuf =
|
||||||
@@ -1082,9 +1082,9 @@ Glib::RefPtr<Gdk::Paintable> TrayService::parse_icon_pixmap(GVariant *variant) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *dest = pixbuf->get_pixels();
|
auto *dest = pixbuf->get_pixels();
|
||||||
const int destRowstride = pixbuf->get_rowstride();
|
const int destRowstride = pixbuf->get_rowstride();
|
||||||
const int srcRowstride = width * 4;
|
const int srcRowstride = width * 4;
|
||||||
|
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
std::memcpy(dest + y * destRowstride,
|
std::memcpy(dest + y * destRowstride,
|
||||||
|
|||||||
16
src/widgets/date.cpp
Normal file
16
src/widgets/date.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "widgets/date.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
bool Date::onUpdate() {
|
||||||
|
auto now =
|
||||||
|
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::put_time(std::localtime(&now), "%a, %d.%m.%Y");
|
||||||
|
|
||||||
|
set_text(ss.str());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ TrayIconWidget::TrayIconWidget(TrayService &service, std::string id)
|
|||||||
set_focusable(false);
|
set_focusable(false);
|
||||||
set_valign(Gtk::Align::CENTER);
|
set_valign(Gtk::Align::CENTER);
|
||||||
set_halign(Gtk::Align::CENTER);
|
set_halign(Gtk::Align::CENTER);
|
||||||
|
add_css_class("tray-icon");
|
||||||
|
|
||||||
picture.set_halign(Gtk::Align::CENTER);
|
picture.set_halign(Gtk::Align::CENTER);
|
||||||
picture.set_valign(Gtk::Align::CENTER);
|
picture.set_valign(Gtk::Align::CENTER);
|
||||||
@@ -98,8 +99,8 @@ void TrayIconWidget::on_secondary_released(int /*n_press*/, double x,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingX = x;
|
pendingX = x;
|
||||||
pendingY = y;
|
pendingY = y;
|
||||||
menuPopupPending = true;
|
menuPopupPending = true;
|
||||||
try_popup();
|
try_popup();
|
||||||
}
|
}
|
||||||
@@ -124,7 +125,7 @@ bool TrayIconWidget::ensure_menu() {
|
|||||||
|
|
||||||
const auto &layout = *layoutOpt;
|
const auto &layout = *layoutOpt;
|
||||||
|
|
||||||
auto menu = Gio::Menu::create();
|
auto menu = Gio::Menu::create();
|
||||||
auto actions = Gio::SimpleActionGroup::create();
|
auto actions = Gio::SimpleActionGroup::create();
|
||||||
|
|
||||||
populate_menu_items(layout.children, menu, actions);
|
populate_menu_items(layout.children, menu, actions);
|
||||||
@@ -137,7 +138,7 @@ bool TrayIconWidget::ensure_menu() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
menuModel = menu;
|
menuModel = menu;
|
||||||
menuActions = actions;
|
menuActions = actions;
|
||||||
|
|
||||||
if (!menuPopover) {
|
if (!menuPopover) {
|
||||||
|
|||||||
@@ -17,15 +17,10 @@ VolumeWidget::VolumeWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
|||||||
|
|
||||||
append(label);
|
append(label);
|
||||||
|
|
||||||
// Click toggles mute using wpctl
|
|
||||||
click = Gtk::GestureClick::create();
|
click = Gtk::GestureClick::create();
|
||||||
click->set_button(GDK_BUTTON_PRIMARY);
|
click->set_button(GDK_BUTTON_PRIMARY);
|
||||||
// signal_released provides (int, double, double) — use lambda to ignore
|
click->signal_released().connect([this](int, double, double) {
|
||||||
// args
|
|
||||||
click->signal_released().connect([this](int /*n_press*/, double /*x*/,
|
|
||||||
double /*y*/) {
|
|
||||||
try {
|
try {
|
||||||
// Toggle mute then refresh
|
|
||||||
(void)SystemHelper::get_command_output(
|
(void)SystemHelper::get_command_output(
|
||||||
"wpctl set-mute @DEFAULT_SINK@ toggle");
|
"wpctl set-mute @DEFAULT_SINK@ toggle");
|
||||||
} catch (const std::exception &ex) {
|
} catch (const std::exception &ex) {
|
||||||
@@ -34,19 +29,17 @@ VolumeWidget::VolumeWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
|||||||
}
|
}
|
||||||
this->update();
|
this->update();
|
||||||
});
|
});
|
||||||
add_controller(click);
|
|
||||||
|
|
||||||
// Initial read
|
add_controller(click);
|
||||||
update();
|
update();
|
||||||
|
|
||||||
// Start polling every 1 second to keep the display up to date
|
this->timeoutConn = Glib::signal_timeout().connect(
|
||||||
timeoutConn = Glib::signal_timeout().connect(
|
|
||||||
sigc::mem_fun(*this, &VolumeWidget::on_timeout), 100);
|
sigc::mem_fun(*this, &VolumeWidget::on_timeout), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
VolumeWidget::~VolumeWidget() {
|
VolumeWidget::~VolumeWidget() {
|
||||||
if (timeoutConn.connected())
|
if (this->timeoutConn.connected())
|
||||||
timeoutConn.disconnect();
|
this->timeoutConn.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VolumeWidget::update() {
|
void VolumeWidget::update() {
|
||||||
@@ -54,18 +47,16 @@ void VolumeWidget::update() {
|
|||||||
const std::string out =
|
const std::string out =
|
||||||
SystemHelper::get_command_output("wpctl get-volume @DEFAULT_SINK@");
|
SystemHelper::get_command_output("wpctl get-volume @DEFAULT_SINK@");
|
||||||
|
|
||||||
// Attempt to parse a number (percentage or fraction)
|
|
||||||
std::smatch m;
|
std::smatch m;
|
||||||
std::regex r_percent(R"((\d+(?:\.\d+)?)%)");
|
std::regex r_percent(R"((\d+(?:\.\d+)?)%)");
|
||||||
std::regex r_number(R"((\d+(?:\.\d+)?))");
|
std::regex r_number(R"((\d+(?:\.\d+)?))");
|
||||||
|
|
||||||
std::string text = out;
|
std::string text = out;
|
||||||
int percent = -1;
|
int percent = -1;
|
||||||
|
|
||||||
if (std::regex_search(text, m, r_percent)) {
|
if (std::regex_search(text, m, r_percent)) {
|
||||||
percent = static_cast<int>(std::round(std::stod(m[1].str())));
|
percent = static_cast<int>(std::round(std::stod(m[1].str())));
|
||||||
} else if (std::regex_search(text, m, r_number)) {
|
} else if (std::regex_search(text, m, r_number)) {
|
||||||
// If number looks like 0.8 treat as fraction
|
|
||||||
const double v = std::stod(m[1].str());
|
const double v = std::stod(m[1].str());
|
||||||
if (v <= 1.0)
|
if (v <= 1.0)
|
||||||
percent = static_cast<int>(std::round(v * 100.0));
|
percent = static_cast<int>(std::round(v * 100.0));
|
||||||
@@ -76,7 +67,6 @@ void VolumeWidget::update() {
|
|||||||
if (percent >= 0) {
|
if (percent >= 0) {
|
||||||
label.set_text(std::to_string(percent) + "%");
|
label.set_text(std::to_string(percent) + "%");
|
||||||
} else {
|
} else {
|
||||||
// Fallback to raw output (trimmed)
|
|
||||||
auto pos = text.find_first_not_of(" \t\n\r");
|
auto pos = text.find_first_not_of(" \t\n\r");
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
auto end = text.find_last_not_of(" \t\n\r");
|
auto end = text.find_last_not_of(" \t\n\r");
|
||||||
@@ -94,5 +84,6 @@ void VolumeWidget::update() {
|
|||||||
|
|
||||||
bool VolumeWidget::on_timeout() {
|
bool VolumeWidget::on_timeout() {
|
||||||
update();
|
update();
|
||||||
|
|
||||||
return true; // keep timeout active
|
return true; // keep timeout active
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
#include "widgets/webWidget.hpp"
|
#include "widgets/webWidget.hpp"
|
||||||
#include <gtkmm/box.h>
|
#include <gtkmm/box.h>
|
||||||
|
#include <gtkmm/label.h>
|
||||||
#include <webkit/webkit.h>
|
#include <webkit/webkit.h>
|
||||||
|
|
||||||
WebWidget::WebWidget(std::string label, std::string title, std::string url) {
|
WebWidget::WebWidget(std::string icon, std::string title, std::string url) {
|
||||||
set_label(label);
|
auto label = Gtk::make_managed<Gtk::Label>(icon);
|
||||||
|
label->add_css_class("icon-label");
|
||||||
|
set_child(*label);
|
||||||
|
|
||||||
signal_clicked().connect(
|
signal_clicked().connect(
|
||||||
sigc::mem_fun(*this, &WebWidget::on_toggle_window));
|
sigc::mem_fun(*this, &WebWidget::on_toggle_window));
|
||||||
|
|
||||||
@@ -23,12 +27,10 @@ WebWidget::WebWidget(std::string label, std::string title, std::string url) {
|
|||||||
|
|
||||||
auto settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview));
|
auto settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview));
|
||||||
webkit_settings_set_hardware_acceleration_policy(
|
webkit_settings_set_hardware_acceleration_policy(
|
||||||
settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS);
|
settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER);
|
||||||
|
|
||||||
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), url.c_str());
|
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), url.c_str());
|
||||||
|
|
||||||
// Use C API to set child because we don't have a C++ wrapper for
|
|
||||||
// WebKitWebView
|
|
||||||
gtk_popover_set_child(popover->gobj(), webview);
|
gtk_popover_set_child(popover->gobj(), webview);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "widgets/workspaceIndicator.hpp"
|
#include "widgets/workspaceIndicator.hpp"
|
||||||
|
#include "services/hyprland.hpp"
|
||||||
|
|
||||||
#include <exception>
|
#include <cassert>
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
#include <gtkmm/gestureclick.h>
|
#include <gtkmm/gestureclick.h>
|
||||||
#include <gtkmm/widget.h>
|
#include <gtkmm/widget.h>
|
||||||
@@ -17,6 +18,25 @@ WorkspaceIndicator::WorkspaceIndicator(HyprlandService &service, int monitorId)
|
|||||||
monitorConnection = service.monitorStateChanged.connect(
|
monitorConnection = service.monitorStateChanged.connect(
|
||||||
sigc::mem_fun(*this, &WorkspaceIndicator::on_monitor_update));
|
sigc::mem_fun(*this, &WorkspaceIndicator::on_monitor_update));
|
||||||
|
|
||||||
|
for (int i = 1; i <= HyprlandService::kWorkspaceSlotCount; ++i) {
|
||||||
|
auto label = Gtk::make_managed<Gtk::Label>(std::to_string(i));
|
||||||
|
label->add_css_class("workspace-pill");
|
||||||
|
|
||||||
|
// create and store a gesture controller once to avoid duplicate handlers
|
||||||
|
auto gesture = Gtk::GestureClick::create();
|
||||||
|
gesture->set_button(GDK_BUTTON_PRIMARY);
|
||||||
|
gesture->signal_released().connect(
|
||||||
|
[this, i](int, double, double) {
|
||||||
|
this->service.switchToWorkspace(
|
||||||
|
i + this->monitorId * HyprlandService::kWorkspaceSlotCount);
|
||||||
|
});
|
||||||
|
label->add_controller(gesture);
|
||||||
|
workspaceGestures[i] = gesture;
|
||||||
|
|
||||||
|
workspaceLabels[i] = label;
|
||||||
|
append(*label);
|
||||||
|
}
|
||||||
|
|
||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,77 +50,34 @@ WorkspaceIndicator::~WorkspaceIndicator() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorkspaceIndicator::on_workspace_update(int monitorId) {
|
void WorkspaceIndicator::on_workspace_update() {
|
||||||
if (monitorId != monitorId && monitorId != -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorkspaceIndicator::on_monitor_update() { rebuild(); }
|
void WorkspaceIndicator::on_monitor_update() { rebuild(); }
|
||||||
|
|
||||||
|
void WorkspaceIndicator::refreshLabel(Gtk::Label *label, const HyprlandService::WorkspaceState &state) {
|
||||||
|
label->remove_css_class("workspace-pill-active");
|
||||||
|
label->remove_css_class("workspace-pill-focused");
|
||||||
|
label->remove_css_class("workspace-pill-urgent");
|
||||||
|
|
||||||
|
// controller created once in constructor and reused
|
||||||
|
if (state.urgentWindows.size() > 0) {
|
||||||
|
label->add_css_class("workspace-pill-urgent");
|
||||||
|
} else {
|
||||||
|
if (state.focused) {
|
||||||
|
label->add_css_class("workspace-pill-focused");
|
||||||
|
} else if (state.active) {
|
||||||
|
label->add_css_class("workspace-pill-active");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WorkspaceIndicator::rebuild() {
|
void WorkspaceIndicator::rebuild() {
|
||||||
clear_children();
|
HyprlandService::Monitor *mon = service.getMonitorById(this->monitorId);
|
||||||
|
|
||||||
HyprlandService::Monitor *monitor = nullptr;
|
for (auto [id, workspaceState] : mon->workspaceStates) {
|
||||||
try {
|
Gtk::Label *label = workspaceLabels[id];
|
||||||
monitor = service.getMonitorById(monitorId);
|
this->refreshLabel(label, *workspaceState);
|
||||||
} catch (const std::exception &) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (monitor == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int workspaceId = 1;
|
|
||||||
workspaceId <= HyprlandService::kWorkspaceSlotCount; ++workspaceId) {
|
|
||||||
const HyprlandService::WorkspaceState *state = nullptr;
|
|
||||||
auto it = monitor->workspaceStates.find(workspaceId);
|
|
||||||
|
|
||||||
if (it != monitor->workspaceStates.end()) {
|
|
||||||
state = &it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string display = (state && !state->label.empty())
|
|
||||||
? state->label
|
|
||||||
: std::to_string(workspaceId);
|
|
||||||
|
|
||||||
auto label = Gtk::make_managed<Gtk::Label>(display);
|
|
||||||
label->add_css_class("workspace-pill");
|
|
||||||
|
|
||||||
auto gesture = Gtk::GestureClick::create();
|
|
||||||
gesture->set_button(GDK_BUTTON_PRIMARY);
|
|
||||||
gesture->signal_released().connect(
|
|
||||||
[this, workspaceId](int /*n_press*/, double /*x*/, double /*y*/) {
|
|
||||||
int realWorkspaceId = workspaceId + 5 * (monitorId);
|
|
||||||
|
|
||||||
service.switchToWorkspace(realWorkspaceId);
|
|
||||||
});
|
|
||||||
label->add_controller(gesture);
|
|
||||||
|
|
||||||
if (state != nullptr) {
|
|
||||||
if (state->focused) {
|
|
||||||
label->add_css_class("workspace-pill-focused");
|
|
||||||
} else if (state->active) {
|
|
||||||
label->add_css_class("workspace-pill-active");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state->urgent) {
|
|
||||||
label->add_css_class("workspace-pill-urgent");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
append(*label);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkspaceIndicator::clear_children() {
|
|
||||||
Gtk::Widget *child = get_first_child();
|
|
||||||
while (child != nullptr) {
|
|
||||||
Gtk::Widget *next = child->get_next_sibling();
|
|
||||||
remove(*child);
|
|
||||||
child = next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
tmp_test.cpp
10
tmp_test.cpp
@@ -1,10 +0,0 @@
|
|||||||
#include <giomm/menumodel.h>
|
|
||||||
#include <gio/gio.h>
|
|
||||||
#include <gio/gdbusmenumodel.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