qulogic/libgnt

Merged default branch
soc.2013.gobjectification.plugins
2014-04-22, Ankit Vani
992410780911
Merged default branch
  • +14 -0
    gnt.h
  • +0 -1
    gntbindable.h
  • +0 -4
    gntcolors.c
  • +3 -1
    gntinternal.h
  • +62 -5
    gntkeys.h
  • +99 -4
    gntmain.c
  • +0 -1
    gntwidget.c
  • +0 -1
    gntwidget.h
  • --- a/gnt.h Sat Apr 19 20:05:35 2014 +0530
    +++ b/gnt.h Tue Apr 22 13:18:02 2014 +0530
    @@ -30,6 +30,20 @@
    */
    #include <glib.h>
    +
    +#ifdef HAVE_CONFIG_H
    +# include <config.h>
    +#endif
    +#ifdef _WIN32
    +# undef KEY_EVENT
    +#endif
    +#ifdef NO_WIDECHAR
    +# define NCURSES_WIDECHAR 0
    +#else
    +# define NCURSES_WIDECHAR 1
    +#endif
    +#include <ncurses.h>
    +
    #include "gntwidget.h"
    #include "gntclipboard.h"
    #include "gntcolors.h"
    --- a/gntbindable.h Sat Apr 19 20:05:35 2014 +0530
    +++ b/gntbindable.h Tue Apr 22 13:18:02 2014 +0530
    @@ -32,7 +32,6 @@
    #include <stdio.h>
    #include <glib.h>
    #include <glib-object.h>
    -#include <ncurses.h>
    #define GNT_TYPE_BINDABLE (gnt_bindable_get_type())
    #define GNT_BINDABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_BINDABLE, GntBindable))
    --- a/gntcolors.c Sat Apr 19 20:05:35 2014 +0530
    +++ b/gntcolors.c Tue Apr 22 13:18:02 2014 +0530
    @@ -20,10 +20,6 @@
    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
    */
    -#include "config.h"
    -
    -#include <ncurses.h>
    -
    #include "gntinternal.h"
    #undef GNT_LOG_DOMAIN
    #define GNT_LOG_DOMAIN "Colors"
    --- a/gntinternal.h Sat Apr 19 20:05:35 2014 +0530
    +++ b/gntinternal.h Tue Apr 22 13:18:02 2014 +0530
    @@ -19,7 +19,9 @@
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
    */
    -#include <glib.h>
    +
    +#include "gnt.h"
    +
    #undef G_LOG_DOMAIN
    #define G_LOG_DOMAIN "Gnt"
    --- a/gntkeys.h Sat Apr 19 20:05:35 2014 +0530
    +++ b/gntkeys.h Tue Apr 22 13:18:02 2014 +0530
    @@ -29,7 +29,6 @@
    * @title: Keys API
    */
    -#include <curses.h>
    #include <term.h>
    /*
    @@ -44,6 +43,54 @@
    #define SAFE(x) ((cur_term && (x)) ? (x) : "")
    +/* This is needed so that g-ir-scanner does not take GNT_KEY_CTRL_* as
    + constants -- because if it does, the .gir contains the following invalid XML
    + characters, and parsing explodes */
    +#define CONST(x) x
    +
    +#ifdef _WIN32
    +
    +/* XXX: \xe1 is a hacky alias for \x00 key code */
    +
    +#define GNT_KEY_POPUP CONST("") /* not supported? */
    +
    +#define GNT_KEY_UP CONST("\xe0\x48")
    +#define GNT_KEY_DOWN CONST("\xe0\x50")
    +#define GNT_KEY_LEFT CONST("\xe0\x4B")
    +#define GNT_KEY_RIGHT CONST("\xe0\x4D")
    +
    +#define GNT_KEY_CTRL_UP CONST("\xe0\x8d")
    +#define GNT_KEY_CTRL_DOWN CONST("\xe0\x91")
    +#define GNT_KEY_CTRL_LEFT CONST("\xe0\x73")
    +#define GNT_KEY_CTRL_RIGHT CONST("\xe0\x74")
    +
    +#define GNT_KEY_PGUP CONST("\xe0\x49")
    +#define GNT_KEY_PGDOWN CONST("\xe0\x51")
    +#define GNT_KEY_HOME CONST("\xe0\x47")
    +#define GNT_KEY_END CONST("\xe0\x4f")
    +
    +#define GNT_KEY_ENTER CONST("\x0d")
    +
    +#define GNT_KEY_BACKSPACE CONST("\x08")
    +#define GNT_KEY_DEL CONST("\xe0\x53")
    +#define GNT_KEY_INS CONST("\xe0\x52")
    +#define GNT_KEY_BACK_TAB CONST("\xe1\x94")
    +
    +#define GNT_KEY_F1 CONST("\xe1\x3b")
    +#define GNT_KEY_F2 CONST("\xe1\x3c")
    +#define GNT_KEY_F3 CONST("\xe1\x3d")
    +#define GNT_KEY_F4 CONST("\xe1\x3e")
    +#define GNT_KEY_F5 CONST("\xe1\x3f")
    +#define GNT_KEY_F6 CONST("\xe1\x40")
    +#define GNT_KEY_F7 CONST("\xe1\x41")
    +#define GNT_KEY_F8 CONST("\xe1\x42")
    +#define GNT_KEY_F9 CONST("\xe1\x43")
    +#define GNT_KEY_F10 CONST("\xe1\x44")
    +#define GNT_KEY_F11 CONST("\xe0\x85")
    +#define GNT_KEY_F12 CONST("\xe0\x86")
    +
    +#else
    +
    #define GNT_KEY_POPUP SAFE(key_f16) /* Apparently */
    /* Arrow keys */
    @@ -69,10 +116,20 @@
    #define GNT_KEY_INS SAFE(key_ic)
    #define GNT_KEY_BACK_TAB ((cur_term && back_tab) ? back_tab : SAFE(key_btab))
    -/* This is needed so that g-ir-scanner does not take GNT_KEY_CTRL_* as
    - constants -- because if it does, the .gir contains the following invalid XML
    - characters, and parsing explodes */
    -#define CONST(x) x
    +#define GNT_KEY_F1 SAFE(key_f1)
    +#define GNT_KEY_F2 SAFE(key_f2)
    +#define GNT_KEY_F3 SAFE(key_f3)
    +#define GNT_KEY_F4 SAFE(key_f4)
    +#define GNT_KEY_F5 SAFE(key_f5)
    +#define GNT_KEY_F6 SAFE(key_f6)
    +#define GNT_KEY_F7 SAFE(key_f7)
    +#define GNT_KEY_F8 SAFE(key_f8)
    +#define GNT_KEY_F9 SAFE(key_f9)
    +#define GNT_KEY_F10 SAFE(key_f10)
    +#define GNT_KEY_F11 SAFE(key_f11)
    +#define GNT_KEY_F12 SAFE(key_f12)
    +
    +#endif
    #define GNT_KEY_CTRL_A CONST("\001")
    #define GNT_KEY_CTRL_B CONST("\002")
    --- a/gntmain.c Sat Apr 19 20:05:35 2014 +0530
    +++ b/gntmain.c Tue Apr 22 13:18:02 2014 +0530
    @@ -30,7 +30,9 @@
    #include <gmodule.h>
    #include <sys/types.h>
    +#ifndef _WIN32
    #include <sys/wait.h>
    +#endif
    #include "gntinternal.h"
    #undef GNT_LOG_DOMAIN
    @@ -61,6 +63,12 @@
    #include <ctype.h>
    #include <errno.h>
    +#ifdef _WIN32
    +#undef _getch
    +#undef getch
    +#include <conio.h>
    +#endif
    +
    /*
    * Notes: Interesting functions to look at:
    * scr_dump, scr_init, scr_restore: for workspaces
    @@ -98,6 +106,7 @@
    return FALSE;
    }
    +#ifndef _WIN32
    /**
    * detect_mouse_action:
    *
    @@ -214,22 +223,90 @@
    gnt_widget_clicked(widget, event, x, y);
    return TRUE;
    }
    +#endif
    static gboolean
    io_invoke_error(GIOChannel *source, GIOCondition cond, gpointer data)
    {
    + /* XXX: it throws an error after evey io_invoke, I have no idea why */
    +#ifndef _WIN32
    int id = GPOINTER_TO_INT(data);
    +
    g_source_remove(id);
    g_io_channel_unref(source);
    channel = NULL;
    setup_io();
    +#endif
    +
    return TRUE;
    }
    +
    static gboolean
    io_invoke(GIOChannel *source, GIOCondition cond, gpointer null)
    {
    +#ifdef _WIN32
    + gchar keys[8];
    + gchar *k = keys;
    + int ch;
    + gboolean is_special = FALSE;
    +
    + if (wm->mode == GNT_KP_MODE_WAIT_ON_CHILD)
    + return FALSE;
    +
    + if (HOLDING_ESCAPE) {
    + *k = '\033';
    + k++;
    + g_source_remove(escape_stuff.timer);
    + escape_stuff.timer = 0;
    + }
    +
    + ch = _getch(); /* we could use _getch_nolock */
    +
    + /* a small hack - we don't want to put NUL anywhere */
    + if (ch == 0x00)
    + ch = 0xE1;
    +
    + if (ch == 0xE0 || ch == 0xE1) {
    + is_special = TRUE;
    + *k = ch;
    + k++;
    + ch = _getch();
    + }
    + k[0] = ch;
    + k[1] = '\0';
    +
    + if (ch == 0x1B && !is_special) { /* ESC */
    + escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL);
    + return TRUE;
    + }
    +
    + if (wm)
    + gnt_wm_set_event_stack(wm, TRUE);
    +
    + if (!is_special) {
    + gchar *converted;
    + gsize converted_len = 0;
    +
    + converted = g_locale_to_utf8(k, 1, NULL, &converted_len, NULL);
    + if (converted_len > 0 && converted_len <= 4) {
    + memcpy(k, converted, converted_len);
    + k[converted_len] = '\0';
    + }
    + }
    +
    + /* TODO: we could call detect_mouse_action here, but no
    + * events are triggered (yet?) for mouse on win32.
    + */
    +
    + gnt_wm_process_input(wm, keys);
    +
    + if (wm)
    + gnt_wm_set_event_stack(wm, FALSE);
    +
    + return TRUE;
    +#else
    char keys[256];
    gssize rd;
    char *k;
    @@ -302,13 +379,25 @@
    gnt_wm_set_event_stack(wm, FALSE);
    g_free(cvrt);
    return TRUE;
    +#endif
    }
    static void
    setup_io()
    {
    int result;
    +
    +#ifdef _WIN32
    + channel = g_io_channel_win32_new_fd(STDIN_FILENO);
    +#else
    channel = g_io_channel_unix_new(STDIN_FILENO);
    +#endif
    +
    + if (channel == NULL) {
    + gnt_warning("failed creating new channel%s", "");
    + return;
    + }
    +
    g_io_channel_set_close_on_unref(channel, TRUE);
    #if 0
    @@ -325,9 +414,7 @@
    (G_IO_NVAL),
    io_invoke_error, GINT_TO_POINTER(result), NULL);
    - g_io_channel_unref(channel); /* Apparently this caused crashes for some people.
    - But irssi does this, so I am going to assume the
    - crashes were caused by some other stuff. */
    + g_io_channel_unref(channel);
    gnt_warning("setting up IO (%d)", channel_read_callback);
    }
    @@ -339,6 +426,7 @@
    return FALSE;
    }
    +#ifndef _WIN32
    /* Xerox */
    static void
    clean_pid(void)
    @@ -356,6 +444,7 @@
    perror(errmsg);
    }
    }
    +#endif
    static void
    exit_confirmed(gpointer null)
    @@ -425,10 +514,12 @@
    signal(SIGWINCH, sighandler);
    break;
    #endif
    +#ifndef _WIN32
    case SIGCHLD:
    clean_pid();
    signal(SIGCHLD, sighandler);
    break;
    +#endif
    case SIGINT:
    ask_before_exit();
    signal(SIGINT, sighandler);
    @@ -508,9 +599,11 @@
    #ifdef SIGWINCH
    org_winch_handler = signal(SIGWINCH, sighandler);
    #endif
    +#ifndef _WIN32
    signal(SIGCHLD, sighandler);
    + signal(SIGPIPE, SIG_IGN);
    +#endif
    signal(SIGINT, sighandler);
    - signal(SIGPIPE, SIG_IGN);
    #if !GLIB_CHECK_VERSION(2, 36, 0)
    /* GLib type system is automaticaly initialized since 2.36. */
    @@ -696,7 +789,9 @@
    cp->callback(status, cp->data);
    }
    g_free(cp);
    +#ifndef _WIN32
    clean_pid();
    +#endif
    wm->mode = GNT_KP_MODE_NORMAL;
    endwin();
    setup_io();
    --- a/gntwidget.c Sat Apr 19 20:05:35 2014 +0530
    +++ b/gntwidget.c Tue Apr 22 13:18:02 2014 +0530
    @@ -27,7 +27,6 @@
    #include "gntstyle.h"
    #include "gntmarshal.h"
    #include "gntutils.h"
    -#include "gnt.h"
    enum
    {
    --- a/gntwidget.h Sat Apr 19 20:05:35 2014 +0530
    +++ b/gntwidget.h Tue Apr 22 13:18:02 2014 +0530
    @@ -31,7 +31,6 @@
    #include <stdio.h>
    #include <glib.h>
    -#include <ncurses.h>
    #include "gntbindable.h"