home assistant widget
This commit is contained in:
@@ -23,9 +23,10 @@ endif()
|
|||||||
|
|
||||||
pkg_check_modules(GTKMM REQUIRED gtkmm-4.0)
|
pkg_check_modules(GTKMM REQUIRED gtkmm-4.0)
|
||||||
pkg_check_modules(LAYERSHELL REQUIRED gtk4-layer-shell-0)
|
pkg_check_modules(LAYERSHELL REQUIRED gtk4-layer-shell-0)
|
||||||
|
pkg_check_modules(WEBKIT REQUIRED webkitgtk-6.0)
|
||||||
|
|
||||||
include_directories(${GTKMM_INCLUDE_DIRS} ${LAYERSHELL_INCLUDE_DIRS})
|
include_directories(${GTKMM_INCLUDE_DIRS} ${LAYERSHELL_INCLUDE_DIRS} ${WEBKIT_INCLUDE_DIRS})
|
||||||
link_directories(${GTKMM_LIBRARY_DIRS} ${LAYERSHELL_LIBRARY_DIRS})
|
link_directories(${GTKMM_LIBRARY_DIRS} ${LAYERSHELL_LIBRARY_DIRS} ${WEBKIT_LIBRARY_DIRS})
|
||||||
|
|
||||||
add_library(bar_lib)
|
add_library(bar_lib)
|
||||||
target_sources(bar_lib
|
target_sources(bar_lib
|
||||||
@@ -35,6 +36,7 @@ target_sources(bar_lib
|
|||||||
src/widgets/clock.cpp
|
src/widgets/clock.cpp
|
||||||
src/widgets/workspaceIndicator.cpp
|
src/widgets/workspaceIndicator.cpp
|
||||||
src/widgets/volumeWidget.cpp
|
src/widgets/volumeWidget.cpp
|
||||||
|
src/widgets/webWidget.cpp
|
||||||
src/services/hyprland.cpp
|
src/services/hyprland.cpp
|
||||||
src/services/tray.cpp
|
src/services/tray.cpp
|
||||||
src/widgets/tray.cpp
|
src/widgets/tray.cpp
|
||||||
@@ -45,7 +47,7 @@ include_directories(bar_lib PRIVATE
|
|||||||
|
|
||||||
add_executable(bar main.cpp)
|
add_executable(bar main.cpp)
|
||||||
|
|
||||||
target_link_libraries(bar bar_lib ${GTKMM_LIBRARIES} ${LAYERSHELL_LIBRARIES})
|
target_link_libraries(bar bar_lib ${GTKMM_LIBRARIES} ${LAYERSHELL_LIBRARIES} ${WEBKIT_LIBRARIES})
|
||||||
|
|
||||||
# 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")
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "services/tray.hpp"
|
#include "services/tray.hpp"
|
||||||
#include "widgets/clock.hpp"
|
#include "widgets/clock.hpp"
|
||||||
#include "widgets/tray.hpp"
|
#include "widgets/tray.hpp"
|
||||||
|
#include "widgets/webWidget.hpp"
|
||||||
#include "widgets/workspaceIndicator.hpp"
|
#include "widgets/workspaceIndicator.hpp"
|
||||||
|
|
||||||
class Bar : public Gtk::Window {
|
class Bar : public Gtk::Window {
|
||||||
@@ -22,6 +23,8 @@ class Bar : public Gtk::Window {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Clock clock;
|
Clock clock;
|
||||||
|
WebWidget homeAssistant {"HA", "Home Assistant",
|
||||||
|
"https://home.rivercry.com"};
|
||||||
TrayService &trayService;
|
TrayService &trayService;
|
||||||
HyprlandService &hyprlandService;
|
HyprlandService &hyprlandService;
|
||||||
int monitorId;
|
int monitorId;
|
||||||
|
|||||||
14
include/widgets/webWidget.hpp
Normal file
14
include/widgets/webWidget.hpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtkmm/button.h>
|
||||||
|
#include <gtkmm/window.h>
|
||||||
|
|
||||||
|
class WebWidget : public Gtk::Button {
|
||||||
|
public:
|
||||||
|
WebWidget(std::string label, std::string title, std::string url);
|
||||||
|
~WebWidget() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void on_toggle_window();
|
||||||
|
Gtk::Window* web_window = nullptr;
|
||||||
|
};
|
||||||
@@ -41,6 +41,15 @@ window {
|
|||||||
color: #111;
|
color: #111;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.minimized {
|
||||||
|
background-color: rgba(50, 50, 50, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.restored {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
button {
|
button {
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
margin: 0 2px;
|
margin: 0 2px;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bar::setup_ui() {
|
void Bar::setup_ui() {
|
||||||
@@ -73,8 +74,10 @@ void Bar::setup_ui() {
|
|||||||
volumeWidget = Gtk::make_managed<VolumeWidget>();
|
volumeWidget = Gtk::make_managed<VolumeWidget>();
|
||||||
center_box.append(*volumeWidget);
|
center_box.append(*volumeWidget);
|
||||||
|
|
||||||
|
|
||||||
trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
||||||
right_box.append(*trayWidget);
|
right_box.append(*trayWidget);
|
||||||
|
right_box.append(homeAssistant);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bar::load_css() {
|
void Bar::load_css() {
|
||||||
|
|||||||
52
src/widgets/webWidget.cpp
Normal file
52
src/widgets/webWidget.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#include "widgets/webWidget.hpp"
|
||||||
|
#include <gtkmm/box.h>
|
||||||
|
#include <webkit/webkit.h>
|
||||||
|
|
||||||
|
WebWidget::WebWidget(std::string label, std::string title, std::string url) {
|
||||||
|
set_label(label);
|
||||||
|
signal_clicked().connect(
|
||||||
|
sigc::mem_fun(*this, &WebWidget::on_toggle_window));
|
||||||
|
|
||||||
|
web_window = new Gtk::Window();
|
||||||
|
web_window->set_title(title);
|
||||||
|
web_window->set_default_size(1024, 768);
|
||||||
|
|
||||||
|
web_window->signal_close_request().connect(
|
||||||
|
[this]() {
|
||||||
|
web_window->hide();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
false);
|
||||||
|
|
||||||
|
auto webview = webkit_web_view_new();
|
||||||
|
gtk_widget_set_hexpand(webview, true);
|
||||||
|
gtk_widget_set_vexpand(webview, true);
|
||||||
|
|
||||||
|
auto settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview));
|
||||||
|
webkit_settings_set_hardware_acceleration_policy(
|
||||||
|
settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS);
|
||||||
|
|
||||||
|
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_window_set_child(web_window->gobj(), webview);
|
||||||
|
}
|
||||||
|
|
||||||
|
WebWidget::~WebWidget() { delete web_window; }
|
||||||
|
|
||||||
|
void WebWidget::on_toggle_window() {
|
||||||
|
if (web_window->is_visible()) {
|
||||||
|
web_window->set_visible(false);
|
||||||
|
|
||||||
|
this->add_css_class("minimized");
|
||||||
|
this->remove_css_class("restored");
|
||||||
|
} else {
|
||||||
|
web_window->set_visible(true);
|
||||||
|
this->remove_css_class("minimized");
|
||||||
|
this->add_css_class("restored");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user