mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-25 04:32:10 +00:00
SNI: Add config
This commit is contained in:
parent
67f048cd01
commit
31e070a3da
9 changed files with 108 additions and 49 deletions
|
@ -71,6 +71,9 @@ NetworkAdapter: eno1
|
||||||
# Disables the network widget when set to false
|
# Disables the network widget when set to false
|
||||||
NetworkWidget: true
|
NetworkWidget: true
|
||||||
|
|
||||||
|
# Enables tray icons
|
||||||
|
EnableSNI: true
|
||||||
|
|
||||||
# These set the range for the network widget. The widget changes colors at six intervals:
|
# These set the range for the network widget. The widget changes colors at six intervals:
|
||||||
# - Below Min...Bytes ("under")
|
# - Below Min...Bytes ("under")
|
||||||
# - Between ]0%;25%]. 0% = Min...Bytes; 100% = Max...Bytes ("low")
|
# - Between ]0%;25%]. 0% = Min...Bytes; 100% = Max...Bytes ("low")
|
||||||
|
|
109
meson.build
109
meson.build
|
@ -2,7 +2,7 @@ project('gBar',
|
||||||
['c', 'cpp'],
|
['c', 'cpp'],
|
||||||
version: '0.0.1',
|
version: '0.0.1',
|
||||||
license: 'MIT',
|
license: 'MIT',
|
||||||
meson_version: '>=0.49.0',
|
meson_version: '>=0.53.0',
|
||||||
default_options: ['cpp_std=c++17',
|
default_options: ['cpp_std=c++17',
|
||||||
'warning_level=3',
|
'warning_level=3',
|
||||||
'default_library=static',
|
'default_library=static',
|
||||||
|
@ -23,32 +23,11 @@ ext_workspace_header = custom_target('generate-ext-workspace-header',
|
||||||
output: ['ext-workspace-unstable-v1.h'],
|
output: ['ext-workspace-unstable-v1.h'],
|
||||||
command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'])
|
command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'])
|
||||||
|
|
||||||
# DBus protocols
|
|
||||||
dbus_gen = find_program('gdbus-codegen')
|
|
||||||
sni_item_src = custom_target('generate-sni-item-src',
|
|
||||||
input: ['protocols/sni-item.xml'],
|
|
||||||
output: ['sni-item.c'],
|
|
||||||
command: [dbus_gen, '--c-namespace', 'sni', '--body', '--output', '@OUTPUT@', '@INPUT@'])
|
|
||||||
|
|
||||||
sni_item_header = custom_target('generate-sni-item-header',
|
|
||||||
input: ['protocols/sni-item.xml'],
|
|
||||||
output: ['sni-item.h'],
|
|
||||||
command: [dbus_gen, '--c-namespace', 'sni', '--header', '--output', '@OUTPUT@', '@INPUT@'])
|
|
||||||
|
|
||||||
sni_watcher_src = custom_target('generate-sni-watcher-src',
|
|
||||||
input: ['protocols/sni-watcher.xml'],
|
|
||||||
output: ['sni-watcher.c'],
|
|
||||||
command: [dbus_gen, '--c-namespace', 'sni', '--body', '--output', '@OUTPUT@', '@INPUT@'])
|
|
||||||
|
|
||||||
sni_watcher_header = custom_target('generate-sni-watcher-header',
|
|
||||||
input: ['protocols/sni-watcher.xml'],
|
|
||||||
output: ['sni-watcher.h'],
|
|
||||||
command: [dbus_gen, '--c-namespace', 'sni', '--header', '--output', '@OUTPUT@', '@INPUT@'])
|
|
||||||
libdbusmenu = dependency('dbusmenu-gtk3-0.4')
|
|
||||||
|
|
||||||
gtk = dependency('gtk+-3.0')
|
gtk = dependency('gtk+-3.0')
|
||||||
gtk_layer_shell = dependency('gtk-layer-shell-0')
|
gtk_layer_shell = dependency('gtk-layer-shell-0')
|
||||||
|
|
||||||
|
pulse = dependency('libpulse')
|
||||||
|
|
||||||
headers = [
|
headers = [
|
||||||
'src/Common.h',
|
'src/Common.h',
|
||||||
'src/Log.h',
|
'src/Log.h',
|
||||||
|
@ -60,6 +39,25 @@ headers = [
|
||||||
'src/CSS.h'
|
'src/CSS.h'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
sources = [
|
||||||
|
ext_workspace_src,
|
||||||
|
ext_workspace_header,
|
||||||
|
'src/Window.cpp',
|
||||||
|
'src/Widget.cpp',
|
||||||
|
'src/System.cpp',
|
||||||
|
'src/Bar.cpp',
|
||||||
|
'src/Workspaces.cpp',
|
||||||
|
'src/AudioFlyin.cpp',
|
||||||
|
'src/BluetoothDevices.cpp',
|
||||||
|
'src/Plugin.cpp',
|
||||||
|
'src/Config.cpp',
|
||||||
|
'src/CSS.cpp',
|
||||||
|
'src/Log.cpp',
|
||||||
|
'src/SNI.cpp',
|
||||||
|
]
|
||||||
|
|
||||||
|
dependencies = [gtk, gtk_layer_shell, pulse, wayland_client ]
|
||||||
|
|
||||||
if get_option('WithHyprland')
|
if get_option('WithHyprland')
|
||||||
add_global_arguments('-DWITH_HYPRLAND', language: 'cpp')
|
add_global_arguments('-DWITH_HYPRLAND', language: 'cpp')
|
||||||
headers += 'src/Workspaces.h'
|
headers += 'src/Workspaces.h'
|
||||||
|
@ -82,35 +80,54 @@ endif
|
||||||
if get_option('WithSys')
|
if get_option('WithSys')
|
||||||
add_global_arguments('-DWITH_SYS', language: 'cpp')
|
add_global_arguments('-DWITH_SYS', language: 'cpp')
|
||||||
endif
|
endif
|
||||||
|
if get_option('WithSNI')
|
||||||
|
add_global_arguments('-DWITH_SNI', language: 'cpp')
|
||||||
|
|
||||||
|
# DBus protocols
|
||||||
|
dbus_gen = find_program('gdbus-codegen')
|
||||||
|
sni_item_src = custom_target('generate-sni-item-src',
|
||||||
|
input: ['protocols/sni-item.xml'],
|
||||||
|
output: ['sni-item.c'],
|
||||||
|
command: [dbus_gen, '--c-namespace', 'sni', '--body', '--output', '@OUTPUT@', '@INPUT@'])
|
||||||
|
|
||||||
|
sni_item_header = custom_target('generate-sni-item-header',
|
||||||
|
input: ['protocols/sni-item.xml'],
|
||||||
|
output: ['sni-item.h'],
|
||||||
|
command: [dbus_gen, '--c-namespace', 'sni', '--header', '--output', '@OUTPUT@', '@INPUT@'])
|
||||||
|
|
||||||
|
sni_watcher_src = custom_target('generate-sni-watcher-src',
|
||||||
|
input: ['protocols/sni-watcher.xml'],
|
||||||
|
output: ['sni-watcher.c'],
|
||||||
|
command: [dbus_gen, '--c-namespace', 'sni', '--body', '--output', '@OUTPUT@', '@INPUT@'])
|
||||||
|
|
||||||
|
sni_watcher_header = custom_target('generate-sni-watcher-header',
|
||||||
|
input: ['protocols/sni-watcher.xml'],
|
||||||
|
output: ['sni-watcher.h'],
|
||||||
|
command: [dbus_gen, '--c-namespace', 'sni', '--header', '--output', '@OUTPUT@', '@INPUT@'])
|
||||||
|
libdbusmenu = dependency('dbusmenu-gtk3-0.4')
|
||||||
|
|
||||||
|
sources += sni_item_src
|
||||||
|
sources += sni_item_header
|
||||||
|
sources += sni_watcher_src
|
||||||
|
sources += sni_watcher_header
|
||||||
|
|
||||||
|
dependencies += libdbusmenu
|
||||||
|
endif
|
||||||
|
|
||||||
add_global_arguments('-DUSE_LOGFILE', language: 'cpp')
|
add_global_arguments('-DUSE_LOGFILE', language: 'cpp')
|
||||||
|
|
||||||
pulse = dependency('libpulse')
|
|
||||||
|
|
||||||
# stb
|
# stb
|
||||||
|
fs = import('fs')
|
||||||
stb = include_directories('thirdparty')
|
stb = include_directories('thirdparty')
|
||||||
|
if fs.exists('thirdparty/stb/stb_image.h')
|
||||||
|
add_global_arguments('-DHAS_STB', language: 'cpp')
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
libgBar = library('gBar',
|
libgBar = library('gBar',
|
||||||
[ ext_workspace_src,
|
sources,
|
||||||
ext_workspace_header,
|
dependencies: dependencies,
|
||||||
sni_item_src,
|
|
||||||
sni_item_header,
|
|
||||||
sni_watcher_src,
|
|
||||||
sni_watcher_header,
|
|
||||||
'src/Window.cpp',
|
|
||||||
'src/Widget.cpp',
|
|
||||||
'src/System.cpp',
|
|
||||||
'src/Bar.cpp',
|
|
||||||
'src/Workspaces.cpp',
|
|
||||||
'src/AudioFlyin.cpp',
|
|
||||||
'src/BluetoothDevices.cpp',
|
|
||||||
'src/Plugin.cpp',
|
|
||||||
'src/Config.cpp',
|
|
||||||
'src/CSS.cpp',
|
|
||||||
'src/Log.cpp',
|
|
||||||
'src/SNI.cpp',
|
|
||||||
],
|
|
||||||
dependencies: [gtk, gtk_layer_shell, pulse, wayland_client, libdbusmenu],
|
|
||||||
include_directories: stb,
|
include_directories: stb,
|
||||||
install: true)
|
install: true)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,9 @@ option('WithHyprland', type: 'boolean', value : true)
|
||||||
# Workspaces general, enables Wayland protocol
|
# Workspaces general, enables Wayland protocol
|
||||||
option('WithWorkspaces', type: 'boolean', value : true)
|
option('WithWorkspaces', type: 'boolean', value : true)
|
||||||
|
|
||||||
|
# Tray icons, requires stb git submodule
|
||||||
|
option('WithSNI', type: 'boolean', value : true)
|
||||||
|
|
||||||
option('WithNvidia', type: 'boolean', value : true)
|
option('WithNvidia', type: 'boolean', value : true)
|
||||||
option('WithAMD', type: 'boolean', value : true)
|
option('WithAMD', type: 'boolean', value : true)
|
||||||
option('WithBlueZ', type: 'boolean', value : true)
|
option('WithBlueZ', type: 'boolean', value : true)
|
||||||
|
|
|
@ -647,7 +647,9 @@ namespace Bar
|
||||||
right->SetSpacing({8, false});
|
right->SetSpacing({8, false});
|
||||||
right->SetHorizontalTransform({-1, true, Alignment::Right});
|
right->SetHorizontalTransform({-1, true, Alignment::Right});
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_SNI
|
||||||
SNI::WidgetSNI(*right);
|
SNI::WidgetSNI(*right);
|
||||||
|
#endif
|
||||||
|
|
||||||
WidgetPackages(*right);
|
WidgetPackages(*right);
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,7 @@ void Config::Load()
|
||||||
AddConfigVar("WorkspaceScrollOnMonitor", config.workspaceScrollOnMonitor, lineView, foundProperty);
|
AddConfigVar("WorkspaceScrollOnMonitor", config.workspaceScrollOnMonitor, lineView, foundProperty);
|
||||||
AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty);
|
AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty);
|
||||||
AddConfigVar("UseHyprlandIPC", config.useHyprlandIPC, lineView, foundProperty);
|
AddConfigVar("UseHyprlandIPC", config.useHyprlandIPC, lineView, foundProperty);
|
||||||
|
AddConfigVar("EnableSNI", config.enableSNI, lineView, foundProperty);
|
||||||
|
|
||||||
AddConfigVar("MinUploadBytes", config.minUploadBytes, lineView, foundProperty);
|
AddConfigVar("MinUploadBytes", config.minUploadBytes, lineView, foundProperty);
|
||||||
AddConfigVar("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty);
|
AddConfigVar("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty);
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
bool workspaceScrollOnMonitor = true; // Scroll through workspaces on monitor instead of all
|
bool workspaceScrollOnMonitor = true; // Scroll through workspaces on monitor instead of all
|
||||||
bool workspaceScrollInvert = false; // Up = +1, instead of Up = -1
|
bool workspaceScrollInvert = false; // Up = +1, instead of Up = -1
|
||||||
bool useHyprlandIPC = false; // Use Hyprland IPC instead of ext_workspaces protocol (Less buggy, but also less performant)
|
bool useHyprlandIPC = false; // Use Hyprland IPC instead of ext_workspaces protocol (Less buggy, but also less performant)
|
||||||
|
bool enableSNI = true; // Enable tray icon
|
||||||
|
|
||||||
// Controls for color progression of the network widget
|
// Controls for color progression of the network widget
|
||||||
uint32_t minUploadBytes = 0; // Bottom limit of the network widgets upload. Everything below it is considered "under"
|
uint32_t minUploadBytes = 0; // Bottom limit of the network widgets upload. Everything below it is considered "under"
|
||||||
|
@ -73,6 +74,12 @@ public:
|
||||||
bool hasBlueZ = false;
|
bool hasBlueZ = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined WITH_SNI && defined HAS_STB
|
||||||
|
bool hasSNI = true;
|
||||||
|
#else
|
||||||
|
bool hasSNI = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool hasNet = true;
|
bool hasNet = true;
|
||||||
|
|
||||||
bool hasPackagesScript = true;
|
bool hasPackagesScript = true;
|
||||||
|
|
26
src/SNI.cpp
26
src/SNI.cpp
|
@ -1,6 +1,9 @@
|
||||||
#include "SNI.h"
|
#include "SNI.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Widget.h"
|
#include "Widget.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
#ifdef WITH_SNI
|
||||||
|
|
||||||
#include <sni-watcher.h>
|
#include <sni-watcher.h>
|
||||||
#include <sni-item.h>
|
#include <sni-item.h>
|
||||||
|
@ -245,6 +248,11 @@ namespace SNI
|
||||||
|
|
||||||
static TimerResult UpdateWidgets(Box&)
|
static TimerResult UpdateWidgets(Box&)
|
||||||
{
|
{
|
||||||
|
if (RuntimeConfig::Get().hasSNI == false || Config::Get().enableSNI == false)
|
||||||
|
{
|
||||||
|
// Don't bother
|
||||||
|
return TimerResult::Delete;
|
||||||
|
}
|
||||||
for (auto& client : clientsToQuery)
|
for (auto& client : clientsToQuery)
|
||||||
{
|
{
|
||||||
LOG("SNI: Creating Item " << client.name << " " << client.object);
|
LOG("SNI: Creating Item " << client.name << " " << client.object);
|
||||||
|
@ -324,6 +332,10 @@ namespace SNI
|
||||||
|
|
||||||
void WidgetSNI(Widget& parent)
|
void WidgetSNI(Widget& parent)
|
||||||
{
|
{
|
||||||
|
if (RuntimeConfig::Get().hasSNI == false || Config::Get().enableSNI == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Add parent box
|
// Add parent box
|
||||||
auto box = Widget::Create<Box>();
|
auto box = Widget::Create<Box>();
|
||||||
auto container = Widget::Create<Box>();
|
auto container = Widget::Create<Box>();
|
||||||
|
@ -386,13 +398,19 @@ namespace SNI
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
|
if (RuntimeConfig::Get().hasSNI == false || Config::Get().enableSNI == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto busAcquired = [](GDBusConnection* connection, const char*, void*)
|
auto busAcquired = [](GDBusConnection* connection, const char*, void*)
|
||||||
{
|
{
|
||||||
GError* err = nullptr;
|
GError* err = nullptr;
|
||||||
g_dbus_interface_skeleton_export((GDBusInterfaceSkeleton*)watcherSkeleton, connection, "/StatusNotifierWatcher", &err);
|
g_dbus_interface_skeleton_export((GDBusInterfaceSkeleton*)watcherSkeleton, connection, "/StatusNotifierWatcher", &err);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
LOG("Failed to connect to dbus! Error: " << err->message);
|
LOG("SNI: Failed to connect to dbus! Disabling SNI. Error: " << err->message);
|
||||||
|
RuntimeConfig::Get().hasSNI = false;
|
||||||
g_error_free(err);
|
g_error_free(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -409,9 +427,10 @@ namespace SNI
|
||||||
sni_watcher_set_is_status_notifier_host_registered(watcherSkeleton, true);
|
sni_watcher_set_is_status_notifier_host_registered(watcherSkeleton, true);
|
||||||
};
|
};
|
||||||
auto emptyCallback = [](GDBusConnection*, const char*, void*) {};
|
auto emptyCallback = [](GDBusConnection*, const char*, void*) {};
|
||||||
auto lostName = [](GDBusConnection*, const char*, void*)
|
auto lostName = [](GDBusConnection*, const char* msg, void*)
|
||||||
{
|
{
|
||||||
LOG("Lost name!");
|
LOG("SNI: Lost Name! Disabling SNI!");
|
||||||
|
RuntimeConfig::Get().hasSNI = false;
|
||||||
};
|
};
|
||||||
auto flags = G_BUS_NAME_OWNER_FLAGS_REPLACE | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
|
auto flags = G_BUS_NAME_OWNER_FLAGS_REPLACE | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
|
||||||
g_bus_own_name(G_BUS_TYPE_SESSION, "org.kde.StatusNotifierWatcher", (GBusNameOwnerFlags)flags, +busAcquired, +emptyCallback, +lostName,
|
g_bus_own_name(G_BUS_TYPE_SESSION, "org.kde.StatusNotifierWatcher", (GBusNameOwnerFlags)flags, +busAcquired, +emptyCallback, +lostName,
|
||||||
|
@ -429,3 +448,4 @@ namespace SNI
|
||||||
|
|
||||||
void Shutdown() {}
|
void Shutdown() {}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#ifdef WITH_SNI
|
||||||
class Widget;
|
class Widget;
|
||||||
namespace SNI
|
namespace SNI
|
||||||
{
|
{
|
||||||
|
@ -6,3 +7,4 @@ namespace SNI
|
||||||
void WidgetSNI(Widget& parent);
|
void WidgetSNI(Widget& parent);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -647,7 +647,9 @@ namespace System
|
||||||
|
|
||||||
PulseAudio::Init();
|
PulseAudio::Init();
|
||||||
|
|
||||||
|
#ifdef WITH_SNI
|
||||||
SNI::Init();
|
SNI::Init();
|
||||||
|
#endif
|
||||||
|
|
||||||
CheckNetwork();
|
CheckNetwork();
|
||||||
}
|
}
|
||||||
|
@ -665,7 +667,9 @@ namespace System
|
||||||
#ifdef WITH_BLUEZ
|
#ifdef WITH_BLUEZ
|
||||||
StopBTScan();
|
StopBTScan();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WITH_SNI
|
||||||
SNI::Shutdown();
|
SNI::Shutdown();
|
||||||
|
#endif
|
||||||
|
|
||||||
Logging::Shutdown();
|
Logging::Shutdown();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue