Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNI implementation for tray icons #12

Merged
merged 16 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,32 @@ jobs:
pacman-key --populate archlinux
- name: Download pacman packages
run: |
pacman -Syu --noconfirm base-devel gcc git ninja meson gtk-layer-shell pulseaudio wayland
pacman -Syu --noconfirm base-devel gcc git ninja meson gtk-layer-shell pulseaudio wayland libdbusmenu-gtk3

- name: Download gBar
uses: actions/checkout@v3.3.0

uses: actions/checkout@v3.3.0
with:
submodules: recursive

- name: Run meson
run: |
meson setup build

- name: Build gBar
run: |
ninja -C build
nix:
name: Build using Nix
runs-on: ubuntu-latest
steps:
- name: Download gBar
uses: actions/checkout@v3.3.0

- name: Install Nix
uses: cachix/install-nix-action@v20


- name: Download gBar
uses: actions/checkout@v3.3.0
with:
submodules: recursive

- name: Build Nix flake
run: |
nix build --print-build-logs


3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "thirdparty/stb"]
path = thirdparty/stb
url = https://github.com/nothings/stb
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Bar:
- Disk: Free/Total
- Network: Current upload and download speed
- Update checking (Non-Arch systems need to be configured manually)
- Tray icons

Bluetooth:
- Scanning of nearby bluetooth devices
Expand Down Expand Up @@ -162,3 +163,10 @@ See *Configuration for your system*
### The icons are not showing!
Please install a Nerd Font from https://www.nerdfonts.com (I use Caskaydia Cove NF), and change style.css/style.scss accordingly (Refer to 'I want to customize the colors' for that). You _will_ a Nerd Font with version 2.3.0 or newer (For more details see [this comment](https://github.com/scorpion-26/gBar/issues/5#issuecomment-1442037005))

### The tray doesn't show
Some apps sometimes don't actively query for tray applications. A fix for this is to start gBar before the tray app
If it still doesn't show, please open an issue with your application
The tray icons are confirmed to work with Discord, Telegram, OBS and KeePassXC

### Clicking on the tray opens a glitchy transparent menu
This is semi-intentional and a known bug (See https://github.com/scorpion-26/gBar/pull/12#issuecomment-1529143790 for an explanation). You can make it opaque by setting the background-color property of .popup in style.css/style.scss
4 changes: 4 additions & 0 deletions css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion css/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ $textsize: 16px;
//background-color: #00cc00
}

.popup {
color: #50fa7b;
}


