#include gboolean scale_press (GtkWidget *widget, GdkEventButton *event, gpointer data) { /* HACK: clicking with the left mouse button moves the slider to the location of the click. */ if (event->button == 1) event->button = 2; return FALSE; } gboolean scale_release (GtkWidget *widget, GdkEventButton *event, gpointer data) { if (event->button == 1) event->button = 2; return FALSE; } int main (int argc, char **argv) { GtkWidget *window, *vbox, *toolbar, *scale; GtkAdjustment *adjustment; GtkStyleContext *context; GtkToolItem *boxitem; gtk_init (&argc, &argv); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request (window, 300, 200); gtk_window_set_resizable (GTK_WINDOW (window), FALSE); toolbar = gtk_toolbar_new (); context = gtk_widget_get_style_context (toolbar); gtk_style_context_add_class (context, GTK_STYLE_CLASS_PRIMARY_TOOLBAR); adjustment = gtk_adjustment_new (0, 0, 10, 1, 2, 0); scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adjustment); gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE); gtk_widget_set_can_focus (scale, FALSE); gtk_widget_set_size_request (scale, 296, -1); boxitem = gtk_tool_item_new (); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), boxitem, 0); gtk_container_add (GTK_CONTAINER (boxitem), scale); gtk_container_add (GTK_CONTAINER (vbox), toolbar); gtk_container_add (GTK_CONTAINER (window), vbox); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (scale, "button-press-event", G_CALLBACK (scale_press), NULL); g_signal_connect (scale, "button-release-event", G_CALLBACK (scale_release), NULL); gtk_widget_show_all (window); gtk_main (); return 0; }