Factored some more code
This commit is contained in:
parent
3d9a1a1c85
commit
0497a8ab85
|
@ -62,6 +62,7 @@ typedef struct _PanelWindow
|
|||
struct _Panel
|
||||
{
|
||||
Config * config;
|
||||
PanelAppletHelper helper;
|
||||
|
||||
/* FIXME should not be needed */
|
||||
GtkWidget * window;
|
||||
|
@ -93,12 +94,23 @@ int panel_window_get_height(PanelWindow * panel);
|
|||
|
||||
/* private */
|
||||
/* prototypes */
|
||||
static int _panel_init(Panel * panel, GtkIconSize iconsize);
|
||||
/* Panel */
|
||||
static int _panel_init(Panel * panel, PanelAppletType type,
|
||||
GtkIconSize iconsize);
|
||||
static void _panel_destroy(Panel * panel);
|
||||
|
||||
#define HELPER_POSITION_MENU_WIDGET
|
||||
#include "../src/helper.c"
|
||||
static int _panel_append(Panel * panel, unsigned int window,
|
||||
char const * applet);
|
||||
|
||||
/* PanelWindow */
|
||||
static void _panel_window_init(PanelWindow * panel, GtkIconSize iconsize);
|
||||
static void _panel_window_destroy(PanelWindow * panel);
|
||||
|
||||
static int _panel_window_append(PanelWindow * window,
|
||||
PanelAppletHelper * helper, char const * applet);
|
||||
|
||||
static int _applet_list(void);
|
||||
static char * _config_get_filename(void);
|
||||
|
||||
|
@ -113,12 +125,6 @@ static gboolean _panel_window_on_closex(void);
|
|||
static void _helper_init(PanelAppletHelper * helper, Panel * panel,
|
||||
PanelAppletType type, GtkIconSize iconsize);
|
||||
|
||||
/* useful */
|
||||
#define HELPER_POSITION_MENU_WIDGET
|
||||
#include "../src/helper.c"
|
||||
static int _helper_append(PanelAppletHelper * helper, PanelWindow * window,
|
||||
char const * applet);
|
||||
|
||||
|
||||
/* public */
|
||||
/* functions */
|
||||
|
@ -147,8 +153,10 @@ int panel_window_get_height(PanelWindow * panel)
|
|||
|
||||
/* private */
|
||||
/* functions */
|
||||
/* Panel */
|
||||
/* panel_init */
|
||||
static int _panel_init(Panel * panel, GtkIconSize iconsize)
|
||||
static int _panel_init(Panel * panel, PanelAppletType type,
|
||||
GtkIconSize iconsize)
|
||||
{
|
||||
char * filename;
|
||||
GdkScreen * screen;
|
||||
|
@ -174,6 +182,7 @@ static int _panel_init(Panel * panel, GtkIconSize iconsize)
|
|||
gdk_screen_get_monitor_geometry(screen, 0, &rect);
|
||||
panel->root_height = rect.height;
|
||||
panel->root_width = rect.width;
|
||||
_helper_init(&panel->helper, panel, type, iconsize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -195,6 +204,15 @@ static void _panel_destroy(Panel * panel)
|
|||
}
|
||||
|
||||
|
||||
/* panel_append */
|
||||
static int _panel_append(Panel * panel, unsigned int window,
|
||||
char const * applet)
|
||||
{
|
||||
return _panel_window_append(&panel->top, &panel->helper, applet);
|
||||
}
|
||||
|
||||
|
||||
/* PanelWindow */
|
||||
/* panel_window_init */
|
||||
static void _panel_window_init(PanelWindow * panel, GtkIconSize iconsize)
|
||||
{
|
||||
|
@ -231,6 +249,35 @@ static void _panel_window_destroy(PanelWindow * panel)
|
|||
}
|
||||
|
||||
|
||||
/* panel_window_append */
|
||||
static int _panel_window_append(PanelWindow * window,
|
||||
PanelAppletHelper * helper, char const * applet)
|
||||
{
|
||||
PanelApplet * pa;
|
||||
GtkWidget * widget;
|
||||
|
||||
if((pa = realloc(window->applets, sizeof(*pa)
|
||||
* (window->applets_cnt + 1))) == NULL)
|
||||
return error_print(PROGNAME);
|
||||
window->applets = pa;
|
||||
pa = &window->applets[window->applets_cnt];
|
||||
if((pa->plugin = plugin_new(LIBDIR, "Panel", "applets", applet))
|
||||
== NULL)
|
||||
return error_print(PROGNAME);
|
||||
if((pa->pad = plugin_lookup(pa->plugin, "applet")) == NULL)
|
||||
{
|
||||
plugin_delete(pa->plugin);
|
||||
return error_print(PROGNAME);
|
||||
}
|
||||
widget = NULL;
|
||||
if((pa->pa = pa->pad->init(helper, &widget)) != NULL && widget != NULL)
|
||||
gtk_box_pack_start(GTK_BOX(window->box), widget,
|
||||
pa->pad->expand, pa->pad->fill, 0);
|
||||
window->applets_cnt++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* applet_list */
|
||||
static int _applet_list(void)
|
||||
{
|
||||
|
@ -324,33 +371,6 @@ static void _helper_init(PanelAppletHelper * helper, Panel * panel,
|
|||
|
||||
|
||||
/* useful */
|
||||
/* helper_append */
|
||||
static int _helper_append(PanelAppletHelper * helper, PanelWindow * window,
|
||||
char const * applet)
|
||||
{
|
||||
PanelApplet * pa;
|
||||
GtkWidget * widget;
|
||||
|
||||
if((pa = realloc(window->applets, sizeof(*pa)
|
||||
* (window->applets_cnt + 1))) == NULL)
|
||||
return error_print(PROGNAME);
|
||||
window->applets = pa;
|
||||
pa = &window->applets[window->applets_cnt];
|
||||
if((pa->plugin = plugin_new(LIBDIR, "Panel", "applets", applet))
|
||||
== NULL)
|
||||
return error_print(PROGNAME);
|
||||
if((pa->pad = plugin_lookup(pa->plugin, "applet")) == NULL)
|
||||
{
|
||||
plugin_delete(pa->plugin);
|
||||
return error_print(PROGNAME);
|
||||
}
|
||||
widget = NULL;
|
||||
if((pa->pa = pa->pad->init(helper, &widget)) != NULL && widget != NULL)
|
||||
gtk_box_pack_start(GTK_BOX(window->box), widget,
|
||||
pa->pad->expand, pa->pad->fill, 0);
|
||||
window->applets_cnt++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* callbacks */
|
||||
|
|
|
@ -66,9 +66,8 @@ static int _notify(GtkIconSize iconsize, int timeout, char * applets[])
|
|||
{
|
||||
Panel panel;
|
||||
size_t i;
|
||||
PanelAppletHelper helper;
|
||||
|
||||
_panel_init(&panel, iconsize);
|
||||
_panel_init(&panel, PANEL_APPLET_TYPE_NOTIFICATION, iconsize);
|
||||
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||
gtk_window_set_has_resize_grip(GTK_WINDOW(panel.top.window), FALSE);
|
||||
#endif
|
||||
|
@ -78,9 +77,8 @@ static int _notify(GtkIconSize iconsize, int timeout, char * applets[])
|
|||
gtk_window_set_position(GTK_WINDOW(panel.top.window),
|
||||
GTK_WIN_POS_CENTER_ALWAYS);
|
||||
gtk_window_set_title(GTK_WINDOW(panel.top.window), _("Notification"));
|
||||
_helper_init(&helper, &panel, PANEL_APPLET_TYPE_NOTIFICATION, iconsize);
|
||||
for(i = 0; applets[i] != NULL; i++)
|
||||
_helper_append(&helper, &panel.top, applets[i]);
|
||||
_panel_append(&panel, 0, applets[i]);
|
||||
gtk_widget_show_all(panel.top.window);
|
||||
if(timeout > 0)
|
||||
panel.timeout = g_timeout_add(timeout * 1000,
|
||||
|
|
|
@ -64,11 +64,10 @@ static int _test(GtkIconSize iconsize, char * applets[])
|
|||
size_t i;
|
||||
PanelAppletHelper helper;
|
||||
|
||||
_panel_init(&panel, iconsize);
|
||||
_panel_init(&panel, PANEL_APPLET_TYPE_NORMAL, iconsize);
|
||||
gtk_window_set_title(GTK_WINDOW(panel.top.window), _("Applet tester"));
|
||||
_helper_init(&helper, &panel, PANEL_APPLET_TYPE_NORMAL, iconsize);
|
||||
for(i = 0; applets[i] != NULL; i++)
|
||||
_helper_append(&helper, &panel.top, applets[i]);
|
||||
_panel_append(&panel, 0, applets[i]);
|
||||
gtk_widget_show_all(panel.top.window);
|
||||
gtk_main();
|
||||
_panel_destroy(&panel);
|
||||
|
|
Loading…
Reference in New Issue
Block a user