Preparing for code re-use through a common library
This commit is contained in:
parent
1efd43575a
commit
ef32f3fc0e
|
@ -230,7 +230,7 @@ Panel * panel_new(PanelPrefs const * prefs)
|
|||
/* top panel */
|
||||
if(config_get(panel->config, NULL, "top") != NULL)
|
||||
{
|
||||
panel->top = panel_window_new(PANEL_POSITION_TOP,
|
||||
panel->top = panel_window_new(PANEL_WINDOW_POSITION_TOP,
|
||||
&panel->top_helper, &rect);
|
||||
panel_window_set_accept_focus(panel->top, focus);
|
||||
panel_window_set_keep_above(panel->top, above);
|
||||
|
@ -239,7 +239,7 @@ Panel * panel_new(PanelPrefs const * prefs)
|
|||
if(config_get(panel->config, NULL, "bottom") != NULL
|
||||
|| config_get(panel->config, NULL, "top") == NULL)
|
||||
{
|
||||
panel->bottom = panel_window_new(PANEL_POSITION_BOTTOM,
|
||||
panel->bottom = panel_window_new(PANEL_WINDOW_POSITION_BOTTOM,
|
||||
&panel->bottom_helper, &rect);
|
||||
panel_window_set_accept_focus(panel->bottom, focus);
|
||||
panel_window_set_keep_above(panel->bottom, above);
|
||||
|
|
68
src/window.c
68
src/window.c
|
@ -62,7 +62,7 @@ struct _PanelWindow
|
|||
|
||||
/* widgets */
|
||||
GtkWidget * window;
|
||||
GtkWidget * hbox;
|
||||
GtkWidget * box;
|
||||
};
|
||||
|
||||
|
||||
|
@ -79,7 +79,7 @@ static gboolean _panel_window_on_configure_event(GtkWidget * widget,
|
|||
/* public */
|
||||
/* functions */
|
||||
/* panel_window_new */
|
||||
PanelWindow * panel_window_new(PanelPosition position,
|
||||
PanelWindow * panel_window_new(PanelWindowPosition position,
|
||||
PanelAppletHelper * helper, GdkRectangle * root)
|
||||
{
|
||||
PanelWindow * panel;
|
||||
|
@ -98,25 +98,69 @@ PanelWindow * panel_window_new(PanelPosition position,
|
|||
panel->applets = NULL;
|
||||
panel->applets_cnt = 0;
|
||||
panel->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_container_set_border_width(GTK_CONTAINER(panel->window), 4);
|
||||
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||
gtk_window_set_has_resize_grip(GTK_WINDOW(panel->window), FALSE);
|
||||
#endif
|
||||
panel->height = icon_height + (PANEL_BORDER_WIDTH * 4);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s() %u height=%d\n", __func__, position,
|
||||
panel->height);
|
||||
#endif
|
||||
switch(position)
|
||||
{
|
||||
case PANEL_WINDOW_POSITION_TOP:
|
||||
case PANEL_WINDOW_POSITION_BOTTOM:
|
||||
#if GTK_CHECK_VERSION(2, 6, 0)
|
||||
gtk_window_set_focus_on_map(GTK_WINDOW(panel->window), FALSE);
|
||||
gtk_window_set_focus_on_map(GTK_WINDOW(panel->window),
|
||||
FALSE);
|
||||
#endif
|
||||
gtk_window_set_type_hint(GTK_WINDOW(panel->window),
|
||||
GDK_WINDOW_TYPE_HINT_DOCK);
|
||||
gtk_window_stick(GTK_WINDOW(panel->window));
|
||||
gtk_window_set_type_hint(GTK_WINDOW(panel->window),
|
||||
GDK_WINDOW_TYPE_HINT_DOCK);
|
||||
gtk_window_stick(GTK_WINDOW(panel->window));
|
||||
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||
panel->box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
|
||||
#else
|
||||
panel->box = gtk_hbox_new(FALSE, 2);
|
||||
#endif
|
||||
break;
|
||||
case PANEL_WINDOW_POSITION_LEFT:
|
||||
case PANEL_WINDOW_POSITION_RIGHT:
|
||||
#if GTK_CHECK_VERSION(2, 6, 0)
|
||||
gtk_window_set_focus_on_map(GTK_WINDOW(panel->window),
|
||||
FALSE);
|
||||
#endif
|
||||
gtk_window_set_type_hint(GTK_WINDOW(panel->window),
|
||||
GDK_WINDOW_TYPE_HINT_DOCK);
|
||||
gtk_window_stick(GTK_WINDOW(panel->window));
|
||||
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||
panel->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
|
||||
#else
|
||||
panel->box = gtk_vbox_new(FALSE, 2);
|
||||
#endif
|
||||
break;
|
||||
case PANEL_WINDOW_POSITION_CENTER:
|
||||
gtk_window_set_position(GTK_WINDOW(panel->window),
|
||||
GTK_WIN_POS_CENTER_ALWAYS);
|
||||
case PANEL_WINDOW_POSITION_FLOATING:
|
||||
gtk_window_set_accept_focus(GTK_WINDOW(panel->window),
|
||||
FALSE);
|
||||
gtk_window_set_decorated(GTK_WINDOW(panel->window),
|
||||
FALSE);
|
||||
case PANEL_WINDOW_POSITION_MANAGED:
|
||||
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||
panel->box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
|
||||
#else
|
||||
panel->box = gtk_hbox_new(FALSE, 2);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
g_signal_connect(panel->window, "configure-event", G_CALLBACK(
|
||||
_panel_window_on_configure_event), panel);
|
||||
g_signal_connect(panel->window, "delete-event", G_CALLBACK(
|
||||
_panel_window_on_closex), NULL);
|
||||
panel->hbox = gtk_hbox_new(FALSE, 2);
|
||||
gtk_container_add(GTK_CONTAINER(panel->window), panel->hbox);
|
||||
gtk_container_set_border_width(GTK_CONTAINER(panel->window), 4);
|
||||
gtk_widget_show_all(panel->hbox);
|
||||
gtk_container_add(GTK_CONTAINER(panel->window), panel->box);
|
||||
gtk_widget_show_all(panel->box);
|
||||
panel_window_reset(panel, position, root);
|
||||
panel_window_show(panel, TRUE);
|
||||
return panel;
|
||||
|
@ -166,7 +210,7 @@ int panel_window_append(PanelWindow * panel, char const * applet)
|
|||
return -error_set_code(1, "%s", strerror(errno));
|
||||
panel->applets = pa;
|
||||
pa = &panel->applets[panel->applets_cnt];
|
||||
if((pa->plugin = plugin_new(LIBDIR, "Panel", "applets", applet))
|
||||
if((pa->plugin = plugin_new(LIBDIR, PACKAGE, "applets", applet))
|
||||
== NULL)
|
||||
return -1;
|
||||
pa->widget = NULL;
|
||||
|
@ -179,7 +223,7 @@ int panel_window_append(PanelWindow * panel, char const * applet)
|
|||
plugin_delete(pa->plugin);
|
||||
return -1;
|
||||
}
|
||||
gtk_box_pack_start(GTK_BOX(panel->hbox), pa->widget, pa->pad->expand,
|
||||
gtk_box_pack_start(GTK_BOX(panel->box), pa->widget, pa->pad->expand,
|
||||
pa->pad->fill, 0);
|
||||
panel->applets_cnt++;
|
||||
return 0;
|
||||
|
|
14
src/window.h
14
src/window.h
|
@ -23,11 +23,23 @@
|
|||
|
||||
/* PanelWindow */
|
||||
/* types */
|
||||
typedef enum _PanelWindowPosition
|
||||
{
|
||||
PANEL_WINDOW_POSITION_BOTTOM = 0,
|
||||
PANEL_WINDOW_POSITION_TOP,
|
||||
PANEL_WINDOW_POSITION_LEFT,
|
||||
PANEL_WINDOW_POSITION_RIGHT,
|
||||
PANEL_WINDOW_POSITION_CENTER,
|
||||
PANEL_WINDOW_POSITION_FLOATING,
|
||||
PANEL_WINDOW_POSITION_MANAGED
|
||||
} PanelWindowPosition;
|
||||
# define PANEL_WINDOW_POSITION_DEFAULT PANEL_WINDOW_POSITION_BOTTOM
|
||||
|
||||
typedef struct _PanelWindow PanelWindow;
|
||||
|
||||
|
||||
/* functions */
|
||||
PanelWindow * panel_window_new(PanelPosition position,
|
||||
PanelWindow * panel_window_new(PanelWindowPosition position,
|
||||
PanelAppletHelper * helper, GdkRectangle * root);
|
||||
void panel_window_delete(PanelWindow * panel);
|
||||
|
||||
|
|
|
@ -99,6 +99,8 @@ static int _panel_init(Panel * panel, PanelAppletType type,
|
|||
GtkIconSize iconsize);
|
||||
static void _panel_destroy(Panel * panel);
|
||||
|
||||
static void _panel_set_title(Panel * panel, char const * title);
|
||||
|
||||
#define HELPER_POSITION_MENU_WIDGET
|
||||
#include "../src/helper.c"
|
||||
static int _panel_append(Panel * panel, PanelPosition position,
|
||||
|
@ -204,6 +206,13 @@ static void _panel_destroy(Panel * panel)
|
|||
}
|
||||
|
||||
|
||||
/* panel_set_title */
|
||||
static void _panel_set_title(Panel * panel, char const * title)
|
||||
{
|
||||
gtk_window_set_title(GTK_WINDOW(panel->top.window), title);
|
||||
}
|
||||
|
||||
|
||||
/* panel_append */
|
||||
static int _panel_append(Panel * panel, PanelPosition position,
|
||||
char const * applet)
|
||||
|
@ -265,7 +274,7 @@ static int _panel_window_append(PanelWindow * window, char const * applet)
|
|||
return -error_set_code(1, "%s", strerror(errno));
|
||||
window->applets = pa;
|
||||
pa = &window->applets[window->applets_cnt];
|
||||
if((pa->plugin = plugin_new(LIBDIR, "Panel", "applets", applet))
|
||||
if((pa->plugin = plugin_new(LIBDIR, PACKAGE, "applets", applet))
|
||||
== NULL)
|
||||
return -1;
|
||||
pa->widget = NULL;
|
||||
|
|
|
@ -76,7 +76,7 @@ static int _notify(GtkIconSize iconsize, int timeout, char * applets[])
|
|||
gtk_window_set_decorated(GTK_WINDOW(panel.top.window), FALSE);
|
||||
gtk_window_set_position(GTK_WINDOW(panel.top.window),
|
||||
GTK_WIN_POS_CENTER_ALWAYS);
|
||||
gtk_window_set_title(GTK_WINDOW(panel.top.window), _("Notification"));
|
||||
_panel_set_title(&panel, _("Notification"));
|
||||
for(i = 0; applets[i] != NULL; i++)
|
||||
if(_panel_append(&panel, PANEL_POSITION_TOP, applets[i]) != 0)
|
||||
error_print(PROGNAME);
|
||||
|
|
|
@ -64,7 +64,7 @@ static int _test(GtkIconSize iconsize, char * applets[])
|
|||
size_t i;
|
||||
|
||||
_panel_init(&panel, PANEL_APPLET_TYPE_NORMAL, iconsize);
|
||||
gtk_window_set_title(GTK_WINDOW(panel.top.window), _("Applet tester"));
|
||||
_panel_set_title(&panel, _("Applet tester"));
|
||||
for(i = 0; applets[i] != NULL; i++)
|
||||
if(_panel_append(&panel, PANEL_POSITION_TOP, applets[i]) != 0)
|
||||
error_print(PROGNAME);
|
||||
|
|
Loading…
Reference in New Issue
Block a user