Ticket #3011: mc-gpm-x-term-fixes.patch

File mc-gpm-x-term-fixes.patch, 8.5 KB (added by acobar, 11 years ago)

mc gpm x terminal improvments

  • lib/tty/mouse.h

    old new  
    9797/* Type of the currently used mouse */ 
    9898extern Mouse_Type use_mouse_p; 
    9999 
     100/* To be used when gpm_fd were initially >= 0 */ 
     101extern int mouse_fd; 
     102 
    100103/* String indicating that a mouse event has occurred, usually "\E[M" */ 
    101104extern const char *xmouse_seq; 
    102105 
  • lib/tty/mouse.c

    old new  
    4747 
    4848Mouse_Type use_mouse_p = MOUSE_NONE; 
    4949gboolean mouse_enabled = FALSE; 
     50int mouse_fd = -1; /* for when gpm_fd changes to < 0 and the old one must be cleared from select_set */ 
    5051const char *xmouse_seq; 
    5152const char *xmouse_extended_seq; 
    5253 
     
    114115#ifdef HAVE_LIBGPM 
    115116    case MOUSE_GPM: 
    116117        { 
    117             int mouse_d; 
    118118            Gpm_Connect conn; 
    119119 
    120120            conn.eventMask = ~GPM_MOVE; 
     
    122122            conn.minMod = 0; 
    123123            conn.maxMod = 0; 
    124124 
    125             mouse_d = Gpm_Open (&conn, 0); 
    126             if (mouse_d == -1) 
     125            mouse_fd = Gpm_Open (&conn, 0); 
     126            if (mouse_fd == -1) 
    127127            { 
    128128                use_mouse_p = MOUSE_NONE; 
    129129                return; 
  • lib/tty/key.c

    old new  
    13421342        || (term != NULL 
    13431343            && (strncmp (term, "iris-ansi", 9) == 0 
    13441344                || strncmp (term, "xterm", 5) == 0 
    1345                 || strncmp (term, "rxvt", 4) == 0 || strcmp (term, "screen") == 0))) 
     1345                || strncmp (term, "rxvt", 4) == 0 || strncmp (term, "screen", 6) == 0))) 
    13461346        define_sequences (xterm_key_defines); 
    13471347 
    13481348    /* load some additional keys (e.g. direct Alt-? support) */ 
     
    17241724gboolean 
    17251725is_idle (void) 
    17261726{ 
    1727     int maxfdp; 
     1727    int nfd = max (0, input_fd) + 1; 
    17281728    fd_set select_set; 
    17291729    struct timeval time_out; 
    17301730 
    17311731    FD_ZERO (&select_set); 
    17321732    FD_SET (input_fd, &select_set); 
    1733     maxfdp = input_fd; 
     1733    time_out.tv_sec = 0; 
     1734    time_out.tv_usec = 0; 
    17341735#ifdef HAVE_LIBGPM 
    1735     if (mouse_enabled && (use_mouse_p == MOUSE_GPM) && (gpm_fd > 0)) 
     1736    if (mouse_enabled && use_mouse_p == MOUSE_GPM) 
    17361737    { 
    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        } 
    17391758    } 
    17401759#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); 
    17441761} 
    17451762 
    17461763/* --------------------------------------------------------------------------------------------- */ 
     
    19741991    /* Repeat if using mouse */ 
    19751992    while (pending_keys == NULL) 
    19761993    { 
    1977         int maxfdp; 
     1994        int nfd; 
    19781995        fd_set select_set; 
    19791996 
    19801997        FD_ZERO (&select_set); 
    19811998        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; 
    19832000 
    19842001#ifdef HAVE_LIBGPM 
    19852002        if (mouse_enabled && (use_mouse_p == MOUSE_GPM)) 
    19862003        { 
    1987             if (gpm_fd < 0) 
     2004            if (gpm_fd >= 0) 
    19882005            { 
    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                } 
    19922023                break; 
    19932024            } 
    1994  
    1995             FD_SET (gpm_fd, &select_set); 
    1996             maxfdp = max (maxfdp, gpm_fd); 
    19972025        } 
    19982026#endif 
    19992027 
     
    20322060        } 
    20332061 
    20342062        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); 
    20362064        tty_disable_interrupt_key (); 
    20372065 
    20382066        /* select timed out: it could be for any of the following reasons: 
     
    20562084        if (FD_ISSET (input_fd, &select_set)) 
    20572085            break; 
    20582086#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) 
    20612088        { 
    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            } 
    20662127        } 
    20672128#endif /* !HAVE_LIBGPM */ 
    20682129    } 
  • lib/tty/tty.c

    old new  
    9090tty_check_term (gboolean force_xterm) 
    9191{ 
    9292    const char *termvalue; 
     93    const char *xdisplay; 
    9394 
    9495    termvalue = getenv ("TERM"); 
    9596    if (termvalue == NULL || *termvalue == '\0') 
     
    9798        fputs (_("The TERM environment variable is unset!\n"), stderr); 
    9899        exit (EXIT_FAILURE); 
    99100    } 
     101     
     102    if ((xdisplay = getenv ("DISPLAY")) != NULL && *xdisplay == '\0') 
     103        xdisplay = NULL; 
    100104 
    101105    return force_xterm || strncmp (termvalue, "xterm", 5) == 0 
    102106        || strncmp (termvalue, "konsole", 7) == 0 
    103107        || 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); 
    105111} 
    106112 
    107113/* --------------------------------------------------------------------------------------------- */ 
     
    294300            { 
    295301                /* FIXME: this dirty hack to set supported type of tracking the mouse */ 
    296302                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 
    297311                if (strncmp (termvalue, "rxvt", 4) == 0 || 
    298312                    (color_term != NULL && strncmp (color_term, "rxvt", 4) == 0) || 
    299313                    strcmp (termvalue, "Eterm") == 0)