From 209b02af91d47caabd0dd228e74b257727de833e Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 23 Oct 2015 19:24:14 +0200 Subject: [PATCH] Align tests with the actual code --- src/helper.c | 4 ++-- src/panel.c | 8 +++++++- tools/helper.c | 49 +++++++++++++++++++++++++++++++++---------------- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/helper.c b/src/helper.c index ee1f20f..dfdb6a9 100644 --- a/src/helper.c +++ b/src/helper.c @@ -354,8 +354,8 @@ static void _panel_helper_position_menu_widget(Panel * panel, GtkMenu * menu, #endif if(req.height <= 0) return; - panel_window_get_position(panel->top, x, y); - panel_window_get_size(panel->top, &sx, &sy); + panel_window_get_position(panel->windows[PANEL_POSITION_TOP], x, y); + panel_window_get_size(panel->windows[PANEL_POSITION_TOP], &sx, &sy); *y += sy; *push_in = TRUE; } diff --git a/src/panel.c b/src/panel.c index dc98efc..7cc68a5 100644 --- a/src/panel.c +++ b/src/panel.c @@ -69,7 +69,10 @@ struct _Panel GdkWindow * root; gint root_width; /* width of the root window */ gint root_height; /* height of the root window */ - gint source; + guint source; +#if 1 /* XXX for tests */ + guint timeout; +#endif /* preferences */ GtkWidget * pr_window; @@ -178,6 +181,7 @@ Panel * panel_new(PanelPrefs const * prefs) /* root window */ panel->root = gdk_screen_get_root_window(panel->screen); panel->source = 0; + panel->timeout = 0; /* panel windows */ if(panel_reset(panel) != 0) { @@ -362,6 +366,8 @@ void panel_delete(Panel * panel) { size_t i; + if(panel->timeout != 0) + g_source_remove(panel->timeout); if(panel->source != 0) g_source_remove(panel->source); for(i = 0; i < sizeof(panel->windows) / sizeof(*panel->windows); i++) diff --git a/tools/helper.c b/tools/helper.c index b512cf7..946616a 100644 --- a/tools/helper.c +++ b/tools/helper.c @@ -40,14 +40,18 @@ struct _Panel { Config * config; - PanelAppletHelper helper; - PanelWindow * top; + PanelPrefs prefs; - guint timeout; + PanelAppletHelper helper[PANEL_POSITION_COUNT]; + PanelWindow * windows[PANEL_POSITION_COUNT]; + + GdkScreen * screen; + GdkWindow * root; gint root_width; /* width of the root window */ gint root_height; /* height of the root window */ guint source; + guint timeout; /* dialogs */ GtkWidget * ab_window; @@ -128,8 +132,8 @@ static int _panel_init(Panel * panel, PanelWindowPosition position, PanelWindowType type, GtkIconSize iconsize) { char * filename; - GdkScreen * screen; GdkRectangle rect; + size_t i; if((panel->config = config_new()) == NULL) return -1; @@ -137,18 +141,26 @@ static int _panel_init(Panel * panel, PanelWindowPosition position, && config_load(panel->config, filename) != 0) error_print(PROGNAME); free(filename); + panel->prefs.iconsize = NULL; + panel->prefs.monitor = -1; /* root window */ - screen = gdk_screen_get_default(); - gdk_screen_get_monitor_geometry(screen, 0, &rect); + panel->screen = gdk_screen_get_default(); + panel->root = gdk_screen_get_root_window(panel->screen); + gdk_screen_get_monitor_geometry(panel->screen, 0, &rect); panel->root_height = rect.height; panel->root_width = rect.width; /* panel window */ - _helper_init(&panel->helper, panel, type, iconsize); - panel->top = panel_window_new(&panel->helper, PANEL_WINDOW_TYPE_NORMAL, - position, iconsize, &rect); - panel->helper.window = panel->top; - panel->timeout = 0; + _helper_init(&panel->helper[PANEL_POSITION_TOP], panel, type, iconsize); + panel->windows[PANEL_POSITION_TOP] = panel_window_new( + &panel->helper[PANEL_POSITION_TOP], + PANEL_WINDOW_TYPE_NORMAL, position, iconsize, &rect); + panel->helper[PANEL_POSITION_TOP].window + = panel->windows[PANEL_POSITION_TOP]; + for(i = 0; i < sizeof(panel->windows) / sizeof(*panel->windows); i++) + if(i != PANEL_POSITION_TOP) + panel->windows[i] = NULL; panel->source = 0; + panel->timeout = 0; panel->ab_window = NULL; panel->lo_window = NULL; panel->sh_window = NULL; @@ -159,11 +171,15 @@ static int _panel_init(Panel * panel, PanelWindowPosition position, /* panel_destroy */ static void _panel_destroy(Panel * panel) { + size_t i; + if(panel->timeout != 0) g_source_remove(panel->timeout); if(panel->source != 0) g_source_remove(panel->source); - panel_window_delete(panel->top); + for(i = 0; i < sizeof(panel->windows) / sizeof(*panel->windows); i++) + if(panel->windows[i] != NULL) + panel_window_delete(panel->windows[i]); if(panel->ab_window != NULL) gtk_widget_destroy(panel->ab_window); if(panel->lo_window != NULL) @@ -177,14 +193,14 @@ static void _panel_destroy(Panel * panel) /* panel_get_xid */ static uint32_t _panel_get_xid(Panel * panel) { - return panel_window_get_xid(panel->top); + return panel_window_get_xid(panel->windows[PANEL_POSITION_TOP]); } /* panel_set_title */ static void _panel_set_title(Panel * panel, char const * title) { - panel_window_set_title(panel->top, title); + panel_window_set_title(panel->windows[PANEL_POSITION_TOP], title); } @@ -194,7 +210,8 @@ static int _panel_append(Panel * panel, PanelPosition position, char const * applet) { if(position == PANEL_POSITION_TOP) - return panel_window_append(panel->top, applet); + return panel_window_append(panel->windows[PANEL_POSITION_TOP], + applet); return -error_set_code(1, "%s", _("Invalid panel position")); } @@ -202,7 +219,7 @@ static int _panel_append(Panel * panel, PanelPosition position, /* panel_show */ static void _panel_show(Panel * panel, gboolean show) { - panel_window_show(panel->top, show); + panel_window_show(panel->windows[PANEL_POSITION_TOP], show); }