qulogic/libgnt

Merged default branch
soc.2013.gobjectification.plugins
2014-04-25, Ankit Vani
6ffbf6b5e698
Merged default branch
  • +11 -0
    Makefile.am
  • +11 -0
    gnt.h
  • +1 -1
    gntinternal.h
  • +8 -1
    gntkeys.c
  • +27 -27
    gntkeys.h
  • +72 -16
    gntmain.c
  • +3 -3
    gntwm.c
  • +30 -0
    libgnt_winres.rc.in
  • --- a/Makefile.am Tue Apr 22 13:18:02 2014 +0530
    +++ b/Makefile.am Fri Apr 25 16:55:07 2014 +0530
    @@ -92,6 +92,17 @@
    $(INTROSPECTION_LIBS) \
    $(PY_LIBS)
    +if IS_WIN32
    +
    +.rc.o: %.rc
    + $(AM_V_GEN)$(WINDRES) -i $< -o $@
    +
    +LIBGNT_WIN32RES = libgnt_winres.o
    +libgnt_la_DEPENDENCIES += $(LIBGNT_WIN32RES)
    +libgnt_la_LDFLAGS += -Wl,$(LIBGNT_WIN32RES)
    +
    +endif
    +
    AM_CPPFLAGS = \
    $(GLIB_CFLAGS) \
    $(GNT_CFLAGS) \
    --- a/gnt.h Tue Apr 22 13:18:02 2014 +0530
    +++ b/gnt.h Fri Apr 25 16:55:07 2014 +0530
    @@ -57,6 +57,17 @@
    void gnt_init(void);
    /**
    + * gnt_set_config_dir:
    + * @config_dir: the path to a configuration directory, may be %NULL.
    + *
    + * Change directory to store gnt configuration files (default is ~).
    + *
    + * You have to call this before #gnt_init. You might want to call this
    + * with %NULL, to free the resources, but not before a call to #gnt_quit.
    + */
    +void gnt_set_config_dir(const gchar *config_dir);
    +
    +/**
    * gnt_main:
    *
    * Start running the mainloop for gnt.
    --- a/gntinternal.h Tue Apr 22 13:18:02 2014 +0530
    +++ b/gntinternal.h Fri Apr 25 16:55:07 2014 +0530
    @@ -44,4 +44,4 @@
    extern int gnt_need_conversation_to_locale;
    extern const char *C_(const char *x);
    -
    +const gchar *gnt_get_config_dir(void);
    --- a/gntkeys.c Tue Apr 22 13:18:02 2014 +0530
    +++ b/gntkeys.c Fri Apr 25 16:55:07 2014 +0530
    @@ -51,6 +51,12 @@
    term = ""; /* Just in case */
    }
    +#ifdef _WIN32
    + gnt_key_cup = GNT_KEY_CTRL_UP;
    + gnt_key_cdown = GNT_KEY_CTRL_DOWN;
    + gnt_key_cright = GNT_KEY_CTRL_RIGHT;
    + gnt_key_cleft = GNT_KEY_CTRL_LEFT;
    +#else
    if (strstr(term, "xterm") == term || strcmp(term, "rxvt") == 0) {
    gnt_key_cup = "\033" "[1;5A";
    gnt_key_cdown = "\033" "[1;5B";
    @@ -62,6 +68,7 @@
    gnt_key_cright = "\033" "Oc";
    gnt_key_cleft = "\033" "Od";
    }
    +#endif
    specials = g_hash_table_new(g_str_hash, g_str_equal);
    @@ -141,7 +148,7 @@
    }
    }
    c = 0;
    - for (a = 0; alts[a]; a++) {
    + for (a = 0; alts[a]; a++) { /* XXX: is that loop necessary? */
    /* Upper-case alphabets */
    for (ch = 0; ch < 26; ch++) {
    char str[2] = {'A' + ch, 0}, code[] = {'\033', 'A' + ch, 0};
    --- a/gntkeys.h Tue Apr 22 13:18:02 2014 +0530
    +++ b/gntkeys.h Fri Apr 25 16:55:07 2014 +0530
    @@ -54,40 +54,40 @@
    #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_UP CONST("\033\xe0\x48")
    +#define GNT_KEY_DOWN CONST("\033\xe0\x50")
    +#define GNT_KEY_LEFT CONST("\033\xe0\x4B")
    +#define GNT_KEY_RIGHT CONST("\033\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_CTRL_UP CONST("\033\xe0\x8d")
    +#define GNT_KEY_CTRL_DOWN CONST("\033\xe0\x91")
    +#define GNT_KEY_CTRL_LEFT CONST("\033\xe0\x73")
    +#define GNT_KEY_CTRL_RIGHT CONST("\033\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_PGUP CONST("\033\xe0\x49")
    +#define GNT_KEY_PGDOWN CONST("\033\xe0\x51")
    +#define GNT_KEY_HOME CONST("\033\xe0\x47")
    +#define GNT_KEY_END CONST("\033\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_DEL CONST("\033\xe0\x53")
    +#define GNT_KEY_INS CONST("\033\xe0\x52")
    +#define GNT_KEY_BACK_TAB CONST("\033\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")
    +#define GNT_KEY_F1 CONST("\033\xe1\x3b")
    +#define GNT_KEY_F2 CONST("\033\xe1\x3c")
    +#define GNT_KEY_F3 CONST("\033\xe1\x3d")
    +#define GNT_KEY_F4 CONST("\033\xe1\x3e")
    +#define GNT_KEY_F5 CONST("\033\xe1\x3f")
    +#define GNT_KEY_F6 CONST("\033\xe1\x40")
    +#define GNT_KEY_F7 CONST("\033\xe1\x41")
    +#define GNT_KEY_F8 CONST("\033\xe1\x42")
    +#define GNT_KEY_F9 CONST("\033\xe1\x43")
    +#define GNT_KEY_F10 CONST("\033\xe1\x44")
    +#define GNT_KEY_F11 CONST("\033\xe0\x85")
    +#define GNT_KEY_F12 CONST("\033\xe0\x86")
    #else
    --- a/gntmain.c Tue Apr 22 13:18:02 2014 +0530
    +++ b/gntmain.c Fri Apr 25 16:55:07 2014 +0530
    @@ -66,6 +66,7 @@
    #ifdef _WIN32
    #undef _getch
    #undef getch
    +#include <windows.h>
    #include <conio.h>
    #endif
    @@ -92,6 +93,8 @@
    int gnt_need_conversation_to_locale;
    +static gchar *custom_config_dir = NULL;
    +
    #define HOLDING_ESCAPE (escape_stuff.timer != 0)
    static struct {
    @@ -106,6 +109,25 @@
    return FALSE;
    }
    +void
    +gnt_set_config_dir(const gchar *config_dir)
    +{
    + if (channel) {
    + gnt_warning("gnt_set_config_dir failed: %s",
    + "gnt already initialized");
    + }
    + free(custom_config_dir);
    + custom_config_dir = g_strdup(config_dir);
    +}
    +
    +const gchar *
    +gnt_get_config_dir(void)
    +{
    + if (custom_config_dir)
    + return custom_config_dir;
    + return g_get_home_dir();
    +}
    +
    #ifndef _WIN32
    /**
    * detect_mouse_action:
    @@ -247,22 +269,38 @@
    io_invoke(GIOChannel *source, GIOCondition cond, gpointer null)
    {
    #ifdef _WIN32
    + /* We need:
    + * - 1 for escape prefix
    + * - 6 for gunichar-to-gchar conversion (see g_unichar_to_utf8)
    + * - 1 for the terminating NUL
    + * or:
    + * - 1 for escape prefix
    + * - 1 for special key prefix
    + * - 1 for the key
    + * - 1 for the terminating NUL
    + */
    gchar keys[8];
    gchar *k = keys;
    int ch;
    gboolean is_special = FALSE;
    + gboolean is_escape = FALSE;
    if (wm->mode == GNT_KP_MODE_WAIT_ON_CHILD)
    return FALSE;
    if (HOLDING_ESCAPE) {
    - *k = '\033';
    - k++;
    + is_escape = TRUE;
    g_source_remove(escape_stuff.timer);
    escape_stuff.timer = 0;
    + } else if (GetAsyncKeyState(VK_LMENU)) { /* left-ALT key */
    + is_escape = TRUE;
    + }
    + if (is_escape) {
    + *k = '\033';
    + k++;
    }
    - ch = _getch(); /* we could use _getch_nolock */
    + ch = _getwch(); /* we could use _getwch_nolock */
    /* a small hack - we don't want to put NUL anywhere */
    if (ch == 0x00)
    @@ -270,14 +308,16 @@
    if (ch == 0xE0 || ch == 0xE1) {
    is_special = TRUE;
    + if (!is_escape) {
    + *k = '\033';
    + k++;
    + }
    *k = ch;
    k++;
    - ch = _getch();
    + ch = _getwch();
    }
    - k[0] = ch;
    - k[1] = '\0';
    - if (ch == 0x1B && !is_special) { /* ESC */
    + if (ch == 0x1B && !is_special) { /* ESC key */
    escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL);
    return TRUE;
    }
    @@ -285,16 +325,26 @@
    if (wm)
    gnt_wm_set_event_stack(wm, TRUE);
    - if (!is_special) {
    - gchar *converted;
    - gsize converted_len = 0;
    + if (is_special) {
    + if (ch > 0xFF) {
    + gnt_warning("a special key out of gchar range (%d)", ch);
    + return TRUE;
    + }
    + *k = ch;
    + k++;
    + } else {
    + gint result_len;
    - 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';
    - }
    + result_len = g_unichar_to_utf8(ch, k);
    + k += result_len;
    }
    + *k = '\0';
    +
    +#if 0
    + gnt_warning("a key: [%s] %#x %#x %#x %#x %#x %#x", keys,
    + (guchar)keys[0], (guchar)keys[1], (guchar)keys[2],
    + (guchar)keys[3], (guchar)keys[4], (guchar)keys[5]);
    +#endif
    /* TODO: we could call detect_mouse_action here, but no
    * events are triggered (yet?) for mouse on win32.
    @@ -554,6 +604,12 @@
    if (channel)
    return;
    +#ifdef _WIN32
    + /* UTF-8 for input */
    + /* TODO: check it with NO_WIDECHAR. */
    + SetConsoleCP(65001);
    +#endif
    +
    locale = setlocale(LC_ALL, "");
    setup_io();
    @@ -578,7 +634,7 @@
    gnt_init_keys();
    gnt_init_styles();
    - filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL);
    + filename = g_build_filename(gnt_get_config_dir(), ".gntrc", NULL);
    gnt_style_read_configure_file(filename);
    g_free(filename);
    --- a/gntwm.c Tue Apr 22 13:18:02 2014 +0530
    +++ b/gntwm.c Fri Apr 25 16:55:07 2014 +0530
    @@ -331,7 +331,7 @@
    read_window_positions(GntWM *wm)
    {
    GKeyFile *gfile = g_key_file_new();
    - char *filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL);
    + char *filename = g_build_filename(gnt_get_config_dir(), ".gntpositions", NULL);
    GError *error = NULL;
    char **keys;
    gsize nk;
    @@ -427,7 +427,7 @@
    w = wm->cws->ordered->data;
    orgpos = pos = g_list_index(wm->cws->list, w);
    - g_return_if_fail(pos < 0);
    + g_return_if_fail(pos >= 0);
    do {
    pos += direction;
    @@ -2120,7 +2120,7 @@
    FILE *file;
    char *filename;
    - filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL);
    + filename = g_build_filename(gnt_get_config_dir(), ".gntpositions", NULL);
    file = fopen(filename, "wb");
    if (file == NULL) {
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/libgnt_winres.rc.in Fri Apr 25 16:55:07 2014 +0530
    @@ -0,0 +1,30 @@
    +#include <winver.h>
    +
    +VS_VERSION_INFO VERSIONINFO
    + FILEVERSION @GNT_MAJOR_VERSION@,@GNT_MINOR_VERSION@,@GNT_MICRO_VERSION@,0
    + PRODUCTVERSION @GNT_MAJOR_VERSION@,@GNT_MINOR_VERSION@,@GNT_MICRO_VERSION@,0
    + FILEFLAGSMASK 0
    + FILEFLAGS 0
    + FILEOS VOS__WINDOWS32
    + FILETYPE VFT_APP
    + FILESUBTYPE VFT2_UNKNOWN
    + BEGIN
    + BLOCK "StringFileInfo"
    + BEGIN
    + BLOCK "040904B0"
    + BEGIN
    + VALUE "CompanyName", "The Pidgin developer community"
    + VALUE "FileDescription", "Glib ncurses toolkit"
    + VALUE "FileVersion", "@GNT_VERSION@"
    + VALUE "InternalName", "libgnt"
    + VALUE "LegalCopyright", "Copyright (C) 1998-2014 The Pidgin developer community (See the COPYRIGHT file in the source distribution)."
    + VALUE "OriginalFilename", "libgnt-@GNT_API_VERSION@.dll"
    + VALUE "ProductName", "libgnt"
    + VALUE "ProductVersion", "@GNT_VERSION@"
    + END
    + END
    + BLOCK "VarFileInfo"
    + BEGIN
    + VALUE "Translation", 0x409, 1200
    + END
    + END