SNI: Add context menu

Since it uses a 13 year old library, it is broken. The popup size is
hard-fixed at 200x200, with looks really ugly with non-transparent
background.
This commit is contained in:
scorpion-26 2023-04-30 23:13:41 +02:00
parent 40115befdd
commit b7a92e50d9
7 changed files with 65 additions and 3 deletions

View file

@ -3,6 +3,10 @@
font-family: "CaskaydiaCove Nerd Font";
}
.popup {
color: #50fa7b;
}
.bar, tooltip {
background-color: #282a36;
border-radius: 16px;

View file

@ -1 +1 @@
{"version":3,"sourceRoot":"","sources":["style.scss"],"names":[],"mappings":"AAmBA;EACI;EACA;;;AASJ;EACI,kBA7BC;EA8BD;;;AAGJ;EACI;EACA;;;AAGJ;EACI,WAxBO;;;AA2BX;EACI;EAEA;EAEA,OA5CO;;;AA8CX;EACI;EAGA,OAlDO;;;AAoDX;EACI;EAGA,OAxDO;;;AA2DX;EACI;EAGA,OAzDE;;;AA+DN;EACI;;;AAIJ;EACI;EACA;EACA;EACA,kBA/EO;EAgFP;EACA;EACA;;;AAGJ;EAEI;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;;;AAGJ;EACI;EACA,OArGK;EAsGL;;;AAIA;EACI,kBA/GG;;AAkHP;EACI;;AAGJ;EACI,kBAnHC;;;AAuHT;EACI;EACA,OAvHK;EAwHL;;;AAIA;EACI,kBAnIG;;AAsIP;EACI;;AAGJ;EACI,kBArIC;;;AAyIT;EACI;EACA;EACA;EACA,OA5IE;;;AA+IN;EACI,WA1IO;EA2IP,OA7IK;EA8IL;;;AAEJ;EACI;EACA,OAlJK;EAmJL;;;AAEJ;EACI;EACA,OAvJK;EAwJL;;;AAEJ;EACI;EACA,OA5JK;EA6JL;;;AAGJ;EACI,OAtKK;EAuKL,kBA7KO;EA8KP,WAjKO;;;AAmKX;EACI,OA3KK;EA4KL;EACA,WAtKO;;;AAyKX;EACI,OAnLK;EAoLL,kBAxLO;;;AA0LX;EACI,OAvLK;EAwLL;EACA,WAhLO;;;AAmLX;EACI,OAzLK;EA0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AAED;EAaI,OAjZK;EAkZL,kBA1ZO;EA2ZP;EACA;EACH;EACG;;AAjBA;EACI;EACA;EACA;EACA;;AAEJ;EACI;EACA;EACA;EACA","file":"style.css"}
{"version":3,"sourceRoot":"","sources":["style.scss"],"names":[],"mappings":"AAmBA;EACI;EACA;;;AASJ;EACI,kBA7BC;EA8BD;;;AAGJ;EACI;EACA;;;AAGJ;EACI,WAxBO;;;AA2BX;EACI;EAEA;EAEA,OA5CO;;;AA8CX;EACI;EAGA,OAlDO;;;AAoDX;EACI;EAGA,OAxDO;;;AA2DX;EACI;EAGA,OAzDE;;;AA+DN;EACI;;;AAIJ;EACI;EACA;EACA;EACA,kBA/EO;EAgFP;EACA;EACA;;;AAGJ;EAEI;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;;;AAGJ;EACI;EACA,OArGK;EAsGL;;;AAIA;EACI,kBA/GG;;AAkHP;EACI;;AAGJ;EACI,kBAnHC;;;AAuHT;EACI;EACA,OAvHK;EAwHL;;;AAIA;EACI,kBAnIG;;AAsIP;EACI;;AAGJ;EACI,kBArIC;;;AAyIT;EACI;EACA;EACA;EACA,OA5IE;;;AA+IN;EACI,WA1IO;EA2IP,OA7IK;EA8IL;;;AAEJ;EACI;EACA,OAlJK;EAmJL;;;AAEJ;EACI;EACA,OAvJK;EAwJL;;;AAEJ;EACI;EACA,OA5JK;EA6JL;;;AAGJ;EACI,OAtKK;EAuKL,kBA7KO;EA8KP,WAjKO;;;AAmKX;EACI,OA3KK;EA4KL;EACA,WAtKO;;;AAyKX;EACI,OAnLK;EAoLL,kBAxLO;;;AA0LX;EACI,OAvLK;EAwLL;EACA,WAhLO;;;AAmLX;EACI,OAzLK;EA0LL,kBAlMO;;;AAoMX;EACI,OA7LK;EA8LL;EACA,WA1LO;;;AA6LX;EACI,OAzMG;EA0MH,kBA5MO;;;AA8MX;EACI,OA7MG;EA8MH;EACA,WApMO;;;AAuMX;EACI,OAlNI;EAmNJ,kBAtNO;EAuNP,WA1MO;;;AA4MX;EACI,OAvNI;EAwNJ;EACA,WA/MO;;;AAkNX;EACI,OA3NG;EA4NH,kBAjOO;EAkOP,WArNO;;;AAuNX;EACI,OAhOG;EAiOH;EACA,WA1NO;;;AA6NX;EACI,OAxOI;EAyOJ;EACA,WAhOO;;;AAoOX;EACI,OAlPO;;;AAqPX;EACI,OAnPI;;;AAsPR;EACI,OAlPK;;;AAqPT;EACI,OA1PK;;;AA6PT;EACI,OA5PK;;;AA+PT;EACI,OA/PE;;;AAmQN;EACI,OA3QO;;;AA8QX;EACI,OA5QI;;;AA+QR;EACI,OA3QK;;;AA8QT;EACI,OAnRK;;;AAsRT;EACI,OArRK;;;AAwRT;EACI,OAxRE;;;AA2RN;EACI,OAnSO;EAoSP,WAvRO;;;AAyRX;EACI,OAtSO;EAuSP,WA3RO;;;AA6RX;EACI,OAzSG;EA0SH,WA/RO;;;AAiSX;EACI,OAvSK;EAwSL,WAnSO;;;AAqSX;EACI,OAhTI;EAiTJ,WAvSO;;;AA2SX;EACI;IACI;;EAEJ;IACI;;;AAGR;EACI;IACI;;EAEJ;IACI;;;AAIR;EACI;IACI,OAnUC;;EAqUL;IACI,OA3UA;;;AA8UR;EACI;IACI,OAhVA;;EAkVJ;IACI,OA9UC;;;AAkVT;EACI,kBA7VC;EA8VD;;;AAEJ;EACI;EACA;EACA;EACA;EACA,OAxVK;;;AA0VT;EACI;EACA;;;AAEJ;EAgBI;EACA;EACA;EACA;EACA;EAEA;EACA;EAEA;;AAxBA;EACI;EACA;EACA;EACA;;AAEJ;EACI;EACA;EACA;EACA;;AAEJ;EACI,OAhXF;;;AA8XN;EACI,OA/XE;EAgYF,kBAvYO;EAwYP;EACH;EACA;;;AAED;EAaI,OAjZK;EAkZL,kBA1ZO;EA2ZP;EACA;EACH;EACG;;AAjBA;EACI;EACA;EACA;EACA;;AAEJ;EACI;EACA;EACA;EACA","file":"style.css"}

View file

@ -27,6 +27,10 @@ $textsize: 16px;
//background-color: #00cc00
}
.popup {
color: #50fa7b;
}
.bar,tooltip{
background-color: $bg;

View file

@ -44,6 +44,7 @@ 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_layer_shell = dependency('gtk-layer-shell-0')
@ -109,7 +110,7 @@ libgBar = library('gBar',
'src/Log.cpp',
'src/SNI.cpp',
],
dependencies: [gtk, gtk_layer_shell, pulse, wayland_client],
dependencies: [gtk, gtk_layer_shell, pulse, wayland_client, libdbusmenu],
include_directories: stb,
install: true)

