/* Compile with: 
*       gcc -Wall -o keybinding_css `pkg-config --cflags --libs gtk+-3.0` keybinding_css.c                           
*/
#include <gtk/gtk.h>

int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget * textview;
  GtkCssProvider *provider;
  GtkTextBuffer *buffer;
  gtk_init (&argc, &argv);


  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  textview = gtk_text_view_new();
  buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));

  char * text = "this is a test";
  gtk_text_buffer_set_text(buffer, text, -1);
  
  gtk_window_set_default_size (GTK_WINDOW(window),
                               500, 300);

  g_signal_connect (GTK_WIDGET(window),
                    "destroy",
                    G_CALLBACK (gtk_main_quit),
                    NULL);

/*------  CSS  ---------------------------------------------------------------------------------------------------------------*/
  provider = gtk_css_provider_new ();
  
  gtk_style_context_add_provider(gtk_widget_get_style_context(textview),GTK_STYLE_PROVIDER(provider),GTK_STYLE_PROVIDER_PRIORITY_USER);
  
  gtk_css_provider_load_from_data (GTK_CSS_PROVIDER(provider),
                                   "@binding-set MoveCursor3 {\n"
                                   "bind \"<Control>k\" { \"move-cursor\" (visual-positions, 0, 1) };\n"
                                   "bind \"<Control>l\" { \"move-cursor\" (buffer-starts, 0, 0) };\n"
                                   "}\n"
                                   " GtkTextView {\n"
                                   "   background-color: blue;\n"              /* named color units */
                                    "gtk-key-bindings: MoveCursor3;\n"
                                   "}\n", -1, NULL);
  g_object_unref (provider);
/*----------------------------------------------------------------------------------------------------------------------------*/

  gtk_container_add(GTK_CONTAINER(window), textview);
  gtk_widget_show_all (window);
  gtk_main ();
return (0);
}
