如何设置xfce的面板插件宽度
how to set xfce's panel plugin width
我构建了一个简单的 xfce 面板插件,它显示了一个标记为“Hello World”的按钮。但是,只能显示一半的字符串。
http://en.zimagez.com/miniature/debian807092016010347.png
代码很简单:
#include <gtk/gtk.h>
#include <libxfce4panel/xfce-panel-plugin.h>
static void sample_construct(XfcePanelPlugin *plugin);
XFCE_PANEL_PLUGIN_REGISTER(sample_construct);
static void hello(GtkWidget *widget, gpointer data)
{
g_print("Hello World\n");
}
static void sample_construct(XfcePanelPlugin *plugin)
{
GtkWidget *button;
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL);
gtk_container_add (GTK_CONTAINER (plugin), button);
gtk_widget_show (button);
}
使用此脚本构建和安装:
#!/bin/bash
gcc -Wall -shared -o libsample.so -fPIC sample.c $(pkg-config --cflags --libs libxfce4panel-1.0) $(pkg-config --cflags --libs gtk+-2.0) || \
{ echo "Compiling failed!"; exit 10; }
cp libsample.so /usr/lib/xfce4/panel-plugins
cp sample.desktop /usr/share/xfce4/panel-plugins
其他信息:xfce4.10、Debian 8 jessie。
您错过了 "size-changed" 信号。
如果您添加以下代码,它将按预期工作:
static gboolean
sample_size_changed (XfcePanelPlugin *plugin,
gint size,
void *data)
{
GtkOrientation orientation;
orientation = xfce_panel_plugin_get_orientation (plugin);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
else
gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
return TRUE;
}
static void sample_construct(XfcePanelPlugin *plugin)
{
...
g_signal_connect (G_OBJECT (plugin), "size-changed",
G_CALLBACK (sample_size_changed), NULL);
gtk_widget_show_all (button);
}
请注意,您还缺少重要的回调,例如 "free-data" 和 "orientation-changed"。请注意,自 Xfce 4.12 起,还支持 GTK+ 3.0 插件,您只需在 .desktop 文件中设置 X-XFCE-API=2.0.
我构建了一个简单的 xfce 面板插件,它显示了一个标记为“Hello World”的按钮。但是,只能显示一半的字符串。
http://en.zimagez.com/miniature/debian807092016010347.png
代码很简单:
#include <gtk/gtk.h>
#include <libxfce4panel/xfce-panel-plugin.h>
static void sample_construct(XfcePanelPlugin *plugin);
XFCE_PANEL_PLUGIN_REGISTER(sample_construct);
static void hello(GtkWidget *widget, gpointer data)
{
g_print("Hello World\n");
}
static void sample_construct(XfcePanelPlugin *plugin)
{
GtkWidget *button;
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL);
gtk_container_add (GTK_CONTAINER (plugin), button);
gtk_widget_show (button);
}
使用此脚本构建和安装:
#!/bin/bash
gcc -Wall -shared -o libsample.so -fPIC sample.c $(pkg-config --cflags --libs libxfce4panel-1.0) $(pkg-config --cflags --libs gtk+-2.0) || \
{ echo "Compiling failed!"; exit 10; }
cp libsample.so /usr/lib/xfce4/panel-plugins
cp sample.desktop /usr/share/xfce4/panel-plugins
其他信息:xfce4.10、Debian 8 jessie。
您错过了 "size-changed" 信号。 如果您添加以下代码,它将按预期工作:
static gboolean
sample_size_changed (XfcePanelPlugin *plugin,
gint size,
void *data)
{
GtkOrientation orientation;
orientation = xfce_panel_plugin_get_orientation (plugin);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
else
gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
return TRUE;
}
static void sample_construct(XfcePanelPlugin *plugin)
{
...
g_signal_connect (G_OBJECT (plugin), "size-changed",
G_CALLBACK (sample_size_changed), NULL);
gtk_widget_show_all (button);
}
请注意,您还缺少重要的回调,例如 "free-data" 和 "orientation-changed"。请注意,自 Xfce 4.12 起,还支持 GTK+ 3.0 插件,您只需在 .desktop 文件中设置 X-XFCE-API=2.0.