View file

@ -5,6 +5,7 @@
#include <sni-watcher.h>
#include <sni-item.h>
#include <gio/gio.h>
#include <libdbusmenu-gtk/menu.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb/stb_image.h>
@ -28,6 +29,10 @@ namespace SNI
uint8_t* iconData = nullptr;
std::string tooltip;
std::string menuObjectPath;
EventBox* gtkEvent;
};
std::vector<Item> items;
@ -182,6 +187,22 @@ namespace SNI
g_variant_unref(tooltipVar);
}
// Query menu
GVariant* menuPath = getProperty("Menu");
if (menuPath)
{
GVariant* menuVariant;
g_variant_get_child(menuPath, 0, "v", &menuVariant);
const char* objectPath;
g_variant_get(menuVariant, "o", &objectPath);
LOG("SNI: Menu object path: " << objectPath);
item.menuObjectPath = objectPath;
g_variant_unref(menuVariant);
g_variant_unref(menuPath);
}
return item;
}
@ -266,11 +287,36 @@ namespace SNI
{
if (item.iconData)
{
auto eventBox = Widget::Create<EventBox>();
item.gtkEvent = eventBox.get();
eventBox->SetOnCreate(
[&](Widget& w)
{
auto clickFn = [](GtkWidget*, GdkEventButton* event, void* data) -> gboolean
{
if (event->button == 1)
{
Item* item = (Item*)data;
GtkMenu* menu = (GtkMenu*)dbusmenu_gtkmenu_new(item->name.data(), item->menuObjectPath.data());
LOG(menu);
gtk_menu_attach_to_widget(menu, item->gtkEvent->Get(), nullptr);
gtk_menu_popup_at_pointer(menu, (GdkEvent*)event);
LOG(item->menuObjectPath << " click");
}
return GDK_EVENT_STOP;
};
g_signal_connect(w.Get(), "button-release-event", G_CALLBACK(+clickFn), &item);
});
auto texture = Widget::Create<Texture>();
texture->SetHorizontalTransform({0, true, Alignment::Fill});
texture->SetBuf(item.w, item.h, item.iconData);
texture->SetTooltip(item.tooltip);
iconBox->AddChild(std::move(texture));
eventBox->AddChild(std::move(texture));
iconBox->AddChild(std::move(eventBox));
}
}
parentBox->AddChild(std::move(container));

View file

@ -173,6 +173,9 @@ void Widget::ApplyPropertiesToWidget()
gtk_widget_set_valign(m_Widget, Utils::ToGtkAlign(m_VerticalTransform.alignment));
gtk_widget_set_hexpand(m_Widget, m_HorizontalTransform.expand);
gtk_widget_set_vexpand(m_Widget, m_VerticalTransform.expand);
if (m_OnCreate)
m_OnCreate(*this);
}
void Box::SetOrientation(Orientation orientation)

View file

@ -157,6 +157,8 @@ public:
void SetVisible(bool visible);
void SetOnCreate(Callback<Widget>&& onCreate) { m_OnCreate = onCreate; }
protected:
void PropagateToParent(GdkEvent* event);
void ApplyPropertiesToWidget();
@ -169,6 +171,8 @@ protected:
std::string m_Tooltip;
Transform m_HorizontalTransform; // X
Transform m_VerticalTransform; // Y
Callback<Widget> m_OnCreate;
};
class Box : public Widget