mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
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:
parent
40115befdd
commit
b7a92e50d9
7 changed files with 65 additions and 3 deletions
|
@ -3,6 +3,10 @@
|
||||||
font-family: "CaskaydiaCove Nerd Font";
|
font-family: "CaskaydiaCove Nerd Font";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.popup {
|
||||||
|
color: #50fa7b;
|
||||||
|
}
|
||||||
|
|
||||||
.bar, tooltip {
|
.bar, tooltip {
|
||||||
background-color: #282a36;
|
background-color: #282a36;
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
|
|
|
@ -27,6 +27,10 @@ $textsize: 16px;
|
||||||
//background-color: #00cc00
|
//background-color: #00cc00
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.popup {
|
||||||
|
color: #50fa7b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.bar,tooltip{
|
.bar,tooltip{
|
||||||
background-color: $bg;
|
background-color: $bg;
|
||||||
|
|
|
@ -44,6 +44,7 @@ sni_watcher_header = custom_target('generate-sni-watcher-header',
|
||||||
input: ['protocols/sni-watcher.xml'],
|
input: ['protocols/sni-watcher.xml'],
|
||||||
output: ['sni-watcher.h'],
|
output: ['sni-watcher.h'],
|
||||||
command: [dbus_gen, '--c-namespace', 'sni', '--header', '--output', '@OUTPUT@', '@INPUT@'])
|
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')
|
||||||
|
@ -109,7 +110,7 @@ libgBar = library('gBar',
|
||||||
'src/Log.cpp',
|
'src/Log.cpp',
|
||||||
'src/SNI.cpp',
|
'src/SNI.cpp',
|
||||||
],
|
],
|
||||||
dependencies: [gtk, gtk_layer_shell, pulse, wayland_client],
|
dependencies: [gtk, gtk_layer_shell, pulse, wayland_client, libdbusmenu],
|
||||||
include_directories: stb,
|
include_directories: stb,
|
||||||
install: true)
|
install: true)
|
||||||
|
|
||||||
|
|
48
src/SNI.cpp
48
src/SNI.cpp
|
@ -5,6 +5,7 @@
|
||||||
#include <sni-watcher.h>
|
#include <sni-watcher.h>
|
||||||
#include <sni-item.h>
|
#include <sni-item.h>
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
#include <libdbusmenu-gtk/menu.h>
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include <stb/stb_image.h>
|
#include <stb/stb_image.h>
|
||||||
|
@ -28,6 +29,10 @@ namespace SNI
|
||||||
uint8_t* iconData = nullptr;
|
uint8_t* iconData = nullptr;
|
||||||
|
|
||||||
std::string tooltip;
|
std::string tooltip;
|
||||||
|
|
||||||
|
std::string menuObjectPath;
|
||||||
|
|
||||||
|
EventBox* gtkEvent;
|
||||||
};
|
};
|
||||||
std::vector<Item> items;
|
std::vector<Item> items;
|
||||||
|
|
||||||
|
@ -182,6 +187,22 @@ namespace SNI
|
||||||
g_variant_unref(tooltipVar);
|
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;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,11 +287,36 @@ namespace SNI
|
||||||
{
|
{
|
||||||
if (item.iconData)
|
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>();
|
auto texture = Widget::Create<Texture>();
|
||||||
texture->SetHorizontalTransform({0, true, Alignment::Fill});
|
texture->SetHorizontalTransform({0, true, Alignment::Fill});
|
||||||
texture->SetBuf(item.w, item.h, item.iconData);
|
texture->SetBuf(item.w, item.h, item.iconData);
|
||||||
texture->SetTooltip(item.tooltip);
|
texture->SetTooltip(item.tooltip);
|
||||||
iconBox->AddChild(std::move(texture));
|
|
||||||
|
eventBox->AddChild(std::move(texture));
|
||||||
|
iconBox->AddChild(std::move(eventBox));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parentBox->AddChild(std::move(container));
|
parentBox->AddChild(std::move(container));
|
||||||
|
|
|
@ -173,6 +173,9 @@ void Widget::ApplyPropertiesToWidget()
|
||||||
gtk_widget_set_valign(m_Widget, Utils::ToGtkAlign(m_VerticalTransform.alignment));
|
gtk_widget_set_valign(m_Widget, Utils::ToGtkAlign(m_VerticalTransform.alignment));
|
||||||
gtk_widget_set_hexpand(m_Widget, m_HorizontalTransform.expand);
|
gtk_widget_set_hexpand(m_Widget, m_HorizontalTransform.expand);
|
||||||
gtk_widget_set_vexpand(m_Widget, m_VerticalTransform.expand);
|
gtk_widget_set_vexpand(m_Widget, m_VerticalTransform.expand);
|
||||||
|
|
||||||
|
if (m_OnCreate)
|
||||||
|
m_OnCreate(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Box::SetOrientation(Orientation orientation)
|
void Box::SetOrientation(Orientation orientation)
|
||||||
|
|
|
@ -157,6 +157,8 @@ public:
|
||||||
|
|
||||||
void SetVisible(bool visible);
|
void SetVisible(bool visible);
|
||||||
|
|
||||||
|
void SetOnCreate(Callback<Widget>&& onCreate) { m_OnCreate = onCreate; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void PropagateToParent(GdkEvent* event);
|
void PropagateToParent(GdkEvent* event);
|
||||||
void ApplyPropertiesToWidget();
|
void ApplyPropertiesToWidget();
|
||||||
|
@ -169,6 +171,8 @@ protected:
|
||||||
std::string m_Tooltip;
|
std::string m_Tooltip;
|
||||||
Transform m_HorizontalTransform; // X
|
Transform m_HorizontalTransform; // X
|
||||||
Transform m_VerticalTransform; // Y
|
Transform m_VerticalTransform; // Y
|
||||||
|
|
||||||
|
Callback<Widget> m_OnCreate;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Box : public Widget
|
class Box : public Widget
|
||||||
|
|
Loading…
Reference in a new issue