Ticket #3011: mc-gpm-x-term-fixes.patch
File mc-gpm-x-term-fixes.patch, 8.5 KB (added by acobar, 11 years ago) |
---|
-
lib/tty/mouse.h
old new 97 97 /* Type of the currently used mouse */ 98 98 extern Mouse_Type use_mouse_p; 99 99 100 /* To be used when gpm_fd were initially >= 0 */ 101 extern int mouse_fd; 102 100 103 /* String indicating that a mouse event has occurred, usually "\E[M" */ 101 104 extern const char *xmouse_seq; 102 105 -
lib/tty/mouse.c
old new 47 47 48 48 Mouse_Type use_mouse_p = MOUSE_NONE; 49 49 gboolean mouse_enabled = FALSE; 50 int mouse_fd = -1; /* for when gpm_fd changes to < 0 and the old one must be cleared from select_set */ 50 51 const char *xmouse_seq; 51 52 const char *xmouse_extended_seq; 52 53 … … 114 115 #ifdef HAVE_LIBGPM 115 116 case MOUSE_GPM: 116 117 { 117 int mouse_d;118 118 Gpm_Connect conn; 119 119 120 120 conn.eventMask = ~GPM_MOVE; … … 122 122 conn.minMod = 0; 123 123 conn.maxMod = 0; 124 124 125 mouse_ d = Gpm_Open (&conn, 0);126 if (mouse_ d == -1)125 mouse_fd = Gpm_Open (&conn, 0); 126 if (mouse_fd == -1) 127 127 { 128 128 use_mouse_p = MOUSE_NONE; 129 129 return; -
lib/tty/key.c
old new 1342 1342 || (term != NULL 1343 1343 && (strncmp (term, "iris-ansi", 9) == 0 1344 1344 || strncmp (term, "xterm", 5) == 0 1345 || strncmp (term, "rxvt", 4) == 0 || str cmp (term, "screen") == 0)))1345 || strncmp (term, "rxvt", 4) == 0 || strncmp (term, "screen", 6) == 0))) 1346 1346 define_sequences (xterm_key_defines); 1347 1347 1348 1348 /* load some additional keys (e.g. direct Alt-? support) */ … … 1724 1724 gboolean 1725 1725 is_idle (void) 1726 1726 { 1727 int maxfdp;1727 int nfd = max (0, input_fd) + 1; 1728 1728 fd_set select_set; 1729 1729 struct timeval time_out; 1730 1730 1731 1731 FD_ZERO (&select_set); 1732 1732 FD_SET (input_fd, &select_set); 1733 maxfdp = input_fd; 1733 time_out.tv_sec = 0; 1734 time_out.tv_usec = 0; 1734 1735 #ifdef HAVE_LIBGPM 1735 if (mouse_enabled && (use_mouse_p == MOUSE_GPM) && (gpm_fd > 0))1736 if (mouse_enabled && use_mouse_p == MOUSE_GPM) 1736 1737 { 1737 FD_SET (gpm_fd, &select_set); 1738 maxfdp = max (maxfdp, gpm_fd); 1738 if (gpm_fd >= 0) 1739 { 1740 FD_SET (gpm_fd, &select_set); 1741 nfd = max (nfd, gpm_fd + 1); 1742 } 1743 else 1744 { 1745 if (mouse_fd >= 0) /* error indicative */ 1746 { 1747 if (FD_ISSET (mouse_fd, &select_set)) 1748 FD_CLR (mouse_fd, &select_set); 1749 mouse_fd = gpm_fd; 1750 } 1751 /* gpm_fd == -2 means under some X terminal */ 1752 if (gpm_fd == -1) 1753 { 1754 mouse_enabled = FALSE; 1755 use_mouse_p = MOUSE_NONE; 1756 } 1757 } 1739 1758 } 1740 1759 #endif 1741 time_out.tv_sec = 0; 1742 time_out.tv_usec = 0; 1743 return (select (maxfdp + 1, &select_set, 0, 0, &time_out) <= 0); 1760 return (select (nfd, &select_set, 0, 0, &time_out) <= 0); 1744 1761 } 1745 1762 1746 1763 /* --------------------------------------------------------------------------------------------- */ … … 1974 1991 /* Repeat if using mouse */ 1975 1992 while (pending_keys == NULL) 1976 1993 { 1977 int maxfdp;1994 int nfd; 1978 1995 fd_set select_set; 1979 1996 1980 1997 FD_ZERO (&select_set); 1981 1998 FD_SET (input_fd, &select_set); 1982 maxfdp = max (add_selects (&select_set), input_fd);1999 nfd = max (add_selects (&select_set), max (0, input_fd)) + 1; 1983 2000 1984 2001 #ifdef HAVE_LIBGPM 1985 2002 if (mouse_enabled && (use_mouse_p == MOUSE_GPM)) 1986 2003 { 1987 if (gpm_fd <0)2004 if (gpm_fd >= 0) 1988 2005 { 1989 /* Connection to gpm broken, possibly gpm has died */ 1990 mouse_enabled = FALSE; 1991 use_mouse_p = MOUSE_NONE; 2006 FD_SET (gpm_fd, &select_set); 2007 nfd = max (nfd, gpm_fd + 1); 2008 } 2009 else 2010 { 2011 if (mouse_fd >= 0) /* error indicative */ 2012 { 2013 if (FD_ISSET (mouse_fd, &select_set)) 2014 FD_CLR (mouse_fd, &select_set); 2015 mouse_fd = gpm_fd; 2016 } 2017 /* gpm_fd == -2 means under some X terminal */ 2018 if (gpm_fd == -1) 2019 { 2020 mouse_enabled = FALSE; 2021 use_mouse_p = MOUSE_NONE; 2022 } 1992 2023 break; 1993 2024 } 1994 1995 FD_SET (gpm_fd, &select_set);1996 maxfdp = max (maxfdp, gpm_fd);1997 2025 } 1998 2026 #endif 1999 2027 … … 2032 2060 } 2033 2061 2034 2062 tty_enable_interrupt_key (); 2035 flag = select ( maxfdp + 1, &select_set, NULL, NULL, time_addr);2063 flag = select (nfd, &select_set, NULL, NULL, time_addr); 2036 2064 tty_disable_interrupt_key (); 2037 2065 2038 2066 /* select timed out: it could be for any of the following reasons: … … 2056 2084 if (FD_ISSET (input_fd, &select_set)) 2057 2085 break; 2058 2086 #ifdef HAVE_LIBGPM 2059 if (mouse_enabled && use_mouse_p == MOUSE_GPM 2060 && gpm_fd > 0 && FD_ISSET (gpm_fd, &select_set)) 2087 if (mouse_enabled && use_mouse_p == MOUSE_GPM) 2061 2088 { 2062 Gpm_GetEvent (&ev); 2063 Gpm_FitEvent (&ev); 2064 *event = ev; 2065 return EV_MOUSE; 2089 if (gpm_fd >= 0) 2090 { 2091 if (FD_ISSET (gpm_fd, &select_set)) 2092 { 2093 int status = Gpm_GetEvent (&ev); 2094 if (status == 1) /* success */ 2095 { 2096 Gpm_FitEvent (&ev); 2097 *event = ev; 2098 return EV_MOUSE; 2099 } 2100 else if (status == 0) /* connection closed; -1 == error */ 2101 { 2102 if (mouse_fd >= 0 && FD_ISSET (mouse_fd, &select_set)) 2103 FD_CLR (mouse_fd, &select_set); 2104 2105 /* Try to reopen gpm_mouse connection */ 2106 disable_mouse (); 2107 enable_mouse (); 2108 } 2109 } 2110 } 2111 else 2112 { 2113 if (mouse_fd >= 0) /* error indicative */ 2114 { 2115 if (FD_ISSET (mouse_fd, &select_set)) 2116 FD_CLR (mouse_fd, &select_set); 2117 mouse_fd = gpm_fd; 2118 } 2119 /* gpm_fd == -2 means under some X terminal */ 2120 if (gpm_fd == -1) 2121 { 2122 mouse_enabled = FALSE; 2123 use_mouse_p = MOUSE_NONE; 2124 } 2125 break; 2126 } 2066 2127 } 2067 2128 #endif /* !HAVE_LIBGPM */ 2068 2129 } -
lib/tty/tty.c
old new 90 90 tty_check_term (gboolean force_xterm) 91 91 { 92 92 const char *termvalue; 93 const char *xdisplay; 93 94 94 95 termvalue = getenv ("TERM"); 95 96 if (termvalue == NULL || *termvalue == '\0') … … 97 98 fputs (_("The TERM environment variable is unset!\n"), stderr); 98 99 exit (EXIT_FAILURE); 99 100 } 101 102 if ((xdisplay = getenv ("DISPLAY")) != NULL && *xdisplay == '\0') 103 xdisplay = NULL; 100 104 101 105 return force_xterm || strncmp (termvalue, "xterm", 5) == 0 102 106 || strncmp (termvalue, "konsole", 7) == 0 103 107 || strncmp (termvalue, "rxvt", 4) == 0 104 || strcmp (termvalue, "Eterm") == 0 || strcmp (termvalue, "dtterm") == 0; 108 || strcmp (termvalue, "Eterm") == 0 109 || strcmp (termvalue, "dtterm") == 0 110 || (strncmp (termvalue, "screen", 6) == 0 && xdisplay != NULL); 105 111 } 106 112 107 113 /* --------------------------------------------------------------------------------------------- */ … … 294 300 { 295 301 /* FIXME: this dirty hack to set supported type of tracking the mouse */ 296 302 const char *color_term = getenv ("COLORTERM"); 303 304 /** Need more information first 305 const char *xdisplay; 306 307 if ((xdisplay = getenv ("DISPLAY")) != NULL && *xdisplay == '\0') 308 xdisplay = NULL; 309 */ 310 297 311 if (strncmp (termvalue, "rxvt", 4) == 0 || 298 312 (color_term != NULL && strncmp (color_term, "rxvt", 4) == 0) || 299 313 strcmp (termvalue, "Eterm") == 0)