]> granicus.if.org Git - vim/commitdiff
patch 9.0.0881: cannot get the currently showing mouse shape v9.0.0881
authorBram Moolenaar <Bram@vim.org>
Mon, 14 Nov 2022 19:49:15 +0000 (19:49 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 14 Nov 2022 19:49:15 +0000 (19:49 +0000)
Problem:    Cannot get the currently showing mouse shape.
Solution:   Add getmouseshape().

runtime/doc/builtin.txt
runtime/doc/usr_41.txt
src/evalfunc.c
src/misc2.c
src/proto/misc2.pro
src/testdir/test_functions.vim
src/version.c

index ff93437caf979375f286aa09d61e1d266a36eb28..727ff2a5e0d080854ad62d6e7c133cd29b234fb3 100644 (file)
@@ -246,6 +246,7 @@ getloclist({nr}, {what})    Dict    get specific location list properties
 getmarklist([{buf}])           List    list of global/local marks
 getmatches([{win}])            List    list of current matches
 getmousepos()                  Dict    last known mouse position
+getmouseshape()                        String  current mouse shape name
 getpid()                       Number  process ID of Vim
 getpos({expr})                 List    position of cursor, mark, etc.
 getqflist()                    List    list of quickfix items
@@ -3879,6 +3880,12 @@ getmousepos()                                            *getmousepos()*
                When using |getchar()| the Vim variables |v:mouse_lnum|,
                |v:mouse_col| and |v:mouse_winid| also provide these values.
 
+getmouseshape()                                                *getmouseshape()*
+               Returns the name of the currently showing mouse pointer.
+               When the |+mouseshape| feature is not supported or the shape
+               is unknown an empty string is returned.
+               This function is mainly intended for testing.
+
                                                        *getpid()*
 getpid()       Return a Number which is the process ID of the Vim process.
                On Unix and MS-Windows this is a unique number, until Vim
index e449003a55bda2f346630102fa799652ee1a02cd..5a7820ed77aae081ac34f59ba1d5e5ce53454eaa 100644 (file)
@@ -1110,6 +1110,7 @@ Interactive:                                      *interactive-functions*
        getcharstr()            get a character from the user as a string
        getcharmod()            get modifiers for the last typed character
        getmousepos()           get last known mouse position
+       getmouseshape()         get name of the current mouse shape
        echoraw()               output characters as-is
        feedkeys()              put characters in the typeahead queue
        input()                 get a line from the user
index 4c9ee4cd8d69c179dce39f54001d9e587dc06057..310fa784e0516e65dfdebdabd0208d067e46455a 100644 (file)
@@ -1983,6 +1983,8 @@ static funcentry_T global_functions[] =
                        ret_list_dict_any,  f_getmatches},
     {"getmousepos",    0, 0, 0,            NULL,
                        ret_dict_number,    f_getmousepos},
+    {"getmouseshape",  0, 0, 0,            NULL,
+                       ret_string,         f_getmouseshape},
     {"getpid",         0, 0, 0,            NULL,
                        ret_number,         f_getpid},
     {"getpos",         1, 1, FEARG_1,      arg1_string,
index 84c5f431986f61237eea09e30896652735de4643..d16fb46b6fbf94e18179fc006b0ccd65a11785d1 100644 (file)
@@ -2027,12 +2027,12 @@ cursorentry_T shape_table[SHAPE_IDX_COUNT] =
     {0,        0, 0, 100L, 100L, 100L, 0, 0, "sm", SHAPE_CURSOR},
 };
 
-#ifdef FEAT_MOUSESHAPE
+# ifdef FEAT_MOUSESHAPE
 /*
  * Table with names for mouse shapes.  Keep in sync with all the tables for
  * mch_set_mouse_shape()!.
  */
-static char * mshape_names[] =
+static char *mshape_names[] =
 {
     "arrow",   // default, must be the first one
     "blank",   // hidden
@@ -2052,7 +2052,9 @@ static char * mshape_names[] =
     "up-arrow",
     NULL
 };
