After about an hour of coding I get a simple application which changes the cursor's color according to the layout. I used two third party scripts: your Python script which reloads GTK settings and the xkblayout application written on the C language which returns the current keyboard layout. I combined this two in my own Ruby script which checks the current layout, changes the style of the text cursor and reloads settings for all of the opened applications. Yet it can only work with GTK applications but I would like to enable Qt and the console support.
The application has a simple structure.
[code='Application sturcture']
layout_indicator/
- reload_gtk_settings.py # a Python script
- show_the_current_layout # a C script
- switch_layout_style.rb # a Ruby scirpt
[/code]
To enable this application to work you should have Python and Ruby installed. You should also create a bunch of GTK configuration files.
First you need to create ~/.gtkrc-2.0: touch ~/.gtkrc-2.0.
The file should contain a single line.
[code='~/.gtkrc']
include ".gtkrc-custom"
[/code]
Second you need to to create ~/.gtkrc-custom-us, ~/.gtkrc-custom-<your_language> and ~/.gtk-custom-default: touch ~/.gtkrc-custom-us ~/.gtkrc-custom-<your_language> ~/.gtk-custom-default.
They should contain the following.
~/.gtk-custom-us
style "custom" {
GtkWidget::cursor-color = "#0000FF"
GtkWidget::secondary-cursor-color = "#0000FF"
}
widget_class "*" style "custom"
This style specifies the blue color for the en-us layout.
~/.gtk-custom-<your-language>
style "custom" {
GtkWidget::cursor-color = "#FF0000"
GtkWidget::secondary-cursor-color = "#FF0000"
}
widget_class "*" style "custom"
This style specifies the red color for your layout.
~/.gtk-custom-default
style "custom" {
GtkWidget::cursor-color = "#000000"
GtkWidget::secondary-cursor-color = "#000000"
}
widget_class "*" style "custom"
This style specifies the black color for the default layout.
Third you need to create a symlink to the ~/.gtkrc-custom-us file: ln -sf /home/<username>/.gtkrc-custom-us /home/<username>/.gtkrc-custom.
Note the symlink should be named .gtkrc-custom.
Fourth you need to place an application directory somewhere. You could move it to the ~/my_scripts directory for example.
Fifth you should change the lines 30, 31 and 32 of the ruby script replacing the default Russian layout to your own.
30. when 'RU' # change to your layout
31. if File.readlink("#{home}/.gtkrc-custom") != "#{home}/.gtkrc-custom-ru" # change the .gtkrc-custom-ru file to .gtkrc-custom-<your_language> here
32. ln_sf("#{home}/.gtkrc-custom-ru", "#{home}/.gtkrc-custom") # and here
And after all of that you can run the script <path_to_layout_indicator>/switch_layout_style.rb. Of course you should have the reload_gtk_settings.py, switch_layout_style.rb and show_the_current_layout files executable. You can use the chmod u+x <filename> command to change ther modes.
To have an ability to autoload that script you can add it to the application list which GNOME loads on the start. To achieve it you should start the application launcher (usually Alt+F2) and then type gnome-session-properties there. The session window should appear and after that you can add the script to the autoloaded application list.
Here's the list of the features that I would like to add to the application.
- an ability to load the application at the start of the system but not GNOME's;
- an ability to change another properties of the text cursor such as its width, blink rate etc.;
- an ability to change the cursor's properties not only for GTK applications but also for Qt and XUL.;
- an ability to change the cursor's color in the console;
- an ability to change the color of the rectangular selection box.
I'd like to hear what you think about how to realise them.
I attach the files of the application to the post. The archive contains the application itself in the layout_indicator directory and the source code of xkblayout. Probably, you'll need to compile it by itself. If so don't forget to rename the output executable file to show_the_current_layout and add it to the layout_indicator dir.
[file name=layout_indicator_source.tar.gz size=4086]http://www.linux.com/media/kunena/attachments/legacy/files/layout_indicator_source-fca906721321cd80791ca9b06754da7e.gz[/file]


