How to change a cursor?

Asked by Ivan Goncharov on 2011-10-26

How to change the cursor from square ⎕ to the underline _ (or some other)?

Question information

Language:
English Edit question
Status:
Solved
For:
Sakura Edit question
Assignee:
No assignee Edit question
Solved by:
Ivan Goncharov
Solved:
2011-10-26
Last query:
2011-10-26
Last reply:
Ivan Goncharov (kovrik0) said : #1

Well, I've just wrote a patch by myself.
Not tested (works fine for me):
http://pastebin.com/KCpUgwZY

--- sakura.c 2011-07-30 23:35:11.000000000 +0400
+++ sakura_u.c 2011-10-26 14:16:13.000000000 +0400
@@ -164,6 +164,7 @@
  bool show_closebutton;
  bool audible_bell;
  bool visible_bell;
+ bool underline_cursor;
  bool blinking_cursor;
  bool borderless;
  bool maximized;
@@ -1276,6 +1277,24 @@

 static void
+sakura_underline_cursor (GtkWidget *widget, void *data)
+{
+ int page;
+ struct terminal *term;
+
+ page = gtk_notebook_get_current_page(GTK_NOTEBOOK(sakura.notebook));
+ term = sakura_get_page_term(sakura, page);
+
+ if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) {
+ vte_terminal_set_cursor_shape (VTE_TERMINAL(term->vte), VTE_CURSOR_SHAPE_UNDERLINE);
+ sakura_set_config_string("underline_cursor", "Yes");
+ } else {
+ vte_terminal_set_cursor_shape (VTE_TERMINAL(term->vte), VTE_CURSOR_SHAPE_BLOCK);
+ sakura_set_config_string("underline_cursor", "No");
+ }
+}
+
+static void
 sakura_borderless (GtkWidget *widget, void *data)
 {
  if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) {
@@ -1686,6 +1705,13 @@
  sakura.blinking_cursor= (strcmp(cfgtmp, "Yes")==0) ? 1 : 0;
  g_free(cfgtmp);

+ if (!g_key_file_has_key(sakura.cfg, cfg_group, "underline_cursor", NULL)) {
+ sakura_set_config_string("underline_cursor", "No");
+ }
+ cfgtmp = g_key_file_get_value(sakura.cfg, cfg_group, "underline_cursor", NULL);
+ sakura.underline_cursor= (strcmp(cfgtmp, "Yes")==0) ? 1 : 0;
+ g_free(cfgtmp);
+
  if (!g_key_file_has_key(sakura.cfg, cfg_group, "borderless", NULL)) {
   sakura_set_config_string("borderless", "No");
  }
@@ -1882,7 +1908,7 @@
            *item_select_background, *item_set_title, *item_full_screen,
            *item_toggle_scrollbar, *item_options, *item_input_methods,
            *item_opacity_menu, *item_show_first_tab, *item_audible_bell, *item_visible_bell,
- *item_blinking_cursor, *item_borderless_maximized,
+ *item_blinking_cursor, *item_borderless_maximized, *item_underline_cursor,
            *item_palette, *item_palette_tango, *item_palette_linux, *item_palette_xterm, *item_palette_rxvt,
            *item_show_close_button;
  GtkAction *action_open_link, *action_copy_link, *action_new_tab, *action_set_name, *action_close_tab,
@@ -1932,6 +1958,7 @@
  item_audible_bell=gtk_check_menu_item_new_with_label(_("Set audible bell"));
  item_visible_bell=gtk_check_menu_item_new_with_label(_("Set visible bell"));
  item_blinking_cursor=gtk_check_menu_item_new_with_label(_("Set blinking cursor"));
+ item_underline_cursor=gtk_check_menu_item_new_with_label(_("Set underline cursor"));
  item_borderless_maximized=gtk_check_menu_item_new_with_label(_("Borderless and maximized"));
  item_input_methods=gtk_menu_item_new_with_label(_("Input methods"));
  item_palette_tango=gtk_radio_menu_item_new_with_label(NULL, "Tango");
@@ -1976,6 +2003,10 @@
   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item_blinking_cursor), TRUE);
  }

+ if (sakura.underline_cursor) {
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item_underline_cursor), TRUE);
+ }
+
  if (sakura.borderless && sakura.maximized) {
   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item_borderless_maximized), TRUE);
  }
@@ -2029,6 +2060,7 @@
  gtk_menu_shell_append(GTK_MENU_SHELL(options_menu), item_visible_bell);
  gtk_menu_shell_append(GTK_MENU_SHELL(options_menu), item_blinking_cursor);
  gtk_menu_shell_append(GTK_MENU_SHELL(options_menu), item_borderless_maximized);
+ gtk_menu_shell_append(GTK_MENU_SHELL(options_menu), item_underline_cursor);
  gtk_menu_shell_append(GTK_MENU_SHELL(options_menu), gtk_separator_menu_item_new());
  gtk_menu_shell_append(GTK_MENU_SHELL(options_menu), item_set_title);
  gtk_menu_shell_append(GTK_MENU_SHELL(options_menu), item_opacity_menu);
@@ -2065,6 +2097,7 @@
  g_signal_connect(G_OBJECT(item_audible_bell), "activate", G_CALLBACK(sakura_audible_bell), NULL);
  g_signal_connect(G_OBJECT(item_visible_bell), "activate", G_CALLBACK(sakura_visible_bell), NULL);
  g_signal_connect(G_OBJECT(item_blinking_cursor), "activate", G_CALLBACK(sakura_blinking_cursor), NULL);
+ g_signal_connect(G_OBJECT(item_underline_cursor), "activate", G_CALLBACK(sakura_underline_cursor), NULL);
  g_signal_connect(G_OBJECT(item_borderless_maximized), "activate", G_CALLBACK(sakura_borderless), NULL);
  g_signal_connect(G_OBJECT(item_borderless_maximized), "activate", G_CALLBACK(sakura_maximized), NULL);
  g_signal_connect(G_OBJECT(action_opacity), "activate", G_CALLBACK(sakura_opacity_dialog), NULL);
@@ -2416,6 +2449,9 @@
  /* Disable stupid blinking cursor */
  vte_terminal_set_cursor_blink_mode (VTE_TERMINAL(term->vte), sakura.blinking_cursor ? VTE_CURSOR_BLINK_ON : VTE_CURSOR_BLINK_OFF);

+ /* Change cursor */
+ vte_terminal_set_cursor_shape (VTE_TERMINAL(term->vte), sakura.underline_cursor ? VTE_CURSOR_SHAPE_UNDERLINE : VTE_CURSOR_SHAPE_BLOCK);
+
  /* Apply user defined window configuration */
  gtk_window_set_decorated (GTK_WINDOW(sakura.main_window), sakura.borderless ? FALSE : TRUE);
  if (sakura.maximized) {

David Gómez (dabisu) said : #2

I added this one. But instead of giving an option to enable underline cursor, i've put a "set cursor type" options that allows to choose from the three cursor types availaible.

Ivan Goncharov (kovrik0) said : #3

Oh, great!
But I have version 2.4.2 installed and can't see such an option...

David Gómez (dabisu) said : #4

It's in the bazaar version. Not released yet because there are some bugs i need to fix before.

Ivan Goncharov (kovrik0) said : #5

OK, thank you very much for your replies! :)
sakura is awesome.