2016-09-06 55 views
0

我建立一個簡單的XFCE面板插件,它dispalys標記爲「Hello World」的按鈕,但只能顯示字符串的一半。如何設置XFCE的面板插件寬度

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。

回答

0

你錯過了「大小改變」的信號。 如果添加以下代碼它會按預期方式工作:

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); 
} 

enter image description here

講究,你還缺少重要的回調,如「無數據」和「方向改變的」。請注意,由於Xfce 4.12,GTK + 3.0插件也受支持,您只需在.desktop文件中設置X-XFCE-API = 2.0即可。

來源:xfce4-sample-plugin

+0

它確實有效!謝謝! –