コード例 #1
0
ファイル: cpufreq-applet.c プロジェクト: dnk/mate-applets
cpufreq_applet_size_request (GtkWidget *widget, GtkRequisition *requisition)
#endif
{
	CPUFreqApplet *applet;
	gint           labels_width = 0;
	gint           width;

	applet = CPUFREQ_APPLET (widget);

#if !GTK_CHECK_VERSION (3, 0, 0)
	GTK_WIDGET_CLASS (cpufreq_applet_parent_class)->size_request (widget, requisition);
#endif

	if (applet->orient == MATE_PANEL_APPLET_ORIENT_LEFT ||
	    applet->orient == MATE_PANEL_APPLET_ORIENT_RIGHT)
		return;


 	if (applet->show_freq) {
		labels_width += cpufreq_applet_get_max_label_width (applet) + 2;
 	}
 
 	if (applet->show_perc) {
		labels_width += cpufreq_applet_get_max_perc_width (applet);
 	}
 
 	if (applet->show_unit) {
		labels_width += cpufreq_applet_get_max_unit_width (applet);
	}

	if (applet->show_icon) {
#if GTK_CHECK_VERSION (3, 0, 0)
		gint icon_width;

		gtk_widget_get_preferred_width (applet->icon, &icon_width, NULL);
		width = gtk_orientable_get_orientation (GTK_ORIENTABLE (applet->box)) == GTK_ORIENTATION_HORIZONTAL ?
			labels_width + icon_width + 2 :
			MAX (labels_width, icon_width + 2);
#else
		GtkRequisition req;

		gtk_widget_size_request (applet->icon, &req);
		width = GTK_IS_HBOX (applet->box) ?
			labels_width + req.width + 2 :
			MAX (labels_width, req.width + 2);
#endif
	} else {
		width = labels_width;
	}

#if GTK_CHECK_VERSION (3, 0, 0)
	*minimum_width = *natural_width = width;
#else
	requisition->width = width;
#endif
}
コード例 #2
0
static void
cpufreq_applet_get_preferred_width (GtkWidget *widget,
                                    gint      *minimum_width,
                                    gint      *natural_width)
{
        CPUFreqApplet *applet;
        gint           labels_width = 0;
        gint           width;

        applet = CPUFREQ_APPLET (widget);

        if (applet->orient == PANEL_APPLET_ORIENT_LEFT ||
            applet->orient == PANEL_APPLET_ORIENT_RIGHT)
                return;

        if (applet->show_freq) {
		labels_width += cpufreq_applet_get_max_label_width (applet) + 2;
	}

	if (applet->show_perc) {
		labels_width += cpufreq_applet_get_max_perc_width (applet);
	}

	if (applet->show_unit) {
		labels_width += cpufreq_applet_get_max_unit_width (applet);
	}

	if (applet->show_icon) {
		gint icon_width;

                gtk_widget_get_preferred_width (applet->icon, &icon_width, NULL);
		width = gtk_orientable_get_orientation (GTK_ORIENTABLE (applet->box)) == GTK_ORIENTATION_HORIZONTAL ?
			labels_width + icon_width + 2 :
			MAX (labels_width, icon_width + 2);
	} else {
		width = labels_width;
	}

        *minimum_width = *natural_width = width;
}
コード例 #3
0
static void
cpufreq_applet_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
	CPUFreqApplet *applet;
	gint           labels_width = 0;
	gint           width;

	applet = CPUFREQ_APPLET (widget);

	GTK_WIDGET_CLASS (cpufreq_applet_parent_class)->size_request (widget, requisition);

	if (applet->orient == MATE_PANEL_APPLET_ORIENT_LEFT ||
	    applet->orient == MATE_PANEL_APPLET_ORIENT_RIGHT)
		return;

	if (applet->show_freq) {
		labels_width += cpufreq_applet_get_max_label_width (applet) + 2;
	}

	if (applet->show_perc) {
		labels_width += cpufreq_applet_get_max_perc_width (applet);
	}

	if (applet->show_unit) {
		labels_width += cpufreq_applet_get_max_unit_width (applet);
	}

	if (applet->show_icon) {
		GtkRequisition req;

		gtk_widget_size_request (applet->icon, &req);
		width = GTK_IS_HBOX (applet->box) ?
			labels_width + req.width + 2 :
			MAX (labels_width, req.width + 2);
	} else {
		width = labels_width;
	}

	requisition->width = width;
}
コード例 #4
0
ファイル: cpufreq-applet.c プロジェクト: dnk/mate-applets
static void
cpufreq_applet_refresh (CPUFreqApplet *applet)
{
        gint      total_size = 0;
        gint      panel_size, label_size;
        gint      unit_label_size, pixmap_size;
        gint      size_step = 12;
	gboolean  horizontal;
        gboolean  do_unref = FALSE;

        panel_size = applet->size - 1; /* 1 pixel margin */

	horizontal = (applet->orient == MATE_PANEL_APPLET_ORIENT_UP ||
		      applet->orient == MATE_PANEL_APPLET_ORIENT_DOWN);

        /* We want a fixed label size, the biggest */
	if (horizontal)
		label_size = cpufreq_applet_get_widget_size (applet, applet->label);
	else
		label_size = cpufreq_applet_get_max_label_width (applet);
        total_size += label_size;

	if (horizontal)
		unit_label_size = cpufreq_applet_get_widget_size (applet, applet->unit_label);
	else
		unit_label_size = cpufreq_applet_get_max_unit_width (applet);
        total_size += unit_label_size;

        pixmap_size = cpufreq_applet_get_widget_size (applet, applet->icon);
        total_size += pixmap_size;

        if (applet->box) {
                do_unref = TRUE;
                g_object_ref (applet->icon);
                gtk_container_remove (GTK_CONTAINER (applet->box), applet->icon);
		if (applet->labels_box) {
                        g_object_ref (applet->label);
                        gtk_container_remove (GTK_CONTAINER (applet->labels_box), applet->label);
                        g_object_ref (applet->unit_label);
                        gtk_container_remove (GTK_CONTAINER (applet->labels_box), applet->unit_label);
                }
                gtk_widget_destroy (applet->box);
        }

	if (horizontal) {
#if GTK_CHECK_VERSION (3, 0, 0)
		applet->labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
		if ((label_size + pixmap_size) <= panel_size)
			applet->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
		else
			applet->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
	} else {
                if (total_size <= panel_size) {
                        applet->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
                        applet->labels_box  = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
                } else if ((label_size + unit_label_size) <= (panel_size - size_step)) {
                        applet->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
                        applet->labels_box  = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
                } else {
                        applet->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
                        applet->labels_box  = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
#else
		applet->labels_box = gtk_hbox_new (FALSE, 2);
		if ((label_size + pixmap_size) <= panel_size)
			applet->box = gtk_vbox_new (FALSE, 2);
		else
			applet->box = gtk_hbox_new (FALSE, 2);
	} else {
                if (total_size <= panel_size) {
                        applet->box = gtk_hbox_new (FALSE, 2);
                        applet->labels_box  = gtk_hbox_new (FALSE, 2);
                } else if ((label_size + unit_label_size) <= (panel_size - size_step)) {
                        applet->box = gtk_vbox_new (FALSE, 2);
                        applet->labels_box  = gtk_hbox_new (FALSE, 2);
                } else {
                        applet->box = gtk_vbox_new (FALSE, 2);
                        applet->labels_box  = gtk_vbox_new (FALSE, 2);
#endif
                }
	}

        gtk_box_pack_start (GTK_BOX (applet->labels_box), applet->label, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (applet->labels_box), applet->unit_label, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (applet->box), applet->icon, FALSE, FALSE, 0);

        gtk_box_pack_start (GTK_BOX (applet->box), applet->labels_box, FALSE, FALSE, 0);
        gtk_widget_show (applet->labels_box);

        gtk_container_add (GTK_CONTAINER (applet->container), applet->box);
        gtk_widget_show (applet->box);

        if (do_unref) {
                g_object_unref (applet->label);
                g_object_unref (applet->unit_label);
                g_object_unref (applet->icon);
        }
}