Code

screen_utils: move KEY_MOUSE check to ignore_key(), avoid recursion
[ncmpc.git] / src / screen_utils.c
index 4bb18750fcdb0d92c5e638afc8d0378f422a5fa4..8f69930d64126752b048164fcd1a8d7e9d0df379 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
+ * (c) 2004-2017 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
  *
  * This program is free software; you can redistribute it and/or modify
@@ -38,6 +38,17 @@ screen_bell(void)
                flash();
 }
 
+static bool
+ignore_key(int key)
+{
+       return
+#ifdef HAVE_GETMOUSE
+               /* ignore mouse events */
+               key == KEY_MOUSE ||
+#endif
+               key == ERR;
+}
+
 int
 screen_getch(const char *prompt)
 {
@@ -52,14 +63,7 @@ screen_getch(const char *prompt)
        curs_set(1);
 
        int key;
-       while ((key = wgetch(w)) == ERR)
-               ;
-
-#ifdef HAVE_GETMOUSE
-       /* ignore mouse events */
-       if (key == KEY_MOUSE)
-               return screen_getch(prompt);
-#endif
+       while (ignore_key(key = wgetch(w))) {}
 
        noecho();
        curs_set(0);
@@ -153,28 +157,5 @@ screen_display_completion_list(GList *list)
        }
 
        wrefresh(w);
-       doupdate();
        colors_use(w, COLOR_LIST);
 }
-
-#ifndef NCMPC_MINI
-void
-set_xterm_title(const char *format, ...)
-{
-       /* the current xterm title exists under the WM_NAME property */
-       /* and can be retrieved with xprop -id $WINDOWID */
-
-       if (options.enable_xterm_title) {
-               if (g_getenv("WINDOWID")) {
-                       va_list ap;
-                       va_start(ap,format);
-                       char *msg = g_strdup_vprintf(format,ap);
-                       va_end(ap);
-                       printf("\033]0;%s\033\\", msg);
-                       fflush(stdout);
-                       g_free(msg);
-               } else
-                       options.enable_xterm_title = FALSE;
-       }
-}
-#endif