예제 #1
0
파일: helper.c 프로젝트: DeforaOS/Panel
/* panel_init */
static int _panel_init(Panel * panel, PanelWindowPosition position,
		PanelWindowType type, GtkIconSize iconsize)
{
	const PanelPosition top = PANEL_POSITION_TOP;
	char * filename;
	GdkRectangle rect;
	size_t i;

	if((panel->config = config_new()) == NULL)
		return -1;
	if((filename = _config_get_filename()) != NULL
			&& config_load(panel->config, filename) != 0)
		error_print(PROGNAME);
	free(filename);
	panel->prefs.iconsize = NULL;
	panel->prefs.monitor = -1;
	/* root window */
	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[top], panel, type, iconsize);
	panel->windows[top] = panel_window_new(&panel->helper[top],
			PANEL_WINDOW_TYPE_NORMAL, position, iconsize, &rect);
	panel->helper[top].window = panel->windows[top];
	for(i = 0; i < sizeof(panel->windows) / sizeof(*panel->windows); i++)
		if(i != top)
			panel->windows[i] = NULL;
	panel->source = 0;
	panel->timeout = 0;
	panel->ab_window = NULL;
	panel->lk_window = NULL;
	panel->lo_window = NULL;
	panel->sh_window = NULL;
	panel->su_window = NULL;
	return 0;
}
예제 #2
0
파일: panel.c 프로젝트: khorben/DeforaOS
Panel * panel_new(PanelPrefs const * prefs)
{
	Panel * panel;
	GdkRectangle rect;
	GtkIconSize iconsize;
	char const * p;
	gboolean focus;
	gboolean above;

	if((panel = object_new(sizeof(*panel))) == NULL)
		return NULL;
	panel->screen = gdk_screen_get_default();
	if(_new_config(panel) == 0)
		_new_prefs(panel->config, panel->screen, &panel->prefs, prefs);
	panel->top_helper.panel = panel;
	panel->top_helper.type = PANEL_APPLET_TYPE_NORMAL;
	panel->top_helper.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
	panel->top_helper.config_get = _panel_helper_config_get;
	panel->top_helper.config_set = _panel_helper_config_set;
	panel->top_helper.error = _panel_helper_error;
	panel->top_helper.about_dialog = _panel_helper_about_dialog;
	panel->top_helper.lock = _panel_helper_lock;
#ifndef EMBEDDED
	panel->top_helper.logout_dialog = _panel_helper_logout_dialog;
#else
	panel->top_helper.logout_dialog = NULL;
#endif
	panel->top_helper.position_menu = _panel_helper_position_menu_top;
	panel->top_helper.preferences_dialog = _panel_helper_preferences_dialog;
	panel->top_helper.rotate_screen = _panel_helper_rotate_screen;
	panel->top_helper.shutdown_dialog = _panel_helper_shutdown_dialog;
	panel->top_helper.suspend = (_panel_can_suspend())
		? _panel_helper_suspend : NULL;
	panel->top = NULL;
	panel->bottom_helper = panel->top_helper;
	panel->bottom_helper.position_menu = _panel_helper_position_menu_bottom;
	panel->bottom = NULL;
	iconsize = GTK_ICON_SIZE_INVALID;
	if(panel->prefs.iconsize != NULL)
		iconsize = gtk_icon_size_from_name(panel->prefs.iconsize);
	if(iconsize == GTK_ICON_SIZE_INVALID)
	{
		panel->top_helper.icon_size = _new_size(panel,
				PANEL_POSITION_TOP);
		panel->bottom_helper.icon_size = _new_size(panel,
				PANEL_POSITION_BOTTOM);
	}
	else
	{
		panel->top_helper.icon_size = iconsize;
		panel->bottom_helper.icon_size = iconsize;
	}
	panel->pr_window = NULL;
	panel->ab_window = NULL;
#ifndef EMBEDDED
	panel->lo_window = NULL;
#endif
	panel->sh_window = NULL;
	if(panel->config == NULL)
	{
		panel_error(NULL, error_get(), 0); /* XXX put up a dialog box */
		panel_delete(panel);
		return NULL;
	}
	/* root window */
	panel->root = gdk_screen_get_root_window(panel->screen);
	_panel_reset(panel, &rect);
	focus = ((p = config_get(panel->config, NULL, "accept_focus")) == NULL
			|| strcmp(p, "1") == 0) ? TRUE : FALSE;
	above = ((p = config_get(panel->config, NULL, "keep_above")) == NULL
			|| strcmp(p, "1") == 0) ? TRUE : FALSE;
	panel->source = 0;
	/* top panel */
	if(config_get(panel->config, NULL, "top") != NULL)
	{
		panel->top = panel_window_new(PANEL_POSITION_TOP,
				&panel->top_helper, &rect);
		panel_window_set_accept_focus(panel->top, focus);
		panel_window_set_keep_above(panel->top, above);
	}
	/* bottom panel */
	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_helper, &rect);
		panel_window_set_accept_focus(panel->bottom, focus);
		panel_window_set_keep_above(panel->bottom, above);
	}
	/* messages */
	desktop_message_register(PANEL_CLIENT_MESSAGE, _new_on_message, panel);
	/* manage root window events */
	gdk_window_set_events(panel->root, gdk_window_get_events(
				panel->root) | GDK_PROPERTY_CHANGE_MASK);
	gdk_window_add_filter(panel->root, _on_root_event, panel);
	/* load plug-ins when idle */
	panel->source = g_idle_add(_on_idle, panel);
	return panel;
}