static void cpufreq_applet_change_orient (MatePanelApplet *pa, MatePanelAppletOrient orient) { CPUFreqApplet *applet; GtkAllocation allocation; gint size; applet = CPUFREQ_APPLET (pa); applet->orient = orient; gtk_widget_get_allocation (GTK_WIDGET (applet), &allocation); if ((orient == MATE_PANEL_APPLET_ORIENT_LEFT) || (orient == MATE_PANEL_APPLET_ORIENT_RIGHT)) { size = allocation.width; gtk_alignment_set (GTK_ALIGNMENT (applet->container), 0.5, 0.5, 0, 0); } else { size = allocation.height; gtk_alignment_set (GTK_ALIGNMENT (applet->container), 0, 0.5, 0, 0); } if (size != applet->size) { applet->size = size; cpufreq_applet_refresh (applet); } }
static void cpufreq_applet_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { CPUFreqApplet *applet; gint size = 0; applet = CPUFREQ_APPLET (widget); GTK_WIDGET_CLASS (cpufreq_applet_parent_class)->size_allocate (widget, allocation); switch (applet->orient) { case MATE_PANEL_APPLET_ORIENT_LEFT: case MATE_PANEL_APPLET_ORIENT_RIGHT: size = allocation->width; break; case MATE_PANEL_APPLET_ORIENT_UP: case MATE_PANEL_APPLET_ORIENT_DOWN: size = allocation->height; break; } if (size != applet->size) { applet->size = size; cpufreq_applet_refresh (applet); } }
static void cpufreq_applet_dispose (GObject *widget) { CPUFreqApplet *applet; gint i; applet = CPUFREQ_APPLET (widget); if (applet->monitor) { g_object_unref (G_OBJECT (applet->monitor)); applet->monitor = NULL; } for (i = 0; i <= 3; i++) { if (applet->pixbufs[i]) { g_object_unref (G_OBJECT (applet->pixbufs[i])); applet->pixbufs[i] = NULL; } } if (applet->prefs) { g_object_unref (applet->prefs); applet->prefs = NULL; } if (applet->popup) { g_object_unref (applet->popup); applet->popup = NULL; } G_OBJECT_CLASS (cpufreq_applet_parent_class)->dispose (widget); }
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 }
static gboolean cpufreq_applet_button_press (GtkWidget *widget, GdkEventButton *event) { CPUFreqApplet *applet; applet = CPUFREQ_APPLET (widget); if (event->button == 2) return FALSE; if (event->button == 1 && event->type != GDK_2BUTTON_PRESS && event->type != GDK_3BUTTON_PRESS) { cpufreq_applet_menu_popup (applet, event->time); return TRUE; } return GTK_WIDGET_CLASS (cpufreq_applet_parent_class)->button_press_event (widget, event); }
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; }
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; }
static gboolean cpufreq_applet_key_press (GtkWidget *widget, GdkEventKey *event) { CPUFreqApplet *applet; applet = CPUFREQ_APPLET (widget); switch (event->keyval) { case GDK_KEY_KP_Enter: case GDK_KEY_ISO_Enter: case GDK_KEY_3270_Enter: case GDK_KEY_Return: case GDK_KEY_space: case GDK_KEY_KP_Space: cpufreq_applet_menu_popup (applet, event->time); return TRUE; default: break; } return FALSE; }