-#endif
+
+#  define MSHAPE_NAMES_COUNT  (ARRAY_LENGTH(mshape_names) - 1)
+# endif
 
 /*
  * Parse the 'guicursor' option ("what" is SHAPE_CURSOR) or 'mouseshape'
@@ -2355,7 +2357,7 @@ get_shape_idx(int mouse)
 #endif
 
 # if defined(FEAT_MOUSESHAPE) || defined(PROTO)
-static int old_mouse_shape = 0;
+static int current_mouse_shape = 0;
 
 /*
  * Set the mouse shape:
@@ -2389,18 +2391,18 @@ update_mouseshape(int shape_idx)
        shape_idx = -2;
 
     if (shape_idx == -2
-           && old_mouse_shape != shape_table[SHAPE_IDX_CLINE].mshape
-           && old_mouse_shape != shape_table[SHAPE_IDX_STATUS].mshape
-           && old_mouse_shape != shape_table[SHAPE_IDX_VSEP].mshape)
+           && current_mouse_shape != shape_table[SHAPE_IDX_CLINE].mshape
+           && current_mouse_shape != shape_table[SHAPE_IDX_STATUS].mshape
+           && current_mouse_shape != shape_table[SHAPE_IDX_VSEP].mshape)
        return;
     if (shape_idx < 0)
        new_mouse_shape = shape_table[get_shape_idx(TRUE)].mshape;
     else
        new_mouse_shape = shape_table[shape_idx].mshape;
-    if (new_mouse_shape != old_mouse_shape)
+    if (new_mouse_shape != current_mouse_shape)
     {
        mch_set_mouse_shape(new_mouse_shape);
-       old_mouse_shape = new_mouse_shape;
+       current_mouse_shape = new_mouse_shape;
     }
     postponed_mouseshape = FALSE;
 }
@@ -2408,6 +2410,25 @@ update_mouseshape(int shape_idx)
 
 #endif // CURSOR_SHAPE
 
+#if defined(FEAT_EVAL) || defined(PROTO)
+/*
+ * Mainly for tests: get the name of the current mouse shape.
+ */
+    void
+f_getmouseshape(typval_T *argvars UNUSED, typval_T *rettv)
+{
+    rettv->v_type = VAR_STRING;
+    rettv->vval.v_string = NULL;
+# if defined(FEAT_MOUSESHAPE) || defined(PROTO)
+    if (current_mouse_shape >= 0
+                             && current_mouse_shape < (int)MSHAPE_NAMES_COUNT)
+       rettv->vval.v_string = vim_strsave(
+                                 (char_u *)mshape_names[current_mouse_shape]);
+# endif
+}
+#endif
+
+
 
 /*
  * Change directory to "new_dir".  Search 'cdpath' for relative directory
index 2728ffe64fe2943aff6f5946657288acb8458c75..3d3a5a604a95f3330c5ad37ce874a53b1f4c28f6 100644 (file)
@@ -3,8 +3,8 @@ int virtual_active(void);
 int getviscol(void);
 int coladvance_force(colnr_T wcol);
 int getviscol2(colnr_T col, colnr_T coladd);
-int coladvance(colnr_T wcol);
-int getvpos(pos_T *pos, colnr_T wcol);
+int coladvance(colnr_T wantcol);
+int getvpos(pos_T *pos, colnr_T wantcol);
 int inc_cursor(void);
 int inc(pos_T *lp);
 int incl(pos_T *lp);
@@ -47,6 +47,7 @@ int vim_stat(const char *name, stat_T *stp);
 char *parse_shape_opt(int what);
 int get_shape_idx(int mouse);
 void update_mouseshape(int shape_idx);
+void f_getmouseshape(typval_T *argvars, typval_T *rettv);
 int vim_chdir(char_u *new_dir);
 int get_user_name(char_u *buf, int len);
 void free_username(void);
index cb072215d99562d147b15492f0d30346afc15074..6f109e83589e939d034c1350fcb35b2e2730b696 100644 (file)
@@ -2890,6 +2890,12 @@ func Test_getmousepos()
   bwipe!
 endfunc
 
+func Test_getmouseshape()
+  CheckFeature mouseshape
+
+  call assert_equal('arrow', getmouseshape())
+endfunc
+
 " Test for glob()
 func Test_glob()
   call assert_equal('', glob(test_null_string()))
index f89595a84e4ac2366b9b28db3318ecd25d2075d9..c5e78389a5f90e64075904ec127b676f4b9709c9 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    881,
 /**/
     880,
 /**/