.bar,tooltip{
background-color: $bg;
Expand Down
14 changes: 14 additions & 0 deletions data/config
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ NetworkAdapter: eno1
# Disables the network widget when set to false
NetworkWidget: true

# Enables tray icons
EnableSNI: true

# SNIIconSize sets the icon size for a SNI icon.
# SNIPaddingTop Can be used to push the Icon down. Negative values are allowed
# For both: The first parameter is a filter of the tooltip(The text that pops up, when the icon is hovered) of the icon

# Scale everything down to 25 pixels ('*' as filter means everything)
SNIIconSize: *, 25
# Explicitly make OBS a bit smaller than default
SNIIconSize: OBS, 23
# Nudges the Discord icon a bit down
# SNIPaddingTop: Discord, 5

# These set the range for the network widget. The widget changes colors at six intervals:
# - Below Min...Bytes ("under")
# - Between ]0%;25%]. 0% = Min...Bytes; 100% = Max...Bytes ("low")
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
gtk3
gtk-layer-shell
libpulseaudio
stb
libdbusmenu-gtk3
];
});
in {
Expand Down
83 changes: 66 additions & 17 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project('gBar',
['c', 'cpp'],
version: '0.0.1',
license: 'MIT',
meson_version: '>=0.49.0',
meson_version: '>=0.53.0',
default_options: ['cpp_std=c++17',
'warning_level=3',
'default_library=static',
Expand All @@ -26,6 +26,8 @@ ext_workspace_header = custom_target('generate-ext-workspace-header',
gtk = dependency('gtk+-3.0')
gtk_layer_shell = dependency('gtk-layer-shell-0')

pulse = dependency('libpulse')

headers = [
'src/Common.h',
'src/Log.h',
Expand All @@ -37,6 +39,25 @@ headers = [
'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')
add_global_arguments('-DWITH_HYPRLAND', language: 'cpp')
headers += 'src/Workspaces.h'
Expand All @@ -59,27 +80,55 @@ endif
if get_option('WithSys')
add_global_arguments('-DWITH_SYS', language: 'cpp')
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')

pulse = dependency('libpulse')
# stb
fs = import('fs')
stb = include_directories('thirdparty')
if fs.exists('thirdparty/stb/stb_image.h')
add_global_arguments('-DHAS_STB', language: 'cpp')
endif



libgBar = library('gBar',
[ 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',
],
dependencies: [gtk, gtk_layer_shell, pulse, wayland_client],
sources,
dependencies: dependencies,
include_directories: stb,
install: true)

pkg = import('pkgconfig')
Expand Down
3 changes: 3 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ option('WithHyprland', type: 'boolean', value : true)
# Workspaces general, enables Wayland protocol
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('WithAMD', type: 'boolean', value : true)
option('WithBlueZ', type: 'boolean', value : true)
Expand Down
46 changes: 46 additions & 0 deletions protocols/sni-item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.StatusNotifierItem">
<annotation name="org.gtk.GDBus.C.Name" value="item"/>
<property name="Category" type="s" access="read"/>
<property name="Id" type="s" access="read"/>
<property name="Title" type="s" access="read"/>
<property name="Status" type="s" access="read"/>
<property name="WindowId" type="u" access="read"/>
<property name="IconName" type="s" access="read"/>
<property name="IconPixmap" type="a(iiay)" access="read"/>
<property name="OverlayIconName" type="s" access="read"/>
<property name="OverlayIconPixmap" type="a(iiay)" access="read"/>
<property name="AttentionIconName" type="s" access="read"/>
<property name="AttentionIconPixmap" type="a(iiay)" access="read"/>
<property name="AttentionMovieName" type="s" access="read"/>
<property name="ToolTip" type="(sa(iiay)ss)" access="read"/>
<property name="ItemIsMenu" type="b" access="read"/>
<property name="Menu" type="o" access="read"/>
<method name="ContextMenu">
<arg type="i" direction="in" name="x"/>
<arg type="i" direction="in" name="y"/>
</method>
<method name="Activate">
<arg type="i" direction="in" name="x"/>
<arg type="i" direction="in" name="y"/>
</method>
<method name="SecondaryActivate">
<arg type="i" direction="in" name="x"/>
<arg type="i" direction="in" name="y"/>
</method>
<method name="Scroll">
<arg type="i" direction="in" name="delta"/>
<arg type="s" direction="in" name="orientation"/>
</method>
<signal name="NewTitle"/>
<signal name="NewIcon"/>
<signal name="NewAttentionIcon"/>
<signal name="NewOverlayIcon"/>
<signal name="NewToolTip"/>
<signal name="NewStatus">
<arg type="s" direction="in" name="status"/>
</signal>
</interface>
</node>
23 changes: 23 additions & 0 deletions protocols/sni-watcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.StatusNotifierWatcher">
<annotation name="org.gtk.GDBus.C.Name" value="watcher"/>
<property name="RegisteredStatusNotifierItems" type="as" access="read"/>
<property name="IsStatusNotifierHostRegistered" type="b" access="read"/>
<property name="ProtocolVersion" type="i" access="read"/>
<method name="RegisterStatusNotifierItem">
<arg type="s" direction="in" name="service"/>
</method>
<method name="RegisterStatusNotifierHost">
<arg type="s" direction="in" name="service"/>
</method>
<signal name="StatusNotifierItemRegistered">
<arg type="s" direction="out" name="service"/>
</signal>
<signal name="StatusNotifierItemUnregistered">
<arg type="s" direction="out" name="service"/>
</signal>
<signal name="StatusNotifierHostRegistered"/>
</interface>
</node>
5 changes: 5 additions & 0 deletions src/Bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "System.h"
#include "Common.h"
#include "Config.h"
#include "SNI.h"
#include <mutex>

namespace Bar
Expand Down Expand Up @@ -646,6 +647,10 @@ namespace Bar
right->SetSpacing({8, false});
right->SetHorizontalTransform({-1, true, Alignment::Right});
{
#ifdef WITH_SNI
SNI::WidgetSNI(*right);
#endif

WidgetPackages(*right);

WidgetAudio(*right);
Expand Down
Loading